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