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)
107 if( !result && changed_params->timecode >= 0 ) {
108 double rate = indexable->get_frame_rate();
109 changed_params->timecode =
110 atoi(window->tc_hrs->get_text()) * 3600 +
111 atoi(window->tc_mins->get_text()) * 60 +
112 atoi(window->tc_secs->get_text()) +
113 atoi(window->tc_rest->get_text()) / rate;
117 void AssetEdit::handle_close_event(int result)
124 if( indexable->is_asset ) {
125 asset = (Asset*)indexable;
126 if( !changed_params->equivalent(*asset, 1, 1, mwindow->edl) )
130 nested_edl = (EDL*)indexable;
131 if( strcmp(changed_params->path, nested_edl->path)
132 // || changed_params->sample_rate != nested_edl->session->sample_rate
133 // || !EQUIV(changed_params->frame_rate, nested_edl->session->frame_rate
138 mwindow->gui->lock_window();
139 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
141 // Omit index status from copy since an index rebuild may have been
142 // happening when new_asset was created but not be happening anymore.
144 mwindow->remove_from_caches(asset);
145 //printf("AssetEdit::handle_close_event %d %f\n", __LINE__, asset->get_frame_rate());
146 asset->copy_from(changed_params, 0);
147 //printf("AssetEdit::handle_close_event %d %d %d\n", __LINE__, changed_params->bits, asset->bits);
150 strcpy(nested_edl->path, changed_params->path);
151 // Other parameters can't be changed because they're defined in the other EDL
152 // nested_edl->session->frame_rate = changed_params->frame_rate;
153 // nested_edl->session->sample_rate = changed_params->sample_rate;
155 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
157 mwindow->gui->update(0, FORCE_REDRAW, 0, 0, 0, 0, 0);
158 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
160 // Start index rebuilding
161 if( (asset && asset->audio_data) || nested_edl) {
162 char source_filename[BCTEXTLEN];
163 char index_filename[BCTEXTLEN];
164 IndexFile::get_index_filename(source_filename,
165 mwindow->preferences->index_directory,
168 remove_file(index_filename);
169 indexable->index_state->index_status = INDEX_NOTTESTED;
170 mwindow->mainindexes->add_indexable(indexable);
171 mwindow->mainindexes->start_build();
173 mwindow->gui->unlock_window();
174 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
175 mwindow->awindow->gui->update_picon(indexable);
176 mwindow->awindow->gui->async_update_assets();
178 mwindow->restart_brender();
179 mwindow->sync_parameters(CHANGE_ALL);
180 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
184 this->indexable->remove_user();
186 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
189 BC_Window* AssetEdit::new_gui()
191 window = new AssetEditWindow(mwindow, this);
192 window->create_objects();
196 int AssetEdit::window_height()
198 int h = yS(128 + 64);
199 if( indexable->have_audio() ) h += yS(200);
200 if( indexable->have_video() ) {
202 if( indexable->is_asset ) {
203 Asset *asset = (Asset *)indexable;
204 if( File::can_scale_input(asset) )
206 if( asset->timecode >= 0 )
213 #define AEW_W xS(450)
215 AssetEditWindow::AssetEditWindow(MWindow *mwindow, AssetEdit *asset_edit)
216 : BC_Window(_(PROGRAM_NAME ": Asset Info"),
217 asset_edit->x - AEW_W/2, asset_edit->y - asset_edit->window_height()/2,
218 AEW_W, asset_edit->window_height(), 0, 0, 1)
220 this->mwindow = mwindow;
221 this->asset_edit = asset_edit;
237 AssetEditWindow::~AssetEditWindow()
239 lock_window("AssetEditWindow::~AssetEditWindow");
241 delete detail_dialog;
248 void AssetEditWindow::create_objects()
251 int ypad5 = yS(5), ypad10 = yS(10), ypad20 = yS(20), ypad30 = yS(30);
252 int y = ypad10, x = xpad10, x1 = xpad10, x2 = xS(190);
253 char string[BCTEXTLEN];
259 if( asset_edit->indexable->is_asset )
260 asset = (Asset*)asset_edit->indexable;
262 nested_edl = (EDL*)asset_edit->indexable;
264 allow_edits = asset && asset->format == FILE_PCM ? 1 : 0;
265 int vmargin = yS(allow_edits ? 30 : 20);
266 lock_window("AssetEditWindow::create_objects");
268 add_subwindow(path_text = new AssetEditPathText(this, y));
269 add_subwindow(path_button = new AssetEditPath(mwindow, this,
270 path_text, y, asset_edit->indexable->path,
271 _(PROGRAM_NAME ": Asset path"),
272 _("Select a file for this asset:")));
276 add_subwindow(new BC_Title(x, y, _("File format:")));
278 add_subwindow(new BC_Title(x, y, File::formattostr(asset->format),
280 mwindow->theme->assetedit_color));
284 int64_t bytes = fs.get_size(asset->path);
285 add_subwindow(new BC_Title(x, y, _("Bytes:")));
286 sprintf(string, "%jd", bytes);
287 Units::punctuate(string);
290 add_subwindow(new BC_Title(x2, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
291 if( asset->format == FILE_MPEG || asset->format == FILE_FFMPEG ) {
292 detail_dialog = new DetailAssetDialog(mwindow);
293 BC_GenericButton *detail = new DetailAssetButton(this, x2+xS(120), y);
294 add_subwindow(detail);
304 if( asset->audio_length > 0 )
305 length = (double)asset->audio_length / asset->sample_rate;
306 if( asset->video_length > 0 )
307 length = MAX(length, (double)asset->video_length / asset->frame_rate);
309 if( !EQUIV(length, 0) )
310 bitrate = (int64_t)(bytes * 8 / length);
313 add_subwindow(new BC_Title(x, y, _("Bitrate (bits/sec):")));
314 sprintf(string, "%jd", bitrate);
316 Units::punctuate(string);
317 add_subwindow(new BC_Title(x2, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
323 if( (asset && asset->audio_data) || nested_edl ) {
324 add_subwindow(new BC_Bar(x, y, get_w() - x * 2));
327 add_subwindow(new BC_Title(x, y, _("Audio:"), LARGEFONT, RED));
332 if( asset->get_compression_text(1, 0) ) {
333 add_subwindow(new BC_Title(x, y, _("Compression:")));
335 add_subwindow(new BC_Title(x,
337 asset->get_compression_text(1, 0),
339 mwindow->theme->assetedit_color));
345 add_subwindow(new BC_Title(x, y, _("Channels:")));
346 sprintf(string, "%d", asset_edit->changed_params->channels);
350 BC_TumbleTextBox *textbox = new AssetEditChannels(this,
354 textbox->create_objects();
358 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
363 add_subwindow(new BC_Title(x, y, _("Sample rate:")));
364 sprintf(string, "%d", asset_edit->changed_params->sample_rate);
369 add_subwindow(textbox = new AssetEditRate(this, string, x, y));
370 x += textbox->get_w();
371 add_subwindow(new SampleRatePulldown(mwindow, textbox, x, y));
374 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
381 add_subwindow(new BC_Title(x, y, _("Bits:")));
384 bitspopup = new BitsPopup(this, x, y,
385 &asset_edit->changed_params->bits,
387 bitspopup->create_objects();
390 add_subwindow(new BC_Title(x, y, File::bitstostr(asset->bits), MEDIUMFONT, mwindow->theme->assetedit_color));
395 add_subwindow(new BC_Title(x, y, _("Header length:")));
396 sprintf(string, "%d", asset->header);
400 add_subwindow(new AssetEditHeader(this, string, x, y));
402 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
407 add_subwindow(new BC_Title(x, y, _("Byte order:")));
413 add_subwindow(lohi = new AssetEditByteOrderLOHI(this,
414 asset->byte_order, x, y));
416 add_subwindow(hilo = new AssetEditByteOrderHILO(this,
417 !asset->byte_order, x, y));
422 if( asset->byte_order )
423 add_subwindow(new BC_Title(x, y, _("Lo-Hi"), MEDIUMFONT, mwindow->theme->assetedit_color));
425 add_subwindow(new BC_Title(x, y, _("Hi-Lo"), MEDIUMFONT, mwindow->theme->assetedit_color));
432 // add_subwindow(new BC_Title(x, y, _("Values are signed:")));
433 add_subwindow(new AssetEditSigned(this, asset->signed_, x, y));
436 if( !asset->signed_ && asset->bits == 8 )
437 add_subwindow(new BC_Title(x, y, _("Values are unsigned")));
439 add_subwindow(new BC_Title(x, y, _("Values are signed")));
447 if( (asset && asset->video_data) || nested_edl ) {
448 add_subwindow(new BC_Bar(x, y, get_w() - x * 2));
451 add_subwindow(new BC_Title(x, y, _("Video:"), LARGEFONT, RED));
456 if( asset && asset->get_compression_text(0,1) ) {
457 add_subwindow(new BC_Title(x, y, _("Compression:")));
459 add_subwindow(new BC_Title(x,
461 asset->get_compression_text(0,1),
463 mwindow->theme->assetedit_color));
468 add_subwindow(new BC_Title(x, y, _("Frame rate:")));
470 sprintf(string, "%.4f", asset_edit->changed_params->frame_rate);
472 //printf("AssetEditWindow::create_objects %d %f\n", __LINE__, asset_edit->changed_params->frame_rate);
474 BC_TextBox *framerate;
475 add_subwindow(framerate = new AssetEditFRate(this, string, x, y));
476 x += framerate->get_w();
477 add_subwindow(new FrameRatePulldown(mwindow, framerate, x, y));
480 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
485 add_subwindow(new BC_Title(x, y, _("Width:")));
487 sprintf(string, "%d", asset_edit->changed_params->width);
488 win_width = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
489 add_subwindow(win_width);
493 add_subwindow(new BC_Title(x, y, _("Height:")));
495 sprintf(string, "%d", asset_edit->changed_params->height);
496 win_height = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
497 add_subwindow(win_height);
498 y += win_height->get_h() + ypad5;
500 if( asset && File::can_scale_input(asset) ) {
503 add_subwindow(new BC_Title(x, y, _("Actual width:")));
505 sprintf(string, "%d", asset->actual_width);
506 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
508 BC_GenericButton *resize = new ResizeAssetButton(this, x+xS(64), y);
509 add_subwindow(resize);
513 add_subwindow(new BC_Title(x, y, _("Actual height:")));
515 sprintf(string, "%d", asset->actual_height);
516 title = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
517 add_subwindow(title);
518 y += title->get_h() + ypad5;
521 add_subwindow(title = new BC_Title(x1, y, _("Asset's interlacing:")));
522 ilacemode_to_text(string, asset->interlace_mode);
523 AssetEditILacemode *edit_ilace_mode;
524 add_subwindow(edit_ilace_mode = new AssetEditILacemode(this, string, x2, y, xS(160)));
525 add_subwindow(new AssetEditInterlacemodePulldown(mwindow, edit_ilace_mode,
526 &asset_edit->changed_params->interlace_mode,
527 (ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_asset_modes,
528 x2 + edit_ilace_mode->get_w(), y));
529 y += title->get_h() + yS(15);
532 if( asset && asset->timecode >= 0 ) {
533 char text[BCSTRLEN], *tc = text;
534 Units::totext(tc, asset->timecode, TIME_HMSF,
535 asset->sample_rate, asset->frame_rate);
536 const char *hrs = tc; tc = strchr(tc, ':'); *tc++ = 0;
537 const char *mins = tc; tc = strchr(tc, ':'); *tc++ = 0;
538 const char *secs = tc; tc = strchr(tc, ':'); *tc++ = 0;
539 const char *rest = tc;
540 int padw = BC_Title::calculate_w(this, ":", MEDIUMFONT);
541 int fldw = BC_Title::calculate_w(this, "00", MEDIUMFONT) + 5;
542 int hdrw = fldw + padw; x = x2;
543 add_subwindow(title = new BC_Title(x, y, _("hour"), SMALLFONT)); x += hdrw;
544 add_subwindow(title = new BC_Title(x, y, _("min"), SMALLFONT)); x += hdrw;
545 add_subwindow(title = new BC_Title(x, y, _("sec"), SMALLFONT)); x += hdrw;
546 add_subwindow(title = new BC_Title(x, y, _("frms"), SMALLFONT));
547 y += title->get_h() + xS(3);
548 add_subwindow(title = new BC_Title(x1, y, _("Time Code Start:")));
549 add_subwindow(tc_hrs = new BC_TextBox(x=x2, y, fldw, 1, hrs));
550 add_subwindow(new BC_Title(x += tc_hrs->get_w(), y, ":"));
551 add_subwindow(tc_mins = new BC_TextBox(x += padw, y, fldw, 1, mins));
552 add_subwindow(new BC_Title(x += tc_mins->get_w(), y, ":"));
553 add_subwindow(tc_secs = new BC_TextBox(x += padw, y , fldw, 1, secs));
554 add_subwindow(new BC_Title(x += tc_secs->get_w(), y, ":"));
555 add_subwindow(tc_rest = new BC_TextBox(x += 10, y, fldw, 1, rest));
556 y += title->get_h() + ypad5;
559 add_subwindow(new BC_OKButton(this));
560 add_subwindow(new BC_CancelButton(this));
565 void AssetEditWindow::show_info_detail()
568 get_abs_cursor(cur_x, cur_y, 0);
569 detail_dialog->start((Asset*)asset_edit->indexable, cur_x, cur_y);
573 AssetEditChannels::AssetEditChannels(AssetEditWindow *fwindow,
577 : BC_TumbleTextBox(fwindow, (int)atol(text), (int)1,
578 (int)MAXCHANNELS, x, y, xS(50))
580 this->fwindow = fwindow;
583 int AssetEditChannels::handle_event()
585 Asset *asset = fwindow->asset_edit->changed_params;
586 asset->channels = atol(get_text());
590 AssetEditRate::AssetEditRate(AssetEditWindow *fwindow, char *text, int x, int y)
591 : BC_TextBox(x, y, xS(100), 1, text)
593 this->fwindow = fwindow;
596 int AssetEditRate::handle_event()
598 Asset *asset = fwindow->asset_edit->changed_params;
599 asset->sample_rate = atol(get_text());
603 AssetEditFRate::AssetEditFRate(AssetEditWindow *fwindow, char *text, int x, int y)
604 : BC_TextBox(x, y, xS(100), 1, text)
606 this->fwindow = fwindow;
609 int AssetEditFRate::handle_event()
611 Asset *asset = fwindow->asset_edit->changed_params;
612 asset->frame_rate = atof(get_text());
617 AssetEditILacemode::AssetEditILacemode(AssetEditWindow *fwindow, const char *text, int x, int y, int w)
618 : BC_TextBox(x, y, w, 1, text)
620 this->fwindow = fwindow;
623 int AssetEditILacemode::handle_event()
625 Asset *asset = fwindow->asset_edit->changed_params;
626 asset->interlace_mode = ilacemode_from_text(get_text(), ILACE_ASSET_MODEDEFAULT);
630 AssetEditInterlacemodePulldown::AssetEditInterlacemodePulldown(MWindow *mwindow,
631 BC_TextBox *output_text, int *output_value,
632 ArrayList<BC_ListBoxItem*> *data, int x, int y)
633 : BC_ListBox(x, y, xS(160), yS(80), LISTBOX_TEXT, data, 0, 0, 1, 0, 1)
635 this->mwindow = mwindow;
636 this->output_text = output_text;
637 this->output_value = output_value;
638 output_text->update(interlacemode_to_text());
641 int AssetEditInterlacemodePulldown::handle_event()
643 output_text->update(get_selection(0, 0)->get_text());
644 *output_value = ((InterlacemodeItem*)get_selection(0, 0))->value;
648 char* AssetEditInterlacemodePulldown::interlacemode_to_text()
650 ilacemode_to_text(this->string,*output_value);
651 return (this->string);
654 AssetEditHeader::AssetEditHeader(AssetEditWindow *fwindow, char *text, int x, int y)
655 : BC_TextBox(x, y, xS(100), 1, text)
657 this->fwindow = fwindow;
660 int AssetEditHeader::handle_event()
662 Asset *asset = fwindow->asset_edit->changed_params;
663 asset->header = atol(get_text());
667 AssetEditByteOrderLOHI::AssetEditByteOrderLOHI(AssetEditWindow *fwindow,
671 : BC_Radial(x, y, value, _("Lo-Hi"))
673 this->fwindow = fwindow;
676 int AssetEditByteOrderLOHI::handle_event()
678 Asset *asset = fwindow->asset_edit->changed_params;
679 asset->byte_order = 1;
680 fwindow->hilo->update(0);
685 AssetEditByteOrderHILO::AssetEditByteOrderHILO(AssetEditWindow *fwindow,
689 : BC_Radial(x, y, value, _("Hi-Lo"))
691 this->fwindow = fwindow;
694 int AssetEditByteOrderHILO::handle_event()
696 Asset *asset = fwindow->asset_edit->changed_params;
697 asset->byte_order = 0;
698 fwindow->lohi->update(0);
703 AssetEditSigned::AssetEditSigned(AssetEditWindow *fwindow,
707 : BC_CheckBox(x, y, value, _("Values are signed"))
709 this->fwindow = fwindow;
712 int AssetEditSigned::handle_event()
714 Asset *asset = fwindow->asset_edit->changed_params;
715 asset->signed_ = get_value();
725 AssetEditPathText::AssetEditPathText(AssetEditWindow *fwindow, int y)
726 : BC_TextBox(5, y, xS(300), 1, fwindow->asset_edit->changed_params->path)
728 this->fwindow = fwindow;
730 AssetEditPathText::~AssetEditPathText()
733 int AssetEditPathText::handle_event()
735 strcpy(fwindow->asset_edit->changed_params->path, get_text());
739 AssetEditPath::AssetEditPath(MWindow *mwindow, AssetEditWindow *fwindow,
740 BC_TextBox *textbox, int y, const char *text,
741 const char *window_title, const char *window_caption)
742 : BrowseButton(mwindow->theme, fwindow, textbox, yS(310), y, text,
743 window_title, window_caption, 0)
745 this->fwindow = fwindow;
748 AssetEditPath::~AssetEditPath() {}
753 DetailAssetButton::DetailAssetButton(AssetEditWindow *fwindow, int x, int y)
754 : BC_GenericButton(x, y, _("Detail"))
756 this->fwindow = fwindow;
759 DetailAssetButton::~DetailAssetButton()
763 int DetailAssetButton::handle_event()
765 fwindow->show_info_detail();
769 #define DTL_W xS(600)
770 #define DTL_H yS(500)
772 DetailAssetWindow::DetailAssetWindow(MWindow *mwindow,
773 DetailAssetDialog *detail_dialog, Asset *asset)
774 : BC_Window(_("Asset Detail"),
775 detail_dialog->x - DTL_W/2, detail_dialog->y - DTL_H/2, DTL_W, DTL_H)
777 this->mwindow = mwindow;
778 this->detail_dialog = detail_dialog;
785 DetailAssetWindow::~DetailAssetWindow()
787 asset->remove_user();
791 DetailAssetDialog::DetailAssetDialog(MWindow *mwindow)
794 this->mwindow = mwindow;
798 DetailAssetDialog::~DetailAssetDialog()
803 void DetailAssetWindow::create_objects()
805 int y = yS(10), x = xS(10);
806 char file_name[BCTEXTLEN];
807 int len = sizeof(info);
808 strncpy(info,_("no info available"),len);
809 if( !mwindow->preferences->get_asset_file_path(asset, file_name) ) {
810 switch( asset->format ) {
813 FileMPEG::get_info(asset->path, file_name, &info[0],len);
817 FileFFMPEG::get_info(asset->path, &info[0],len);
821 lock_window("DetailAssetWindow::create_objects");
822 int text_h = get_h()-y - BC_OKButton::calculate_h() - yS(15);
823 int lines = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
824 text = new BC_ScrollTextBox(this, x, y, get_w()-xS(32), lines, info, -len);
825 text->create_objects(); text->set_text_row(0);
826 add_subwindow(new BC_OKButton(this));
831 void DetailAssetDialog::start(Asset *asset, int x, int y)
835 this->x = x; this->y = y;
836 BC_DialogThread::start();
839 BC_Window *DetailAssetDialog::new_gui()
841 dwindow = new DetailAssetWindow(mwindow, this, asset);
842 dwindow->create_objects();