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