r602: Fix baver's code... don't insert timecode when show_tc is not set
[cinelerra_cv/mob.git] / cinelerra / formattools.C
blob052e59c0b3762d9c0cb91043ac6fcf9739a77381
1 #include "asset.h"
2 #include "guicast.h"
3 #include "file.h"
4 #include "formattools.h"
5 #include "maxchannels.h"
6 #include "mwindow.h"
7 #include "preferences.h"
8 #include "theme.h"
9 #include <string.h>
10 #include "pipe.h"
12 #include <libintl.h>
13 #define _(String) gettext(String)
14 #define gettext_noop(String) String
15 #define N_(String) gettext_noop (String)
17 FormatTools::FormatTools(MWindow *mwindow,
18                                 BC_WindowBase *window, 
19                                 Asset *asset)
21         this->mwindow = mwindow;
22         this->window = window;
23         this->asset = asset;
24         this->plugindb = mwindow->plugindb;
26         aparams_thread = 0;
27         vparams_thread = 0;
28         w = 0;
31 FormatTools::~FormatTools()
33         delete aparams_thread;
34         delete vparams_thread;
37 int FormatTools::create_objects(int &init_x, 
38                                                 int &init_y, 
39                                                 int do_audio,    // Include support for audio
40                                                 int do_video,   // Include support for video
41                                                 int prompt_audio,  // Include checkbox for audio
42                                                 int prompt_video,
43                                                 int prompt_audio_channels,
44                                                 int prompt_video_compression,
45                                                 int lock_compressor,
46                                                 int recording,
47                                                 int *strategy,
48                                                 int brender)
50         int x = init_x;
51         int y = init_y;
53         this->lock_compressor = lock_compressor;
54         this->recording = recording;
55         this->use_brender = brender;
56         this->do_audio = do_audio;
57         this->do_video = do_video;
58         this->prompt_audio = prompt_audio;
59         this->prompt_audio_channels = prompt_audio_channels;
60         this->prompt_video = prompt_video;
61         this->prompt_video_compression = prompt_video_compression;
62         this->strategy = strategy;
64 //printf("FormatTools::create_objects 1\n");
66 // Modify strategy depending on render farm
67         if(strategy)
68         {
69                 if(mwindow->preferences->use_renderfarm)
70                 {
71                         if(*strategy == FILE_PER_LABEL)
72                                 *strategy = FILE_PER_LABEL_FARM;
73                         else
74                         if(*strategy == SINGLE_PASS)
75                                 *strategy = SINGLE_PASS_FARM;
76                 }
77                 else
78                 {
79                         if(*strategy == FILE_PER_LABEL_FARM)
80                                 *strategy = FILE_PER_LABEL;
81                         else
82                         if(*strategy == SINGLE_PASS_FARM)
83                                 *strategy = SINGLE_PASS;
84                 }
85         }
87 //printf("FormatTools::create_objects 1\n");
88         window->add_subwindow(path_textbox = new FormatPathText(x, y, this));
89         x += 300;
90         path_recent = new BC_RecentList("PATH", mwindow->defaults,
91                                         path_textbox, 10, x, y, 300, 100);
92         window->add_subwindow(path_recent);
93         path_recent->load_items(FILE_FORMAT_PREFIX(asset->format));
95         x += 18;
96         window->add_subwindow(path_button = new BrowseButton(
97                 mwindow,
98                 window,
99                 path_textbox, 
100                 x, 
101                 y - 4, 
102                 asset->path,
103                 _("Output to file"),
104                 _("Select a file to write to:"),
105                 0));
107         w = x + path_button->get_w() + 5;
108 //printf("FormatTools::create_objects 2\n");
109         x -= 305;
111         y += 25;
113         pipe_status = new PipeStatus(x, y, "");
114         window->add_subwindow(pipe_status);
115         pipe_status->set_status(asset);
116         
117         y += 25;
119 //printf("FormatTools::create_objects 3\n");
120         window->add_subwindow(format_title = new BC_Title(x, y, _("File Format:")));
121         x += 90;
122         window->add_subwindow(format_text = new BC_TextBox(x, 
123                 y, 
124                 200, 
125                 1, 
126                 File::formattostr(plugindb, asset->format)));
127         x += format_text->get_w();
128         window->add_subwindow(format_button = new FormatFormat(x, 
129                 y, 
130                 this));
131         format_button->create_objects();
133 //printf("FormatTools::create_objects 4\n");
134         x = init_x;
135         y += format_button->get_h() + 10;
136         if(do_audio)
137         {
138                 window->add_subwindow(audio_title = new BC_Title(x, y, _("Audio:"), LARGEFONT,  BC_WindowBase::get_resources()->audiovideo_color));
139                 x += 80;
140                 window->add_subwindow(aparams_button = new FormatAParams(mwindow, this, x, y));
141                 x += aparams_button->get_w() + 10;
142                 if(prompt_audio) 
143                 {
144                         window->add_subwindow(audio_switch = new FormatAudio(x, y, this, asset->audio_data));
145                 }
146                 x = init_x;
147                 y += aparams_button->get_h() + 20;
149 //printf("FormatTools::create_objects 5\n");
150 // Audio channels only used for recording.
151                 if(prompt_audio_channels)
152                 {
153                         window->add_subwindow(channels_title = new BC_Title(x, y, _("Number of audio channels to record:")));
154                         x += 260;
155                         window->add_subwindow(channels_button = new FormatChannels(x, y, this));
156                         x += channels_button->get_w() + 5;
157                         window->add_subwindow(channels_tumbler = new BC_ITumbler(channels_button, 1, MAXCHANNELS, x, y));
158                         y += channels_button->get_h() + 20;
159                         x = init_x;
160                 }
162 //printf("FormatTools::create_objects 6\n");
163                 aparams_thread = new FormatAThread(this);
164         }
166 //printf("FormatTools::create_objects 7\n");
167         if(do_video)
168         {
170 //printf("FormatTools::create_objects 8\n");
171                 window->add_subwindow(video_title = new BC_Title(x, y, _("Video:"), LARGEFONT,  BC_WindowBase::get_resources()->audiovideo_color));
172                 x += 80;
173                 if(prompt_video_compression)
174                 {
175                         window->add_subwindow(vparams_button = new FormatVParams(mwindow, this, x, y));
176                         x += vparams_button->get_w() + 10;
177                 }
179 //printf("FormatTools::create_objects 9\n");
180                 if(prompt_video)
181                 {
182                         window->add_subwindow(video_switch = new FormatVideo(x, y, this, asset->video_data));
183                         y += video_switch->get_h();
184                 }
185                 else
186                 {
187                         y += vparams_button->get_h();
188                 }
190 //printf("FormatTools::create_objects 10\n");
191                 y += 10;
192                 vparams_thread = new FormatVThread(this, lock_compressor);
193         }
195 //printf("FormatTools::create_objects 11\n");
197         x = init_x;
198         if(strategy)
199         {
200                 window->add_subwindow(multiple_files = new FormatMultiple(mwindow, x, y, strategy));
201                 y += multiple_files->get_h() + 10;
202         }
204 //printf("FormatTools::create_objects 12\n");
206         init_y = y;
207         return 0;
210 int FormatTools::handle_event()
212         return 0;
215 Asset* FormatTools::get_asset()
217         return asset;
220 void FormatTools::update(Asset *asset, int *strategy)
222         this->asset = asset;
223         this->strategy = strategy;
225         path_textbox->update(asset->path);
226         format_text->update(File::formattostr(plugindb, asset->format));
227         if(do_audio && audio_switch) audio_switch->update(asset->audio_data);
228         if(do_video && video_switch) video_switch->update(asset->video_data);
229         if(strategy)
230         {
231                 multiple_files->update(strategy);
232         }
233         close_format_windows();
236 void FormatTools::close_format_windows()
238         if(aparams_thread) aparams_thread->file->close_window();
239         if(vparams_thread) vparams_thread->file->close_window();
242 int FormatTools::get_w()
244         return w;
247 void FormatTools::reposition_window(int &init_x, int &init_y)
249         int x = init_x;
250         int y = init_y;
252         path_textbox->reposition_window(x, y);
253         x += 305;
254         path_button->reposition_window(x, y);
256         x -= 305;
257         y += 35;
258         format_title->reposition_window(x, y);
259         x += 90;
260         format_text->reposition_window(x, y);
261         x += format_text->get_w();
262         format_button->reposition_window(x, y);
264         x = init_x;
265         y += format_button->get_h() + 10;
267         if(do_audio)
268         {
269                 audio_title->reposition_window(x, y);
270                 x += 80;
271                 aparams_button->reposition_window(x, y);
272                 x += aparams_button->get_w() + 10;
273                 if(prompt_audio) audio_switch->reposition_window(x, y);
275                 x = init_x;
276                 y += aparams_button->get_h() + 20;
277                 if(prompt_audio_channels)
278                 {
279                         channels_title->reposition_window(x, y);
280                         x += 260;
281                         channels_button->reposition_window(x, y);
282                         x += channels_button->get_w() + 5;
283                         channels_tumbler->reposition_window(x, y);
284                         y += channels_button->get_h() + 20;
285                         x = init_x;
286                 }
287         }
290         if(do_video)
291         {
292                 video_title->reposition_window(x, y);
293                 x += 80;
294                 if(prompt_video_compression)
295                 {
296                         vparams_button->reposition_window(x, y);
297                         x += vparams_button->get_w() + 10;
298                 }
300                 if(prompt_video)
301                 {
302                         video_switch->reposition_window(x, y);
303                         y += video_switch->get_h();
304                 }
305                 else
306                 {
307                         y += vparams_button->get_h();
308                 }
310                 y += 10;
311                 x = init_x;
312         }
314         if(strategy)
315         {
316                 multiple_files->reposition_window(x, y);
317                 y += multiple_files->get_h() + 10;
318         }
320         init_y = y;
324 int FormatTools::set_audio_options()
326         if(!aparams_thread->running())
327         {
328                 aparams_thread->start();
329         }
330         else
331         {
332                 aparams_thread->file->raise_window();
333         }
335         return 0;
338 int FormatTools::set_video_options()
340         if(!vparams_thread->running())
341         {
342                 vparams_thread->start();
343         }
344         else
345         {
346                 vparams_thread->file->raise_window();
347         }
348         return 0;
355 FormatAParams::FormatAParams(MWindow *mwindow, FormatTools *format, int x, int y)
356  : BC_Button(x, y, mwindow->theme->wrench_data)
358         this->format = format;
359         set_tooltip(_("Configure audio compression"));
361 FormatAParams::~FormatAParams() 
364 int FormatAParams::handle_event() 
366         format->set_audio_options(); 
369 FormatVParams::FormatVParams(MWindow *mwindow, FormatTools *format, int x, int y)
370  : BC_Button(x, y, mwindow->theme->wrench_data)
372         this->format = format; 
373         set_tooltip(_("Configure video compression"));
375 FormatVParams::~FormatVParams() 
378 int FormatVParams::handle_event() 
380         format->set_video_options(); 
384 FormatAThread::FormatAThread(FormatTools *format)
385  : Thread()
387         this->format = format; 
388         file = new File;
391 FormatAThread::~FormatAThread() 
393         delete file;
396 void FormatAThread::run()
398         file->get_options(format, 1, 0, 0);
404 FormatVThread::FormatVThread(FormatTools *format, 
405         int lock_compressor)
406  : Thread()
408         this->lock_compressor = lock_compressor;
409         this->format = format;
410         file = new File;
413 FormatVThread::~FormatVThread() 
415         delete file;
418 void FormatVThread::run()
420         file->get_options(format, 0, 1, lock_compressor);
423 FormatPathText::FormatPathText(int x, int y, FormatTools *format)
424  : BC_TextBox(x, y, 300, 1, format->asset->path) 
426         this->format = format; 
428 FormatPathText::~FormatPathText() 
431 int FormatPathText::handle_event() 
433         strcpy(format->asset->path, get_text());
434         format->handle_event();
440 FormatAudio::FormatAudio(int x, int y, FormatTools *format, int default_)
441  : BC_CheckBox(x, 
442         y, 
443         default_, 
444         (char*)(format->recording ? _("Record audio tracks") : _("Render audio tracks")))
446         this->format = format; 
448 FormatAudio::~FormatAudio() {}
449 int FormatAudio::handle_event()
451         format->asset->audio_data = get_value();
455 FormatVideo::FormatVideo(int x, int y, FormatTools *format, int default_)
456  : BC_CheckBox(x, 
457         y, 
458         default_, 
459         (char*)(format->recording ? _("Record video tracks") : _("Render video tracks")))
461 this->format = format; 
463 FormatVideo::~FormatVideo() {}
464 int FormatVideo::handle_event()
466         format->asset->video_data = get_value();
472 FormatFormat::FormatFormat(int x, 
473         int y, 
474         FormatTools *format)
475  : FormatPopup(format->plugindb, 
476         x, 
477         y,
478         format->use_brender)
480         this->format = format; 
482 FormatFormat::~FormatFormat() 
485 int FormatFormat::handle_event()
487         if(get_selection(0, 0) >= 0)
488         {
489                 int new_format = File::strtoformat(format->plugindb, get_selection(0, 0)->get_text());
490                 if(new_format != format->asset->format)
491                 {
492                         // save the state of the old format
493                         format->asset->save_format_defaults
494                                 (format->mwindow->defaults);
496                         // close the configure window if open
497                         format->close_format_windows();
499                         // change to the new format
500                         format->asset->format = new_format;
502                         // load the state for the new format
503                         format->asset->load_format_defaults
504                                 (format->mwindow->defaults);
506                         // update the render window to match
507                         format->format_text->
508                                 update(get_selection(0, 0)->get_text());
509                         format->path_textbox->update(format->asset->path);
510                         format->pipe_status->set_status(format->asset);
511                         format->path_recent->load_items
512                                 (FILE_FORMAT_PREFIX(format->asset->format));
513                 }
514         }
515         return 1;
520 FormatChannels::FormatChannels(int x, int y, FormatTools *format)
521  : BC_TextBox(x, y, 100, 1, format->asset->channels) 
523         this->format = format; 
525 FormatChannels::~FormatChannels() 
528 int FormatChannels::handle_event() 
530         format->asset->channels = atol(get_text());
531         return 1;
534 FormatToTracks::FormatToTracks(int x, int y, int *output)
535  : BC_CheckBox(x, y, *output, _("Overwrite project with output"))
537         this->output = output; 
539 FormatToTracks::~FormatToTracks() 
542 int FormatToTracks::handle_event()
544         *output = get_value();
545         return 1;
549 FormatMultiple::FormatMultiple(MWindow *mwindow, int x, int y, int *output)
550  : BC_CheckBox(x, 
551         y, 
552         (*output == FILE_PER_LABEL) || (*output == FILE_PER_LABEL_FARM), 
553         _("Create new file at each label"))
555         this->output = output;
556         this->mwindow = mwindow;
558 FormatMultiple::~FormatMultiple() 
561 int FormatMultiple::handle_event()
563         if(get_value())
564         {
565                 if(mwindow->preferences->use_renderfarm)
566                         *output = FILE_PER_LABEL_FARM;
567                 else
568                         *output = FILE_PER_LABEL;
569         }
570         else
571         {
572                 if(mwindow->preferences->use_renderfarm)
573                         *output = SINGLE_PASS_FARM;
574                 else
575                         *output = SINGLE_PASS;
576         }
577         return 1;
580 void FormatMultiple::update(int *output)
582         this->output = output;
583         if(*output == FILE_PER_LABEL_FARM ||
584                 *output ==FILE_PER_LABEL)
585                 set_value(1);
586         else
587                 set_value(0);