4 * Copyright (C) 2010 Adam Williams <broadcast at earthling dot net>
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.
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.
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
23 #include "assetedit.h"
25 #include "awindowgui.h"
26 #include "bcprogressbox.h"
27 #include "bcsignals.h"
28 #include "bitspopup.h"
31 #include "cplayback.h"
34 #include "edlsession.h"
37 #include "fileffmpeg.h"
38 #include "filesystem.h"
39 #include "indexable.h"
40 #include "indexfile.h"
41 #include "indexstate.h"
43 #include "mainindexes.h"
45 #include "mwindowgui.h"
48 #include "preferences.h"
49 #include "resizetrackthread.h"
50 #include "removefile.h"
52 #include "transportque.h"
53 #include "interlacemodes.h"
55 #include "edlsession.h"
61 AssetEdit::AssetEdit(MWindow *mwindow)
64 this->mwindow = mwindow;
67 changed_params = new Asset;
72 AssetEdit::~AssetEdit()
75 changed_params->remove_user();
79 void AssetEdit::edit_asset(Indexable *indexable, int x, int y)
82 this->indexable = indexable;
83 this->indexable->add_user();
84 this->x = x; this->y = y;
86 // Copy asset parameters into temporary storage for editing.
87 if( indexable->is_asset ) {
88 changed_params->copy_from((Asset*)indexable, 0);
91 EDL *nested_edl = (EDL*)indexable;
92 strcpy(changed_params->path, nested_edl->path);
93 changed_params->sample_rate = nested_edl->session->sample_rate;
94 changed_params->channels = nested_edl->session->audio_channels;
96 //printf("AssetEdit::edit_asset %d %f\n", __LINE__, nested_edl->session->frame_rate);
97 changed_params->frame_rate = nested_edl->session->frame_rate;
98 changed_params->width = nested_edl->session->output_w;
99 changed_params->height = nested_edl->session->output_h;
102 BC_DialogThread::start();
105 void AssetEdit::handle_done_event(int result)
109 void AssetEdit::handle_close_event(int result)
116 if( indexable->is_asset ) {
117 asset = (Asset*)indexable;
118 if( !changed_params->equivalent(*asset, 1, 1, mwindow->edl) )
122 nested_edl = (EDL*)indexable;
123 if( strcmp(changed_params->path, nested_edl->path)
124 // || changed_params->sample_rate != nested_edl->session->sample_rate
125 // || !EQUIV(changed_params->frame_rate, nested_edl->session->frame_rate
130 mwindow->gui->lock_window();
131 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
133 // Omit index status from copy since an index rebuild may have been
134 // happening when new_asset was created but not be happening anymore.
136 mwindow->remove_from_caches(asset);
137 //printf("AssetEdit::handle_close_event %d %f\n", __LINE__, asset->get_frame_rate());
138 asset->copy_from(changed_params, 0);
139 //printf("AssetEdit::handle_close_event %d %d %d\n", __LINE__, changed_params->bits, asset->bits);
142 strcpy(nested_edl->path, changed_params->path);
143 // Other parameters can't be changed because they're defined in the other EDL
144 // nested_edl->session->frame_rate = changed_params->frame_rate;
145 // nested_edl->session->sample_rate = changed_params->sample_rate;
147 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
149 mwindow->gui->update(0, FORCE_REDRAW, 0, 0, 0, 0, 0);
150 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
152 // Start index rebuilding
153 if( (asset && asset->audio_data) || nested_edl) {
154 char source_filename[BCTEXTLEN];
155 char index_filename[BCTEXTLEN];
156 IndexFile::get_index_filename(source_filename,
157 mwindow->preferences->index_directory,
160 remove_file(index_filename);
161 indexable->index_state->index_status = INDEX_NOTTESTED;
162 mwindow->mainindexes->add_indexable(indexable);
163 mwindow->mainindexes->start_build();
165 mwindow->gui->unlock_window();
166 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
167 mwindow->awindow->gui->update_picon(indexable);
168 mwindow->awindow->gui->async_update_assets();
170 mwindow->restart_brender();
171 mwindow->sync_parameters(CHANGE_ALL);
172 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
176 this->indexable->remove_user();
178 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
181 BC_Window* AssetEdit::new_gui()
183 window = new AssetEditWindow(mwindow, this);
184 window->create_objects();
188 int AssetEdit::window_height()
191 if( indexable->have_audio() ) h += 200;
192 if( indexable->have_video() ) {
194 if( indexable->is_asset ) {
195 Asset *asset = (Asset *)indexable;
196 if( File::can_scale_input(asset) )
203 #define AEW_W xS(450)
205 AssetEditWindow::AssetEditWindow(MWindow *mwindow, AssetEdit *asset_edit)
206 : BC_Window(_(PROGRAM_NAME ": Asset Info"),
207 asset_edit->x - AEW_W/2, asset_edit->y - asset_edit->window_height()/2,
208 AEW_W, asset_edit->window_height(), 0, 0, 1)
210 this->mwindow = mwindow;
211 this->asset_edit = asset_edit;
227 AssetEditWindow::~AssetEditWindow()
229 lock_window("AssetEditWindow::~AssetEditWindow");
231 delete detail_dialog;
238 void AssetEditWindow::create_objects()
241 int ypad5 = yS(5), ypad10 = yS(10), ypad20 = yS(20), ypad30 = yS(30);
242 int y = ypad10, x = xpad10, x1 = xpad10, x2 = xS(190);
243 char string[BCTEXTLEN];
249 if( asset_edit->indexable->is_asset )
250 asset = (Asset*)asset_edit->indexable;
252 nested_edl = (EDL*)asset_edit->indexable;
254 allow_edits = asset && asset->format == FILE_PCM ? 1 : 0;
255 int vmargin = yS(allow_edits ? 30 : 20);
256 lock_window("AssetEditWindow::create_objects");
258 add_subwindow(path_text = new AssetEditPathText(this, y));
259 add_subwindow(path_button = new AssetEditPath(mwindow, this,
260 path_text, y, asset_edit->indexable->path,
261 _(PROGRAM_NAME ": Asset path"),
262 _("Select a file for this asset:")));
266 add_subwindow(new BC_Title(x, y, _("File format:")));
268 add_subwindow(new BC_Title(x, y, File::formattostr(asset->format),
270 mwindow->theme->assetedit_color));
274 int64_t bytes = fs.get_size(asset->path);
275 add_subwindow(new BC_Title(x, y, _("Bytes:")));
276 sprintf(string, "%jd", bytes);
277 Units::punctuate(string);
280 add_subwindow(new BC_Title(x2, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
281 if( asset->format == FILE_MPEG || asset->format == FILE_FFMPEG ) {
282 detail_dialog = new DetailAssetDialog(mwindow);
283 BC_GenericButton *detail = new DetailAssetButton(this, x2+xS(120), y);
284 add_subwindow(detail);
294 if( asset->audio_length > 0 )
295 length = (double)asset->audio_length / asset->sample_rate;
296 if( asset->video_length > 0 )
297 length = MAX(length, (double)asset->video_length / asset->frame_rate);
299 if( !EQUIV(length, 0) )
300 bitrate = (int64_t)(bytes * 8 / length);
303 add_subwindow(new BC_Title(x, y, _("Bitrate (bits/sec):")));
304 sprintf(string, "%jd", bitrate);
306 Units::punctuate(string);
307 add_subwindow(new BC_Title(x2, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
313 if( (asset && asset->audio_data) || nested_edl ) {
314 add_subwindow(new BC_Bar(x, y, get_w() - x * 2));
317 add_subwindow(new BC_Title(x, y, _("Audio:"), LARGEFONT, RED));
322 if( asset->get_compression_text(1, 0) ) {
323 add_subwindow(new BC_Title(x, y, _("Compression:")));
325 add_subwindow(new BC_Title(x,
327 asset->get_compression_text(1, 0),
329 mwindow->theme->assetedit_color));
335 add_subwindow(new BC_Title(x, y, _("Channels:")));
336 sprintf(string, "%d", asset_edit->changed_params->channels);
340 BC_TumbleTextBox *textbox = new AssetEditChannels(this,
344 textbox->create_objects();
348 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
353 add_subwindow(new BC_Title(x, y, _("Sample rate:")));
354 sprintf(string, "%d", asset_edit->changed_params->sample_rate);
359 add_subwindow(textbox = new AssetEditRate(this, string, x, y));
360 x += textbox->get_w();
361 add_subwindow(new SampleRatePulldown(mwindow, textbox, x, y));
364 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
371 add_subwindow(new BC_Title(x, y, _("Bits:")));
374 bitspopup = new BitsPopup(this, x, y,
375 &asset_edit->changed_params->bits,
377 bitspopup->create_objects();
380 add_subwindow(new BC_Title(x, y, File::bitstostr(asset->bits), MEDIUMFONT, mwindow->theme->assetedit_color));
385 add_subwindow(new BC_Title(x, y, _("Header length:")));
386 sprintf(string, "%d", asset->header);
390 add_subwindow(new AssetEditHeader(this, string, x, y));
392 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
397 add_subwindow(new BC_Title(x, y, _("Byte order:")));
403 add_subwindow(lohi = new AssetEditByteOrderLOHI(this,
404 asset->byte_order, x, y));
406 add_subwindow(hilo = new AssetEditByteOrderHILO(this,
407 !asset->byte_order, x, y));
412 if( asset->byte_order )
413 add_subwindow(new BC_Title(x, y, _("Lo-Hi"), MEDIUMFONT, mwindow->theme->assetedit_color));
415 add_subwindow(new BC_Title(x, y, _("Hi-Lo"), MEDIUMFONT, mwindow->theme->assetedit_color));
422 // add_subwindow(new BC_Title(x, y, _("Values are signed:")));
423 add_subwindow(new AssetEditSigned(this, asset->signed_, x, y));
426 if( !asset->signed_ && asset->bits == 8 )
427 add_subwindow(new BC_Title(x, y, _("Values are unsigned")));
429 add_subwindow(new BC_Title(x, y, _("Values are signed")));
437 if( (asset && asset->video_data) || nested_edl ) {
438 add_subwindow(new BC_Bar(x, y, get_w() - x * 2));
441 add_subwindow(new BC_Title(x, y, _("Video:"), LARGEFONT, RED));
446 if( asset && asset->get_compression_text(0,1) ) {
447 add_subwindow(new BC_Title(x, y, _("Compression:")));
449 add_subwindow(new BC_Title(x,
451 asset->get_compression_text(0,1),
453 mwindow->theme->assetedit_color));
458 add_subwindow(new BC_Title(x, y, _("Frame rate:")));
460 sprintf(string, "%.4f", asset_edit->changed_params->frame_rate);
462 //printf("AssetEditWindow::create_objects %d %f\n", __LINE__, asset_edit->changed_params->frame_rate);
464 BC_TextBox *framerate;
465 add_subwindow(framerate = new AssetEditFRate(this, string, x, y));
466 x += framerate->get_w();
467 add_subwindow(new FrameRatePulldown(mwindow, framerate, x, y));
470 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
475 add_subwindow(new BC_Title(x, y, _("Width:")));
477 sprintf(string, "%d", asset_edit->changed_params->width);
478 win_width = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
479 add_subwindow(win_width);
483 add_subwindow(new BC_Title(x, y, _("Height:")));
485 sprintf(string, "%d", asset_edit->changed_params->height);
486 win_height = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
487 add_subwindow(win_height);
488 y += win_height->get_h() + ypad5;
490 if( asset && File::can_scale_input(asset) ) {
493 add_subwindow(new BC_Title(x, y, _("Actual width:")));
495 sprintf(string, "%d", asset->actual_width);
496 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
498 BC_GenericButton *resize = new ResizeAssetButton(this, x+xS(64), y);
499 add_subwindow(resize);
503 add_subwindow(new BC_Title(x, y, _("Actual height:")));
505 sprintf(string, "%d", asset->actual_height);
506 title = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
507 add_subwindow(title);
508 y += title->get_h() + ypad5;
511 add_subwindow(title = new BC_Title(x1, y, _("Asset's interlacing:")));
512 ilacemode_to_text(string, asset->interlace_mode);
513 AssetEditILacemode *edit_ilace_mode;
514 add_subwindow(edit_ilace_mode = new AssetEditILacemode(this, string, x2, y, xS(160)));
515 add_subwindow(new AssetEditInterlacemodePulldown(mwindow, edit_ilace_mode,
516 &asset_edit->changed_params->interlace_mode,
517 (ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_asset_modes,
518 x2 + edit_ilace_mode->get_w(), y));
522 add_subwindow(new BC_OKButton(this));
523 add_subwindow(new BC_CancelButton(this));
528 void AssetEditWindow::show_info_detail()
531 get_abs_cursor(cur_x, cur_y, 0);
532 detail_dialog->start((Asset*)asset_edit->indexable, cur_x, cur_y);
536 AssetEditChannels::AssetEditChannels(AssetEditWindow *fwindow,
540 : BC_TumbleTextBox(fwindow, (int)atol(text), (int)1,
541 (int)MAXCHANNELS, x, y, xS(50))
543 this->fwindow = fwindow;
546 int AssetEditChannels::handle_event()
548 Asset *asset = fwindow->asset_edit->changed_params;
549 asset->channels = atol(get_text());
553 AssetEditRate::AssetEditRate(AssetEditWindow *fwindow, char *text, int x, int y)
554 : BC_TextBox(x, y, xS(100), 1, text)
556 this->fwindow = fwindow;
559 int AssetEditRate::handle_event()
561 Asset *asset = fwindow->asset_edit->changed_params;
562 asset->sample_rate = atol(get_text());
566 AssetEditFRate::AssetEditFRate(AssetEditWindow *fwindow, char *text, int x, int y)
567 : BC_TextBox(x, y, xS(100), 1, text)
569 this->fwindow = fwindow;
572 int AssetEditFRate::handle_event()
574 Asset *asset = fwindow->asset_edit->changed_params;
575 asset->frame_rate = atof(get_text());
580 AssetEditILacemode::AssetEditILacemode(AssetEditWindow *fwindow, const char *text, int x, int y, int w)
581 : BC_TextBox(x, y, w, 1, text)
583 this->fwindow = fwindow;
586 int AssetEditILacemode::handle_event()
588 Asset *asset = fwindow->asset_edit->changed_params;
589 asset->interlace_mode = ilacemode_from_text(get_text(), ILACE_ASSET_MODEDEFAULT);
593 AssetEditInterlacemodePulldown::AssetEditInterlacemodePulldown(MWindow *mwindow,
594 BC_TextBox *output_text, int *output_value,
595 ArrayList<BC_ListBoxItem*> *data, int x, int y)
596 : BC_ListBox(x, y, xS(160), yS(80), LISTBOX_TEXT, data, 0, 0, 1, 0, 1)
598 this->mwindow = mwindow;
599 this->output_text = output_text;
600 this->output_value = output_value;
601 output_text->update(interlacemode_to_text());
604 int AssetEditInterlacemodePulldown::handle_event()
606 output_text->update(get_selection(0, 0)->get_text());
607 *output_value = ((InterlacemodeItem*)get_selection(0, 0))->value;
611 char* AssetEditInterlacemodePulldown::interlacemode_to_text()
613 ilacemode_to_text(this->string,*output_value);
614 return (this->string);
617 AssetEditHeader::AssetEditHeader(AssetEditWindow *fwindow, char *text, int x, int y)
618 : BC_TextBox(x, y, xS(100), 1, text)
620 this->fwindow = fwindow;
623 int AssetEditHeader::handle_event()
625 Asset *asset = fwindow->asset_edit->changed_params;
626 asset->header = atol(get_text());
630 AssetEditByteOrderLOHI::AssetEditByteOrderLOHI(AssetEditWindow *fwindow,
634 : BC_Radial(x, y, value, _("Lo-Hi"))
636 this->fwindow = fwindow;
639 int AssetEditByteOrderLOHI::handle_event()
641 Asset *asset = fwindow->asset_edit->changed_params;
642 asset->byte_order = 1;
643 fwindow->hilo->update(0);
648 AssetEditByteOrderHILO::AssetEditByteOrderHILO(AssetEditWindow *fwindow,
652 : BC_Radial(x, y, value, _("Hi-Lo"))
654 this->fwindow = fwindow;
657 int AssetEditByteOrderHILO::handle_event()
659 Asset *asset = fwindow->asset_edit->changed_params;
660 asset->byte_order = 0;
661 fwindow->lohi->update(0);
666 AssetEditSigned::AssetEditSigned(AssetEditWindow *fwindow,
670 : BC_CheckBox(x, y, value, _("Values are signed"))
672 this->fwindow = fwindow;
675 int AssetEditSigned::handle_event()
677 Asset *asset = fwindow->asset_edit->changed_params;
678 asset->signed_ = get_value();
688 AssetEditPathText::AssetEditPathText(AssetEditWindow *fwindow, int y)
689 : BC_TextBox(5, y, xS(300), 1, fwindow->asset_edit->changed_params->path)
691 this->fwindow = fwindow;
693 AssetEditPathText::~AssetEditPathText()
696 int AssetEditPathText::handle_event()
698 strcpy(fwindow->asset_edit->changed_params->path, get_text());
702 AssetEditPath::AssetEditPath(MWindow *mwindow, AssetEditWindow *fwindow,
703 BC_TextBox *textbox, int y, const char *text,
704 const char *window_title, const char *window_caption)
705 : BrowseButton(mwindow->theme, fwindow, textbox, yS(310), y, text,
706 window_title, window_caption, 0)
708 this->fwindow = fwindow;
711 AssetEditPath::~AssetEditPath() {}
716 DetailAssetButton::DetailAssetButton(AssetEditWindow *fwindow, int x, int y)
717 : BC_GenericButton(x, y, _("Detail"))
719 this->fwindow = fwindow;
722 DetailAssetButton::~DetailAssetButton()
726 int DetailAssetButton::handle_event()
728 fwindow->show_info_detail();
732 #define DTL_W xS(600)
733 #define DTL_H yS(500)
735 DetailAssetWindow::DetailAssetWindow(MWindow *mwindow,
736 DetailAssetDialog *detail_dialog, Asset *asset)
737 : BC_Window(_("Asset Detail"),
738 detail_dialog->x - DTL_W/2, detail_dialog->y - DTL_H/2, DTL_W, DTL_H)
740 this->mwindow = mwindow;
741 this->detail_dialog = detail_dialog;
748 DetailAssetWindow::~DetailAssetWindow()
750 asset->remove_user();
754 DetailAssetDialog::DetailAssetDialog(MWindow *mwindow)
757 this->mwindow = mwindow;
761 DetailAssetDialog::~DetailAssetDialog()
766 void DetailAssetWindow::create_objects()
768 int y = yS(10), x = xS(10);
769 char file_name[BCTEXTLEN];
770 int len = sizeof(info);
771 strncpy(info,_("no info available"),len);
772 if( !mwindow->preferences->get_asset_file_path(asset, file_name) ) {
773 switch( asset->format ) {
776 FileMPEG::get_info(asset->path, file_name, &info[0],len);
780 FileFFMPEG::get_info(asset->path, &info[0],len);
784 lock_window("DetailAssetWindow::create_objects");
785 int text_h = get_h()-y - BC_OKButton::calculate_h() - yS(15);
786 int lines = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
787 text = new BC_ScrollTextBox(this, x, y, get_w()-xS(32), lines, info, -len);
788 text->create_objects(); text->set_text_row(0);
789 add_subwindow(new BC_OKButton(this));
794 void DetailAssetDialog::start(Asset *asset, int x, int y)
798 this->x = x; this->y = y;
799 BC_DialogThread::start();
802 BC_Window *DetailAssetDialog::new_gui()
804 dwindow = new DetailAssetWindow(mwindow, this, asset);
805 dwindow->create_objects();