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