r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / formattools.C
blobacdcac78115403a5a5887549c005cd909e09254f
1 #include "assets.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>
11 #include <libintl.h>
12 #define _(String) gettext(String)
13 #define gettext_noop(String) String
14 #define N_(String) gettext_noop (String)
16 FormatTools::FormatTools(MWindow *mwindow,
17                                 BC_WindowBase *window, 
18                                 Asset *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;
32 FormatTools::~FormatTools()
34         delete path_button;
35         delete path_textbox;
36         delete format_button;
38         if(aparams_button) delete aparams_button;
39         if(vparams_button) delete vparams_button;
40         if(aparams_thread) delete aparams_thread;
41         if(vparams_thread) delete vparams_thread;
42         if(channels_tumbler) delete channels_tumbler;
45 int FormatTools::create_objects(int &init_x, 
46                                                 int &init_y, 
47                                                 int do_audio,    // Include support for audio
48                                                 int do_video,   // Include support for video
49                                                 int prompt_audio,  // Include checkbox for audio
50                                                 int prompt_video,
51                                                 int prompt_audio_channels,
52                                                 int prompt_video_compression,
53                                                 int lock_compressor,
54                                                 int recording,
55                                                 int *strategy,
56                                                 int brender)
58         int x = init_x;
59         int y = init_y;
61         this->lock_compressor = lock_compressor;
62         this->recording = recording;
63         this->use_brender = brender;
64         this->do_audio = do_audio;
65         this->do_video = do_video;
66         this->prompt_audio = prompt_audio;
67         this->prompt_audio_channels = prompt_audio_channels;
68         this->prompt_video = prompt_video;
69         this->prompt_video_compression = prompt_video_compression;
70         this->strategy = strategy;
72 //printf("FormatTools::create_objects 1\n");
74 // Modify strategy depending on render farm
75         if(strategy)
76         {
77                 if(mwindow->preferences->use_renderfarm)
78                 {
79                         if(*strategy == FILE_PER_LABEL)
80                                 *strategy = FILE_PER_LABEL_FARM;
81                         else
82                         if(*strategy == SINGLE_PASS)
83                                 *strategy = SINGLE_PASS_FARM;
84                 }
85                 else
86                 {
87                         if(*strategy == FILE_PER_LABEL_FARM)
88                                 *strategy = FILE_PER_LABEL;
89                         else
90                         if(*strategy == SINGLE_PASS_FARM)
91                                 *strategy = SINGLE_PASS;
92                 }
93         }
95 //printf("FormatTools::create_objects 1\n");
96         window->add_subwindow(path_textbox = new FormatPathText(x, y, this, asset));
97         x += 305;
98         window->add_subwindow(path_button = new BrowseButton(
99                 mwindow,
100                 window,
101                 path_textbox, 
102                 x, 
103                 y, 
104                 asset->path,
105                 _("Output to file"),
106                 _("Select a file to write to:"),
107                 0));
109 //printf("FormatTools::create_objects 2\n");
110         x -= 305;
111         y += 35;
113 //printf("FormatTools::create_objects 3\n");
114         window->add_subwindow(format_title = new BC_Title(x, y, _("File Format:")));
115         x += 90;
116         window->add_subwindow(format_text = new BC_TextBox(x, 
117                 y, 
118                 200, 
119                 1, 
120                 File::formattostr(plugindb, asset->format)));
121         x += format_text->get_w();
122         window->add_subwindow(format_button = new FormatFormat(x, 
123                 y, 
124                 this, 
125                 asset));
126         format_button->create_objects();
128 //printf("FormatTools::create_objects 4\n");
129         x = init_x;
130         y += format_button->get_h() + 10;
131         if(do_audio)
132         {
133                 window->add_subwindow(audio_title = new BC_Title(x, y, _("Audio:"), LARGEFONT, RED));
134                 x += 80;
135                 window->add_subwindow(aparams_button = new FormatAParams(mwindow, this, x, y));
136                 x += aparams_button->get_w() + 10;
137                 if(prompt_audio) 
138                 {
139                         window->add_subwindow(audio_switch = new FormatAudio(x, y, this, asset->audio_data));
140                 }
141                 x = init_x;
142                 y += aparams_button->get_h() + 20;
144 //printf("FormatTools::create_objects 5\n");
145 // Audio channels only used for recording.
146                 if(prompt_audio_channels)
147                 {
148                         window->add_subwindow(channels_title = new BC_Title(x, y, _("Number of audio channels to record:")));
149                         x += 260;
150                         window->add_subwindow(channels_button = new FormatChannels(x, y, asset));
151                         x += channels_button->get_w() + 5;
152                         window->add_subwindow(channels_tumbler = new BC_ITumbler(channels_button, 1, MAXCHANNELS, x, y));
153                         y += channels_button->get_h() + 20;
154                         x = init_x;
155                 }
157 //printf("FormatTools::create_objects 6\n");
158                 aparams_thread = new FormatAThread(this);
159         }
161 //printf("FormatTools::create_objects 7\n");
162         if(do_video)
163         {
165 //printf("FormatTools::create_objects 8\n");
166                 window->add_subwindow(video_title = new BC_Title(x, y, _("Video:"), LARGEFONT, RED));
167                 x += 80;
168                 if(prompt_video_compression)
169                 {
170                         window->add_subwindow(vparams_button = new FormatVParams(mwindow, this, x, y));
171                         x += vparams_button->get_w() + 10;
172                 }
174 //printf("FormatTools::create_objects 9\n");
175                 if(prompt_video)
176                 {
177                         window->add_subwindow(video_switch = new FormatVideo(x, y, this, asset->video_data));
178                         y += video_switch->get_h();
179                 }
180                 else
181                 {
182                         y += vparams_button->get_h();
183                 }
185 //printf("FormatTools::create_objects 10\n");
186                 y += 10;
187                 vparams_thread = new FormatVThread(this, lock_compressor);
188         }
190 //printf("FormatTools::create_objects 11\n");
192         x = init_x;
193         if(strategy)
194         {
195                 window->add_subwindow(multiple_files = new FormatMultiple(mwindow, x, y, strategy));
196                 y += multiple_files->get_h() + 10;
197         }
199 //printf("FormatTools::create_objects 12\n");
201         init_y = y;
202         return 0;
205 void FormatTools::reposition_window(int &init_x, int &init_y)
207         int x = init_x;
208         int y = init_y;
210         path_textbox->reposition_window(x, y);
211         x += 305;
212         path_button->reposition_window(x, y);
214         x -= 305;
215         y += 35;
216         format_title->reposition_window(x, y);
217         x += 90;
218         format_text->reposition_window(x, y);
219         x += format_text->get_w();
220         format_button->reposition_window(x, y);
222         x = init_x;
223         y += format_button->get_h() + 10;
225         if(do_audio)
226         {
227                 audio_title->reposition_window(x, y);
228                 x += 80;
229                 aparams_button->reposition_window(x, y);
230                 x += aparams_button->get_w() + 10;
231                 if(prompt_audio) audio_switch->reposition_window(x, y);
233                 x = init_x;
234                 y += aparams_button->get_h() + 20;
235                 if(prompt_audio_channels)
236                 {
237                         channels_title->reposition_window(x, y);
238                         x += 260;
239                         channels_button->reposition_window(x, y);
240                         x += channels_button->get_w() + 5;
241                         channels_tumbler->reposition_window(x, y);
242                         y += channels_button->get_h() + 20;
243                         x = init_x;
244                 }
245         }
248         if(do_video)
249         {
250                 video_title->reposition_window(x, y);
251                 x += 80;
252                 if(prompt_video_compression)
253                 {
254                         vparams_button->reposition_window(x, y);
255                         x += vparams_button->get_w() + 10;
256                 }
258                 if(prompt_video)
259                 {
260                         video_switch->reposition_window(x, y);
261                         y += video_switch->get_h();
262                 }
263                 else
264                 {
265                         y += vparams_button->get_h();
266                 }
268                 y += 10;
269                 x = init_x;
270         }
272         if(strategy)
273         {
274                 multiple_files->reposition_window(x, y);
275                 y += multiple_files->get_h() + 10;
276         }
278         init_y = y;
282 int FormatTools::set_audio_options()
284         if(!aparams_thread->running())
285         {
286                 aparams_thread->start();
287         }
288         else
289         {
290                 aparams_thread->file->raise_window();
291         }
293         return 0;
296 int FormatTools::set_video_options()
298         if(!vparams_thread->running())
299         {
300                 vparams_thread->start();
301         }
302         else
303         {
304                 vparams_thread->file->raise_window();
305         }
306         return 0;
313 FormatAParams::FormatAParams(MWindow *mwindow, FormatTools *format, int x, int y)
314  : BC_Button(x, y, mwindow->theme->wrench_data)
316         this->format = format;
317         set_tooltip(_("Configure audio compression"));
319 FormatAParams::~FormatAParams() 
322 int FormatAParams::handle_event() 
324         format->set_audio_options(); 
327 FormatVParams::FormatVParams(MWindow *mwindow, FormatTools *format, int x, int y)
328  : BC_Button(x, y, mwindow->theme->wrench_data)
330         this->format = format; 
331         set_tooltip(_("Configure video compression"));
333 FormatVParams::~FormatVParams() 
336 int FormatVParams::handle_event() 
338         format->set_video_options(); 
342 FormatAThread::FormatAThread(FormatTools *format)
343  : Thread()
345         this->format = format; 
346         file = new File;
348 FormatAThread::~FormatAThread() 
350         delete file;
352 void FormatAThread::run()
354         file->get_options(format->window, 
355                 format->plugindb, 
356                 format->asset, 
357                 1, 
358                 0,
359                 0);
365 FormatVThread::FormatVThread(FormatTools *format, 
366         int lock_compressor)
367  : Thread()
369         this->lock_compressor = lock_compressor;
370         this->format = format;
371         file = new File;
373 FormatVThread::~FormatVThread() 
375         delete file;
377 void FormatVThread::run()
379         file->get_options(format->window, 
380                 format->plugindb, 
381                 format->asset, 
382                 0, 
383                 1, 
384                 lock_compressor);
387 FormatPathText::FormatPathText(int x, int y, FormatTools *format, Asset *asset)
388  : BC_TextBox(x, y, 300, 1, asset->path) 
390         this->format = format; 
391         this->asset = asset; 
393 FormatPathText::~FormatPathText() 
395 int FormatPathText::handle_event() 
397         strcpy(asset->path, get_text());
403 FormatAudio::FormatAudio(int x, int y, FormatTools *format, int default_)
404  : BC_CheckBox(x, 
405         y, 
406         default_, 
407         (char*)(format->recording ? _("Record audio tracks") : _("Render audio tracks")))
409         this->format = format; 
411 FormatAudio::~FormatAudio() {}
412 int FormatAudio::handle_event()
414         format->asset->audio_data = get_value();
418 FormatVideo::FormatVideo(int x, int y, FormatTools *format, int default_)
419  : BC_CheckBox(x, 
420         y, 
421         default_, 
422         (char*)(format->recording ? _("Record video tracks") : _("Render video tracks")))
424 this->format = format; 
426 FormatVideo::~FormatVideo() {}
427 int FormatVideo::handle_event()
429         format->asset->video_data = get_value();
435 FormatFormat::FormatFormat(int x, 
436         int y, 
437         FormatTools *format, 
438         Asset *asset)
439  : FormatPopup(format->plugindb, 
440         x, 
441         y,
442         format->use_brender)
444         this->format = format; 
445         this->asset = asset; 
447 FormatFormat::~FormatFormat() 
450 int FormatFormat::handle_event()
452         if(get_selection(0, 0) >= 0)
453         {
454                 asset->format = File::strtoformat(format->plugindb, get_selection(0, 0)->get_text());
455                 format->format_text->update(get_selection(0, 0)->get_text());
456 //printf("FormatFormat::handle_event %d %s\n", asset->format, get_selection(0, 0)->get_text());
457         }
458         return 1;
463 FormatChannels::FormatChannels(int x, int y, Asset *asset)
464  : BC_TextBox(x, y, 100, 1, asset->channels) 
466         this->asset = asset; 
468 FormatChannels::~FormatChannels() {}
469 int FormatChannels::handle_event() 
471         asset->channels = atol(get_text());
472         return 1;
475 FormatToTracks::FormatToTracks(int x, int y, int *output)
476  : BC_CheckBox(x, y, *output, _("Overwrite project with output"))
478         this->output = output; 
480 FormatToTracks::~FormatToTracks() 
483 int FormatToTracks::handle_event()
485         *output = get_value();
486         return 1;
490 FormatMultiple::FormatMultiple(MWindow *mwindow, int x, int y, int *output)
491  : BC_CheckBox(x, 
492         y, 
493         (*output == FILE_PER_LABEL) || (*output == FILE_PER_LABEL_FARM), 
494         _("Create new file at each label"))
496         this->output = output;
497         this->mwindow = mwindow;
499 FormatMultiple::~FormatMultiple() 
502 int FormatMultiple::handle_event()
504         if(get_value())
505         {
506                 if(mwindow->preferences->use_renderfarm)
507                         *output = FILE_PER_LABEL_FARM;
508                 else
509                         *output = FILE_PER_LABEL;
510         }
511         else
512         {
513                 if(mwindow->preferences->use_renderfarm)
514                         *output = SINGLE_PASS_FARM;
515                 else
516                         *output = SINGLE_PASS;
517         }
518         return 1;