Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

formattools.C

Go to the documentation of this file.
00001 #include "asset.h"
00002 #include "guicast.h"
00003 #include "file.h"
00004 #include "formattools.h"
00005 #include "maxchannels.h"
00006 #include "mwindow.h"
00007 #include "preferences.h"
00008 #include "theme.h"
00009 #include <string.h>
00010 #include "pipe.h"
00011 
00012 #include <libintl.h>
00013 #define _(String) gettext(String)
00014 #define gettext_noop(String) String
00015 #define N_(String) gettext_noop (String)
00016 
00017 FormatTools::FormatTools(MWindow *mwindow,
00018                                 BC_WindowBase *window, 
00019                                 Asset *asset)
00020 {
00021         this->mwindow = mwindow;
00022         this->window = window;
00023         this->asset = asset;
00024         this->plugindb = mwindow->plugindb;
00025 
00026         aparams_thread = 0;
00027         vparams_thread = 0;
00028         w = 0;
00029 }
00030 
00031 FormatTools::~FormatTools()
00032 {
00033         delete aparams_thread;
00034         delete vparams_thread;
00035 }
00036 
00037 int FormatTools::create_objects(int &init_x, 
00038                                                 int &init_y, 
00039                                                 int do_audio,    // Include support for audio
00040                                                 int do_video,   // Include support for video
00041                                                 int prompt_audio,  // Include checkbox for audio
00042                                                 int prompt_video,
00043                                                 int prompt_audio_channels,
00044                                                 int prompt_video_compression,
00045                                                 int lock_compressor,
00046                                                 int recording,
00047                                                 int *strategy,
00048                                                 int brender)
00049 {
00050         int x = init_x;
00051         int y = init_y;
00052 
00053         this->lock_compressor = lock_compressor;
00054         this->recording = recording;
00055         this->use_brender = brender;
00056         this->do_audio = do_audio;
00057         this->do_video = do_video;
00058         this->prompt_audio = prompt_audio;
00059         this->prompt_audio_channels = prompt_audio_channels;
00060         this->prompt_video = prompt_video;
00061         this->prompt_video_compression = prompt_video_compression;
00062         this->strategy = strategy;
00063 
00064 //printf("FormatTools::create_objects 1\n");
00065 
00066 // Modify strategy depending on render farm
00067         if(strategy)
00068         {
00069                 if(mwindow->preferences->use_renderfarm)
00070                 {
00071                         if(*strategy == FILE_PER_LABEL)
00072                                 *strategy = FILE_PER_LABEL_FARM;
00073                         else
00074                         if(*strategy == SINGLE_PASS)
00075                                 *strategy = SINGLE_PASS_FARM;
00076                 }
00077                 else
00078                 {
00079                         if(*strategy == FILE_PER_LABEL_FARM)
00080                                 *strategy = FILE_PER_LABEL;
00081                         else
00082                         if(*strategy == SINGLE_PASS_FARM)
00083                                 *strategy = SINGLE_PASS;
00084                 }
00085         }
00086 
00087 //printf("FormatTools::create_objects 1\n");
00088         window->add_subwindow(path_textbox = new FormatPathText(x, y, this));
00089         x += 300;
00090         path_recent = new BC_RecentList("PATH", mwindow->defaults,
00091                                         path_textbox, 10, x, y, 300, 100);
00092         window->add_subwindow(path_recent);
00093         path_recent->load_items(FILE_FORMAT_PREFIX(asset->format));
00094 
00095         x += 18;
00096         window->add_subwindow(path_button = new BrowseButton(
00097                 mwindow,
00098                 window,
00099                 path_textbox, 
00100                 x, 
00101                 y - 4, 
00102                 asset->path,
00103                 _("Output to file"),
00104                 _("Select a file to write to:"),
00105                 0));
00106 
00107         w = x + path_button->get_w() + 5;
00108 //printf("FormatTools::create_objects 2\n");
00109         x -= 305;
00110 
00111         y += 25;
00112 
00113         pipe_status = new PipeStatus(x, y, "");
00114         window->add_subwindow(pipe_status);
00115         pipe_status->set_status(asset);
00116         
00117         y += 25;
00118 
00119 //printf("FormatTools::create_objects 3\n");
00120         window->add_subwindow(format_title = new BC_Title(x, y, _("File Format:")));
00121         x += 90;
00122         window->add_subwindow(format_text = new BC_TextBox(x, 
00123                 y, 
00124                 200, 
00125                 1, 
00126                 File::formattostr(plugindb, asset->format)));
00127         x += format_text->get_w();
00128         window->add_subwindow(format_button = new FormatFormat(x, 
00129                 y, 
00130                 this));
00131         format_button->create_objects();
00132 
00133 //printf("FormatTools::create_objects 4\n");
00134         x = init_x;
00135         y += format_button->get_h() + 10;
00136         if(do_audio)
00137         {
00138                 window->add_subwindow(audio_title = new BC_Title(x, y, _("Audio:"), LARGEFONT,  BC_WindowBase::get_resources()->audiovideo_color));
00139                 x += 80;
00140                 window->add_subwindow(aparams_button = new FormatAParams(mwindow, this, x, y));
00141                 x += aparams_button->get_w() + 10;
00142                 if(prompt_audio) 
00143                 {
00144                         window->add_subwindow(audio_switch = new FormatAudio(x, y, this, asset->audio_data));
00145                 }
00146                 x = init_x;
00147                 y += aparams_button->get_h() + 20;
00148 
00149 //printf("FormatTools::create_objects 5\n");
00150 // Audio channels only used for recording.
00151                 if(prompt_audio_channels)
00152                 {
00153                         window->add_subwindow(channels_title = new BC_Title(x, y, _("Number of audio channels to record:")));
00154                         x += 260;
00155                         window->add_subwindow(channels_button = new FormatChannels(x, y, this));
00156                         x += channels_button->get_w() + 5;
00157                         window->add_subwindow(channels_tumbler = new BC_ITumbler(channels_button, 1, MAXCHANNELS, x, y));
00158                         y += channels_button->get_h() + 20;
00159                         x = init_x;
00160                 }
00161 
00162 //printf("FormatTools::create_objects 6\n");
00163                 aparams_thread = new FormatAThread(this);
00164         }
00165 
00166 //printf("FormatTools::create_objects 7\n");
00167         if(do_video)
00168         {
00169 
00170 //printf("FormatTools::create_objects 8\n");
00171                 window->add_subwindow(video_title = new BC_Title(x, y, _("Video:"), LARGEFONT,  BC_WindowBase::get_resources()->audiovideo_color));
00172                 x += 80;
00173                 if(prompt_video_compression)
00174                 {
00175                         window->add_subwindow(vparams_button = new FormatVParams(mwindow, this, x, y));
00176                         x += vparams_button->get_w() + 10;
00177                 }
00178 
00179 //printf("FormatTools::create_objects 9\n");
00180                 if(prompt_video)
00181                 {
00182                         window->add_subwindow(video_switch = new FormatVideo(x, y, this, asset->video_data));
00183                         y += video_switch->get_h();
00184                 }
00185                 else
00186                 {
00187                         y += vparams_button->get_h();
00188                 }
00189 
00190 //printf("FormatTools::create_objects 10\n");
00191                 y += 10;
00192                 vparams_thread = new FormatVThread(this, lock_compressor);
00193         }
00194 
00195 //printf("FormatTools::create_objects 11\n");
00196 
00197         x = init_x;
00198         if(strategy)
00199         {
00200                 window->add_subwindow(multiple_files = new FormatMultiple(mwindow, x, y, strategy));
00201                 y += multiple_files->get_h() + 10;
00202         }
00203 
00204 //printf("FormatTools::create_objects 12\n");
00205 
00206         init_y = y;
00207         return 0;
00208 }
00209 
00210 int FormatTools::handle_event()
00211 {
00212         return 0;
00213 }
00214 
00215 Asset* FormatTools::get_asset()
00216 {
00217         return asset;
00218 }
00219 
00220 void FormatTools::update(Asset *asset, int *strategy)
00221 {
00222         this->asset = asset;
00223         this->strategy = strategy;
00224 
00225         path_textbox->update(asset->path);
00226         format_text->update(File::formattostr(plugindb, asset->format));
00227         if(do_audio && audio_switch) audio_switch->update(asset->audio_data);
00228         if(do_video && video_switch) video_switch->update(asset->video_data);
00229         if(strategy)
00230         {
00231                 multiple_files->update(strategy);
00232         }
00233         close_format_windows();
00234 }
00235 
00236 void FormatTools::close_format_windows()
00237 {
00238         if(aparams_thread) aparams_thread->file->close_window();
00239         if(vparams_thread) vparams_thread->file->close_window();
00240 }
00241 
00242 int FormatTools::get_w()
00243 {
00244         return w;
00245 }
00246 
00247 void FormatTools::reposition_window(int &init_x, int &init_y)
00248 {
00249         int x = init_x;
00250         int y = init_y;
00251 
00252         path_textbox->reposition_window(x, y);
00253         x += 305;
00254         path_button->reposition_window(x, y);
00255 
00256         x -= 305;
00257         y += 35;
00258         format_title->reposition_window(x, y);
00259         x += 90;
00260         format_text->reposition_window(x, y);
00261         x += format_text->get_w();
00262         format_button->reposition_window(x, y);
00263 
00264         x = init_x;
00265         y += format_button->get_h() + 10;
00266 
00267         if(do_audio)
00268         {
00269                 audio_title->reposition_window(x, y);
00270                 x += 80;
00271                 aparams_button->reposition_window(x, y);
00272                 x += aparams_button->get_w() + 10;
00273                 if(prompt_audio) audio_switch->reposition_window(x, y);
00274 
00275                 x = init_x;
00276                 y += aparams_button->get_h() + 20;
00277                 if(prompt_audio_channels)
00278                 {
00279                         channels_title->reposition_window(x, y);
00280                         x += 260;
00281                         channels_button->reposition_window(x, y);
00282                         x += channels_button->get_w() + 5;
00283                         channels_tumbler->reposition_window(x, y);
00284                         y += channels_button->get_h() + 20;
00285                         x = init_x;
00286                 }
00287         }
00288 
00289 
00290         if(do_video)
00291         {
00292                 video_title->reposition_window(x, y);
00293                 x += 80;
00294                 if(prompt_video_compression)
00295                 {
00296                         vparams_button->reposition_window(x, y);
00297                         x += vparams_button->get_w() + 10;
00298                 }
00299 
00300                 if(prompt_video)
00301                 {
00302                         video_switch->reposition_window(x, y);
00303                         y += video_switch->get_h();
00304                 }
00305                 else
00306                 {
00307                         y += vparams_button->get_h();
00308                 }
00309 
00310                 y += 10;
00311                 x = init_x;
00312         }
00313 
00314         if(strategy)
00315         {
00316                 multiple_files->reposition_window(x, y);
00317                 y += multiple_files->get_h() + 10;
00318         }
00319 
00320         init_y = y;
00321 }
00322 
00323 
00324 int FormatTools::set_audio_options()
00325 {
00326         if(!aparams_thread->running())
00327         {
00328                 aparams_thread->start();
00329         }
00330         else
00331         {
00332                 aparams_thread->file->raise_window();
00333         }
00334 
00335         return 0;
00336 }
00337 
00338 int FormatTools::set_video_options()
00339 {
00340         if(!vparams_thread->running())
00341         {
00342                 vparams_thread->start();
00343         }
00344         else
00345         {
00346                 vparams_thread->file->raise_window();
00347         }
00348         return 0;
00349 }
00350 
00351 
00352 
00353 
00354 
00355 FormatAParams::FormatAParams(MWindow *mwindow, FormatTools *format, int x, int y)
00356  : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
00357 {
00358         this->format = format;
00359         set_tooltip(_("Configure audio compression"));
00360 }
00361 FormatAParams::~FormatAParams() 
00362 {
00363 }
00364 int FormatAParams::handle_event() 
00365 {
00366         format->set_audio_options(); 
00367 }
00368 
00369 FormatVParams::FormatVParams(MWindow *mwindow, FormatTools *format, int x, int y)
00370  : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
00371 { 
00372         this->format = format; 
00373         set_tooltip(_("Configure video compression"));
00374 }
00375 FormatVParams::~FormatVParams() 
00376 {
00377 }
00378 int FormatVParams::handle_event() 
00379 { 
00380         format->set_video_options(); 
00381 }
00382 
00383 
00384 FormatAThread::FormatAThread(FormatTools *format)
00385  : Thread()
00386 { 
00387         this->format = format; 
00388         file = new File;
00389 }
00390 
00391 FormatAThread::~FormatAThread() 
00392 {
00393         delete file;
00394 }
00395 
00396 void FormatAThread::run()
00397 {
00398         file->get_options(format, 1, 0, 0);
00399 }
00400 
00401 
00402 
00403 
00404 FormatVThread::FormatVThread(FormatTools *format, 
00405         int lock_compressor)
00406  : Thread()
00407 {
00408         this->lock_compressor = lock_compressor;
00409         this->format = format;
00410         file = new File;
00411 }
00412 
00413 FormatVThread::~FormatVThread() 
00414 {
00415         delete file;
00416 }
00417 
00418 void FormatVThread::run()
00419 {
00420         file->get_options(format, 0, 1, lock_compressor);
00421 }
00422 
00423 FormatPathText::FormatPathText(int x, int y, FormatTools *format)
00424  : BC_TextBox(x, y, 300, 1, format->asset->path) 
00425 {
00426         this->format = format; 
00427 }
00428 FormatPathText::~FormatPathText() 
00429 {
00430 }
00431 int FormatPathText::handle_event() 
00432 {
00433         strcpy(format->asset->path, get_text());
00434         format->handle_event();
00435 }
00436 
00437 
00438 
00439 
00440 FormatAudio::FormatAudio(int x, int y, FormatTools *format, int default_)
00441  : BC_CheckBox(x, 
00442         y, 
00443         default_, 
00444         (char*)(format->recording ? _("Record audio tracks") : _("Render audio tracks")))
00445 { 
00446         this->format = format; 
00447 }
00448 FormatAudio::~FormatAudio() {}
00449 int FormatAudio::handle_event()
00450 {
00451         format->asset->audio_data = get_value();
00452 }
00453 
00454 
00455 FormatVideo::FormatVideo(int x, int y, FormatTools *format, int default_)
00456  : BC_CheckBox(x, 
00457         y, 
00458         default_, 
00459         (char*)(format->recording ? _("Record video tracks") : _("Render video tracks")))
00460 {
00461 this->format = format; 
00462 }
00463 FormatVideo::~FormatVideo() {}
00464 int FormatVideo::handle_event()
00465 {
00466         format->asset->video_data = get_value();
00467 }
00468 
00469 
00470 
00471 
00472 FormatFormat::FormatFormat(int x, 
00473         int y, 
00474         FormatTools *format)
00475  : FormatPopup(format->plugindb, 
00476         x, 
00477         y,
00478         format->use_brender)
00479 { 
00480         this->format = format; 
00481 }
00482 FormatFormat::~FormatFormat() 
00483 {
00484 }
00485 int FormatFormat::handle_event()
00486 {
00487         if(get_selection(0, 0) >= 0)
00488         {
00489                 int new_format = File::strtoformat(format->plugindb, get_selection(0, 0)->get_text());
00490                 if(new_format != format->asset->format)
00491                 {
00492                         // save the state of the old format
00493                         format->asset->save_format_defaults
00494                                 (format->mwindow->defaults);
00495 
00496                         // close the configure window if open
00497                         format->close_format_windows();
00498 
00499                         // change to the new format
00500                         format->asset->format = new_format;
00501 
00502                         // load the state for the new format
00503                         format->asset->load_format_defaults
00504                                 (format->mwindow->defaults);
00505 
00506                         // update the render window to match
00507                         format->format_text->
00508                                 update(get_selection(0, 0)->get_text());
00509                         format->path_textbox->update(format->asset->path);
00510                         format->pipe_status->set_status(format->asset);
00511                         format->path_recent->load_items
00512                                 (FILE_FORMAT_PREFIX(format->asset->format));
00513                 }
00514         }
00515         return 1;
00516 }
00517 
00518 
00519 
00520 FormatChannels::FormatChannels(int x, int y, FormatTools *format)
00521  : BC_TextBox(x, y, 100, 1, format->asset->channels) 
00522 { 
00523         this->format = format; 
00524 }
00525 FormatChannels::~FormatChannels() 
00526 {
00527 }
00528 int FormatChannels::handle_event() 
00529 {
00530         format->asset->channels = atol(get_text());
00531         return 1;
00532 }
00533 
00534 FormatToTracks::FormatToTracks(int x, int y, int *output)
00535  : BC_CheckBox(x, y, *output, _("Overwrite project with output"))
00536 { 
00537         this->output = output; 
00538 }
00539 FormatToTracks::~FormatToTracks() 
00540 {
00541 }
00542 int FormatToTracks::handle_event()
00543 {
00544         *output = get_value();
00545         return 1;
00546 }
00547 
00548 
00549 FormatMultiple::FormatMultiple(MWindow *mwindow, int x, int y, int *output)
00550  : BC_CheckBox(x, 
00551         y, 
00552         (*output == FILE_PER_LABEL) || (*output == FILE_PER_LABEL_FARM), 
00553         _("Create new file at each label"))
00554 { 
00555         this->output = output;
00556         this->mwindow = mwindow;
00557 }
00558 FormatMultiple::~FormatMultiple() 
00559 {
00560 }
00561 int FormatMultiple::handle_event()
00562 {
00563         if(get_value())
00564         {
00565                 if(mwindow->preferences->use_renderfarm)
00566                         *output = FILE_PER_LABEL_FARM;
00567                 else
00568                         *output = FILE_PER_LABEL;
00569         }
00570         else
00571         {
00572                 if(mwindow->preferences->use_renderfarm)
00573                         *output = SINGLE_PASS_FARM;
00574                 else
00575                         *output = SINGLE_PASS;
00576         }
00577         return 1;
00578 }
00579 
00580 void FormatMultiple::update(int *output)
00581 {
00582         this->output = output;
00583         if(*output == FILE_PER_LABEL_FARM ||
00584                 *output ==FILE_PER_LABEL)
00585                 set_value(1);
00586         else
00587                 set_value(0);
00588 }
00589 
00590 

Generated on Sun Jan 8 13:38:55 2006 for Cinelerra-svn by  doxygen 1.4.4