awindowgui / mwindowedit / label rework
[goodguy/history.git] / cinelerra-5.1 / cinelerra / assetedit.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2010 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "asset.h"
23 #include "assetedit.h"
24 #include "awindow.h"
25 #include "awindowgui.h"
26 #include "bcprogressbox.h"
27 #include "bcsignals.h"
28 #include "bitspopup.h"
29 #include "cache.h"
30 #include "clip.h"
31 #include "cplayback.h"
32 #include "cwindow.h"
33 #include "edl.h"
34 #include "edlsession.h"
35 #include "file.h"
36 #include "filempeg.h"
37 #include "fileffmpeg.h"
38 #include "filesystem.h"
39 #include "indexable.h"
40 #include "indexfile.h"
41 #include "indexstate.h"
42 #include "language.h"
43 #include "mainindexes.h"
44 #include "mwindow.h"
45 #include "mwindowgui.h"
46 #include "theme.h"
47 #include "new.h"
48 #include "preferences.h"
49 #include "resizetrackthread.h"
50 #include "removefile.h"
51 #include "theme.h"
52 #include "transportque.h"
53 #include "interlacemodes.h"
54 #include "edl.h"
55 #include "edlsession.h"
56
57 #include <string.h>
58
59
60
61 AssetEdit::AssetEdit(MWindow *mwindow)
62  : BC_DialogThread()
63 {
64         this->mwindow = mwindow;
65         indexable = 0;
66         window = 0;
67         changed_params = new Asset;
68         //set_synchronous(0);
69 }
70
71
72 AssetEdit::~AssetEdit()
73 {
74         close_window();
75         changed_params->remove_user();
76 }
77
78
79 void AssetEdit::edit_asset(Indexable *indexable)
80 {
81         close_window();
82         this->indexable = indexable;
83         this->indexable->add_user();
84
85 // Copy asset parameters into temporary storage for editing.
86         if(indexable->is_asset)
87         {
88                 changed_params->copy_from((Asset*)indexable, 0);
89         }
90         else
91         {
92                 EDL *nested_edl = (EDL*)indexable;
93
94                 strcpy(changed_params->path, nested_edl->path);
95                 changed_params->sample_rate = nested_edl->session->sample_rate;
96                 changed_params->channels = nested_edl->session->audio_channels;
97
98 //printf("AssetEdit::edit_asset %d %f\n", __LINE__, nested_edl->session->frame_rate);
99                 changed_params->frame_rate = nested_edl->session->frame_rate;
100                 changed_params->width = nested_edl->session->output_w;
101                 changed_params->height = nested_edl->session->output_h;
102         }
103
104         BC_DialogThread::start();
105 }
106
107 void AssetEdit::handle_done_event(int result)
108 {
109 }
110
111 void AssetEdit::handle_close_event(int result)
112 {
113         if(!result) {
114                 int changed = 0;
115                 Asset *asset = 0;
116                 EDL *nested_edl = 0;
117
118                 if(indexable->is_asset) {
119                         asset = (Asset*)indexable;
120                         if( !changed_params->equivalent(*asset, 1, 1, mwindow->edl) )
121                                 changed = 1;
122                 }
123                 else {
124                         nested_edl = (EDL*)indexable;
125                         if( strcmp(changed_params->path, nested_edl->path)
126 //                           || changed_params->sample_rate != nested_edl->session->sample_rate
127 //                           || !EQUIV(changed_params->frame_rate, nested_edl->session->frame_rate
128                         )
129                                 changed = 1;
130                 }
131                 if(changed) {
132                         mwindow->gui->lock_window();
133 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
134
135 // Omit index status from copy since an index rebuild may have been
136 // happening when new_asset was created but not be happening anymore.
137                         if(asset) {
138                                 mwindow->remove_asset_from_caches(asset);
139 //printf("AssetEdit::handle_close_event %d %f\n", __LINE__, asset->get_frame_rate());
140                                 asset->copy_from(changed_params, 0);
141 //printf("AssetEdit::handle_close_event %d %d %d\n", __LINE__, changed_params->bits, asset->bits);
142                         }
143                         else {
144                                 strcpy(nested_edl->path, changed_params->path);
145 // Other parameters can't be changed because they're defined in the other EDL
146 //                nested_edl->session->frame_rate = changed_params->frame_rate;
147 //                nested_edl->session->sample_rate = changed_params->sample_rate;
148                         }
149 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
150
151                         mwindow->gui->update(0, 2, 0, 0, 0, 0, 0);
152 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
153
154 // Start index rebuilding
155                         if( (asset && asset->audio_data) || nested_edl) {
156                                 char source_filename[BCTEXTLEN];
157                                 char index_filename[BCTEXTLEN];
158                                 IndexFile::get_index_filename(source_filename,
159                                         mwindow->preferences->index_directory,
160                                         index_filename,
161                                         indexable->path);
162                                 remove_file(index_filename);
163                                 indexable->index_state->index_status = INDEX_NOTTESTED;
164                                 mwindow->mainindexes->add_next_asset(0, indexable);
165                                 mwindow->mainindexes->start_build();
166                         }
167                         mwindow->gui->unlock_window();
168 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
169                         mwindow->awindow->gui->update_picon(indexable);
170                         mwindow->awindow->gui->async_update_assets();
171
172                         mwindow->restart_brender();
173                         mwindow->sync_parameters(CHANGE_ALL);
174 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
175                 }
176         }
177
178         this->indexable->remove_user();
179         this->indexable = 0;
180 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
181 }
182
183 BC_Window* AssetEdit::new_gui()
184 {
185         window = new AssetEditWindow(mwindow, this);
186         window->create_objects();
187         return window;
188 }
189
190 int AssetEdit::window_height()
191 {
192         int h = 128 + 64;
193         if( indexable->have_audio() )
194                 h += 180;
195         if( indexable->have_video() ) {
196                 h += 200;
197                 if( indexable->is_asset ) {
198                         Asset *asset = (Asset *)indexable;
199                         if( asset->format == FILE_MPEG ||
200                             asset->format == FILE_FFMPEG ) {
201                                 h += 40;
202                         }
203                 }
204         }
205         return h;
206 }
207
208 AssetEditWindow::AssetEditWindow(MWindow *mwindow, AssetEdit *asset_edit)
209  : BC_Window(_(PROGRAM_NAME ": Asset Info"),
210         mwindow->gui->get_abs_cursor_x(1) - 400 / 2,
211         mwindow->gui->get_abs_cursor_y(1) - asset_edit->window_height() / 2,
212         450, asset_edit->window_height(), 0, 0, 1)
213 {
214         this->mwindow = mwindow;
215         this->asset_edit = asset_edit;
216         bitspopup = 0;
217         path_text = 0;
218         path_button = 0;
219         hilo = 0;
220         lohi = 0;
221         allow_edits = 0;
222         detail_thread = 0;
223         win_width = 0;
224         win_height = 0;
225 }
226
227
228
229
230
231 AssetEditWindow::~AssetEditWindow()
232 {
233         lock_window("AssetEditWindow::~AssetEditWindow");
234         if(bitspopup) delete bitspopup;
235         if(detail_thread) delete detail_thread;
236         unlock_window();
237 }
238
239
240
241
242 void AssetEditWindow::create_objects()
243 {
244         int y = 10, x = 10, x1 = 10, x2 = 190;
245         char string[BCTEXTLEN];
246         int vmargin;
247         FileSystem fs;
248         BC_Title *title;
249         BC_TextBox  *textboxw;
250         BC_ListBox  *listboxw;
251         Interlaceautofix *ilacefixoption_chkboxw;
252         Asset *asset = 0;
253         EDL *nested_edl = 0;
254
255         if(asset_edit->indexable->is_asset)
256                 asset = (Asset*)asset_edit->indexable;
257         else
258                 nested_edl = (EDL*)asset_edit->indexable;
259
260         if(asset && asset->format == FILE_PCM)
261                 allow_edits = 1;
262         else
263                 allow_edits = 0;
264
265         lock_window("AssetEditWindow::create_objects");
266         if(allow_edits)
267                 vmargin = 30;
268         else
269                 vmargin = 20;
270
271         add_subwindow(path_text = new AssetEditPathText(this, y));
272         add_subwindow(path_button = new AssetEditPath(mwindow,
273                 this,
274                 path_text,
275                 y,
276                 asset_edit->indexable->path,
277                 _(PROGRAM_NAME ": Asset path"), _("Select a file for this asset:")));
278         y += 30;
279
280         if(asset)
281         {
282                 add_subwindow(new BC_Title(x, y, _("File format:")));
283                 x = x2;
284                 add_subwindow(new BC_Title(x, y, File::formattostr(mwindow->plugindb,
285                                 asset->format),
286                         MEDIUMFONT,
287                         mwindow->theme->assetedit_color));
288                 x = x1;
289                 y += 20;
290
291                 int64_t bytes = fs.get_size(asset->path);
292                 add_subwindow(new BC_Title(x, y, _("Bytes:")));
293                 sprintf(string, "%jd", bytes);
294                 Units::punctuate(string);
295
296
297                 add_subwindow(new BC_Title(x2, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
298                 if(asset->format == FILE_MPEG || asset->format == FILE_FFMPEG)
299                 {
300                         detail_thread = new DetailAssetThread(mwindow);
301                         BC_GenericButton *detail = new DetailAssetButton(this, x2+120, y);
302                         add_subwindow(detail);
303                 }
304
305                 y += 20;
306                 x = x1;
307
308                 double length = 0.;
309                 y += 20;
310                 x = x1;
311
312                 if(asset->audio_length > 0)
313                         length = (double)asset->audio_length / asset->sample_rate;
314                 if(asset->video_length > 0)
315                         length = MAX(length, (double)asset->video_length / asset->frame_rate);
316                 int64_t bitrate;
317                 if(!EQUIV(length, 0))
318                         bitrate = (int64_t)(bytes * 8 / length);
319                 else
320                         bitrate = bytes;
321                 add_subwindow(new BC_Title(x, y, _("Bitrate (bits/sec):")));
322                 sprintf(string, "%jd", bitrate);
323
324                 Units::punctuate(string);
325                 add_subwindow(new BC_Title(x2, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
326
327                 y += 30;
328                 x = x1;
329         }
330
331         if((asset && asset->audio_data) || nested_edl)
332         {
333                 add_subwindow(new BC_Bar(x, y, get_w() - x * 2));
334                 y += 5;
335
336                 add_subwindow(new BC_Title(x, y, _("Audio:"), LARGEFONT, RED));
337
338                 y += 30;
339
340                 if(asset)
341                 {
342                         if(asset->get_compression_text(1, 0))
343                         {
344                                 add_subwindow(new BC_Title(x, y, _("Compression:")));
345                                 x = x2;
346                                 add_subwindow(new BC_Title(x,
347                                         y,
348                                         asset->get_compression_text(1, 0),
349                                         MEDIUMFONT,
350                                         mwindow->theme->assetedit_color));
351                                 y += vmargin;
352                                 x = x1;
353                         }
354                 }
355
356                 add_subwindow(new BC_Title(x, y, _("Channels:")));
357                 sprintf(string, "%d", asset_edit->changed_params->channels);
358
359                 x = x2;
360                 if(allow_edits)
361                 {
362                         BC_TumbleTextBox *textbox = new AssetEditChannels(this,
363                                 string,
364                                 x,
365                                 y);
366                         textbox->create_objects();
367                         y += vmargin;
368                 }
369                 else
370                 {
371                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
372                         y += 20;
373                 }
374
375                 x = x1;
376                 add_subwindow(new BC_Title(x, y, _("Sample rate:")));
377                 sprintf(string, "%d", asset_edit->changed_params->sample_rate);
378
379                 x = x2;
380                 if(asset)
381                 {
382                         BC_TextBox *textbox;
383                         add_subwindow(textbox = new AssetEditRate(this, string, x, y));
384                         x += textbox->get_w();
385                         add_subwindow(new SampleRatePulldown(mwindow, textbox, x, y));
386                 }
387                 else
388                 {
389                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
390                 }
391
392                 y += 30;
393                 x = x1;
394
395                 if(asset)
396                 {
397                         add_subwindow(new BC_Title(x, y, _("Bits:")));
398                         x = x2;
399                         if(allow_edits)
400                         {
401                                 bitspopup = new BitsPopup(this,
402                                         x,
403                                         y,
404                                         &asset_edit->changed_params->bits,
405                                         1,
406                                         1,
407                                         1,
408                                         0,
409                                         1);
410                                 bitspopup->create_objects();
411                         }
412                         else
413                                 add_subwindow(new BC_Title(x, y, File::bitstostr(asset->bits), MEDIUMFONT, mwindow->theme->assetedit_color));
414
415
416                         x = x1;
417                         y += vmargin;
418                         add_subwindow(new BC_Title(x, y, _("Header length:")));
419                         sprintf(string, "%d", asset->header);
420
421                         x = x2;
422                         if(allow_edits)
423                                 add_subwindow(new AssetEditHeader(this, string, x, y));
424                         else
425                                 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
426
427                         y += vmargin;
428                         x = x1;
429
430                         add_subwindow(new BC_Title(x, y, _("Byte order:")));
431
432                         if(allow_edits)
433                         {
434                                 x = x2;
435
436                                 add_subwindow(lohi = new AssetEditByteOrderLOHI(this,
437                                         asset->byte_order,
438                                         x,
439                                         y));
440                                 x += 70;
441                                 add_subwindow(hilo = new AssetEditByteOrderHILO(this,
442                                         !asset->byte_order,
443                                         x,
444                                         y));
445                                 y += vmargin;
446                         }
447                         else
448                         {
449                                 x = x2;
450                                 if(asset->byte_order)
451                                         add_subwindow(new BC_Title(x, y, _("Lo-Hi"), MEDIUMFONT, mwindow->theme->assetedit_color));
452                                 else
453                                         add_subwindow(new BC_Title(x, y, _("Hi-Lo"), MEDIUMFONT, mwindow->theme->assetedit_color));
454                                 y += vmargin;
455                         }
456
457
458                         x = x1;
459                         if(allow_edits)
460                         {
461         //                      add_subwindow(new BC_Title(x, y, _("Values are signed:")));
462                                 add_subwindow(new AssetEditSigned(this, asset->signed_, x, y));
463                         }
464                         else
465                         {
466                                 if(!asset->signed_ && asset->bits == 8)
467                                         add_subwindow(new BC_Title(x, y, _("Values are unsigned")));
468                                 else
469                                         add_subwindow(new BC_Title(x, y, _("Values are signed")));
470                         }
471
472                         y += 30;
473                 }
474         }
475
476         x = x1;
477         if((asset && asset->video_data) || nested_edl)
478         {
479                 add_subwindow(new BC_Bar(x, y, get_w() - x * 2));
480                 y += 5;
481
482                 add_subwindow(new BC_Title(x, y, _("Video:"), LARGEFONT, RED));
483                 y += 30;
484                 x = x1;
485
486
487                 if(asset && asset->get_compression_text(0,1))
488                 {
489                         add_subwindow(new BC_Title(x, y, _("Compression:")));
490                         x = x2;
491                         add_subwindow(new BC_Title(x,
492                                 y,
493                                 asset->get_compression_text(0,1),
494                                 MEDIUMFONT,
495                                 mwindow->theme->assetedit_color));
496                         y += vmargin;
497                         x = x1;
498                 }
499
500                 add_subwindow(new BC_Title(x, y, _("Frame rate:")));
501                 x = x2;
502                 sprintf(string, "%.4f", asset_edit->changed_params->frame_rate);
503
504 //printf("AssetEditWindow::create_objects %d %f\n", __LINE__, asset_edit->changed_params->frame_rate);
505                 if(asset)
506                 {
507                         BC_TextBox *framerate;
508                         add_subwindow(framerate = new AssetEditFRate(this, string, x, y));
509                         x += 105;
510                         add_subwindow(new FrameRatePulldown(mwindow, framerate, x, y));
511                 }
512                 else
513                 {
514                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
515                 }
516
517                 y += 30;
518                 x = x1;
519                 add_subwindow(new BC_Title(x, y, _("Width:")));
520                 x = x2;
521                 sprintf(string, "%d", asset_edit->changed_params->width);
522                 win_width = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
523                 add_subwindow(win_width);
524
525                 y += vmargin;
526                 x = x1;
527                 add_subwindow(new BC_Title(x, y, _("Height:")));
528                 x = x2;
529                 sprintf(string, "%d", asset_edit->changed_params->height);
530                 win_height = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
531                 add_subwindow(win_height);
532                 y += win_height->get_h() + 5;
533
534                 if(asset && (asset->format == FILE_MPEG || asset->format == FILE_FFMPEG ) )
535                 {
536                         y += 5;
537                         x = x1;
538                         add_subwindow(new BC_Title(x, y, _("Actual width:")));
539                         x = x2;
540                         sprintf(string, "%d", asset->actual_width);
541                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
542
543                         BC_GenericButton *resize = new ResizeAssetButton(this, x+64, y);
544                         add_subwindow(resize);
545
546                         y += vmargin;
547                         x = x1;
548                         add_subwindow(new BC_Title(x, y, _("Actual height:")));
549                         x = x2;
550                         sprintf(string, "%d", asset->actual_height);
551                         title = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
552                         add_subwindow(title);
553                         y += title->get_h() + 5;
554                 }
555
556                 // --------------------
557                 add_subwindow(title = new BC_Title(x1, y, _("Fix interlacing:")));
558                 add_subwindow(ilacefixoption_chkboxw = new Interlaceautofix(mwindow,this, x2, y));
559                 y += ilacefixoption_chkboxw->get_h() + 5;
560                 // --------------------
561                 add_subwindow(title = new BC_Title(x1, y, _("Asset's interlacing:")));
562                 add_subwindow(textboxw = new AssetEditILacemode(this, "", ILACE_ASSET_MODEDEFAULT, x2, y, 200));
563                 ilacefixoption_chkboxw->ilacemode_textbox = textboxw;
564                 add_subwindow(listboxw = new AssetEditInterlacemodePulldown(mwindow,
565                                                         textboxw,
566                                                         &asset_edit->changed_params->interlace_mode,
567                                                         (ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_asset_modes,
568                                                         ilacefixoption_chkboxw,
569                                                         x2 + textboxw->get_w(),
570                                                         y));
571                 ilacefixoption_chkboxw->ilacemode_listbox = listboxw;
572                 y += textboxw->get_h() + 5;
573
574                 // --------------------
575                 add_subwindow(title = new BC_Title(x1, y, _("Interlace correction:")));
576                 add_subwindow(textboxw = new AssetEditILacefixmethod(this, "", ILACE_FIXDEFAULT, x2, y, 200));
577                 ilacefixoption_chkboxw->ilacefixmethod_textbox = textboxw;
578                 add_subwindow(listboxw = new InterlacefixmethodPulldown(mwindow,
579                                                         textboxw,
580                                                         &asset_edit->changed_params->interlace_fixmethod,
581                                                         (ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_asset_fixmethods,
582                                                         x2 + textboxw->get_w(),
583                                                         y));
584                 ilacefixoption_chkboxw->ilacefixmethod_listbox = listboxw;
585                 ilacefixoption_chkboxw->showhideotherwidgets();
586                 y += textboxw->get_h() + 5;
587         }
588
589         add_subwindow(new BC_OKButton(this));
590         add_subwindow(new BC_CancelButton(this));
591         show_window();
592         unlock_window();
593 }
594
595 void AssetEditWindow::show_info_detail()
596 {
597         detail_thread->start((Asset*)asset_edit->indexable);
598 }
599
600
601 AssetEditChannels::AssetEditChannels(AssetEditWindow *fwindow,
602         char *text,
603         int x,
604         int y)
605  : BC_TumbleTextBox(fwindow,
606                 (int)atol(text),
607                 (int)1,
608                 (int)MAXCHANNELS,
609                 x,
610                 y,
611                 50)
612 {
613         this->fwindow = fwindow;
614 }
615
616 int AssetEditChannels::handle_event()
617 {
618         Asset *asset = fwindow->asset_edit->changed_params;
619         asset->channels = atol(get_text());
620         return 1;
621 }
622
623 AssetEditRate::AssetEditRate(AssetEditWindow *fwindow, char *text, int x, int y)
624  : BC_TextBox(x, y, 100, 1, text)
625 {
626         this->fwindow = fwindow;
627 }
628
629 int AssetEditRate::handle_event()
630 {
631         Asset *asset = fwindow->asset_edit->changed_params;
632         asset->sample_rate = atol(get_text());
633         return 1;
634 }
635
636 AssetEditFRate::AssetEditFRate(AssetEditWindow *fwindow, char *text, int x, int y)
637  : BC_TextBox(x, y, 100, 1, text)
638 {
639         this->fwindow = fwindow;
640 }
641
642 int AssetEditFRate::handle_event()
643 {
644         Asset *asset = fwindow->asset_edit->changed_params;
645         asset->frame_rate = atof(get_text());
646         return 1;
647 }
648
649 Interlaceautofix::Interlaceautofix(MWindow *mwindow,AssetEditWindow *fwindow, int x, int y)
650  : BC_CheckBox(x, y,
651         fwindow->asset_edit->changed_params->interlace_autofixoption,
652         _("Automatically Fix Interlacing"))
653 {
654         this->fwindow = fwindow;
655         this->mwindow = mwindow;
656 }
657
658 Interlaceautofix::~Interlaceautofix()
659 {
660 }
661
662 int Interlaceautofix::handle_event()
663 {
664         Asset *asset = fwindow->asset_edit->changed_params;
665         asset->interlace_autofixoption = get_value();
666         showhideotherwidgets();
667         return 1;
668 }
669
670 void Interlaceautofix::showhideotherwidgets()
671 {
672   int thevalue = get_value();
673
674         Asset *asset = fwindow->asset_edit->changed_params;
675         if (thevalue == ILACE_AUTOFIXOPTION_AUTO)
676           {
677             this->ilacemode_textbox->enable();
678             this->ilacemode_listbox->enable();
679             this->ilacefixmethod_textbox->disable();
680             this->ilacefixmethod_listbox->disable();
681             int xx = ilaceautofixmethod(mwindow->edl->session->interlace_mode,asset->interlace_mode);
682             ilacefixmethod_to_text(string,xx);
683             this->ilacefixmethod_textbox->update(string);
684           }
685         if (thevalue == ILACE_AUTOFIXOPTION_MANUAL)
686           {
687             this->ilacemode_textbox->disable();
688             this->ilacemode_listbox->disable();
689             this->ilacefixmethod_textbox->enable();
690             this->ilacefixmethod_listbox->enable();
691             ilacefixmethod_to_text(string,asset->interlace_fixmethod);
692             this->ilacefixmethod_textbox->update(string);
693           }
694 }
695
696 InterlacefixmethodItem::InterlacefixmethodItem(const char *text, int value)
697  : BC_ListBoxItem(text)
698 {
699         this->value = value;
700 }
701
702 InterlacefixmethodPulldown::InterlacefixmethodPulldown(MWindow *mwindow,
703                 BC_TextBox *output_text, int *output_value,
704                 ArrayList<BC_ListBoxItem*> *data, int x, int y)
705  : BC_ListBox(x, y, 200, 150, LISTBOX_TEXT, data, 0, 0, 1, 0, 1)
706 {
707         this->mwindow = mwindow;
708         this->output_text = output_text;
709         this->output_value = output_value;
710         output_text->update(interlacefixmethod_to_text());
711 }
712
713 int InterlacefixmethodPulldown::handle_event()
714 {
715         output_text->update(get_selection(0, 0)->get_text());
716         *output_value = ((InterlacefixmethodItem*)get_selection(0, 0))->value;
717         return 1;
718 }
719
720 const char* InterlacefixmethodPulldown::interlacefixmethod_to_text()
721 {
722         ilacefixmethod_to_text(this->string,*output_value);
723         return (this->string);
724 }
725
726 AssetEditILaceautofixoption::AssetEditILaceautofixoption(AssetEditWindow *fwindow, char *text, int thedefault, int x, int y, int w)
727  : BC_TextBox(x, y, w, 1, text)
728 {
729         this->fwindow = fwindow;
730         this->thedefault = thedefault;
731 }
732
733 int AssetEditILaceautofixoption::handle_event()
734 {
735         Asset *asset = fwindow->asset_edit->changed_params;
736         asset->interlace_autofixoption = ilaceautofixoption_from_text(get_text(), this->thedefault);
737         return 1;
738 }
739
740
741 AssetEditILacemode::AssetEditILacemode(AssetEditWindow *fwindow, const char *text, int thedefault, int x, int y, int w)
742  : BC_TextBox(x, y, w, 1, text)
743 {
744         this->fwindow = fwindow;
745         this->thedefault = thedefault;
746 }
747
748 int AssetEditILacemode::handle_event()
749 {
750         Asset *asset = fwindow->asset_edit->changed_params;
751         asset->interlace_mode = ilacemode_from_text(get_text(),this->thedefault);
752         return 1;
753 }
754
755 AssetEditInterlacemodePulldown::AssetEditInterlacemodePulldown(MWindow *mwindow,
756                 BC_TextBox *output_text,
757                 int *output_value,
758                 ArrayList<BC_ListBoxItem*> *data,
759                 Interlaceautofix *fixoption_chkboxw,
760                 int x,
761                 int y)
762  : BC_ListBox(x,
763         y,
764         200,
765         150,
766         LISTBOX_TEXT,
767         data,
768         0,
769         0,
770         1,
771         0,
772         1)
773 {
774         this->fixoption_chkbox = fixoption_chkboxw;
775         this->mwindow = mwindow;
776         this->output_text = output_text;
777         this->output_value = output_value;
778         output_text->update(interlacemode_to_text());
779 }
780
781 int AssetEditInterlacemodePulldown::handle_event()
782 {
783         output_text->update(get_selection(0, 0)->get_text());
784         *output_value = ((InterlacemodeItem*)get_selection(0, 0))->value;
785         fixoption_chkbox->showhideotherwidgets();
786         return 1;
787 }
788
789 char* AssetEditInterlacemodePulldown::interlacemode_to_text()
790 {
791         ilacemode_to_text(this->string,*output_value);
792         return (this->string);
793 }
794
795 AssetEditILacefixmethod::AssetEditILacefixmethod(AssetEditWindow *fwindow, const char *text, int thedefault, int x, int y, int w)
796  : BC_TextBox(x, y, w, 1, text)
797 {
798         this->fwindow = fwindow;
799         this->thedefault = thedefault;
800 }
801
802 int AssetEditILacefixmethod::handle_event()
803 {
804         Asset *asset = fwindow->asset_edit->changed_params;
805         asset->interlace_fixmethod = ilacefixmethod_from_text(get_text(),this->thedefault);
806         return 1;
807 }
808
809 AssetEditHeader::AssetEditHeader(AssetEditWindow *fwindow, char *text, int x, int y)
810  : BC_TextBox(x, y, 100, 1, text)
811 {
812         this->fwindow = fwindow;
813 }
814
815 int AssetEditHeader::handle_event()
816 {
817         Asset *asset = fwindow->asset_edit->changed_params;
818         asset->header = atol(get_text());
819         return 1;
820 }
821
822 AssetEditByteOrderLOHI::AssetEditByteOrderLOHI(AssetEditWindow *fwindow,
823         int value,
824         int x,
825         int y)
826  : BC_Radial(x, y, value, _("Lo-Hi"))
827 {
828         this->fwindow = fwindow;
829 }
830
831 int AssetEditByteOrderLOHI::handle_event()
832 {
833         Asset *asset = fwindow->asset_edit->changed_params;
834         asset->byte_order = 1;
835         fwindow->hilo->update(0);
836         update(1);
837         return 1;
838 }
839
840 AssetEditByteOrderHILO::AssetEditByteOrderHILO(AssetEditWindow *fwindow,
841         int value,
842         int x,
843         int y)
844  : BC_Radial(x, y, value, _("Hi-Lo"))
845 {
846         this->fwindow = fwindow;
847 }
848
849 int AssetEditByteOrderHILO::handle_event()
850 {
851         Asset *asset = fwindow->asset_edit->changed_params;
852         asset->byte_order = 0;
853         fwindow->lohi->update(0);
854         update(1);
855         return 1;
856 }
857
858 AssetEditSigned::AssetEditSigned(AssetEditWindow *fwindow,
859         int value,
860         int x,
861         int y)
862  : BC_CheckBox(x, y, value, _("Values are signed"))
863 {
864         this->fwindow = fwindow;
865 }
866
867 int AssetEditSigned::handle_event()
868 {
869         Asset *asset = fwindow->asset_edit->changed_params;
870         asset->signed_ = get_value();
871         return 1;
872 }
873
874
875
876
877
878
879
880 AssetEditPathText::AssetEditPathText(AssetEditWindow *fwindow, int y)
881  : BC_TextBox(5, y, 300, 1, fwindow->asset_edit->changed_params->path)
882 {
883         this->fwindow = fwindow;
884 }
885 AssetEditPathText::~AssetEditPathText()
886 {
887 }
888 int AssetEditPathText::handle_event()
889 {
890         strcpy(fwindow->asset_edit->changed_params->path, get_text());
891         return 1;
892 }
893
894 AssetEditPath::AssetEditPath(MWindow *mwindow, AssetEditWindow *fwindow,
895         BC_TextBox *textbox, int y, const char *text,
896         const char *window_title, const char *window_caption)
897  : BrowseButton(mwindow->theme, fwindow, textbox, 310, y, text,
898         window_title, window_caption, 0)
899 {
900         this->fwindow = fwindow;
901 }
902
903 AssetEditPath::~AssetEditPath() {}
904
905
906
907
908
909
910 AssetEditFormat::AssetEditFormat(AssetEditWindow *fwindow, char* default_, int y)
911  : FormatPopup(fwindow->mwindow->plugindb, 90, y)
912 {
913         this->fwindow = fwindow;
914 }
915 AssetEditFormat::~AssetEditFormat()
916 {
917 }
918 int AssetEditFormat::handle_event()
919 {
920         Asset *asset = fwindow->asset_edit->changed_params;
921         asset->format = File::strtoformat(fwindow->mwindow->plugindb,
922                 get_selection(0, 0)->get_text());
923         return 1;
924 }
925
926
927
928
929 DetailAssetButton::DetailAssetButton(AssetEditWindow *fwindow, int x, int y)
930  : BC_GenericButton(x, y, _("Detail"))
931 {
932         this->fwindow = fwindow;
933         set_underline(0);
934 }
935
936 DetailAssetButton::~DetailAssetButton()
937 {
938 }
939
940 int DetailAssetButton::handle_event()
941 {
942         fwindow->show_info_detail();
943         return 1;
944 }
945
946 DetailAssetWindow::DetailAssetWindow(MWindow *mwindow, Asset *asset)
947  : BC_Window(_("Asset Detail"),
948         mwindow->gui->get_abs_cursor_x(1) - 600/2,
949         mwindow->gui->get_abs_cursor_y(1) - 500/2,
950         600, 500)
951 {
952         this->mwindow = mwindow;
953         this->asset = asset;
954         asset->add_user();
955         info[0] = 0;
956         text = 0;
957 }
958
959 DetailAssetWindow::~DetailAssetWindow()
960 {
961         asset->remove_user();
962         delete text;
963 }
964
965 DetailAssetThread::DetailAssetThread(MWindow *mwindow)
966  : Thread(1, 0, 0)
967 {
968         this->mwindow = mwindow;
969         dwindow = 0;
970 }
971
972 DetailAssetThread::~DetailAssetThread()
973 {
974         stop();
975 }
976
977 void DetailAssetThread::stop()
978 {
979         if( Thread::running() ) {
980                 dwindow->lock_window("DetailAssetThread::stop");
981                 dwindow->set_done(1);
982                 dwindow->unlock_window();
983         }
984         Thread::join();
985 }
986
987 void DetailAssetWindow::create_objects()
988 {
989         int y = 10, x = 10;
990         char file_name[BCTEXTLEN];
991         int len = sizeof(info);
992         strncpy(info,_("no info available"),len);
993         if( !mwindow->preferences->get_asset_file_path(asset, file_name) ) {
994                 switch( asset->format ) {
995                 case FILE_MPEG:
996                         FileMPEG::get_info(asset->path, file_name, &info[0],len);
997                         break;
998                 case FILE_FFMPEG:
999                         FileFFMPEG::get_info(asset->path, &info[0],len);
1000                         break;
1001                 }
1002         }
1003         lock_window("DetailAssetThread::create_objects");
1004         text = new BC_ScrollTextBox(this, x, y, get_w()-32, 23, info, -len);
1005         text->create_objects();  text->set_text_row(0);
1006         add_subwindow(new BC_OKButton(this));
1007         show_window();
1008         unlock_window();
1009 }
1010
1011 void DetailAssetThread::start(Asset *asset)
1012 {
1013         stop();
1014         delete dwindow;
1015         dwindow = new DetailAssetWindow(mwindow, asset);
1016         Thread::start();
1017 }
1018
1019 void DetailAssetThread::run()
1020 {
1021 // Get length from TOC
1022         dwindow->create_objects();
1023         dwindow->run_window();
1024         delete dwindow;
1025         dwindow = 0;
1026 }
1027