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;
61 FormatTools::~FormatTools()
71 if(aparams_button) delete aparams_button;
73 if(vparams_button) delete vparams_button;
75 if(aparams_thread) delete aparams_thread;
77 if(vparams_thread) delete vparams_thread;
79 if(channels_tumbler) delete channels_tumbler;
83 file_entries->remove_all_objects();
88 void FormatTools::create_objects(int &init_x,
90 int do_audio, // Include support for audio
91 int do_video, // Include support for video
92 int prompt_audio, // Include checkbox for audio
94 int prompt_audio_channels,
95 int prompt_video_compression,
96 char *locked_compressor,
104 this->locked_compressor = locked_compressor;
105 this->recording = recording;
106 this->use_brender = brender;
107 this->do_audio = do_audio;
108 this->do_video = do_video;
109 this->prompt_audio = prompt_audio;
110 this->prompt_audio_channels = prompt_audio_channels;
111 this->prompt_video = prompt_video;
112 this->prompt_video_compression = prompt_video_compression;
113 this->strategy = strategy;
116 file_entries = new ArrayList<BC_ListBoxItem*>;
118 char string[BCTEXTLEN];
119 // Load current directory
120 fs.update(getcwd(string, BCTEXTLEN));
121 for(int i = 0; i < fs.total_files(); i++)
123 file_entries->append(
125 fs.get_entry(i)->get_name()));
128 //printf("FormatTools::create_objects 1\n");
130 // Modify strategy depending on render farm
133 if(mwindow->preferences->use_renderfarm)
135 if(*strategy == FILE_PER_LABEL)
136 *strategy = FILE_PER_LABEL_FARM;
138 if(*strategy == SINGLE_PASS)
139 *strategy = SINGLE_PASS_FARM;
143 if(*strategy == FILE_PER_LABEL_FARM)
144 *strategy = FILE_PER_LABEL;
146 if(*strategy == SINGLE_PASS_FARM)
147 *strategy = SINGLE_PASS;
153 window->add_subwindow(path_textbox = new FormatPathText(x, y, this));
154 x += path_textbox->get_w() + 5;
155 window->add_subwindow(path_button = new BrowseButton(
163 _("Select a file to write to:"),
168 // w = x + path_button->get_w() + 5;
169 x -= path_textbox->get_w() + 5;
178 window->add_subwindow(format_title = new BC_Title(x, y, _("File Format:")));
180 window->add_subwindow(format_text = new BC_TextBox(x, y, 200, 1,
181 File::formattostr(asset->format)));
182 x += format_text->get_w();
183 //printf("FormatTools::create_objects %d %p\n", __LINE__, window);
184 window->add_subwindow(format_button = new FormatFormat(x, y, this));
185 format_button->create_objects();
188 y += format_button->get_h() + 10;
191 window->add_subwindow(audio_title = new BC_Title(x, y, _("Audio:"), LARGEFONT, RED));
193 window->add_subwindow(aparams_button = new FormatAParams(mwindow, this, x, y));
194 x += aparams_button->get_w() + 10;
197 window->add_subwindow(audio_switch = new FormatAudio(x, y, this, asset->audio_data));
200 y += aparams_button->get_h() + 10;
202 // Audio channels only used for recording.
203 // if(prompt_audio_channels)
205 // window->add_subwindow(channels_title = new BC_Title(x, y, _("Number of audio channels to record:")));
207 // window->add_subwindow(channels_button = new FormatChannels(x, y, this));
208 // x += channels_button->get_w() + 5;
209 // window->add_subwindow(channels_tumbler = new BC_ITumbler(channels_button, 1, MAXCHANNELS, x, y));
210 // y += channels_button->get_h() + 20;
214 //printf("FormatTools::create_objects 6\n");
215 aparams_thread = new FormatAThread(this);
218 //printf("FormatTools::create_objects 7\n");
222 //printf("FormatTools::create_objects 8\n");
223 window->add_subwindow(video_title = new BC_Title(x, y, _("Video:"), LARGEFONT, RED));
225 if(prompt_video_compression)
227 window->add_subwindow(vparams_button = new FormatVParams(mwindow, this, x, y));
228 x += vparams_button->get_w() + 10;
231 //printf("FormatTools::create_objects 9\n");
234 window->add_subwindow(video_switch = new FormatVideo(x, y, this, asset->video_data));
235 y += video_switch->get_h();
239 y += vparams_button->get_h();
242 //printf("FormatTools::create_objects 10\n");
244 vparams_thread = new FormatVThread(this);
247 //printf("FormatTools::create_objects 11\n");
252 window->add_subwindow(multiple_files = new FormatMultiple(mwindow, x, y, strategy));
253 y += multiple_files->get_h() + 10;
256 //printf("FormatTools::create_objects 12\n");
262 void FormatTools::update_driver(int driver)
264 this->video_driver = driver;
269 case VIDEO4LINUX2MPEG:
270 // Just give the user information about how the stream is going to be
271 // stored but don't change the asset.
272 // Want to be able to revert to user settings.
273 if(asset->format != FILE_MPEG)
275 format_text->update(_("MPEG stream"));
276 asset->format = FILE_MPEG;
278 locked_compressor = 0;
279 audio_switch->update(1);
280 video_switch->update(1);
283 case CAPTURE_IEC61883:
284 case CAPTURE_FIREWIRE:
286 case VIDEO4LINUX2JPEG:
287 case CAPTURE_JPEG_WEBCAM:
288 if(asset->format != FILE_AVI &&
289 asset->format != FILE_MOV)
291 format_text->update(MOV_NAME);
292 asset->format = FILE_MOV;
295 format_text->update(File::formattostr(asset->format));
299 case CAPTURE_IEC61883:
300 case CAPTURE_FIREWIRE:
301 locked_compressor = (char*)QUICKTIME_DVSD;
302 strcpy(asset->vcodec, QUICKTIME_DVSD);
306 case VIDEO4LINUX2JPEG:
307 locked_compressor = (char*)QUICKTIME_MJPA;
308 strcpy(asset->vcodec, QUICKTIME_MJPA);
311 case CAPTURE_JPEG_WEBCAM:
312 locked_compressor = (char*)QUICKTIME_JPEG;
313 strcpy(asset->vcodec, QUICKTIME_JPEG);
317 audio_switch->update(asset->audio_data);
318 video_switch->update(asset->video_data);
326 format_text->update(File::formattostr(asset->format));
327 locked_compressor = 0;
328 audio_switch->update(asset->audio_data);
329 video_switch->update(asset->video_data);
332 close_format_windows();
335 void FormatTools::update_format()
337 if( do_audio && audio_switch ) {
338 asset->audio_data = File::supports_audio(asset->format);
339 audio_switch->update(asset->audio_data);
340 if( !asset->audio_data )
341 audio_switch->disable();
343 audio_switch->enable();
345 if( do_video && video_switch ) {
346 asset->video_data = File::supports_video(asset->format);
347 video_switch->update(asset->video_data);
348 if( !asset->video_data )
349 video_switch->disable();
351 video_switch->enable();
355 int FormatTools::handle_event()
360 Asset* FormatTools::get_asset()
365 void FormatTools::update_extension()
367 const char *extension = File::get_tag(asset->format);
368 // split multiple extensions
369 ArrayList<const char*> extensions;
370 int len = strlen(extension);
371 const char *extension_ptr = extension;
372 for(int i = 0; i <= len; i++)
374 if(extension[i] == '/' || extension[i] == 0)
376 extensions.append(extension_ptr);
377 extension_ptr = extension + i + 1;
381 if(extensions.size())
383 char *ptr = strrchr(asset->path, '.');
386 ptr = asset->path + strlen(asset->path);
392 // test for equivalent extension
393 int need_extension = 1;
394 //int extension_len = 0;
395 for(int i = 0; i < extensions.size() && need_extension; i++)
398 extension_ptr = extensions.get(i);
401 while(*ptr1 != 0 && *extension_ptr != 0 && *extension_ptr != '/')
403 if(tolower(*ptr1) != tolower(*extension_ptr))
413 *extension_ptr != 0 &&
414 *extension_ptr != '/')
418 //printf("FormatTools::update_extension %d %d\n", __LINE__, need_extension);
423 extension_ptr = extensions.get(0);
424 while(*extension_ptr != 0 && *extension_ptr != '/')
425 *ptr1++ = *extension_ptr++;
429 int character1 = ptr - asset->path;
430 int character2 = strlen(asset->path);
431 // *(asset->path + character2) = 0;
434 path_textbox->update(asset->path);
435 path_textbox->set_selection(character1, character2, character2);
440 void FormatTools::update(Asset *asset, int *strategy)
443 this->strategy = strategy;
446 path_textbox->update(asset->path);
447 format_text->update(File::formattostr(plugindb, asset->format));
448 if(do_audio && audio_switch) audio_switch->update(asset->audio_data);
449 if(do_video && video_switch) video_switch->update(asset->video_data);
452 multiple_files->update(strategy);
454 close_format_windows();
457 void FormatTools::close_format_windows()
459 // This is done in ~file
460 if(aparams_thread && aparams_thread->running())
462 aparams_thread->file->close_window();
463 aparams_thread->join();
465 if(vparams_thread && vparams_thread->running())
467 vparams_thread->file->close_window();
468 vparams_thread->join();
472 int FormatTools::get_w()
477 void FormatTools::set_w(int w)
482 void FormatTools::reposition_window(int &init_x, int &init_y)
489 path_textbox->reposition_window(x, y);
490 x += path_textbox->get_w() + 5;
491 path_button->reposition_window(x, y);
492 x -= path_textbox->get_w() + 5;
496 format_title->reposition_window(x, y);
498 format_text->reposition_window(x, y);
499 x += format_text->get_w();
500 format_button->reposition_window(x, y);
503 y += format_button->get_h() + 10;
507 audio_title->reposition_window(x, y);
509 aparams_button->reposition_window(x, y);
510 x += aparams_button->get_w() + 10;
511 if(prompt_audio) audio_switch->reposition_window(x, y);
514 y += aparams_button->get_h() + 20;
515 if(prompt_audio_channels)
517 channels_title->reposition_window(x, y);
519 channels_button->reposition_window(x, y);
520 x += channels_button->get_w() + 5;
521 channels_tumbler->reposition_window(x, y);
522 y += channels_button->get_h() + 20;
530 video_title->reposition_window(x, y);
532 if(prompt_video_compression)
534 vparams_button->reposition_window(x, y);
535 x += vparams_button->get_w() + 10;
540 video_switch->reposition_window(x, y);
541 y += video_switch->get_h();
545 y += vparams_button->get_h();
554 multiple_files->reposition_window(x, y);
555 y += multiple_files->get_h() + 10;
562 int FormatTools::set_audio_options()
564 // if(video_driver == CAPTURE_DVB)
569 if(!aparams_thread->running())
571 aparams_thread->start();
575 aparams_thread->file->raise_window();
580 int FormatTools::set_video_options()
582 // if(video_driver == CAPTURE_DVB)
587 if(!vparams_thread->running())
589 vparams_thread->start();
593 vparams_thread->file->raise_window();
603 FormatAParams::FormatAParams(MWindow *mwindow, FormatTools *format, int x, int y)
604 : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
606 this->format = format;
607 set_tooltip(_("Configure audio compression"));
610 FormatAParams::~FormatAParams()
614 int FormatAParams::handle_event()
616 format->set_audio_options();
624 FormatVParams::FormatVParams(MWindow *mwindow, FormatTools *format, int x, int y)
625 : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
627 this->format = format;
628 set_tooltip(_("Configure video compression"));
631 FormatVParams::~FormatVParams()
635 int FormatVParams::handle_event()
637 format->set_video_options();
645 FormatAThread::FormatAThread(FormatTools *format)
648 this->format = format;
653 FormatAThread::~FormatAThread()
660 void FormatAThread::start()
668 void FormatAThread::run()
670 file->get_options(format, 1, 0);
676 FormatVThread::FormatVThread(FormatTools *format)
679 this->format = format;
684 FormatVThread::~FormatVThread()
691 void FormatVThread::start()
698 void FormatVThread::run()
700 file->get_options(format, 0, 1);
707 FormatPathText::FormatPathText(int x, int y, FormatTools *format)
711 format->mwindow->theme->get_image_set("wrench")[0]->get_w() -
716 this->format = format;
719 FormatPathText::~FormatPathText()
722 int FormatPathText::handle_event()
725 calculate_suggestions(format->file_entries);
729 strcpy(format->asset->path, get_text());
730 format->handle_event();
738 FormatAudio::FormatAudio(int x, int y, FormatTools *format, int default_)
742 (char*)(format->recording ? _("Record audio tracks") : _("Render audio tracks")))
744 this->format = format;
747 FormatAudio::~FormatAudio() {}
748 int FormatAudio::handle_event()
750 format->asset->audio_data = get_value();
755 FormatVideo::FormatVideo(int x, int y, FormatTools *format, int default_)
759 (char*)(format->recording ? _("Record video tracks") : _("Render video tracks")))
761 this->format = format;
764 FormatVideo::~FormatVideo() {}
765 int FormatVideo::handle_event()
767 format->asset->video_data = get_value();
774 FormatFormat::FormatFormat(int x, int y, FormatTools *format)
775 : FormatPopup(format->plugindb, x, y, format->use_brender)
777 this->format = format;
780 FormatFormat::~FormatFormat()
784 int FormatFormat::handle_event()
786 if(get_selection(0, 0) >= 0)
788 int new_format = File::strtoformat(format->plugindb, get_selection(0, 0)->get_text());
789 // if(new_format != format->asset->format)
791 format->asset->format = new_format;
792 format->format_text->update(get_selection(0, 0)->get_text());
793 format->update_extension();
794 format->close_format_windows();
795 format->update_format();
803 FormatChannels::FormatChannels(int x, int y, FormatTools *format)
804 : BC_TextBox(x, y, 100, 1, format->asset->channels)
806 this->format = format;
809 FormatChannels::~FormatChannels()
813 int FormatChannels::handle_event()
815 format->asset->channels = atol(get_text());
820 FormatToTracks::FormatToTracks(int x, int y, int *output)
821 : BC_CheckBox(x, y, *output, _("Overwrite project with output"))
823 this->output = output;
826 FormatToTracks::~FormatToTracks()
830 int FormatToTracks::handle_event()
832 *output = get_value();
837 FormatMultiple::FormatMultiple(MWindow *mwindow, int x, int y, int *output)
840 (*output == FILE_PER_LABEL) || (*output == FILE_PER_LABEL_FARM),
841 _("Create new file at each label"))
843 this->output = output;
844 this->mwindow = mwindow;
847 FormatMultiple::~FormatMultiple()
851 int FormatMultiple::handle_event()
855 if(mwindow->preferences->use_renderfarm)
856 *output = FILE_PER_LABEL_FARM;
858 *output = FILE_PER_LABEL;
862 if(mwindow->preferences->use_renderfarm)
863 *output = SINGLE_PASS_FARM;
865 *output = SINGLE_PASS;
870 void FormatMultiple::update(int *output)
872 this->output = output;
873 if(*output == FILE_PER_LABEL_FARM ||
874 *output ==FILE_PER_LABEL)