3 * Copyright (C) 1997-2011 Adam Williams <broadcast at earthling dot net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "awindowgui.h"
26 #include "batchrender.h"
27 #include "bcprogressbox.h"
28 #include "bcsignals.h"
31 #include "compresspopup.h"
32 #include "condition.h"
33 #include "confirmsave.h"
34 #include "cwindowgui.h"
39 #include "edlsession.h"
42 #include "filesystem.h"
44 #include "formatcheck.h"
45 #include "formatpopup.h"
46 #include "formattools.h"
47 #include "indexable.h"
51 #include "localsession.h"
52 #include "mainprogress.h"
53 #include "mainsession.h"
57 #include "mwindowgui.h"
59 #include "packagedispatcher.h"
60 #include "packagerenderer.h"
62 #include "playabletracks.h"
63 #include "preferences.h"
64 #include "preferencesthread.h"
65 #include "renderfarm.h"
67 #include "renderprofiles.h"
68 #include "statusbar.h"
72 #include "transportque.h"
75 #include "videoconfig.h"
83 RenderItem::RenderItem(MWindow *mwindow)
84 : BC_MenuItem(_("Render..."), _("Shift-R"), 'R')
86 this->mwindow = mwindow;
90 int RenderItem::handle_event()
92 mwindow->gui->unlock_window();
93 mwindow->render->start_interactive();
94 mwindow->gui->lock_window("RenderItem::handle_event");
98 RenderProgress::RenderProgress(MWindow *mwindow, Render *render)
101 this->mwindow = mwindow;
102 this->render = render;
104 Thread::set_synchronous(1);
107 RenderProgress::~RenderProgress()
114 void RenderProgress::run()
116 Thread::disable_cancel();
118 if( render->total_rendered != last_value ) {
119 render->progress->update(render->total_rendered);
120 last_value = render->total_rendered;
122 if( mwindow ) mwindow->preferences_thread->update_rates();
125 Thread::enable_cancel();
127 Thread::disable_cancel();
133 MainPackageRenderer::MainPackageRenderer(Render *render)
136 this->render = render;
141 MainPackageRenderer::~MainPackageRenderer()
146 int MainPackageRenderer::get_master()
151 int MainPackageRenderer::get_result()
153 return render->result;
156 void MainPackageRenderer::set_result(int value)
159 render->result = value;
162 void MainPackageRenderer::set_progress(int64_t value)
164 render->counter_lock->lock("MainPackageRenderer::set_progress");
165 // Increase total rendered for all nodes
166 render->total_rendered += value;
168 // Update frames per second for master node
169 render->preferences->set_rate(frames_per_second, -1);
171 //printf("MainPackageRenderer::set_progress %d %ld %f\n", __LINE__, (long)value, frames_per_second);
173 // If non interactive, print progress out
174 if( !render->progress )
175 render->show_progress();
177 render->counter_lock->unlock();
180 mwindow->preferences->copy_rates_from(preferences);
183 int MainPackageRenderer::progress_cancelled()
185 return (render->progress && render->progress->is_cancelled()) ||
186 render->batch_cancelled;
189 void RenderAssets::clear()
191 for( int i=size(); --i>=0; get(i)->remove_user() );
194 RenderAssets::RenderAssets()
197 RenderAssets::~RenderAssets()
202 Render::Render(MWindow *mwindow)
205 this->mwindow = mwindow;
209 package_lock = new Mutex("Render::package_lock");
210 counter_lock = new Mutex("Render::counter_lock");
211 completion = new Condition(0, "Render::completion");
212 progress_timer = new Timer;
213 range_type = RANGE_BACKCOMPAT;
214 preferences = new Preferences();
215 thread = new RenderThread(mwindow, this);
229 delete progress_timer;
230 if( asset ) asset->Garbage::remove_user();
234 void Render::start_interactive()
236 if( !thread->running() ) {
237 mode = Render::INTERACTIVE;
238 BC_DialogThread::start();
240 else if( in_progress ) {
242 mwindow->gui->get_abs_cursor(cx, cy, 1);
243 ErrorBox error_box(_(PROGRAM_NAME ": Error"), cx, cy);
244 error_box.create_objects(_("Already rendering"));
245 error_box.raise_window();
246 error_box.run_window();
248 else if( render_window ) {
249 render_window->raise_window();
254 void Render::start_batches(ArrayList<BatchRenderJob*> *jobs)
256 if( !thread->running() ) {
257 mode = Render::BATCH;
263 else if( in_progress ) {
265 mwindow->gui->get_abs_cursor(cx, cy, 1);
266 ErrorBox error_box(_(PROGRAM_NAME ": Error"), cx, cy);
267 error_box.create_objects("Already rendering");
268 error_box.raise_window();
269 error_box.run_window();
271 // raise the window if rendering hasn't started yet
272 else if( render_window ) {
273 render_window->raise_window();
277 void Render::start_batches(ArrayList<BatchRenderJob*> *jobs,
278 BC_Hash *boot_defaults, Preferences *batch_prefs)
280 mode = Render::BATCH;
282 preferences->copy_from(batch_prefs);
290 BC_Window* Render::new_gui()
296 if( mode == Render::INTERACTIVE ) {
297 // Fix the asset for rendering
298 if( !asset ) asset = new Asset;
299 load_defaults(asset);
300 check_asset(mwindow->edl, *asset);
301 int px = mwindow->gui->get_pop_cursor_x(1);
302 int py = mwindow->gui->get_pop_cursor_y(1);
303 // Get format from user
304 render_window = new RenderWindow(mwindow, this, asset, px, py);
305 render_window->create_objects();
308 return render_window;
311 void Render::handle_done_event(int result)
314 mwindow->edl->session->render_beep = beep;
315 // add to recentlist only on OK
316 render_window->render_format->path_recent->
317 add_item(File::formattostr(asset->format), asset->path);
318 setenv("CIN_RENDER", asset->path, 1);
323 void Render::handle_close_event(int result)
326 double render_range = get_render_range();
327 const char *err_msg = 0;
329 if( !result && !render_range ) {
330 err_msg = _("zero render range");
333 if( !result && asset->video_data ) {
334 double frame_rate = mwindow->edl->session->frame_rate;
335 if( frame_rate > 0 && render_range+1e-3 < 1./frame_rate ) {
336 err_msg = _("Video data and range less than 1 frame");
340 if( !result && asset->audio_data ) {
341 double sample_rate = mwindow->edl->session->sample_rate;
342 if( sample_rate > 0 && render_range+1e-6 < 1./sample_rate ) {
343 err_msg = _("Audio data and range less than 1 sample");
347 if( !result && File::is_image_render(asset->format) ) {
348 if( asset->video_data ) {
349 double frames = render_range * mwindow->edl->session->frame_rate;
350 if( !EQUIV(frames, 1.) ) {
351 err_msg = _("Image format and not 1 frame");
356 err_msg = _("Image format and no video data");
362 mwindow->gui->get_abs_cursor(cx, cy, 1);
363 ErrorBox error_box(_(PROGRAM_NAME ": Error"),cx, cy);
364 error_box.create_objects(err_msg);
365 error_box.raise_window();
366 error_box.run_window();
370 // Check the asset format for errors.
371 FormatCheck format_check(asset);
372 if( format_check.check_format() )
378 save_defaults(asset);
380 mwindow->save_defaults();
384 if( debug ) printf("Render::handle_close_event %d\n", __LINE__);
385 if( !result ) start_render();
386 if( debug ) printf("Render::handle_close_event %d\n", __LINE__);
393 void Render::stop_operation()
395 if( thread->Thread::running() ) {
397 // Wait for completion
398 completion->lock("Render::stop_operation");
403 int Render::check_asset(EDL *edl, Asset &asset)
405 if( asset.video_data &&
406 edl->tracks->playable_video_tracks() &&
407 File::renders_video(&asset) ) {
408 asset.video_data = 1;
410 asset.width = edl->session->output_w;
411 asset.height = edl->session->output_h;
412 asset.interlace_mode = edl->session->interlace_mode;
415 asset.video_data = 0;
419 if( asset.audio_data &&
420 edl->tracks->playable_audio_tracks() &&
421 File::renders_audio(&asset) ) {
422 asset.audio_data = 1;
423 asset.channels = edl->session->audio_channels;
426 asset.audio_data = 0;
430 if( !asset.audio_data &&
431 !asset.video_data ) {
437 int Render::get_strategy(int use_renderfarm, int use_labels)
439 return use_renderfarm ?
440 (use_labels ? FILE_PER_LABEL_FARM : SINGLE_PASS_FARM) :
441 (use_labels ? FILE_PER_LABEL : SINGLE_PASS ) ;
443 int Render::get_strategy()
445 return get_strategy(preferences->use_renderfarm, use_labels);
448 void Render::start_progress()
450 char filename[BCTEXTLEN];
451 char string[BCTEXTLEN];
452 progress_max = packages->get_progress_max();
454 progress_timer->update();
457 // Generate the progress box
459 fs.extract_name(filename, default_asset->path);
460 sprintf(string, _("Rendering %s..."), filename);
462 // Don't bother with the filename since renderfarm defeats the meaning
463 progress = mwindow->mainprogress->start_progress(_("Rendering..."),
465 render_progress = new RenderProgress(mwindow, this);
466 render_progress->start();
470 void Render::stop_progress()
473 char string[BCTEXTLEN], string2[BCTEXTLEN];
474 delete render_progress;
475 progress->get_time(string);
476 elapsed_time = progress->get_time();
477 progress->stop_progress();
480 sprintf(string2, _("Rendering took %s"), string);
481 mwindow->gui->lock_window("");
482 mwindow->gui->show_message(string2);
483 mwindow->gui->update_default_message();
484 mwindow->gui->stop_hourglass();
485 mwindow->gui->unlock_window();
490 void Render::show_progress()
492 int64_t current_eta = progress_timer->get_scaled_difference(1000);
493 if( current_eta - last_eta < 1000 ) return;
494 double eta = !total_rendered ? 0 :
495 current_eta / 1000. * (progress_max / (double)total_rendered - 1.);
496 char string[BCTEXTLEN]; Units::totext(string, eta, TIME_HMS2);
497 printf("\r%d%% %s: %s ",
498 (int)(100 * (float)total_rendered / progress_max), _("ETA"), string);
500 last_eta = current_eta;
505 void Render::start_render()
515 void Render::create_filename(char *path,
522 int len = strlen(default_path);
523 char printf_string[BCTEXTLEN];
525 for( i=0, j=0; i<number_start; ++i, ++j ) {
526 printf_string[j] = default_path[i];
530 sprintf(&printf_string[j], "%%0%dd", total_digits);
531 j = strlen(printf_string);
534 // Copy remainder of string
535 for( ; i<len; ++i, ++j ) {
536 printf_string[j] = default_path[i];
538 printf_string[j] = 0;
539 // Print the printf argument to the path
540 sprintf(path, printf_string, current_number);
543 void Render::get_starting_number(char *path,
549 int len = strlen(path);
550 char number_text[BCTEXTLEN];
558 ptr2 = strrchr(path, '/');
560 // Search for first 0 after last /.
562 ptr = strchr(ptr2, '0');
564 if( ptr && isdigit(*ptr) ) {
565 number_start = ptr - path;
567 // Store the first number
568 char *ptr2 = number_text;
569 while( isdigit(*ptr) ) *ptr2++ = *ptr++;
571 current_number = atol(number_text);
572 total_digits = strlen(number_text);
576 // No number found or number not long enough
577 if( total_digits < min_digits ) {
580 total_digits = min_digits;
585 int Render::load_defaults(Asset *asset)
587 use_labels = mwindow->defaults->get("RENDER_FILE_PER_LABEL", 0);
588 load_mode = mwindow->defaults->get("RENDER_LOADMODE", LOADMODE_NEW_TRACKS);
589 range_type = mwindow->defaults->get("RENDER_RANGE_TYPE", RANGE_PROJECT);
591 // some defaults which work
592 asset->video_data = 1;
593 asset->audio_data = 1;
594 asset->format = FILE_FFMPEG;
595 strcpy(asset->acodec, "mp4.qt");
596 strcpy(asset->vcodec, "mp4.qt");
598 asset->load_defaults(mwindow->defaults,
599 "RENDER_", 1, 1, 1, 1, 1);
603 int Render::load_profile(int profile_slot, Asset *asset)
605 char string_name[100];
606 sprintf(string_name, "RENDER_%i_FILE_PER_LABEL", profile_slot);
607 use_labels = mwindow->defaults->get(string_name, 0);
608 // Load mode is not part of the profile
609 // printf(string_name, "RENDER_%i_LOADMODE", profile_slot);
610 // load_mode = mwindow->defaults->get(string_name, LOADMODE_NEW_TRACKS);
611 sprintf(string_name, "RENDER_%i_RANGE_TYPE", profile_slot);
612 range_type = mwindow->defaults->get(string_name, RANGE_PROJECT);
614 sprintf(string_name, "RENDER_%i_", profile_slot);
615 asset->load_defaults(mwindow->defaults,
616 string_name, 1, 1, 1, 1, 1);
621 int Render::save_defaults(Asset *asset)
623 mwindow->defaults->update("RENDER_FILE_PER_LABEL", use_labels);
624 mwindow->defaults->update("RENDER_LOADMODE", load_mode);
625 mwindow->defaults->update("RENDER_RANGE_TYPE", range_type);
627 asset->save_defaults(mwindow->defaults,
628 "RENDER_", 1, 1, 1, 1, 1);
632 void Render::update_assets()
635 packages->get_asset_list(assets);
638 static void run_script(const char *script, const char *arg)
640 char *const argv[] = { (char*)script, (char*)arg, 0 };
641 execvp(script ,&argv[0]);
642 perror("execvp script failed");
646 RenderThread::RenderThread(MWindow *mwindow, Render *render)
649 this->mwindow = mwindow;
650 this->render = render;
654 RenderThread::~RenderThread()
659 void RenderThread::render_single(int test_overwrite, Asset *asset, EDL *edl,
660 int strategy, int range_type)
662 // Total length in seconds
663 double total_length = 0;
664 RenderFarmServer *farm_server = 0;
666 render->in_progress = 1;
667 render->default_asset = asset;
668 render->progress = 0;
671 // Create rendering command
672 TransportCommand *command = new TransportCommand;
673 command->command = NORMAL_FWD;
674 command->get_edl()->copy_all(edl);
675 command->change_type = CHANGE_ALL;
677 switch( range_type ) {
678 case RANGE_BACKCOMPAT:
679 // Get highlighted playback range
680 command->set_playback_range();
681 // Adjust playback range with in/out points
682 command->playback_range_adjust_inout();
685 command->playback_range_project();
687 case RANGE_SELECTION:
688 command->set_playback_range();
691 command->playback_range_inout();
694 command->playback_range_1frame();
698 render->packages = new PackageDispatcher;
701 CICache *audio_cache = new CICache(render->preferences);
702 CICache *video_cache = new CICache(render->preferences);
704 render->default_asset->frame_rate = command->get_edl()->session->frame_rate;
705 render->default_asset->sample_rate = command->get_edl()->session->sample_rate;
707 // Conform asset to EDL. Find out if any tracks are playable.
708 render->result = render->check_asset(command->get_edl(),
709 *render->default_asset);
711 if( !render->result ) {
712 // Get total range to render
713 render->total_start = command->start_position;
714 render->total_end = command->end_position;
715 total_length = render->total_end - render->total_start;
718 if( EQUIV(total_length, 0) ) {
722 render_frames = render->default_asset->frame_rate * total_length;
725 if( !render->result ) {
726 // Stop background rendering
727 if( mwindow ) mwindow->stop_brender();
730 fs.complete_path(render->default_asset->path);
732 render->result = render->packages->create_packages(mwindow, command->get_edl(),
733 render->preferences, strategy, render->default_asset,
734 render->total_start, render->total_end, test_overwrite);
737 render->total_rendered = 0;
739 if( !render->result &&
740 ( strategy == SINGLE_PASS_FARM || strategy == FILE_PER_LABEL_FARM ) ) {
741 // Start dispatching external jobs
743 mwindow->gui->lock_window("Render::render 1");
744 mwindow->gui->show_message(_("Starting render farm"));
745 mwindow->gui->start_hourglass();
746 mwindow->gui->unlock_window();
749 printf("Render::render: starting render farm\n");
752 farm_server = new RenderFarmServer(mwindow, render->packages,
753 render->preferences, 1, &render->result,
754 &render->total_rendered, render->counter_lock,
755 render->default_asset, command->get_edl(), 0);
756 render->result = farm_server->start_clients();
758 if( render->result ) {
760 mwindow->gui->lock_window("Render::render 2");
761 mwindow->gui->show_message(_("Failed to start render farm"),
762 mwindow->theme->message_error);
763 mwindow->gui->stop_hourglass();
764 mwindow->gui->unlock_window();
767 printf("Render::render: Failed to start render farm\n");
772 // Perform local rendering
774 render->assets.clear();
775 if( !render->result ) {
776 render->start_progress();
778 MainPackageRenderer package_renderer(render);
779 render->result = package_renderer.initialize(mwindow,
780 command->get_edl(), // Copy of master EDL
782 render->default_asset);
784 while( !render->result ) {
785 int fps = strategy == SINGLE_PASS_FARM ?
786 package_renderer.frames_per_second : 0;
787 // Get unfinished job
788 RenderPackage *package = render->packages->get_package(fps, -1, 1);
790 if( !package ) break;
792 if( package_renderer.render_package(package) )
796 printf("Render::render_single: Session finished.\n");
798 if( strategy == SINGLE_PASS_FARM ||
799 strategy == FILE_PER_LABEL_FARM ) {
800 if( !render->progress ) {
801 while( farm_server->active_clients() > 0 ) {
803 render->show_progress();
806 farm_server->wait_clients();
807 render->result |= render->packages->packages_are_done();
811 if( render->result && !render->batch_cancelled &&
812 (!render->progress || !render->progress->is_cancelled()) ) {
815 mwindow->gui->get_abs_cursor(cx, cy, 1);
816 ErrorBox error_box(_(PROGRAM_NAME ": Error"), cx, cy);
817 error_box.create_objects(_("Error rendering data."));
818 error_box.raise_window();
819 error_box.run_window();
822 printf("Render::render: Error rendering data\n");
826 // Delete the progress box
827 render->stop_progress();
828 render->update_assets();
831 // Paste all packages into timeline if desired
833 if( !render->result && mwindow &&
834 render->load_mode != LOADMODE_NOTHING &&
835 render->mode != Render::BATCH ) {
836 mwindow->gui->lock_window("Render::render 3");
838 mwindow->undo->update_undo_before();
839 if( render->load_mode == LOADMODE_PASTE )
841 mwindow->load_assets(&render->assets,
842 -1, render->load_mode, 0, 0,
843 mwindow->edl->session->labels_follow_edits,
844 mwindow->edl->session->plugins_follow_edits,
845 mwindow->edl->session->autos_follow_edits,
847 mwindow->save_backup();
848 mwindow->undo->update_undo_after(_("render"), LOAD_ALL);
849 mwindow->update_plugin_guis();
850 mwindow->gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
851 mwindow->sync_parameters(CHANGE_ALL);
852 mwindow->gui->unlock_window();
854 mwindow->awindow->gui->async_update_assets();
859 mwindow->gui->lock_window("Render::render 3");
860 mwindow->gui->stop_hourglass();
861 mwindow->gui->unlock_window();
864 //printf("Render::render 110\n");
865 // Need to restart because brender always stops before render.
867 mwindow->restart_brender();
868 if( farm_server ) delete farm_server;
872 // Must delete packages after server
873 delete render->packages;
875 render->packages = 0;
876 render->in_progress = 0;
879 void RenderThread::run()
885 render->preferences->copy_from(mwindow->preferences);
887 if( render->mode == Render::INTERACTIVE ) {
888 render_single(1, render->asset, mwindow->edl,
889 render->get_strategy(), render->range_type);
892 if( render->mode == Render::BATCH ) {
893 for( int i=0; i<render->jobs->total && !render->result; ++i ) {
894 BatchRenderJob *job = render->jobs->values[i];
895 if( !job->enabled ) continue;
897 mwindow->batch_render->update_active(i);
899 printf("Render::run: %s\n", job->edl_path);
901 FileXML *file = new FileXML;
903 edl->create_objects();
904 file->read_from_file(job->edl_path);
905 edl->load_xml(file, LOAD_ALL);
908 render_single(0, job->asset, edl, job->get_strategy(), RANGE_BACKCOMPAT);
909 if( !render->result ) {
911 script = job->create_script(edl, &render->assets);
913 mwindow->batch_render->update_done(i, 1, render->elapsed_time);
915 char string[BCTEXTLEN];
916 render->elapsed_time =
917 (double)render->progress_timer->get_scaled_difference(1);
918 Units::totext(string, render->elapsed_time, TIME_HMS2);
919 printf("Render::run: done in %s\n", string);
924 mwindow->batch_render->update_active(-1);
926 printf("Render::run: failed\n");
930 mwindow->batch_render->update_active(-1);
931 mwindow->batch_render->update_done(-1, 0, 0);
934 render->completion->unlock();
936 if( !render->result ) {
937 double render_time = render_timer.get_difference() / 1000.0;
938 double render_rate = render_time > 0 ? render_frames / render_time : 0;
939 printf("** rendered %jd frames in %0.3f secs, %0.3f fps\n",
940 render_frames, render_time, render_rate);
943 if( render->mode == Render::INTERACTIVE && render->beep )
944 mwindow->beep(3000., 1.5, 0.5);
947 if( !render->result )
948 run_script(script, 0);
958 RenderWindow::RenderWindow(MWindow *mwindow,
963 : BC_Window(_(PROGRAM_NAME ": Render"), x, y,
964 WIDTH, HEIGHT, WIDTH, HEIGHT, 0, 0, 1)
966 this->mwindow = mwindow;
967 this->render = render;
978 RenderWindow::~RenderWindow()
980 lock_window("RenderWindow::~RenderWindow");
981 delete render_format;
983 delete renderprofile;
988 void RenderWindow::load_profile(int profile_slot)
990 render->load_profile(profile_slot, asset);
991 update_range_type(render->range_type);
992 render_format->update(asset, &render->use_labels);
996 void RenderWindow::create_objects()
999 lock_window("RenderWindow::create_objects");
1000 add_subwindow(new BC_Title(x, y,
1001 (char*)(render->use_labels ?
1002 _("Select the first file to render to:") :
1003 _("Select a file to render to:"))));
1006 render_format = new RenderFormat(mwindow, this, asset);
1007 render_format->create_objects(x, y,
1008 1, 1, 1, 1, 0, 1, 0, 0, &render->use_labels, 0);
1011 add_subwindow(title = new BC_Title(x, y, _("Render range:")));
1013 int is_image = File::is_image_render(asset->format);
1015 render->range_type = RANGE_1FRAME;
1017 int x1 = x + title->get_w() + 20, y1 = y;
1018 add_subwindow(rangeproject = new RenderRangeProject(this,
1019 render->range_type == RANGE_PROJECT, x1, y));
1020 int x2 = x1 + rangeproject->get_w();
1022 add_subwindow(rangeselection = new RenderRangeSelection(this,
1023 render->range_type == RANGE_SELECTION, x1, y));
1024 int x3 = x1 + rangeselection->get_w();
1025 if( x2 < x3 ) x2 = x3;
1027 add_subwindow(rangeinout = new RenderRangeInOut(this,
1028 render->range_type == RANGE_INOUT, x1, y));
1029 x3 = x1 + rangeinout->get_w();
1030 if( x2 < x3 ) x2 = x3;
1032 add_subwindow(range1frame = new RenderRange1Frame(this,
1033 render->range_type == RANGE_1FRAME, x1, y));
1034 x3 = x1 + range1frame->get_w();
1035 if( x2 < x3 ) x2 = x3;
1038 enable_render_range(0);
1041 render->beep = mwindow->edl->session->render_beep;
1042 add_subwindow(beep_on_done = new RenderBeepOnDone(this, x1, y1));
1044 renderprofile = new RenderProfile(mwindow, this, x, y, 1);
1045 renderprofile->create_objects();
1048 loadmode = new LoadMode(mwindow, this, x, y, &render->load_mode, 1);
1049 loadmode->create_objects();
1051 add_subwindow(new BC_OKButton(this));
1052 add_subwindow(new BC_CancelButton(this));
1058 void RenderWindow::update_range_type(int range_type)
1060 if( render->range_type == range_type ) return;
1061 render->range_type = range_type;
1062 rangeproject->update(range_type == RANGE_PROJECT);
1063 rangeselection->update(range_type == RANGE_SELECTION);
1064 rangeinout->update(range_type == RANGE_INOUT);
1065 range1frame->update(range_type == RANGE_1FRAME);
1068 void RenderWindow::enable_render_range(int v)
1071 rangeproject->enable();
1072 rangeselection->enable();
1073 rangeinout->enable();
1074 range1frame->enable();
1077 rangeproject->disable();
1078 rangeselection->disable();
1079 rangeinout->disable();
1080 range1frame->disable();
1085 RenderRangeProject::RenderRangeProject(RenderWindow *rwindow, int value, int x, int y)
1086 : BC_Radial(x, y, value, _("Project"))
1088 this->rwindow = rwindow;
1090 int RenderRangeProject::handle_event()
1092 rwindow->update_range_type(RANGE_PROJECT);
1096 RenderRangeSelection::RenderRangeSelection(RenderWindow *rwindow, int value, int x, int y)
1097 : BC_Radial(x, y, value, _("Selection"))
1099 this->rwindow = rwindow;
1101 int RenderRangeSelection::handle_event()
1103 rwindow->update_range_type(RANGE_SELECTION);
1108 RenderRangeInOut::RenderRangeInOut(RenderWindow *rwindow, int value, int x, int y)
1109 : BC_Radial(x, y, value, _("In/Out Points"))
1111 this->rwindow = rwindow;
1113 int RenderRangeInOut::handle_event()
1115 rwindow->update_range_type(RANGE_INOUT);
1119 RenderRange1Frame::RenderRange1Frame(RenderWindow *rwindow, int value, int x, int y)
1120 : BC_Radial(x, y, value, _("One Frame"))
1122 this->rwindow = rwindow;
1124 int RenderRange1Frame::handle_event()
1126 rwindow->update_range_type(RANGE_1FRAME);
1130 double Render::get_render_range()
1132 EDL *edl = mwindow->edl;
1133 double last = edl->tracks->total_playable_length();
1134 double framerate = edl->session->frame_rate;
1135 if( framerate <= 0 ) framerate = 1;
1136 double start = 0, end = last;
1137 switch( range_type ) {
1139 case RANGE_BACKCOMPAT:
1140 start = edl->local_session->get_selectionstart(1);
1141 end = edl->local_session->get_selectionend(1);
1142 if( EQUIV(start, end) ) end = last;
1146 case RANGE_SELECTION:
1147 start = edl->local_session->get_selectionstart(1);
1148 end = edl->local_session->get_selectionend(1);
1151 start = edl->local_session->inpoint_valid() ?
1152 edl->local_session->get_inpoint() : 0;
1153 end = edl->local_session->outpoint_valid() ?
1154 edl->local_session->get_outpoint() : last;
1157 start = end = edl->local_session->get_selectionstart(1);
1158 if( edl->session->frame_rate > 0 ) end += 1./edl->session->frame_rate;
1161 if( start < 0 ) start = 0;
1162 if( end > last ) end = last;
1166 RenderFormat::RenderFormat(MWindow *mwindow, BC_WindowBase *window, Asset *asset)
1167 : FormatTools(mwindow, window, asset)
1170 RenderFormat::~RenderFormat()
1174 void RenderFormat::update_format()
1176 FormatTools::update_format();
1177 RenderWindow *render_window = (RenderWindow *)window;
1178 if( render_window->is_hidden() ) return;
1180 int is_image = File::is_image_render(asset->format);
1182 render_window->update_range_type(RANGE_1FRAME);
1183 render_window->enable_render_range(0);
1186 render_window->enable_render_range(1);
1189 RenderBeepOnDone::RenderBeepOnDone(RenderWindow *rwindow, int x, int y)
1190 : BC_CheckBox(x, y, rwindow->render->beep, _("Beep on done"))
1192 this->rwindow = rwindow;
1195 int RenderBeepOnDone::handle_event()
1197 rwindow->render->beep = get_value();