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"
30 #include "maxchannels.h"
32 #include "preferences.h"
33 #include "quicktime.h"
35 #include "videodevice.inc"
41 FormatTools::FormatTools(MWindow *mwindow,
42 BC_WindowBase *window,
45 this->mwindow = mwindow;
46 this->window = window;
48 this->plugindb = mwindow->plugindb;
77 prompt_audio_channels = 0;
79 prompt_video_compression = 0;
81 locked_compressor = 0;
85 FormatTools::~FormatTools()
95 if(aparams_button) delete aparams_button;
97 if(vparams_button) delete vparams_button;
99 if(aparams_thread) delete aparams_thread;
101 if(vparams_thread) delete vparams_thread;
103 if(channels_tumbler) delete channels_tumbler;
107 file_entries->remove_all_objects();
112 void FormatTools::create_objects(int &init_x,
114 int do_audio, // Include support for audio
115 int do_video, // Include support for video
116 int prompt_audio, // Include checkbox for audio
118 int prompt_audio_channels,
119 int prompt_video_compression,
120 char *locked_compressor,
128 this->locked_compressor = locked_compressor;
129 this->recording = recording;
130 this->use_brender = brender;
131 this->do_audio = do_audio;
132 this->do_video = do_video;
133 this->prompt_audio = prompt_audio;
134 this->prompt_audio_channels = prompt_audio_channels;
135 this->prompt_video = prompt_video;
136 this->prompt_video_compression = prompt_video_compression;
137 this->strategy = strategy;
140 file_entries = new ArrayList<BC_ListBoxItem*>;
142 char string[BCTEXTLEN];
143 // Load current directory
144 fs.update(getcwd(string, BCTEXTLEN));
145 for(int i = 0; i < fs.total_files(); i++)
147 file_entries->append(
149 fs.get_entry(i)->get_name()));
152 //printf("FormatTools::create_objects 1\n");
154 // Modify strategy depending on render farm
157 if(mwindow->preferences->use_renderfarm)
159 if(*strategy == FILE_PER_LABEL)
160 *strategy = FILE_PER_LABEL_FARM;
162 if(*strategy == SINGLE_PASS)
163 *strategy = SINGLE_PASS_FARM;
167 if(*strategy == FILE_PER_LABEL_FARM)
168 *strategy = FILE_PER_LABEL;
170 if(*strategy == SINGLE_PASS_FARM)
171 *strategy = SINGLE_PASS;
177 window->add_subwindow(path_textbox = new FormatPathText(x, y, this));
178 x += path_textbox->get_w() + 5;
179 window->add_subwindow(path_button = new BrowseButton(
187 _("Select a file to write to:"),
192 // w = x + path_button->get_w() + 5;
193 x -= path_textbox->get_w() + 5;
202 window->add_subwindow(format_title = new BC_Title(x, y, _("File Format:")));
204 window->add_subwindow(format_text = new BC_TextBox(x, y, 180, 1,
205 File::formattostr(asset->format)));
206 x += format_text->get_w();
207 //printf("FormatTools::create_objects %d %p\n", __LINE__, window);
208 window->add_subwindow(format_button = new FormatFormat(x, y, this));
209 format_button->create_objects();
210 x += format_button->get_w() + 5;
211 window->add_subwindow(ffmpeg_type = new FFMpegType(x, y, 50, 1, asset->fformat));
212 x += ffmpeg_type->get_w();
213 window->add_subwindow(format_ffmpeg = new FormatFFMPEG(x, y, this));
214 format_ffmpeg->create_objects();
217 y += format_button->get_h() + 10;
220 window->add_subwindow(audio_title = new BC_Title(x, y, _("Audio:"), LARGEFONT, RED));
222 window->add_subwindow(aparams_button = new FormatAParams(mwindow, this, x, y));
223 x += aparams_button->get_w() + 10;
226 window->add_subwindow(audio_switch = new FormatAudio(x, y, this, asset->audio_data));
229 y += aparams_button->get_h() + 10;
231 // Audio channels only used for recording.
232 // if(prompt_audio_channels)
234 // window->add_subwindow(channels_title = new BC_Title(x, y, _("Number of audio channels to record:")));
236 // window->add_subwindow(channels_button = new FormatChannels(x, y, this));
237 // x += channels_button->get_w() + 5;
238 // window->add_subwindow(channels_tumbler = new BC_ITumbler(channels_button, 1, MAXCHANNELS, x, y));
239 // y += channels_button->get_h() + 20;
243 //printf("FormatTools::create_objects 6\n");
244 aparams_thread = new FormatAThread(this);
247 //printf("FormatTools::create_objects 7\n");
251 //printf("FormatTools::create_objects 8\n");
252 window->add_subwindow(video_title = new BC_Title(x, y, _("Video:"), LARGEFONT, RED));
254 if(prompt_video_compression)
256 window->add_subwindow(vparams_button = new FormatVParams(mwindow, this, x, y));
257 x += vparams_button->get_w() + 10;
260 //printf("FormatTools::create_objects 9\n");
263 window->add_subwindow(video_switch = new FormatVideo(x, y, this, asset->video_data));
264 y += video_switch->get_h();
268 y += vparams_button->get_h();
271 //printf("FormatTools::create_objects 10\n");
273 vparams_thread = new FormatVThread(this);
276 //printf("FormatTools::create_objects 11\n");
281 window->add_subwindow(multiple_files = new FormatMultiple(mwindow, x, y, strategy));
282 y += multiple_files->get_h() + 10;
285 //printf("FormatTools::create_objects 12\n");
291 void FormatTools::update_driver(int driver)
293 this->video_driver = driver;
298 case VIDEO4LINUX2MPEG:
299 // Just give the user information about how the stream is going to be
300 // stored but don't change the asset.
301 // Want to be able to revert to user settings.
302 if(asset->format != FILE_MPEG)
304 format_text->update(_("MPEG stream"));
305 asset->format = FILE_MPEG;
307 locked_compressor = 0;
308 audio_switch->update(1);
309 video_switch->update(1);
312 case CAPTURE_IEC61883:
313 case CAPTURE_FIREWIRE:
315 case VIDEO4LINUX2JPEG:
316 case CAPTURE_JPEG_WEBCAM:
317 if(asset->format != FILE_AVI &&
318 asset->format != FILE_MOV)
320 format_text->update(MOV_NAME);
321 asset->format = FILE_MOV;
324 format_text->update(File::formattostr(asset->format));
328 case CAPTURE_IEC61883:
329 case CAPTURE_FIREWIRE:
330 locked_compressor = (char*)QUICKTIME_DVSD;
331 strcpy(asset->vcodec, QUICKTIME_DVSD);
335 case VIDEO4LINUX2JPEG:
336 locked_compressor = (char*)QUICKTIME_MJPA;
337 strcpy(asset->vcodec, QUICKTIME_MJPA);
340 case CAPTURE_JPEG_WEBCAM:
341 locked_compressor = (char*)QUICKTIME_JPEG;
342 strcpy(asset->vcodec, QUICKTIME_JPEG);
346 audio_switch->update(asset->audio_data);
347 video_switch->update(asset->video_data);
355 format_text->update(File::formattostr(asset->format));
356 locked_compressor = 0;
357 audio_switch->update(asset->audio_data);
358 video_switch->update(asset->video_data);
361 close_format_windows();
364 void FormatTools::update_format()
366 if( do_audio && prompt_audio && audio_switch ) {
367 audio_switch->update(asset->audio_data);
368 if( !asset->audio_data )
369 audio_switch->disable();
371 audio_switch->enable();
373 if( do_video && prompt_video && video_switch ) {
374 video_switch->update(asset->video_data);
375 if( !asset->video_data )
376 video_switch->disable();
378 video_switch->enable();
380 if( asset->format == FILE_FFMPEG ) {
382 format_ffmpeg->show();
386 format_ffmpeg->hide();
390 int FormatTools::handle_event()
395 Asset* FormatTools::get_asset()
400 void FormatTools::update_extension()
402 const char *extension = File::get_tag(asset->format);
403 // split multiple extensions
404 ArrayList<const char*> extensions;
405 int len = strlen(extension);
406 const char *extension_ptr = extension;
407 for(int i = 0; i <= len; i++)
409 if(extension[i] == '/' || extension[i] == 0)
411 extensions.append(extension_ptr);
412 extension_ptr = extension + i + 1;
416 if(extensions.size())
418 char *ptr = strrchr(asset->path, '.');
421 ptr = asset->path + strlen(asset->path);
427 // test for equivalent extension
428 int need_extension = 1;
429 //int extension_len = 0;
430 for(int i = 0; i < extensions.size() && need_extension; i++)
433 extension_ptr = extensions.get(i);
436 while(*ptr1 != 0 && *extension_ptr != 0 && *extension_ptr != '/')
438 if(tolower(*ptr1) != tolower(*extension_ptr))
448 *extension_ptr != 0 &&
449 *extension_ptr != '/')
453 //printf("FormatTools::update_extension %d %d\n", __LINE__, need_extension);
458 extension_ptr = asset->format != FILE_FFMPEG ?
459 extensions.get(0) : asset->fformat;
460 while(*extension_ptr != 0 && *extension_ptr != '/')
461 *ptr1++ = *extension_ptr++;
465 int character1 = ptr - asset->path;
466 int character2 = strlen(asset->path);
467 // *(asset->path + character2) = 0;
470 path_textbox->update(asset->path);
471 path_textbox->set_selection(character1, character2, character2);
476 void FormatTools::update(Asset *asset, int *strategy)
479 this->strategy = strategy;
482 path_textbox->update(asset->path);
483 format_text->update(File::formattostr(plugindb, asset->format));
484 if(do_audio && prompt_audio && audio_switch)
485 audio_switch->update(asset->audio_data);
486 if(do_video && prompt_video && video_switch)
487 video_switch->update(asset->video_data);
490 multiple_files->update(strategy);
492 close_format_windows();
495 void FormatTools::close_format_windows()
497 // This is done in ~file
498 if(aparams_thread && aparams_thread->running())
500 aparams_thread->file->close_window();
501 aparams_thread->join();
503 if(vparams_thread && vparams_thread->running())
505 vparams_thread->file->close_window();
506 vparams_thread->join();
510 int FormatTools::get_w()
515 void FormatTools::set_w(int w)
520 void FormatTools::reposition_window(int &init_x, int &init_y)
527 path_textbox->reposition_window(x, y);
528 x += path_textbox->get_w() + 5;
529 path_button->reposition_window(x, y);
530 x -= path_textbox->get_w() + 5;
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() + 20;
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)
749 format->mwindow->theme->get_image_set("wrench")[0]->get_w() -
754 this->format = format;
757 FormatPathText::~FormatPathText()
760 int FormatPathText::handle_event()
763 calculate_suggestions(format->file_entries);
767 strcpy(format->asset->path, get_text());
768 format->handle_event();
776 FormatAudio::FormatAudio(int x, int y, FormatTools *format, int default_)
780 (char*)(format->recording ? _("Record audio tracks") : _("Render audio tracks")))
782 this->format = format;
785 FormatAudio::~FormatAudio() {}
786 int FormatAudio::handle_event()
788 format->asset->audio_data = get_value();
793 FormatVideo::FormatVideo(int x, int y, FormatTools *format, int default_)
797 (char*)(format->recording ? _("Record video tracks") : _("Render video tracks")))
799 this->format = format;
802 FormatVideo::~FormatVideo() {}
803 int FormatVideo::handle_event()
805 format->asset->video_data = get_value();
812 FormatFormat::FormatFormat(int x, int y, FormatTools *format)
813 : FormatPopup(format->plugindb, x, y, format->use_brender)
815 this->format = format;
818 FormatFormat::~FormatFormat()
822 int FormatFormat::handle_event()
824 BC_ListBoxItem *selection = get_selection(0, 0);
826 int new_format = File::strtoformat(format->plugindb, get_selection(0, 0)->get_text());
827 // if(new_format != format->asset->format)
829 Asset *asset = format->asset;
830 asset->format = new_format;
831 asset->audio_data = File::supports_audio(asset->format);
832 asset->video_data = File::supports_video(asset->format);
833 format->format_text->update(selection->get_text());
834 format->update_extension();
835 format->close_format_windows();
836 format->update_format();
843 FormatFFMPEG::FormatFFMPEG(int x, int y, FormatTools *format)
844 : FFMPEGPopup(format->plugindb, x, y)
846 this->format = format;
849 FormatFFMPEG::~FormatFFMPEG()
853 int FormatFFMPEG::load_defaults(const char *path, const char *type,
854 char *codec, char *codec_options, int len)
856 char default_file[BCTEXTLEN];
857 FFMPEG::set_option_path(default_file, "%s/%s.dfl", path, type);
858 FILE *fp = fopen(default_file,"r");
860 fgets(codec, BCSTRLEN, fp);
862 while( *cp && *cp!='\n' ) ++cp;
864 while( len > 0 && fgets(codec_options, len, fp) ) {
865 int n = strlen(codec_options);
866 codec_options += n; len -= n;
869 FFMPEG::set_option_path(default_file, "%s/%s", path, codec);
870 return FFMPEG::load_options(default_file, codec_options, len);
873 int FormatFFMPEG::handle_event()
875 BC_ListBoxItem *selection = get_selection(0, 0);
877 char *text = get_selection(0, 0)->get_text();
878 format->ffmpeg_type->update(text);
879 Asset *asset = format->asset;
880 strcpy(asset->fformat, text);
881 strcpy(asset->ff_audio_options, "");
882 strcpy(asset->ff_video_options, "");
883 asset->audio_data = !load_defaults("audio", text, asset->acodec,
884 asset->ff_audio_options, sizeof(asset->ff_audio_options));
885 asset->video_data = !load_defaults("video", text, asset->vcodec,
886 asset->ff_video_options, sizeof(asset->ff_video_options));
887 format->update_extension();
888 format->close_format_windows();
889 format->update_format();
897 FormatChannels::FormatChannels(int x, int y, FormatTools *format)
898 : BC_TextBox(x, y, 100, 1, format->asset->channels)
900 this->format = format;
903 FormatChannels::~FormatChannels()
907 int FormatChannels::handle_event()
909 format->asset->channels = atol(get_text());
914 FormatToTracks::FormatToTracks(int x, int y, int *output)
915 : BC_CheckBox(x, y, *output, _("Overwrite project with output"))
917 this->output = output;
920 FormatToTracks::~FormatToTracks()
924 int FormatToTracks::handle_event()
926 *output = get_value();
931 FormatMultiple::FormatMultiple(MWindow *mwindow, int x, int y, int *output)
934 (*output == FILE_PER_LABEL) || (*output == FILE_PER_LABEL_FARM),
935 _("Create new file at each label"))
937 this->output = output;
938 this->mwindow = mwindow;
941 FormatMultiple::~FormatMultiple()
945 int FormatMultiple::handle_event()
949 if(mwindow->preferences->use_renderfarm)
950 *output = FILE_PER_LABEL_FARM;
952 *output = FILE_PER_LABEL;
956 if(mwindow->preferences->use_renderfarm)
957 *output = SINGLE_PASS_FARM;
959 *output = SINGLE_PASS;
964 void FormatMultiple::update(int *output)
966 this->output = output;
967 if(*output == FILE_PER_LABEL_FARM ||
968 *output ==FILE_PER_LABEL)