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_asset_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_next_asset(0, 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 AssetEditWindow::AssetEditWindow(MWindow *mwindow, AssetEdit *asset_edit)
204 : BC_Window(_(PROGRAM_NAME ": Asset Info"),
205 asset_edit->x - 450/2, asset_edit->y - asset_edit->window_height()/2,
206 450, asset_edit->window_height(), 0, 0, 1)
208 this->mwindow = mwindow;
209 this->asset_edit = asset_edit;
225 AssetEditWindow::~AssetEditWindow()
227 lock_window("AssetEditWindow::~AssetEditWindow");
229 delete detail_dialog;
236 void AssetEditWindow::create_objects()
238 int y = 10, x = 10, x1 = 10, x2 = 190;
239 char string[BCTEXTLEN];
246 if( asset_edit->indexable->is_asset )
247 asset = (Asset*)asset_edit->indexable;
249 nested_edl = (EDL*)asset_edit->indexable;
251 if( asset && asset->format == FILE_PCM )
256 lock_window("AssetEditWindow::create_objects");
262 add_subwindow(path_text = new AssetEditPathText(this, y));
263 add_subwindow(path_button = new AssetEditPath(mwindow, this,
264 path_text, y, asset_edit->indexable->path,
265 _(PROGRAM_NAME ": Asset path"),
266 _("Select a file for this asset:")));
270 add_subwindow(new BC_Title(x, y, _("File format:")));
272 add_subwindow(new BC_Title(x, y, File::formattostr(asset->format),
274 mwindow->theme->assetedit_color));
278 int64_t bytes = fs.get_size(asset->path);
279 add_subwindow(new BC_Title(x, y, _("Bytes:")));
280 sprintf(string, "%jd", bytes);
281 Units::punctuate(string);
284 add_subwindow(new BC_Title(x2, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
285 if( asset->format == FILE_MPEG || asset->format == FILE_FFMPEG ) {
286 detail_dialog = new DetailAssetDialog(mwindow);
287 BC_GenericButton *detail = new DetailAssetButton(this, x2+120, y);
288 add_subwindow(detail);
298 if( asset->audio_length > 0 )
299 length = (double)asset->audio_length / asset->sample_rate;
300 if( asset->video_length > 0 )
301 length = MAX(length, (double)asset->video_length / asset->frame_rate);
303 if( !EQUIV(length, 0) )
304 bitrate = (int64_t)(bytes * 8 / length);
307 add_subwindow(new BC_Title(x, y, _("Bitrate (bits/sec):")));
308 sprintf(string, "%jd", bitrate);
310 Units::punctuate(string);
311 add_subwindow(new BC_Title(x2, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
317 if( (asset && asset->audio_data) || nested_edl ) {
318 add_subwindow(new BC_Bar(x, y, get_w() - x * 2));
321 add_subwindow(new BC_Title(x, y, _("Audio:"), LARGEFONT, RED));
326 if( asset->get_compression_text(1, 0) ) {
327 add_subwindow(new BC_Title(x, y, _("Compression:")));
329 add_subwindow(new BC_Title(x,
331 asset->get_compression_text(1, 0),
333 mwindow->theme->assetedit_color));
339 add_subwindow(new BC_Title(x, y, _("Channels:")));
340 sprintf(string, "%d", asset_edit->changed_params->channels);
344 BC_TumbleTextBox *textbox = new AssetEditChannels(this,
348 textbox->create_objects();
352 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
357 add_subwindow(new BC_Title(x, y, _("Sample rate:")));
358 sprintf(string, "%d", asset_edit->changed_params->sample_rate);
363 add_subwindow(textbox = new AssetEditRate(this, string, x, y));
364 x += textbox->get_w();
365 add_subwindow(new SampleRatePulldown(mwindow, textbox, x, y));
368 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
375 add_subwindow(new BC_Title(x, y, _("Bits:")));
378 bitspopup = new BitsPopup(this, x, y,
379 &asset_edit->changed_params->bits,
381 bitspopup->create_objects();
384 add_subwindow(new BC_Title(x, y, File::bitstostr(asset->bits), MEDIUMFONT, mwindow->theme->assetedit_color));
389 add_subwindow(new BC_Title(x, y, _("Header length:")));
390 sprintf(string, "%d", asset->header);
394 add_subwindow(new AssetEditHeader(this, string, x, y));
396 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
401 add_subwindow(new BC_Title(x, y, _("Byte order:")));
407 add_subwindow(lohi = new AssetEditByteOrderLOHI(this,
412 add_subwindow(hilo = new AssetEditByteOrderHILO(this,
420 if( asset->byte_order )
421 add_subwindow(new BC_Title(x, y, _("Lo-Hi"), MEDIUMFONT, mwindow->theme->assetedit_color));
423 add_subwindow(new BC_Title(x, y, _("Hi-Lo"), MEDIUMFONT, mwindow->theme->assetedit_color));
430 // add_subwindow(new BC_Title(x, y, _("Values are signed:")));
431 add_subwindow(new AssetEditSigned(this, asset->signed_, x, y));
434 if( !asset->signed_ && asset->bits == 8 )
435 add_subwindow(new BC_Title(x, y, _("Values are unsigned")));
437 add_subwindow(new BC_Title(x, y, _("Values are signed")));
445 if( (asset && asset->video_data) || nested_edl ) {
446 add_subwindow(new BC_Bar(x, y, get_w() - x * 2));
449 add_subwindow(new BC_Title(x, y, _("Video:"), LARGEFONT, RED));
454 if( asset && asset->get_compression_text(0,1) ) {
455 add_subwindow(new BC_Title(x, y, _("Compression:")));
457 add_subwindow(new BC_Title(x,
459 asset->get_compression_text(0,1),
461 mwindow->theme->assetedit_color));
466 add_subwindow(new BC_Title(x, y, _("Frame rate:")));
468 sprintf(string, "%.4f", asset_edit->changed_params->frame_rate);
470 //printf("AssetEditWindow::create_objects %d %f\n", __LINE__, asset_edit->changed_params->frame_rate);
472 BC_TextBox *framerate;
473 add_subwindow(framerate = new AssetEditFRate(this, string, x, y));
475 add_subwindow(new FrameRatePulldown(mwindow, framerate, x, y));
478 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
483 add_subwindow(new BC_Title(x, y, _("Width:")));
485 sprintf(string, "%d", asset_edit->changed_params->width);
486 win_width = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
487 add_subwindow(win_width);
491 add_subwindow(new BC_Title(x, y, _("Height:")));
493 sprintf(string, "%d", asset_edit->changed_params->height);
494 win_height = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
495 add_subwindow(win_height);
496 y += win_height->get_h() + 5;
498 if( asset && File::can_scale_input(asset) ) {
501 add_subwindow(new BC_Title(x, y, _("Actual width:")));
503 sprintf(string, "%d", asset->actual_width);
504 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
506 BC_GenericButton *resize = new ResizeAssetButton(this, x+64, y);
507 add_subwindow(resize);
511 add_subwindow(new BC_Title(x, y, _("Actual height:")));
513 sprintf(string, "%d", asset->actual_height);
514 title = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
515 add_subwindow(title);
516 y += title->get_h() + 5;
519 add_subwindow(title = new BC_Title(x1, y, _("Asset's interlacing:")));
520 ilacemode_to_text(string, asset->interlace_mode);
521 AssetEditILacemode *edit_ilace_mode;
522 add_subwindow(edit_ilace_mode = new AssetEditILacemode(this, string, x2, y, 160));
523 add_subwindow(new AssetEditInterlacemodePulldown(mwindow, edit_ilace_mode,
524 &asset_edit->changed_params->interlace_mode,
525 (ArrayList<BC_ListBoxItem*>*)&mwindow->interlace_asset_modes,
526 x2 + edit_ilace_mode->get_w(), y));
530 add_subwindow(new BC_OKButton(this));
531 add_subwindow(new BC_CancelButton(this));
536 void AssetEditWindow::show_info_detail()
539 get_abs_cursor(cur_x, cur_y, 0);
540 detail_dialog->start((Asset*)asset_edit->indexable, cur_x, cur_y);
544 AssetEditChannels::AssetEditChannels(AssetEditWindow *fwindow,
548 : BC_TumbleTextBox(fwindow,
556 this->fwindow = fwindow;
559 int AssetEditChannels::handle_event()
561 Asset *asset = fwindow->asset_edit->changed_params;
562 asset->channels = atol(get_text());
566 AssetEditRate::AssetEditRate(AssetEditWindow *fwindow, char *text, int x, int y)
567 : BC_TextBox(x, y, 100, 1, text)
569 this->fwindow = fwindow;
572 int AssetEditRate::handle_event()
574 Asset *asset = fwindow->asset_edit->changed_params;
575 asset->sample_rate = atol(get_text());
579 AssetEditFRate::AssetEditFRate(AssetEditWindow *fwindow, char *text, int x, int y)
580 : BC_TextBox(x, y, 100, 1, text)
582 this->fwindow = fwindow;
585 int AssetEditFRate::handle_event()
587 Asset *asset = fwindow->asset_edit->changed_params;
588 asset->frame_rate = atof(get_text());
593 AssetEditILacemode::AssetEditILacemode(AssetEditWindow *fwindow, const char *text, int x, int y, int w)
594 : BC_TextBox(x, y, w, 1, text)
596 this->fwindow = fwindow;
599 int AssetEditILacemode::handle_event()
601 Asset *asset = fwindow->asset_edit->changed_params;
602 asset->interlace_mode = ilacemode_from_text(get_text(), ILACE_ASSET_MODEDEFAULT);
606 AssetEditInterlacemodePulldown::AssetEditInterlacemodePulldown(MWindow *mwindow,
607 BC_TextBox *output_text, int *output_value,
608 ArrayList<BC_ListBoxItem*> *data, int x, int y)
609 : BC_ListBox(x, y, 160, 80, LISTBOX_TEXT, data, 0, 0, 1, 0, 1)
611 this->mwindow = mwindow;
612 this->output_text = output_text;
613 this->output_value = output_value;
614 output_text->update(interlacemode_to_text());
617 int AssetEditInterlacemodePulldown::handle_event()
619 output_text->update(get_selection(0, 0)->get_text());
620 *output_value = ((InterlacemodeItem*)get_selection(0, 0))->value;
624 char* AssetEditInterlacemodePulldown::interlacemode_to_text()
626 ilacemode_to_text(this->string,*output_value);
627 return (this->string);
630 AssetEditHeader::AssetEditHeader(AssetEditWindow *fwindow, char *text, int x, int y)
631 : BC_TextBox(x, y, 100, 1, text)
633 this->fwindow = fwindow;
636 int AssetEditHeader::handle_event()
638 Asset *asset = fwindow->asset_edit->changed_params;
639 asset->header = atol(get_text());
643 AssetEditByteOrderLOHI::AssetEditByteOrderLOHI(AssetEditWindow *fwindow,
647 : BC_Radial(x, y, value, _("Lo-Hi"))
649 this->fwindow = fwindow;
652 int AssetEditByteOrderLOHI::handle_event()
654 Asset *asset = fwindow->asset_edit->changed_params;
655 asset->byte_order = 1;
656 fwindow->hilo->update(0);
661 AssetEditByteOrderHILO::AssetEditByteOrderHILO(AssetEditWindow *fwindow,
665 : BC_Radial(x, y, value, _("Hi-Lo"))
667 this->fwindow = fwindow;
670 int AssetEditByteOrderHILO::handle_event()
672 Asset *asset = fwindow->asset_edit->changed_params;
673 asset->byte_order = 0;
674 fwindow->lohi->update(0);
679 AssetEditSigned::AssetEditSigned(AssetEditWindow *fwindow,
683 : BC_CheckBox(x, y, value, _("Values are signed"))
685 this->fwindow = fwindow;
688 int AssetEditSigned::handle_event()
690 Asset *asset = fwindow->asset_edit->changed_params;
691 asset->signed_ = get_value();
701 AssetEditPathText::AssetEditPathText(AssetEditWindow *fwindow, int y)
702 : BC_TextBox(5, y, 300, 1, fwindow->asset_edit->changed_params->path)
704 this->fwindow = fwindow;
706 AssetEditPathText::~AssetEditPathText()
709 int AssetEditPathText::handle_event()
711 strcpy(fwindow->asset_edit->changed_params->path, get_text());
715 AssetEditPath::AssetEditPath(MWindow *mwindow, AssetEditWindow *fwindow,
716 BC_TextBox *textbox, int y, const char *text,
717 const char *window_title, const char *window_caption)
718 : BrowseButton(mwindow->theme, fwindow, textbox, 310, y, text,
719 window_title, window_caption, 0)
721 this->fwindow = fwindow;
724 AssetEditPath::~AssetEditPath() {}
729 DetailAssetButton::DetailAssetButton(AssetEditWindow *fwindow, int x, int y)
730 : BC_GenericButton(x, y, _("Detail"))
732 this->fwindow = fwindow;
735 DetailAssetButton::~DetailAssetButton()
739 int DetailAssetButton::handle_event()
741 fwindow->show_info_detail();
745 DetailAssetWindow::DetailAssetWindow(MWindow *mwindow,
746 DetailAssetDialog *detail_dialog, Asset *asset)
747 : BC_Window(_("Asset Detail"),
748 detail_dialog->x - 600/2, detail_dialog->y - 500/2, 600, 500)
750 this->mwindow = mwindow;
751 this->detail_dialog = detail_dialog;
758 DetailAssetWindow::~DetailAssetWindow()
760 asset->remove_user();
764 DetailAssetDialog::DetailAssetDialog(MWindow *mwindow)
767 this->mwindow = mwindow;
771 DetailAssetDialog::~DetailAssetDialog()
776 void DetailAssetWindow::create_objects()
779 char file_name[BCTEXTLEN];
780 int len = sizeof(info);
781 strncpy(info,_("no info available"),len);
782 if( !mwindow->preferences->get_asset_file_path(asset, file_name) ) {
783 switch( asset->format ) {
786 FileMPEG::get_info(asset->path, file_name, &info[0],len);
790 FileFFMPEG::get_info(asset->path, &info[0],len);
794 lock_window("DetailAssetWindow::create_objects");
795 text = new BC_ScrollTextBox(this, x, y, get_w()-32, 23, info, -len);
796 text->create_objects(); text->set_text_row(0);
797 add_subwindow(new BC_OKButton(this));
802 void DetailAssetDialog::start(Asset *asset, int x, int y)
806 this->x = x; this->y = y;
807 BC_DialogThread::start();
810 BC_Window *DetailAssetDialog::new_gui()
812 dwindow = new DetailAssetWindow(mwindow, this, asset);
813 dwindow->create_objects();