license header for review
[cinelerra_cv/ct.git] / cinelerra / formattools.C
blobff16478048fc7e4ea5c99b8c9ca5f3cf77f3aba8
1 #include "asset.h"
2 #include "guicast.h"
3 #include "file.h"
4 #include "formattools.h"
5 #include "language.h"
6 #include "maxchannels.h"
7 #include "mwindow.h"
8 #include "preferences.h"
9 #include "quicktime.h"
10 #include "theme.h"
11 #include "videodevice.inc"
12 #include <string.h>
13 #include "pipe.h"
16 FormatTools::FormatTools(MWindow *mwindow,
17                                 BC_WindowBase *window, 
18                                 Asset_GC asset)
20         this->mwindow = mwindow;
21         this->window = window;
22         this->asset = asset;
23         this->plugindb = mwindow->plugindb;
25         aparams_button = 0;
26         vparams_button = 0;
27         aparams_thread = 0;
28         vparams_thread = 0;
29         channels_tumbler = 0;
30         path_textbox = 0;
31         path_button = 0;
32         path_recent = 0;
33         w = 0;
36 FormatTools::~FormatTools()
38         delete path_recent;
39         delete path_button;
40         delete path_textbox;
41         delete format_button;
43         if(aparams_button) delete aparams_button;
44         if(vparams_button) delete vparams_button;
45         if(aparams_thread) delete aparams_thread;
46         if(vparams_thread) delete vparams_thread;
47         if(channels_tumbler) delete channels_tumbler;
50 int FormatTools::create_objects(int &init_x, 
51                                                 int &init_y, 
52                                                 int do_audio,    // Include support for audio
53                                                 int do_video,   // Include support for video
54                                                 int prompt_audio,  // Include checkbox for audio
55                                                 int prompt_video,
56                                                 int prompt_audio_channels,
57                                                 int prompt_video_compression,
58                                                 char *locked_compressor,
59                                                 int recording,
60                                                 int *strategy,
61                                                 int brender)
63         int x = init_x;
64         int y = init_y;
66         this->locked_compressor = locked_compressor;
67         this->recording = recording;
68         this->use_brender = brender;
69         this->do_audio = do_audio;
70         this->do_video = do_video;
71         this->prompt_audio = prompt_audio;
72         this->prompt_audio_channels = prompt_audio_channels;
73         this->prompt_video = prompt_video;
74         this->prompt_video_compression = prompt_video_compression;
75         this->strategy = strategy;
77 //printf("FormatTools::create_objects 1\n");
79 // Modify strategy depending on render farm
80         if(strategy)
81         {
82                 if(mwindow->preferences->use_renderfarm)
83                 {
84                         if(*strategy == FILE_PER_LABEL)
85                                 *strategy = FILE_PER_LABEL_FARM;
86                         else
87                         if(*strategy == SINGLE_PASS)
88                                 *strategy = SINGLE_PASS_FARM;
89                 }
90                 else
91                 {
92                         if(*strategy == FILE_PER_LABEL_FARM)
93                                 *strategy = FILE_PER_LABEL;
94                         else
95                         if(*strategy == SINGLE_PASS_FARM)
96                                 *strategy = SINGLE_PASS;
97                 }
98         }
100 //printf("FormatTools::create_objects 1\n");
101         if(!recording)
102         {
103                 window->add_subwindow(path_textbox = new FormatPathText(x, y, this));
104                 x += 305;
105                 path_recent = new BC_RecentList("PATH", mwindow->defaults,
106                                         path_textbox, 10, x, y, 300, 100);
107                 window->add_subwindow(path_recent);
108                 path_recent->load_items(FILE_FORMAT_PREFIX(asset->format));
110                 x += 18;
111                 window->add_subwindow(path_button = new BrowseButton(
112                         mwindow,
113                         window,
114                         path_textbox, 
115                         x, 
116                         y, 
117                         asset->path,
118                         _("Output to file"),
119                         _("Select a file to write to:"),
120                         0));
122 // Set w for user.
123                 w = x + path_button->get_w() + 5;
124                 x -= 305;
126                 y += 35;
127         }
128         else
129                 w = x + 305;
131         window->add_subwindow(format_title = new BC_Title(x, y, _("File Format:")));
132         x += 90;
133         window->add_subwindow(format_text = new BC_TextBox(x, 
134                 y, 
135                 200, 
136                 1, 
137                 File::formattostr(asset->format)));
138         x += format_text->get_w();
139         window->add_subwindow(format_button = new FormatFormat(x, 
140                 y, 
141                 this));
142         format_button->create_objects();
144         x = init_x;
145         y += format_button->get_h() + 10;
146         if(do_audio)
147         {
148                 window->add_subwindow(audio_title = new BC_Title(x, y, _("Audio:"), LARGEFONT,  BC_WindowBase::get_resources()->audiovideo_color));
149                 x += 80;
150                 window->add_subwindow(aparams_button = new FormatAParams(mwindow, this, x, y));
151                 x += aparams_button->get_w() + 10;
152                 if(prompt_audio) 
153                 {
154                         window->add_subwindow(audio_switch = new FormatAudio(x, y, this, asset->audio_data));
155                 }
156                 x = init_x;
157                 y += aparams_button->get_h() + 20;
159 // Audio channels only used for recording.
160 //              if(prompt_audio_channels)
161 //              {
162 //                      window->add_subwindow(channels_title = new BC_Title(x, y, _("Number of audio channels to record:")));
163 //                      x += 260;
164 //                      window->add_subwindow(channels_button = new FormatChannels(x, y, this));
165 //                      x += channels_button->get_w() + 5;
166 //                      window->add_subwindow(channels_tumbler = new BC_ITumbler(channels_button, 1, MAXCHANNELS, x, y));
167 //                      y += channels_button->get_h() + 20;
168 //                      x = init_x;
169 //              }
171 //printf("FormatTools::create_objects 6\n");
172                 aparams_thread = new FormatAThread(this);
173         }
175 //printf("FormatTools::create_objects 7\n");
176         if(do_video)
177         {
179 //printf("FormatTools::create_objects 8\n");
180                 window->add_subwindow(video_title = new BC_Title(x, y, _("Video:"), LARGEFONT,  BC_WindowBase::get_resources()->audiovideo_color));
181                 x += 80;
182                 if(prompt_video_compression)
183                 {
184                         window->add_subwindow(vparams_button = new FormatVParams(mwindow, this, x, y));
185                         x += vparams_button->get_w() + 10;
186                 }
188 //printf("FormatTools::create_objects 9\n");
189                 if(prompt_video)
190                 {
191                         window->add_subwindow(video_switch = new FormatVideo(x, y, this, asset->video_data));
192                         y += video_switch->get_h();
193                 }
194                 else
195                 {
196                         y += vparams_button->get_h();
197                 }
199 //printf("FormatTools::create_objects 10\n");
200                 y += 10;
201                 vparams_thread = new FormatVThread(this);
202         }
204 //printf("FormatTools::create_objects 11\n");
206         x = init_x;
207         if(strategy)
208         {
209                 window->add_subwindow(multiple_files = new FormatMultiple(mwindow, x, y, strategy));
210                 y += multiple_files->get_h() + 10;
211         }
213 //printf("FormatTools::create_objects 12\n");
215         init_y = y;
216         return 0;
219 void FormatTools::update_driver(int driver)
221         this->video_driver = driver;
223         switch(driver)
224         {
225                 case CAPTURE_DVB:
226 // Just give the user information about how the stream is going to be
227 // stored but don't change the asset.
228 // Want to be able to revert to user settings.
229                         if(asset->format != FILE_MPEG)
230                         {
231                                 format_text->update(_("MPEG transport stream"));
232                                 asset->format = FILE_MPEG;
233                         }
234                         locked_compressor = 0;
235                         audio_switch->update(1);
236                         video_switch->update(1);
237                         break;
239                 case CAPTURE_IEC61883:
240                 case CAPTURE_FIREWIRE:
241                         if(asset->format != FILE_AVI &&
242                                 asset->format != FILE_MOV)
243                         {
244                                 format_text->update(MOV_NAME);
245                                 asset->format = FILE_MOV;
246                         }
247                         else
248                                 format_text->update(File::formattostr(asset->format));
249                         locked_compressor = QUICKTIME_DVSD;
250                         strcpy(asset->vcodec, QUICKTIME_DVSD);
251                         audio_switch->update(asset->audio_data);
252                         video_switch->update(asset->video_data);
253                         break;
255                 case CAPTURE_BUZ:
256                 case VIDEO4LINUX2JPEG:
257                         if(asset->format != FILE_AVI &&
258                                 asset->format != FILE_MOV)
259                         {
260                                 format_text->update(MOV_NAME);
261                                 asset->format = FILE_MOV;
262                         }
263                         else
264                                 format_text->update(File::formattostr(asset->format));
265                         locked_compressor = QUICKTIME_MJPA;
266                         audio_switch->update(asset->audio_data);
267                         video_switch->update(asset->video_data);
268                         break;
270                 default:
271                         format_text->update(File::formattostr(asset->format));
272                         locked_compressor = 0;
273                         audio_switch->update(asset->audio_data);
274                         video_switch->update(asset->video_data);
275                         break;
276         }
277         close_format_windows();
282 int FormatTools::handle_event()
284         return 0;
287 Asset_GC FormatTools::get_asset()
289         return asset;
292 void FormatTools::update_extension()
294         char *extension = File::get_tag(asset->format);
295         if(extension)
296         {
297                 char *ptr = strrchr(asset->path, '.');
298                 if(!ptr)
299                 {
300                         ptr = asset->path + strlen(asset->path);
301                         *ptr = '.';
302                 }
303                 ptr++;
304                 sprintf(ptr, extension);
306                 int character1 = ptr - asset->path;
307                 int character2 = ptr - asset->path + strlen(extension);
308                 *(asset->path + character2) = 0;
309                 if(path_textbox) 
310                 {
311                         path_textbox->update(asset->path);
312                         path_textbox->set_selection(character1, character2, character2);
313                 }
314         }
317 void FormatTools::update(Asset_GC asset, int *strategy)
319         this->asset = asset;
320         this->strategy = strategy;
322         if(path_textbox) 
323                 path_textbox->update(asset->path);
324         format_text->update(File::formattostr(plugindb, asset->format));
325         if(do_audio && audio_switch) audio_switch->update(asset->audio_data);
326         if(do_video && video_switch) video_switch->update(asset->video_data);
327         if(strategy)
328         {
329                 multiple_files->update(strategy);
330         }
331         close_format_windows();
334 void FormatTools::close_format_windows()
336         if(aparams_thread) aparams_thread->file->close_window();
337         if(vparams_thread) vparams_thread->file->close_window();
340 int FormatTools::get_w()
342         return w;
345 void FormatTools::reposition_window(int &init_x, int &init_y)
347         int x = init_x;
348         int y = init_y;
350         if(path_textbox) 
351         {
352                 path_textbox->reposition_window(x, y);
353                 x += 305;
354                 path_button->reposition_window(x, y);
355                 x -= 305;
356                 y += 35;
357         }
359         format_title->reposition_window(x, y);
360         x += 90;
361         format_text->reposition_window(x, y);
362         x += format_text->get_w();
363         format_button->reposition_window(x, y);
365         x = init_x;
366         y += format_button->get_h() + 10;
368         if(do_audio)
369         {
370                 audio_title->reposition_window(x, y);
371                 x += 80;
372                 aparams_button->reposition_window(x, y);
373                 x += aparams_button->get_w() + 10;
374                 if(prompt_audio) audio_switch->reposition_window(x, y);
376                 x = init_x;
377                 y += aparams_button->get_h() + 20;
378                 if(prompt_audio_channels)
379                 {
380                         channels_title->reposition_window(x, y);
381                         x += 260;
382                         channels_button->reposition_window(x, y);
383                         x += channels_button->get_w() + 5;
384                         channels_tumbler->reposition_window(x, y);
385                         y += channels_button->get_h() + 20;
386                         x = init_x;
387                 }
388         }
391         if(do_video)
392         {
393                 video_title->reposition_window(x, y);
394                 x += 80;
395                 if(prompt_video_compression)
396                 {
397                         vparams_button->reposition_window(x, y);
398                         x += vparams_button->get_w() + 10;
399                 }
401                 if(prompt_video)
402                 {
403                         video_switch->reposition_window(x, y);
404                         y += video_switch->get_h();
405                 }
406                 else
407                 {
408                         y += vparams_button->get_h();
409                 }
411                 y += 10;
412                 x = init_x;
413         }
415         if(strategy)
416         {
417                 multiple_files->reposition_window(x, y);
418                 y += multiple_files->get_h() + 10;
419         }
421         init_y = y;
425 int FormatTools::set_audio_options()
427 //      if(video_driver == CAPTURE_DVB)
428 //      {
429 //              return 0;
430 //      }
432         if(!aparams_thread->running())
433         {
434                 aparams_thread->start();
435         }
436         else
437         {
438                 aparams_thread->file->raise_window();
439         }
440         return 0;
443 int FormatTools::set_video_options()
445 //      if(video_driver == CAPTURE_DVB)
446 //      {
447 //              return 0;
448 //      }
450         if(!vparams_thread->running())
451         {
452                 vparams_thread->start();
453         }
454         else
455         {
456                 vparams_thread->file->raise_window();
457         }
459         return 0;
466 FormatAParams::FormatAParams(MWindow *mwindow, FormatTools *format, int x, int y)
467  : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
469         this->format = format;
470         set_tooltip(_("Configure audio compression"));
472 FormatAParams::~FormatAParams() 
475 int FormatAParams::handle_event() 
477         format->set_audio_options(); 
480 FormatVParams::FormatVParams(MWindow *mwindow, FormatTools *format, int x, int y)
481  : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
483         this->format = format; 
484         set_tooltip(_("Configure video compression"));
486 FormatVParams::~FormatVParams() 
489 int FormatVParams::handle_event() 
491         format->set_video_options(); 
495 FormatAThread::FormatAThread(FormatTools *format)
496  : Thread()
498         this->format = format; 
499         file = new File;
502 FormatAThread::~FormatAThread() 
504         delete file;
507 void FormatAThread::run()
509         file->get_options(format, 1, 0);
515 FormatVThread::FormatVThread(FormatTools *format)
516  : Thread()
518         this->format = format;
519         file = new File;
522 FormatVThread::~FormatVThread() 
524         delete file;
527 void FormatVThread::run()
529         file->get_options(format, 0, 1);
532 FormatPathText::FormatPathText(int x, int y, FormatTools *format)
533  : BC_TextBox(x, y, 300, 1, format->asset->path) 
535         this->format = format; 
537 FormatPathText::~FormatPathText() 
540 int FormatPathText::handle_event() 
542         strcpy(format->asset->path, get_text());
543         format->handle_event();
549 FormatAudio::FormatAudio(int x, int y, FormatTools *format, int default_)
550  : BC_CheckBox(x, 
551         y, 
552         default_, 
553         (char*)(format->recording ? _("Record audio tracks") : _("Render audio tracks")))
555         this->format = format; 
557 FormatAudio::~FormatAudio() {}
558 int FormatAudio::handle_event()
560         format->asset->audio_data = get_value();
564 FormatVideo::FormatVideo(int x, int y, FormatTools *format, int default_)
565  : BC_CheckBox(x, 
566         y, 
567         default_, 
568         (char*)(format->recording ? _("Record video tracks") : _("Render video tracks")))
570 this->format = format; 
572 FormatVideo::~FormatVideo() {}
573 int FormatVideo::handle_event()
575         format->asset->video_data = get_value();
581 FormatFormat::FormatFormat(int x, 
582         int y, 
583         FormatTools *format)
584  : FormatPopup(format->plugindb, 
585         x, 
586         y,
587         format->use_brender)
589         this->format = format; 
591 FormatFormat::~FormatFormat() 
594 int FormatFormat::handle_event()
596         if(get_selection(0, 0) >= 0)
597         {
598                 int new_format = File::strtoformat(format->plugindb, get_selection(0, 0)->get_text());
599                 if(new_format != format->asset->format)
600                 {
601                         format->asset->format = new_format;
602                         format->format_text->update(get_selection(0, 0)->get_text());
603                         format->update_extension();
604                         format->close_format_windows();
605                         if (format->path_recent)
606                                 format->path_recent->load_items
607                                         (FILE_FORMAT_PREFIX(format->asset->format));
608                 }
609         }
610         return 1;
615 FormatChannels::FormatChannels(int x, int y, FormatTools *format)
616  : BC_TextBox(x, y, 100, 1, format->asset->channels) 
618         this->format = format; 
620 FormatChannels::~FormatChannels() 
623 int FormatChannels::handle_event() 
625         format->asset->channels = atol(get_text());
626         return 1;
629 FormatToTracks::FormatToTracks(int x, int y, int *output)
630  : BC_CheckBox(x, y, *output, _("Overwrite project with output"))
632         this->output = output; 
634 FormatToTracks::~FormatToTracks() 
637 int FormatToTracks::handle_event()
639         *output = get_value();
640         return 1;
644 FormatMultiple::FormatMultiple(MWindow *mwindow, int x, int y, int *output)
645  : BC_CheckBox(x, 
646         y, 
647         (*output == FILE_PER_LABEL) || (*output == FILE_PER_LABEL_FARM), 
648         _("Create new file at each label"))
650         this->output = output;
651         this->mwindow = mwindow;
653 FormatMultiple::~FormatMultiple() 
656 int FormatMultiple::handle_event()
658         if(get_value())
659         {
660                 if(mwindow->preferences->use_renderfarm)
661                         *output = FILE_PER_LABEL_FARM;
662                 else
663                         *output = FILE_PER_LABEL;
664         }
665         else
666         {
667                 if(mwindow->preferences->use_renderfarm)
668                         *output = SINGLE_PASS_FARM;
669                 else
670                         *output = SINGLE_PASS;
671         }
672         return 1;
675 void FormatMultiple::update(int *output)
677         this->output = output;
678         if(*output == FILE_PER_LABEL_FARM ||
679                 *output ==FILE_PER_LABEL)
680                 set_value(1);
681         else
682                 set_value(0);
687 //      Local Variables:
688 //      mode: C++
689 //      c-file-style: "linux"
690 //      End: