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;
182 window->add_subwindow(path_textbox = new FormatPathText(x, y, this));
183 x += path_textbox->get_w() + 5;
184 path_recent = new BC_RecentList("PATH", mwindow->defaults,
185 path_textbox, 10, x, y, 300, 100);
186 window->add_subwindow(path_recent);
187 path_recent->load_items(File::formattostr(asset->format));
188 x += path_recent->get_w() + 8;
189 window->add_subwindow(path_button = new BrowseButton(
190 mwindow, window, path_textbox, x, y, asset->path,
191 _("Output to file"), _("Select a file to write to:"), 0));
195 // w = x + path_button->get_w() + 5;
196 x -= path_textbox->get_w() + 5;
197 y += path_textbox->get_h() + 10;
206 window->add_subwindow(format_title = new BC_Title(x, y, _("File Format:")));
208 window->add_subwindow(format_text = new BC_TextBox(x, y, 180, 1,
209 File::formattostr(asset->format)));
210 x += format_text->get_w();
211 //printf("FormatTools::create_objects %d %p\n", __LINE__, window);
212 window->add_subwindow(format_button = new FormatFormat(x, y, this));
213 format_button->create_objects();
214 x += format_button->get_w() + 5;
215 window->add_subwindow(ffmpeg_type = new FFMpegType(x, y, 50, 1, asset->fformat));
216 FFMPEG::set_asset_format(asset, asset->fformat);
217 x += ffmpeg_type->get_w();
218 window->add_subwindow(format_ffmpeg = new FormatFFMPEG(x, y, this));
219 format_ffmpeg->create_objects();
221 y += format_button->get_h() + 10;
224 window->add_subwindow(audio_title = new BC_Title(x, y, _("Audio:"), LARGEFONT, BC_WindowBase::get_resources()->audiovideo_color));
226 window->add_subwindow(aparams_button = new FormatAParams(mwindow, this, x, y));
227 x += aparams_button->get_w() + 10;
230 window->add_subwindow(audio_switch = new FormatAudio(x, y, this, asset->audio_data));
234 y += aparams_button->get_h() + 10;
236 // Audio channels only used for recording.
237 // if(prompt_audio_channels)
239 // window->add_subwindow(channels_title = new BC_Title(x, y, _("Number of audio channels to record:")));
241 // window->add_subwindow(channels_button = new FormatChannels(x, y, this));
242 // x += channels_button->get_w() + 5;
243 // window->add_subwindow(channels_tumbler = new BC_ITumbler(channels_button, 1, MAXCHANNELS, x, y));
244 // y += channels_button->get_h() + 20;
248 //printf("FormatTools::create_objects 6\n");
249 aparams_thread = new FormatAThread(this);
252 //printf("FormatTools::create_objects 7\n");
255 if(horizontal_layout && do_audio){
260 //printf("FormatTools::create_objects 8\n");
261 window->add_subwindow(video_title = new BC_Title(x, y, _("Video:"), LARGEFONT, BC_WindowBase::get_resources()->audiovideo_color));
263 if(prompt_video_compression)
265 window->add_subwindow(vparams_button = new FormatVParams(mwindow, this, x, y));
266 x += vparams_button->get_w() + 10;
269 //printf("FormatTools::create_objects 9\n");
272 window->add_subwindow(video_switch = new FormatVideo(x, y, this, asset->video_data));
273 y += video_switch->get_h();
277 y += vparams_button->get_h();
280 //printf("FormatTools::create_objects 10\n");
282 vparams_thread = new FormatVThread(this);
285 //printf("FormatTools::create_objects 11\n");
290 window->add_subwindow(multiple_files = new FormatMultiple(mwindow, x, y, strategy));
291 y += multiple_files->get_h() + 10;
294 //printf("FormatTools::create_objects 12\n");
300 void FormatTools::update_driver(int driver)
302 this->video_driver = driver;
304 locked_compressor = 0;
308 case VIDEO4LINUX2MPEG:
309 // Just give the user information about how the stream is going to be
310 // stored but don't change the asset.
311 // Want to be able to revert to user settings.
312 if(asset->format == FILE_MPEG) break;
313 asset->format = FILE_MPEG;
314 format_text->update(File::formattostr(asset->format));
315 asset->audio_data = 1;
316 asset->video_data = 1;
317 audio_switch->update(1);
318 video_switch->update(1);
321 case CAPTURE_IEC61883:
322 case CAPTURE_FIREWIRE:
325 case VIDEO4LINUX2JPEG:
326 case CAPTURE_JPEG_WEBCAM:
327 asset->format = FILE_FFMPEG;
328 format_text->update(File::formattostr(asset->format));
331 case CAPTURE_IEC61883:
332 case CAPTURE_FIREWIRE:
333 locked_compressor = (char*)CODEC_TAG_DVSD;
338 case VIDEO4LINUX2JPEG:
339 locked_compressor = (char*)CODEC_TAG_MJPEG;
342 case CAPTURE_JPEG_WEBCAM:
343 locked_compressor = (char*)CODEC_TAG_JPEG;
346 if( locked_compressor )
347 strcpy(asset->vcodec, locked_compressor);
349 audio_switch->update(asset->audio_data);
350 video_switch->update(asset->video_data);
354 format_text->update(File::formattostr(asset->format));
355 audio_switch->update(asset->audio_data);
356 video_switch->update(asset->video_data);
359 close_format_windows();
363 void FormatTools::update_format()
365 if( do_audio && prompt_audio && audio_switch ) {
366 audio_switch->update(asset->audio_data);
367 if( !asset->audio_data )
368 audio_switch->disable();
370 audio_switch->enable();
372 if( do_video && prompt_video && video_switch ) {
373 video_switch->update(asset->video_data);
374 if( !asset->video_data )
375 video_switch->disable();
377 video_switch->enable();
379 if( asset->format == FILE_FFMPEG ) {
381 format_ffmpeg->show();
385 format_ffmpeg->hide();
389 int FormatTools::handle_event()
394 Asset* FormatTools::get_asset()
399 void FormatTools::update_extension()
401 const char *extension = File::get_tag(asset->format);
402 // split multiple extensions
403 ArrayList<const char*> extensions;
404 int len = !extension ? -1 : strlen(extension);
405 const char *extension_ptr = extension;
406 for(int i = 0; i <= len; i++)
408 if(extension[i] == '/' || extension[i] == 0)
410 extensions.append(extension_ptr);
411 extension_ptr = extension + i + 1;
415 if(extensions.size())
417 char *ptr = strrchr(asset->path, '.');
420 ptr = asset->path + strlen(asset->path);
425 // test for equivalent extension
426 int need_extension = 1;
427 //int extension_len = 0;
428 for(int i = 0; i < extensions.size() && need_extension; i++)
431 extension_ptr = extensions.get(i);
434 while(*ptr1 != 0 && *extension_ptr != 0 && *extension_ptr != '/')
436 if(tolower(*ptr1) != tolower(*extension_ptr))
446 *extension_ptr != 0 &&
447 *extension_ptr != '/')
451 //printf("FormatTools::update_extension %d %d\n", __LINE__, need_extension);
456 extension_ptr = asset->format != FILE_FFMPEG ?
457 extensions.get(0) : asset->fformat;
458 while(*extension_ptr != 0 && *extension_ptr != '/')
459 *ptr1++ = *extension_ptr++;
463 int character1 = ptr - asset->path;
464 int character2 = strlen(asset->path);
465 // *(asset->path + character2) = 0;
468 path_textbox->update(asset->path);
469 path_textbox->set_selection(character1, character2, character2);
474 void FormatTools::update(Asset *asset, int *strategy)
477 this->strategy = strategy;
480 path_textbox->update(asset->path);
481 format_text->update(File::formattostr(plugindb, asset->format));
482 if(do_audio && prompt_audio && audio_switch)
483 audio_switch->update(asset->audio_data);
484 if(do_video && prompt_video && video_switch)
485 video_switch->update(asset->video_data);
488 multiple_files->update(strategy);
490 close_format_windows();
493 void FormatTools::close_format_windows()
495 // This is done in ~file
496 if( aparams_thread ) {
497 if( aparams_thread->running() )
498 aparams_thread->file->close_window();
499 aparams_thread->join();
501 if( vparams_thread ) {
502 if( vparams_thread->running() )
503 vparams_thread->file->close_window();
504 vparams_thread->join();
508 int FormatTools::get_w()
513 void FormatTools::set_w(int w)
518 void FormatTools::reposition_window(int &init_x, int &init_y)
525 path_textbox->reposition_window(x, y);
526 x += path_textbox->get_w() + 5;
527 path_button->reposition_window(x, y);
528 x -= path_textbox->get_w() + 5;
532 format_title->reposition_window(x, y);
534 format_text->reposition_window(x, y);
535 x += format_text->get_w();
536 format_button->reposition_window(x, y);
539 y += format_button->get_h() + 10;
543 audio_title->reposition_window(x, y);
545 aparams_button->reposition_window(x, y);
546 x += aparams_button->get_w() + 10;
547 if(prompt_audio) audio_switch->reposition_window(x, y);
550 y += aparams_button->get_h() + 20;
551 if(prompt_audio_channels)
553 channels_title->reposition_window(x, y);
555 channels_button->reposition_window(x, y);
556 x += channels_button->get_w() + 5;
557 channels_tumbler->reposition_window(x, y);
558 y += channels_button->get_h() + 20;
566 video_title->reposition_window(x, y);
568 if(prompt_video_compression)
570 vparams_button->reposition_window(x, y);
571 x += vparams_button->get_w() + 10;
576 video_switch->reposition_window(x, y);
577 y += video_switch->get_h();
581 y += vparams_button->get_h();
590 multiple_files->reposition_window(x, y);
591 y += multiple_files->get_h() + 10;
598 int FormatTools::set_audio_options()
600 // if(video_driver == CAPTURE_DVB)
605 if(!aparams_thread->running())
607 aparams_thread->start();
611 aparams_thread->file->raise_window();
616 int FormatTools::set_video_options()
618 // if(video_driver == CAPTURE_DVB)
623 if(!vparams_thread->running())
625 vparams_thread->start();
629 vparams_thread->file->raise_window();
639 FormatAParams::FormatAParams(MWindow *mwindow, FormatTools *format, int x, int y)
640 : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
642 this->format = format;
643 set_tooltip(_("Configure audio compression"));
646 FormatAParams::~FormatAParams()
650 int FormatAParams::handle_event()
652 format->set_audio_options();
660 FormatVParams::FormatVParams(MWindow *mwindow, FormatTools *format, int x, int y)
661 : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
663 this->format = format;
664 set_tooltip(_("Configure video compression"));
667 FormatVParams::~FormatVParams()
671 int FormatVParams::handle_event()
673 format->set_video_options();
681 FormatAThread::FormatAThread(FormatTools *format)
684 this->format = format;
689 FormatAThread::~FormatAThread()
696 void FormatAThread::start()
704 void FormatAThread::run()
706 file->get_options(format, 1, 0);
712 FormatVThread::FormatVThread(FormatTools *format)
715 this->format = format;
720 FormatVThread::~FormatVThread()
727 void FormatVThread::start()
734 void FormatVThread::run()
736 file->get_options(format, 0, 1);
743 FormatPathText::FormatPathText(int x, int y, FormatTools *format)
744 : BC_TextBox(x, y, format->w - x -
745 2*format->mwindow->theme->get_image_set("wrench")[0]->get_w() - 20, 1,
748 this->format = format;
751 FormatPathText::~FormatPathText()
754 int FormatPathText::handle_event()
757 calculate_suggestions(format->file_entries);
761 strcpy(format->asset->path, get_text());
762 format->handle_event();
769 FormatAudio::FormatAudio(int x, int y, FormatTools *format, int default_)
773 (char*)(format->recording ? _("Record audio tracks") : _("Render audio tracks")))
775 this->format = format;
778 FormatAudio::~FormatAudio() {}
779 int FormatAudio::handle_event()
781 format->asset->audio_data = get_value();
786 FormatVideo::FormatVideo(int x, int y, FormatTools *format, int default_)
790 (char*)(format->recording ? _("Record video tracks") : _("Render video tracks")))
792 this->format = format;
795 FormatVideo::~FormatVideo() {}
796 int FormatVideo::handle_event()
798 format->asset->video_data = get_value();
805 FormatFormat::FormatFormat(int x, int y, FormatTools *format)
806 : FormatPopup(format->plugindb, x, y, format->use_brender)
808 this->format = format;
811 FormatFormat::~FormatFormat()
815 int FormatFormat::handle_event()
817 BC_ListBoxItem *selection = get_selection(0, 0);
819 int new_format = File::strtoformat(format->plugindb, get_selection(0, 0)->get_text());
820 // if(new_format != format->asset->format)
822 Asset *asset = format->asset;
823 asset->format = new_format;
824 asset->audio_data = File::supports_audio(asset->format);
825 asset->video_data = File::supports_video(asset->format);
826 asset->ff_audio_options[0] = 0;
827 asset->ff_video_options[0] = 0;
828 format->format_text->update(selection->get_text());
829 format->update_extension();
830 format->close_format_windows();
831 if (format->path_recent) format->path_recent->
832 load_items(File::formattostr(format->asset->format));
833 format->update_format();
840 FormatFFMPEG::FormatFFMPEG(int x, int y, FormatTools *format)
841 : FFMPEGPopup(format->plugindb, x, y)
843 this->format = format;
846 FormatFFMPEG::~FormatFFMPEG()
850 int FormatFFMPEG::handle_event()
852 BC_ListBoxItem *selection = get_selection(0, 0);
854 char *text = get_selection(0, 0)->get_text();
855 format->ffmpeg_type->update(text);
856 format->asset->ff_audio_options[0] = 0;
857 format->asset->ff_video_options[0] = 0;
858 FFMPEG::set_asset_format(format->asset, text);
859 format->update_extension();
860 format->close_format_windows();
861 format->update_format();
869 FormatChannels::FormatChannels(int x, int y, FormatTools *format)
870 : BC_TextBox(x, y, 100, 1, format->asset->channels)
872 this->format = format;
875 FormatChannels::~FormatChannels()
879 int FormatChannels::handle_event()
881 format->asset->channels = atol(get_text());
886 FormatToTracks::FormatToTracks(int x, int y, int *output)
887 : BC_CheckBox(x, y, *output, _("Overwrite project with output"))
889 this->output = output;
892 FormatToTracks::~FormatToTracks()
896 int FormatToTracks::handle_event()
898 *output = get_value();
903 FormatMultiple::FormatMultiple(MWindow *mwindow, int x, int y, int *output)
906 (*output == FILE_PER_LABEL) || (*output == FILE_PER_LABEL_FARM),
907 _("Create new file at each label"))
909 this->output = output;
910 this->mwindow = mwindow;
913 FormatMultiple::~FormatMultiple()
917 int FormatMultiple::handle_event()
921 if(mwindow->preferences->use_renderfarm)
922 *output = FILE_PER_LABEL_FARM;
924 *output = FILE_PER_LABEL;
928 if(mwindow->preferences->use_renderfarm)
929 *output = SINGLE_PASS_FARM;
931 *output = SINGLE_PASS;
936 void FormatMultiple::update(int *output)
938 this->output = output;
939 if(*output == FILE_PER_LABEL_FARM ||
940 *output ==FILE_PER_LABEL)