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