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"
40 #include "indexable.h"
41 #include "indexfile.h"
42 #include "indexstate.h"
44 #include "mainindexes.h"
46 #include "mwindowgui.h"
48 #include "preferences.h"
49 #include "resizetrackthread.h"
50 #include "removefile.h"
52 #include "transportque.h"
58 AssetEdit::AssetEdit(MWindow *mwindow)
61 this->mwindow = mwindow;
64 changed_params = new Asset;
69 AssetEdit::~AssetEdit()
71 changed_params->remove_user();
75 void AssetEdit::edit_asset(Indexable *indexable)
79 BC_DialogThread::close_window();
82 this->indexable = indexable;
83 this->indexable->add_user();
85 // Copy asset parameters into temporary storage for editing.
86 if(indexable->is_asset)
88 changed_params->copy_from((Asset*)indexable, 0);
92 EDL *nested_edl = (EDL*)indexable;
94 strcpy(changed_params->path, nested_edl->path);
95 changed_params->sample_rate = nested_edl->session->sample_rate;
96 changed_params->channels = nested_edl->session->audio_channels;
98 //printf("AssetEdit::edit_asset %d %f\n", __LINE__, nested_edl->session->frame_rate);
99 changed_params->frame_rate = nested_edl->session->frame_rate;
100 changed_params->width = nested_edl->session->output_w;
101 changed_params->height = nested_edl->session->output_h;
104 BC_DialogThread::start();
107 void AssetEdit::handle_close_event(int result)
115 if(indexable->is_asset)
117 asset = (Asset*)indexable;
118 if(!changed_params->equivalent(*asset, 1, 1))
123 nested_edl = (EDL*)indexable;
124 if(strcmp(changed_params->path, nested_edl->path)
126 // changed_params->sample_rate != nested_edl->session->sample_rate ||
127 // !EQUIV(changed_params->frame_rate, nested_edl->session->frame_rate)
131 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
135 mwindow->gui->lock_window();
136 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
138 // Omit index status from copy since an index rebuild may have been
139 // happening when new_asset was created but not be happening anymore.
142 mwindow->remove_asset_from_caches(asset);
143 //printf("AssetEdit::handle_close_event %d %f\n", __LINE__, asset->get_frame_rate());
144 asset->copy_from(changed_params, 0);
145 //printf("AssetEdit::handle_close_event %d %d %d\n", __LINE__, changed_params->bits, asset->bits);
149 strcpy(nested_edl->path, changed_params->path);
150 // Other parameters can't be changed because they're defined in the other EDL
151 // nested_edl->session->frame_rate = changed_params->frame_rate;
152 // nested_edl->session->sample_rate = changed_params->sample_rate;
154 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
156 mwindow->gui->update(0,
163 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
165 // Start index rebuilding
166 if( (asset && asset->audio_data) || nested_edl)
168 char source_filename[BCTEXTLEN];
169 char index_filename[BCTEXTLEN];
170 IndexFile::get_index_filename(source_filename,
171 mwindow->preferences->index_directory,
174 remove_file(index_filename);
175 indexable->index_state->index_status = INDEX_NOTTESTED;
176 mwindow->mainindexes->add_next_asset(0, indexable);
177 mwindow->mainindexes->start_build();
179 mwindow->gui->unlock_window();
180 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
183 mwindow->awindow->gui->lock_window();
184 mwindow->awindow->gui->update_assets();
185 mwindow->awindow->gui->unlock_window();
186 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
188 mwindow->restart_brender();
189 mwindow->sync_parameters(CHANGE_ALL);
190 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
194 this->indexable->remove_user();
196 //printf("AssetEdit::handle_close_event %d\n", __LINE__);
199 BC_Window* AssetEdit::new_gui()
201 window = new AssetEditWindow(mwindow, this);
202 window->create_objects();
214 AssetEditWindow::AssetEditWindow(MWindow *mwindow, AssetEdit *asset_edit)
215 : BC_Window(_(PROGRAM_NAME ": Asset Info"),
216 mwindow->gui->get_abs_cursor_x(1) - 400 / 2,
217 mwindow->gui->get_abs_cursor_y(1) - 500 / 2,
226 this->mwindow = mwindow;
227 this->asset_edit = asset_edit;
241 AssetEditWindow::~AssetEditWindow()
243 lock_window("AssetEditWindow::~AssetEditWindow");
244 if(bitspopup) delete bitspopup;
245 if(detail_thread) delete detail_thread;
252 void AssetEditWindow::create_objects()
254 int y = 10, x = 10, x1 = 10, x2 = 150;
255 char string[BCTEXTLEN];
262 if(asset_edit->indexable->is_asset)
263 asset = (Asset*)asset_edit->indexable;
265 nested_edl = (EDL*)asset_edit->indexable;
267 if(asset && asset->format == FILE_PCM)
272 lock_window("AssetEditWindow::create_objects");
278 add_subwindow(path_text = new AssetEditPathText(this, y));
279 add_subwindow(path_button = new AssetEditPath(mwindow,
283 asset_edit->indexable->path,
284 _(PROGRAM_NAME ": Asset path"), _("Select a file for this asset:")));
289 add_subwindow(new BC_Title(x, y, _("File format:")));
291 add_subwindow(new BC_Title(x, y, File::formattostr(mwindow->plugindb,
294 mwindow->theme->assetedit_color));
298 int64_t bytes = fs.get_size(asset->path);
299 add_subwindow(new BC_Title(x, y, _("Bytes:")));
300 sprintf(string, "" _LD "", bytes);
301 Units::punctuate(string);
304 add_subwindow(new BC_Title(x2, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
305 if(asset->format == FILE_MPEG || asset->format == FILE_FFMPEG)
307 detail_thread = new DetailAssetThread(mwindow);
308 BC_GenericButton *detail = new DetailAssetButton(this, x2+120, y);
309 add_subwindow(detail);
319 if(asset->audio_length > 0)
320 length = (double)asset->audio_length / asset->sample_rate;
321 if(asset->video_length > 0)
322 length = MAX(length, (double)asset->video_length / asset->frame_rate);
324 if(!EQUIV(length, 0))
325 bitrate = (int64_t)(bytes * 8 / length);
328 add_subwindow(new BC_Title(x, y, _("Bitrate (bits/sec):")));
329 sprintf(string, "" _LD "", bitrate);
331 Units::punctuate(string);
332 add_subwindow(new BC_Title(x2, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
338 if((asset && asset->audio_data) || nested_edl)
340 add_subwindow(new BC_Bar(x, y, get_w() - x * 2));
343 add_subwindow(new BC_Title(x, y, _("Audio:"), LARGEFONT, RED));
349 if(asset->get_compression_text(1, 0))
351 add_subwindow(new BC_Title(x, y, _("Compression:")));
353 add_subwindow(new BC_Title(x,
355 asset->get_compression_text(1, 0),
357 mwindow->theme->assetedit_color));
363 add_subwindow(new BC_Title(x, y, _("Channels:")));
364 sprintf(string, "%d", asset_edit->changed_params->channels);
369 BC_TumbleTextBox *textbox = new AssetEditChannels(this,
373 textbox->create_objects();
378 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
383 add_subwindow(new BC_Title(x, y, _("Sample rate:")));
384 sprintf(string, "%d", asset_edit->changed_params->sample_rate);
390 add_subwindow(textbox = new AssetEditRate(this, string, x, y));
391 x += textbox->get_w();
392 add_subwindow(new SampleRatePulldown(mwindow, textbox, x, y));
396 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
404 add_subwindow(new BC_Title(x, y, _("Bits:")));
408 bitspopup = new BitsPopup(this,
411 &asset_edit->changed_params->bits,
417 bitspopup->create_objects();
420 add_subwindow(new BC_Title(x, y, File::bitstostr(asset->bits), MEDIUMFONT, mwindow->theme->assetedit_color));
425 add_subwindow(new BC_Title(x, y, _("Header length:")));
426 sprintf(string, "%d", asset->header);
430 add_subwindow(new AssetEditHeader(this, string, x, y));
432 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
437 add_subwindow(new BC_Title(x, y, _("Byte order:")));
443 add_subwindow(lohi = new AssetEditByteOrderLOHI(this,
448 add_subwindow(hilo = new AssetEditByteOrderHILO(this,
457 if(asset->byte_order)
458 add_subwindow(new BC_Title(x, y, _("Lo-Hi"), MEDIUMFONT, mwindow->theme->assetedit_color));
460 add_subwindow(new BC_Title(x, y, _("Hi-Lo"), MEDIUMFONT, mwindow->theme->assetedit_color));
468 // add_subwindow(new BC_Title(x, y, _("Values are signed:")));
469 add_subwindow(new AssetEditSigned(this, asset->signed_, x, y));
473 if(!asset->signed_ && asset->bits == 8)
474 add_subwindow(new BC_Title(x, y, _("Values are unsigned")));
476 add_subwindow(new BC_Title(x, y, _("Values are signed")));
484 if((asset && asset->video_data) || nested_edl)
486 add_subwindow(new BC_Bar(x, y, get_w() - x * 2));
489 add_subwindow(new BC_Title(x, y, _("Video:"), LARGEFONT, RED));
494 if(asset && asset->get_compression_text(0,1))
496 add_subwindow(new BC_Title(x, y, _("Compression:")));
498 add_subwindow(new BC_Title(x,
500 asset->get_compression_text(0,1),
502 mwindow->theme->assetedit_color));
507 add_subwindow(new BC_Title(x, y, _("Frame rate:")));
509 sprintf(string, "%.2f", asset_edit->changed_params->frame_rate);
511 //printf("AssetEditWindow::create_objects %d %f\n", __LINE__, asset_edit->changed_params->frame_rate);
514 BC_TextBox *framerate;
515 add_subwindow(framerate = new AssetEditFRate(this, string, x, y));
517 add_subwindow(new FrameRatePulldown(mwindow, framerate, x, y));
521 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
526 add_subwindow(new BC_Title(x, y, _("Width:")));
528 sprintf(string, "%d", asset_edit->changed_params->width);
529 win_width = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
530 add_subwindow(win_width);
534 add_subwindow(new BC_Title(x, y, _("Height:")));
536 sprintf(string, "%d", asset_edit->changed_params->height);
537 win_height = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
538 add_subwindow(win_height);
539 y += win_height->get_h() + 5;
541 if(asset && (asset->format == FILE_MPEG || asset->format == FILE_FFMPEG ) )
545 add_subwindow(new BC_Title(x, y, _("Actual width:")));
547 sprintf(string, "%d", asset->actual_width);
548 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color));
550 BC_GenericButton *resize = new ResizeAssetButton(this, x+64, y);
551 add_subwindow(resize);
555 add_subwindow(new BC_Title(x, y, _("Actual height:")));
557 sprintf(string, "%d", asset->actual_height);
558 title = new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->assetedit_color);
559 add_subwindow(title);
560 y += title->get_h() + 5;
564 add_subwindow(new BC_OKButton(this));
565 add_subwindow(new BC_CancelButton(this));
570 void AssetEditWindow::show_info_detail()
572 detail_thread->start((Asset*)asset_edit->indexable);
576 AssetEditChannels::AssetEditChannels(AssetEditWindow *fwindow,
580 : BC_TumbleTextBox(fwindow,
588 this->fwindow = fwindow;
591 int AssetEditChannels::handle_event()
593 Asset *asset = (Asset*)fwindow->asset_edit->changed_params;
594 asset->channels = atol(get_text());
598 AssetEditRate::AssetEditRate(AssetEditWindow *fwindow, char *text, int x, int y)
599 : BC_TextBox(x, y, 100, 1, text)
601 this->fwindow = fwindow;
604 int AssetEditRate::handle_event()
606 Asset *asset = (Asset*)fwindow->asset_edit->changed_params;
607 asset->sample_rate = atol(get_text());
611 AssetEditFRate::AssetEditFRate(AssetEditWindow *fwindow, char *text, int x, int y)
612 : BC_TextBox(x, y, 100, 1, text)
614 this->fwindow = fwindow;
617 int AssetEditFRate::handle_event()
619 Asset *asset = (Asset*)fwindow->asset_edit->changed_params;
620 asset->frame_rate = atof(get_text());
624 AssetEditHeader::AssetEditHeader(AssetEditWindow *fwindow, char *text, int x, int y)
625 : BC_TextBox(x, y, 100, 1, text)
627 this->fwindow = fwindow;
630 int AssetEditHeader::handle_event()
632 Asset *asset = (Asset*)fwindow->asset_edit->changed_params;
633 asset->header = atol(get_text());
637 AssetEditByteOrderLOHI::AssetEditByteOrderLOHI(AssetEditWindow *fwindow,
641 : BC_Radial(x, y, value, _("Lo-Hi"))
643 this->fwindow = fwindow;
646 int AssetEditByteOrderLOHI::handle_event()
648 Asset *asset = (Asset*)fwindow->asset_edit->changed_params;
649 asset->byte_order = 1;
650 fwindow->hilo->update(0);
655 AssetEditByteOrderHILO::AssetEditByteOrderHILO(AssetEditWindow *fwindow,
659 : BC_Radial(x, y, value, _("Hi-Lo"))
661 this->fwindow = fwindow;
664 int AssetEditByteOrderHILO::handle_event()
666 Asset *asset = (Asset*)fwindow->asset_edit->changed_params;
667 asset->byte_order = 0;
668 fwindow->lohi->update(0);
673 AssetEditSigned::AssetEditSigned(AssetEditWindow *fwindow,
677 : BC_CheckBox(x, y, value, _("Values are signed"))
679 this->fwindow = fwindow;
682 int AssetEditSigned::handle_event()
684 Asset *asset = (Asset*)fwindow->asset_edit->changed_params;
685 asset->signed_ = get_value();
695 AssetEditPathText::AssetEditPathText(AssetEditWindow *fwindow, int y)
696 : BC_TextBox(5, y, 300, 1, fwindow->asset_edit->changed_params->path)
698 this->fwindow = fwindow;
700 AssetEditPathText::~AssetEditPathText()
703 int AssetEditPathText::handle_event()
705 strcpy(fwindow->asset_edit->changed_params->path, get_text());
709 AssetEditPath::AssetEditPath(MWindow *mwindow,
710 AssetEditWindow *fwindow,
714 const char *window_title,
715 const char *window_caption)
716 : BrowseButton(mwindow,
726 this->fwindow = fwindow;
728 AssetEditPath::~AssetEditPath() {}
735 AssetEditFormat::AssetEditFormat(AssetEditWindow *fwindow, char* default_, int y)
736 : FormatPopup(fwindow->mwindow->plugindb, 90, y)
738 this->fwindow = fwindow;
740 AssetEditFormat::~AssetEditFormat()
743 int AssetEditFormat::handle_event()
745 Asset *asset = (Asset*)fwindow->asset_edit->changed_params;
746 asset->format = File::strtoformat(fwindow->mwindow->plugindb,
747 get_selection(0, 0)->get_text());
754 DetailAssetButton::DetailAssetButton(AssetEditWindow *fwindow, int x, int y)
755 : BC_GenericButton(x, y, _("Detail"))
757 this->fwindow = fwindow;
761 DetailAssetButton::~DetailAssetButton()
765 int DetailAssetButton::handle_event()
767 fwindow->show_info_detail();
771 DetailAssetWindow::DetailAssetWindow(MWindow *mwindow, Asset *asset)
772 : BC_Window(_("Asset Detail"),
773 mwindow->gui->get_abs_cursor_x(1) - 600/2,
774 mwindow->gui->get_abs_cursor_y(1) - 500/2,
777 this->mwindow = mwindow;
784 DetailAssetWindow::~DetailAssetWindow()
786 asset->remove_user();
790 DetailAssetThread::DetailAssetThread(MWindow *mwindow)
793 this->mwindow = mwindow;
797 DetailAssetThread::~DetailAssetThread()
799 if( Thread::running() ) {
800 dwindow->lock_window("DetailAssetThread::~DetailAssetThread");
801 dwindow->set_done(1);
802 dwindow->unlock_window();
807 void DetailAssetWindow::create_objects()
810 char file_name[BCTEXTLEN];
811 int len = sizeof(info);
812 strncpy(info,_("no info available"),len);
813 if( !mwindow->preferences->get_asset_file_path(asset, file_name) ) {
814 switch( asset->format ) {
816 FileMPEG::get_info(asset->path, file_name, &info[0]);
819 FileFFMPEG::get_info(asset->path, &info[0]);
823 lock_window("DetailAssetThread::create_objects");
824 text = new BC_ScrollTextBox(this, x, y, get_w()-32, 23, info, -len);
825 text->create_objects(); text->set_text_row(0);
826 add_subwindow(new BC_OKButton(this));
831 void DetailAssetThread::start(Asset *asset)
833 if( !Thread::running() ) {
835 dwindow = new DetailAssetWindow(mwindow, asset);
840 void DetailAssetThread::run()
842 // Get length from TOC
843 dwindow->create_objects();
844 dwindow->run_window();