4 * Copyright (C) 2010-2013 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 "bcsignals.h"
27 #include "filesystem.h"
28 #include "formattools.h"
32 #include "maxchannels.h"
34 #include "preferences.h"
36 #include "videodevice.inc"
42 FormatTools::FormatTools(MWindow *mwindow,
43 BC_WindowBase *window,
46 this->mwindow = mwindow;
47 this->window = window;
49 this->plugindb = mwindow->plugindb;
79 prompt_audio_channels = 0;
81 prompt_video_compression = 0;
83 locked_compressor = 0;
87 FormatTools::~FormatTools()
98 if(aparams_button) delete aparams_button;
100 if(vparams_button) delete vparams_button;
102 if(aparams_thread) delete aparams_thread;
104 if(vparams_thread) delete vparams_thread;
106 if(channels_tumbler) delete channels_tumbler;
110 file_entries->remove_all_objects();
115 void FormatTools::create_objects(int &init_x,
117 int do_audio, // Include support for audio
118 int do_video, // Include support for video
119 int prompt_audio, // Include checkbox for audio
121 int prompt_audio_channels,
122 int prompt_video_compression,
123 const char *locked_compressor,
127 int horizontal_layout)
133 this->locked_compressor = locked_compressor;
134 this->recording = recording;
135 this->use_brender = brender;
136 this->do_audio = do_audio;
137 this->do_video = do_video;
138 this->prompt_audio = prompt_audio;
139 this->prompt_audio_channels = prompt_audio_channels;
140 this->prompt_video = prompt_video;
141 this->prompt_video_compression = prompt_video_compression;
142 this->strategy = strategy;
145 file_entries = new ArrayList<BC_ListBoxItem*>;
147 char string[BCTEXTLEN];
148 // Load current directory
149 fs.update(getcwd(string, BCTEXTLEN));
150 for(int i = 0; i < fs.total_files(); i++)
152 file_entries->append(
154 fs.get_entry(i)->get_name()));
157 //printf("FormatTools::create_objects 1\n");
159 // Modify strategy depending on render farm
162 if(mwindow->preferences->use_renderfarm)
164 if(*strategy == FILE_PER_LABEL)
165 *strategy = FILE_PER_LABEL_FARM;
167 if(*strategy == SINGLE_PASS)
168 *strategy = SINGLE_PASS_FARM;
172 if(*strategy == FILE_PER_LABEL_FARM)
173 *strategy = FILE_PER_LABEL;
175 if(*strategy == SINGLE_PASS_FARM)
176 *strategy = SINGLE_PASS;
183 window->add_subwindow(path_textbox = new FormatPathText(px, y, this));
184 px += path_textbox->get_w() + 5;
185 path_recent = new BC_RecentList("PATH", mwindow->defaults,
186 path_textbox, 10, px, y, 300, 100);
187 window->add_subwindow(path_recent);
188 path_recent->load_items(File::formattostr(asset->format));
189 px += path_recent->get_w() + 8;
190 window->add_subwindow(path_button = new BrowseButton(
191 mwindow, window, path_textbox, px, y, asset->path,
192 _("Output to file"), _("Select a file to write to:"), 0));
196 y += path_textbox->get_h() + 10;
205 window->add_subwindow(format_title = new BC_Title(x, y, _("File Format:")));
207 window->add_subwindow(format_text = new BC_TextBox(x, y, 180, 1,
208 File::formattostr(asset->format)));
209 x += format_text->get_w();
210 //printf("FormatTools::create_objects %d %p\n", __LINE__, window);
211 window->add_subwindow(format_button = new FormatFormat(x, y, this));
212 format_button->create_objects();
213 x += format_button->get_w() + 5;
214 window->add_subwindow(ffmpeg_type = new FFMpegType(x, y+5, 50, 1, asset->fformat));
215 FFMPEG::set_asset_format(asset, asset->fformat);
216 x += ffmpeg_type->get_w();
217 window->add_subwindow(format_ffmpeg = new FormatFFMPEG(x, y+5, this));
218 format_ffmpeg->create_objects();
220 y += format_button->get_h() + 10;
223 window->add_subwindow(audio_title = new BC_Title(x, y, _("Audio:"), LARGEFONT, BC_WindowBase::get_resources()->audiovideo_color));
225 window->add_subwindow(aparams_button = new FormatAParams(mwindow, this, x, y));
226 x += aparams_button->get_w() + 10;
229 window->add_subwindow(audio_switch = new FormatAudio(x, y, this, asset->audio_data));
233 y += aparams_button->get_h() + 10;
235 // Audio channels only used for recording.
236 // if(prompt_audio_channels)
238 // window->add_subwindow(channels_title = new BC_Title(x, y, _("Number of audio channels to record:")));
240 // window->add_subwindow(channels_button = new FormatChannels(x, y, this));
241 // x += channels_button->get_w() + 5;
242 // window->add_subwindow(channels_tumbler = new BC_ITumbler(channels_button, 1, MAXCHANNELS, x, y));
243 // y += channels_button->get_h() + 20;
247 //printf("FormatTools::create_objects 6\n");
248 aparams_thread = new FormatAThread(this);
251 //printf("FormatTools::create_objects 7\n");
254 if(horizontal_layout && do_audio){
259 //printf("FormatTools::create_objects 8\n");
260 window->add_subwindow(video_title = new BC_Title(x, y, _("Video:"), LARGEFONT, BC_WindowBase::get_resources()->audiovideo_color));
262 if(prompt_video_compression)
264 window->add_subwindow(vparams_button = new FormatVParams(mwindow, this, x, y));
265 x += vparams_button->get_w() + 10;
268 //printf("FormatTools::create_objects 9\n");
271 window->add_subwindow(video_switch = new FormatVideo(x, y, this, asset->video_data));
272 y += video_switch->get_h();
276 y += vparams_button->get_h();
279 //printf("FormatTools::create_objects 10\n");
281 vparams_thread = new FormatVThread(this);
284 //printf("FormatTools::create_objects 11\n");
289 window->add_subwindow(multiple_files = new FormatMultiple(mwindow, x, y, strategy));
290 y += multiple_files->get_h() + 10;
293 //printf("FormatTools::create_objects 12\n");
299 void FormatTools::update_driver(int driver)
301 this->video_driver = driver;
303 locked_compressor = 0;
307 case VIDEO4LINUX2MPEG:
308 // Just give the user information about how the stream is going to be
309 // stored but don't change the asset.
310 // Want to be able to revert to user settings.
311 if(asset->format == FILE_MPEG) break;
312 asset->format = FILE_MPEG;
313 format_text->update(File::formattostr(asset->format));
314 asset->audio_data = 1;
315 asset->video_data = 1;
316 audio_switch->update(1);
317 video_switch->update(1);
320 case CAPTURE_IEC61883:
321 case CAPTURE_FIREWIRE:
324 case VIDEO4LINUX2JPEG:
325 case CAPTURE_JPEG_WEBCAM:
326 asset->format = FILE_FFMPEG;
327 format_text->update(File::formattostr(asset->format));
330 case CAPTURE_IEC61883:
331 case CAPTURE_FIREWIRE:
332 locked_compressor = (char*)CODEC_TAG_DVSD;
337 case VIDEO4LINUX2JPEG:
338 locked_compressor = (char*)CODEC_TAG_MJPEG;
341 case CAPTURE_JPEG_WEBCAM:
342 locked_compressor = (char*)CODEC_TAG_JPEG;
345 if( locked_compressor )
346 strcpy(asset->vcodec, locked_compressor);
348 audio_switch->update(asset->audio_data);
349 video_switch->update(asset->video_data);
353 format_text->update(File::formattostr(asset->format));
354 audio_switch->update(asset->audio_data);
355 video_switch->update(asset->video_data);
358 close_format_windows();
362 void FormatTools::update_format()
364 if( do_audio && prompt_audio && audio_switch ) {
365 audio_switch->update(asset->audio_data);
366 if( !asset->audio_data )
367 audio_switch->disable();
369 audio_switch->enable();
371 if( do_video && prompt_video && video_switch ) {
372 video_switch->update(asset->video_data);
373 if( !asset->video_data )
374 video_switch->disable();
376 video_switch->enable();
378 if( asset->format == FILE_FFMPEG ) {
380 format_ffmpeg->show();
384 format_ffmpeg->hide();
388 int FormatTools::handle_event()
393 Asset* FormatTools::get_asset()
398 void FormatTools::update_extension()
400 const char *extension = File::get_tag(asset->format);
401 // split multiple extensions
402 ArrayList<const char*> extensions;
403 int len = !extension ? -1 : strlen(extension);
404 const char *extension_ptr = extension;
405 for(int i = 0; i <= len; i++)
407 if(extension[i] == '/' || extension[i] == 0)
409 extensions.append(extension_ptr);
410 extension_ptr = extension + i + 1;
414 if(extensions.size())
416 char *ptr = strrchr(asset->path, '.');
419 ptr = asset->path + strlen(asset->path);
424 // test for equivalent extension
425 int need_extension = 1;
426 //int extension_len = 0;
427 for(int i = 0; i < extensions.size() && need_extension; i++)
430 extension_ptr = extensions.get(i);
433 while(*ptr1 != 0 && *extension_ptr != 0 && *extension_ptr != '/')
435 if(tolower(*ptr1) != tolower(*extension_ptr))
445 *extension_ptr != 0 &&
446 *extension_ptr != '/')
450 //printf("FormatTools::update_extension %d %d\n", __LINE__, need_extension);
455 extension_ptr = asset->format != FILE_FFMPEG ?
456 extensions.get(0) : asset->fformat;
457 while(*extension_ptr != 0 && *extension_ptr != '/')
458 *ptr1++ = *extension_ptr++;
462 int character1 = ptr - asset->path;
463 int character2 = strlen(asset->path);
464 // *(asset->path + character2) = 0;
467 path_textbox->update(asset->path);
468 path_textbox->set_selection(character1, character2, character2);
473 void FormatTools::update(Asset *asset, int *strategy)
476 this->strategy = strategy;
479 path_textbox->update(asset->path);
480 format_text->update(File::formattostr(plugindb, asset->format));
481 if(do_audio && prompt_audio && audio_switch)
482 audio_switch->update(asset->audio_data);
483 if(do_video && prompt_video && video_switch)
484 video_switch->update(asset->video_data);
487 multiple_files->update(strategy);
489 close_format_windows();
492 void FormatTools::close_format_windows()
494 // This is done in ~file
495 if( aparams_thread ) {
496 if( aparams_thread->running() )
497 aparams_thread->file->close_window();
498 aparams_thread->join();
500 if( vparams_thread ) {
501 if( vparams_thread->running() )
502 vparams_thread->file->close_window();
503 vparams_thread->join();
507 int FormatTools::get_w()
509 return asset->format != FILE_FFMPEG ? w :
510 format_ffmpeg->get_x() + format_ffmpeg->get_w();
513 void FormatTools::set_w(int w)
518 void FormatTools::reposition_window(int &init_x, int &init_y)
526 path_textbox->reposition_window(px, y);
527 px += path_textbox->get_w() + 5;
528 path_recent->reposition_window(px, y);
529 px += path_recent->get_w() + 8;
530 path_button->reposition_window(px, y);
531 y += path_textbox->get_h() + 10;
534 format_title->reposition_window(x, y);
536 format_text->reposition_window(x, y);
537 x += format_text->get_w();
538 format_button->reposition_window(x, y);
541 y += format_button->get_h() + 10;
545 audio_title->reposition_window(x, y);
547 aparams_button->reposition_window(x, y);
548 x += aparams_button->get_w() + 10;
549 if(prompt_audio) audio_switch->reposition_window(x, y);
552 y += aparams_button->get_h() + 10;
553 if(prompt_audio_channels)
555 channels_title->reposition_window(x, y);
557 channels_button->reposition_window(x, y);
558 x += channels_button->get_w() + 5;
559 channels_tumbler->reposition_window(x, y);
560 y += channels_button->get_h() + 20;
568 video_title->reposition_window(x, y);
570 if(prompt_video_compression)
572 vparams_button->reposition_window(x, y);
573 x += vparams_button->get_w() + 10;
578 video_switch->reposition_window(x, y);
579 y += video_switch->get_h();
583 y += vparams_button->get_h();
592 multiple_files->reposition_window(x, y);
593 y += multiple_files->get_h() + 10;
600 int FormatTools::set_audio_options()
602 // if(video_driver == CAPTURE_DVB)
607 if(!aparams_thread->running())
609 aparams_thread->start();
613 aparams_thread->file->raise_window();
618 int FormatTools::set_video_options()
620 // if(video_driver == CAPTURE_DVB)
625 if(!vparams_thread->running())
627 vparams_thread->start();
631 vparams_thread->file->raise_window();
641 FormatAParams::FormatAParams(MWindow *mwindow, FormatTools *format, int x, int y)
642 : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
644 this->format = format;
645 set_tooltip(_("Configure audio compression"));
648 FormatAParams::~FormatAParams()
652 int FormatAParams::handle_event()
654 format->set_audio_options();
662 FormatVParams::FormatVParams(MWindow *mwindow, FormatTools *format, int x, int y)
663 : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
665 this->format = format;
666 set_tooltip(_("Configure video compression"));
669 FormatVParams::~FormatVParams()
673 int FormatVParams::handle_event()
675 format->set_video_options();
683 FormatAThread::FormatAThread(FormatTools *format)
686 this->format = format;
691 FormatAThread::~FormatAThread()
698 void FormatAThread::start()
706 void FormatAThread::run()
708 file->get_options(format, 1, 0);
714 FormatVThread::FormatVThread(FormatTools *format)
717 this->format = format;
722 FormatVThread::~FormatVThread()
729 void FormatVThread::start()
736 void FormatVThread::run()
738 file->get_options(format, 0, 1);
745 FormatPathText::FormatPathText(int x, int y, FormatTools *format)
746 : BC_TextBox(x, y, format->w - x -
747 2*format->mwindow->theme->get_image_set("wrench")[0]->get_w() - 20, 1,
750 this->format = format;
753 FormatPathText::~FormatPathText()
756 int FormatPathText::handle_event()
759 calculate_suggestions(format->file_entries);
763 strcpy(format->asset->path, get_text());
764 format->handle_event();
771 FormatAudio::FormatAudio(int x, int y, FormatTools *format, int default_)
775 (char*)(format->recording ? _("Record audio tracks") : _("Render audio tracks")))
777 this->format = format;
780 FormatAudio::~FormatAudio() {}
781 int FormatAudio::handle_event()
783 format->asset->audio_data = get_value();
788 FormatVideo::FormatVideo(int x, int y, FormatTools *format, int default_)
792 (char*)(format->recording ? _("Record video tracks") : _("Render video tracks")))
794 this->format = format;
797 FormatVideo::~FormatVideo() {}
798 int FormatVideo::handle_event()
800 format->asset->video_data = get_value();
807 FormatFormat::FormatFormat(int x, int y, FormatTools *format)
808 : FormatPopup(format->plugindb, x, y, format->use_brender)
810 this->format = format;
813 FormatFormat::~FormatFormat()
817 int FormatFormat::handle_event()
819 BC_ListBoxItem *selection = get_selection(0, 0);
821 int new_format = File::strtoformat(format->plugindb, get_selection(0, 0)->get_text());
822 // if(new_format != format->asset->format)
824 Asset *asset = format->asset;
825 asset->format = new_format;
826 asset->audio_data = File::supports_audio(asset->format);
827 asset->video_data = File::supports_video(asset->format);
828 asset->ff_audio_options[0] = 0;
829 asset->ff_video_options[0] = 0;
830 format->format_text->update(selection->get_text());
831 format->update_extension();
832 format->close_format_windows();
833 if (format->path_recent) format->path_recent->
834 load_items(File::formattostr(format->asset->format));
835 format->update_format();
842 FormatFFMPEG::FormatFFMPEG(int x, int y, FormatTools *format)
843 : FFMPEGPopup(format->plugindb, x, y)
845 this->format = format;
848 FormatFFMPEG::~FormatFFMPEG()
852 int FormatFFMPEG::handle_event()
854 BC_ListBoxItem *selection = get_selection(0, 0);
856 char *text = get_selection(0, 0)->get_text();
857 format->ffmpeg_type->update(text);
858 format->asset->ff_audio_options[0] = 0;
859 format->asset->ff_video_options[0] = 0;
860 FFMPEG::set_asset_format(format->asset, text);
861 format->update_extension();
862 format->close_format_windows();
863 format->update_format();
871 FormatChannels::FormatChannels(int x, int y, FormatTools *format)
872 : BC_TextBox(x, y, 100, 1, format->asset->channels)
874 this->format = format;
877 FormatChannels::~FormatChannels()
881 int FormatChannels::handle_event()
883 format->asset->channels = atol(get_text());
888 FormatToTracks::FormatToTracks(int x, int y, int *output)
889 : BC_CheckBox(x, y, *output, _("Overwrite project with output"))
891 this->output = output;
894 FormatToTracks::~FormatToTracks()
898 int FormatToTracks::handle_event()
900 *output = get_value();
905 FormatMultiple::FormatMultiple(MWindow *mwindow, int x, int y, int *output)
908 (*output == FILE_PER_LABEL) || (*output == FILE_PER_LABEL_FARM),
909 _("Create new file at each label"))
911 this->output = output;
912 this->mwindow = mwindow;
915 FormatMultiple::~FormatMultiple()
919 int FormatMultiple::handle_event()
923 if(mwindow->preferences->use_renderfarm)
924 *output = FILE_PER_LABEL_FARM;
926 *output = FILE_PER_LABEL;
930 if(mwindow->preferences->use_renderfarm)
931 *output = SINGLE_PASS_FARM;
933 *output = SINGLE_PASS;
938 void FormatMultiple::update(int *output)
940 this->output = output;
941 if(*output == FILE_PER_LABEL_FARM ||
942 *output ==FILE_PER_LABEL)