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 "mainerror.h"
53 #include "mainprogress.h"
54 #include "mainsession.h"
58 #include "mwindowgui.h"
60 #include "packagedispatcher.h"
61 #include "packagerenderer.h"
63 #include "playabletracks.h"
64 #include "preferences.h"
65 #include "preferencesthread.h"
66 #include "renderfarm.h"
68 #include "renderprofiles.h"
69 #include "statusbar.h"
73 #include "transportque.h"
76 #include "videoconfig.h"
84 RenderItem::RenderItem(MWindow *mwindow)
85 : BC_MenuItem(_("Render..."), _("Shift-R"), 'R')
87 this->mwindow = mwindow;
91 int RenderItem::handle_event()
93 mwindow->gui->unlock_window();
94 mwindow->render->start_interactive();
95 mwindow->gui->lock_window("RenderItem::handle_event");
99 RenderProgress::RenderProgress(MWindow *mwindow, Render *render)
102 this->mwindow = mwindow;
103 this->render = render;
105 Thread::set_synchronous(1);
108 RenderProgress::~RenderProgress()
115 void RenderProgress::run()
117 Thread::disable_cancel();
119 if( render->total_rendered != last_value ) {
120 render->progress->update(render->total_rendered);
121 last_value = render->total_rendered;
123 if( mwindow ) mwindow->preferences_thread->update_rates();
126 Thread::enable_cancel();
128 Thread::disable_cancel();
134 MainPackageRenderer::MainPackageRenderer(Render *render)
137 this->render = render;
142 MainPackageRenderer::~MainPackageRenderer()
147 int MainPackageRenderer::get_master()
152 int MainPackageRenderer::get_result()
154 return render->result;
157 void MainPackageRenderer::set_result(int value)
160 render->result = value;
163 void MainPackageRenderer::set_progress(int64_t value)
165 render->counter_lock->lock("MainPackageRenderer::set_progress");
166 // Increase total rendered for all nodes
167 render->total_rendered += value;
169 // Update frames per second for master node
170 render->preferences->set_rate(frames_per_second, -1);
172 //printf("MainPackageRenderer::set_progress %d %ld %f\n", __LINE__, (long)value, frames_per_second);
174 // If non interactive, print progress out
175 if( !render->progress )
176 render->show_progress();
178 render->counter_lock->unlock();
181 mwindow->preferences->copy_rates_from(preferences);
184 int MainPackageRenderer::progress_cancelled()
186 return (render->progress && render->progress->is_cancelled()) ||
187 render->batch_cancelled;
190 void RenderAssets::clear()
192 for( int i=size(); --i>=0; get(i)->remove_user() );
195 RenderAssets::RenderAssets()
198 RenderAssets::~RenderAssets()
203 Render::Render(MWindow *mwindow)
206 this->mwindow = mwindow;
210 package_lock = new Mutex("Render::package_lock");
211 counter_lock = new Mutex("Render::counter_lock");
212 completion = new Condition(0, "Render::completion");
213 progress_timer = new Timer;
214 range_type = RANGE_BACKCOMPAT;
215 preferences = new Preferences();
216 thread = new RenderThread(mwindow, this);
231 delete progress_timer;
232 if( asset ) asset->Garbage::remove_user();
236 void Render::start_interactive()
238 if( !thread->running() ) {
239 mode = Render::INTERACTIVE;
240 BC_DialogThread::start();
242 else if( in_progress ) {
244 mwindow->gui->get_abs_cursor(cx, cy, 1);
245 ErrorBox error_box(_(PROGRAM_NAME ": Error"), cx, cy);
246 error_box.create_objects(_("Already rendering"));
247 error_box.raise_window();
248 error_box.run_window();
250 else if( render_window ) {
251 render_window->raise_window();
256 void Render::start_batches(ArrayList<BatchRenderJob*> *jobs)
258 if( !thread->running() ) {
259 mode = Render::BATCH;
265 else if( in_progress ) {
267 mwindow->gui->get_abs_cursor(cx, cy, 1);
268 ErrorBox error_box(_(PROGRAM_NAME ": Error"), cx, cy);
269 error_box.create_objects("Already rendering");
270 error_box.raise_window();
271 error_box.run_window();
273 // raise the window if rendering hasn't started yet
274 else if( render_window ) {
275 render_window->raise_window();
279 void Render::start_batches(ArrayList<BatchRenderJob*> *jobs,
280 BC_Hash *boot_defaults, Preferences *batch_prefs)
282 mode = Render::BATCH;
284 preferences->copy_from(batch_prefs);
292 BC_Window* Render::new_gui()
298 if( mode == Render::INTERACTIVE ) {
299 // Fix the asset for rendering
300 if( !asset ) asset = new Asset;
301 load_defaults(asset);
302 check_asset(mwindow->edl, *asset);
303 int px = mwindow->gui->get_pop_cursor_x(1);
304 int py = mwindow->gui->get_pop_cursor_y(1);
305 // Get format from user
306 render_window = new RenderWindow(mwindow, this, asset, px, py);
307 render_window->create_objects();
310 return render_window;
313 void Render::handle_done_event(int result)
316 mwindow->edl->session->render_beep = beep;
317 // add to recentlist only on OK
318 render_window->render_format->path_recent->
319 add_item(File::formattostr(asset->format), asset->path);
320 setenv("CIN_RENDER", asset->path, 1);
325 void Render::handle_close_event(int result)
328 double render_range = get_render_range();
329 const char *err_msg = 0;
331 if( !result && !render_range ) {
332 err_msg = _("zero render range");
335 if( !result && !asset->audio_data && !asset->video_data ) {
336 err_msg = _("no audio or video in render asset format\n");
339 EDL *edl = mwindow->edl;
340 if( !result && use_labels && !edl->labels->first ) {
341 eprintf(_("render file per label and no labels\n"));
344 if( !result && asset->video_data ) {
345 double frame_rate = edl->session->frame_rate;
346 if( frame_rate > 0 && render_range+1e-3 < 1./frame_rate ) {
347 err_msg = _("Video data and range less than 1 frame");
351 if( !result && asset->audio_data ) {
352 double sample_rate = edl->session->sample_rate;
353 if( sample_rate > 0 && render_range+1e-6 < 1./sample_rate ) {
354 err_msg = _("Audio data and range less than 1 sample");
358 if( !result && File::is_image_render(asset->format) ) {
359 if( asset->video_data ) {
360 double frames = render_range * edl->session->frame_rate;
361 if( !EQUIV(frames, 1.) ) {
362 err_msg = _("Image format and not 1 frame");
367 err_msg = _("Image format and no video data");
374 mwindow->gui->get_abs_cursor(cx, cy, 1);
375 ErrorBox error_box(_(PROGRAM_NAME ": Error"),cx, cy);
376 error_box.create_objects(err_msg);
377 error_box.raise_window();
378 error_box.run_window();
382 // Check the asset format for errors.
383 FormatCheck format_check(asset);
384 if( format_check.check_format() )
390 save_defaults(asset);
392 mwindow->save_defaults();
396 if( debug ) printf("Render::handle_close_event %d\n", __LINE__);
397 if( !result ) start_render();
398 if( debug ) printf("Render::handle_close_event %d\n", __LINE__);
405 void Render::stop_operation()
407 if( thread->Thread::running() ) {
409 // Wait for completion
410 completion->lock("Render::stop_operation");
415 int Render::check_asset(EDL *edl, Asset &asset)
417 if( asset.video_data &&
418 edl->tracks->playable_video_tracks() &&
419 File::renders_video(&asset) ) {
420 asset.video_data = 1;
422 asset.width = edl->session->output_w;
423 asset.height = edl->session->output_h;
424 asset.interlace_mode = edl->session->interlace_mode;
427 asset.video_data = 0;
431 if( asset.audio_data &&
432 edl->tracks->playable_audio_tracks() &&
433 File::renders_audio(&asset) ) {
434 asset.audio_data = 1;
435 asset.channels = edl->session->audio_channels;
438 asset.audio_data = 0;
442 if( !asset.audio_data &&
443 !asset.video_data ) {
449 int Render::get_strategy(int use_renderfarm, int use_labels)
451 return use_renderfarm ?
452 (use_labels ? FILE_PER_LABEL_FARM : SINGLE_PASS_FARM) :
453 (use_labels ? FILE_PER_LABEL : SINGLE_PASS ) ;
455 int Render::get_strategy()
457 return get_strategy(preferences->use_renderfarm, use_labels);
460 void Render::start_progress()
462 char filename[BCTEXTLEN];
463 char string[BCTEXTLEN];
464 progress_max = packages->get_progress_max();
466 progress_timer->update();
469 // Generate the progress box
471 fs.extract_name(filename, default_asset->path);
472 sprintf(string, _("Rendering %s..."), filename);
474 // Don't bother with the filename since renderfarm defeats the meaning
475 mwindow->gui->lock_window("Render::start_progress");
476 progress = mwindow->mainprogress->start_progress(_("Rendering..."),
478 mwindow->gui->unlock_window();
479 render_progress = new RenderProgress(mwindow, this);
480 render_progress->start();
484 void Render::stop_progress()
487 char string[BCTEXTLEN], string2[BCTEXTLEN];
488 delete render_progress;
489 progress->get_time(string);
490 elapsed_time = progress->get_time();
491 progress->stop_progress();
494 sprintf(string2, _("Rendering took %s"), string);
495 mwindow->gui->lock_window("Render::stop_progress");
496 mwindow->gui->show_message(string2);
497 mwindow->gui->update_default_message();
498 mwindow->gui->stop_hourglass();
499 mwindow->gui->unlock_window();
504 void Render::show_progress()
506 int64_t current_eta = progress_timer->get_scaled_difference(1000);
507 if( current_eta - last_eta < 1000 ) return;
508 double eta = !total_rendered ? 0 :
509 current_eta / 1000. * (progress_max / (double)total_rendered - 1.);
510 char string[BCTEXTLEN]; Units::totext(string, eta, TIME_HMS2);
511 printf("\r%d%% %s: %s ",
512 (int)(100 * (float)total_rendered / progress_max), _("ETA"), string);
514 last_eta = current_eta;
519 void Render::start_render()
529 void Render::create_filename(char *path,
536 int len = strlen(default_path);
537 char printf_string[BCTEXTLEN];
539 for( i=0, j=0; i<number_start; ++i, ++j ) {
540 printf_string[j] = default_path[i];
544 sprintf(&printf_string[j], "%%0%dd", total_digits);
545 j = strlen(printf_string);
548 // Copy remainder of string
549 for( ; i<len; ++i, ++j ) {
550 printf_string[j] = default_path[i];
552 printf_string[j] = 0;
553 // Print the printf argument to the path
554 sprintf(path, printf_string, current_number);
557 void Render::get_starting_number(char *path,
563 int len = strlen(path);
564 char number_text[BCTEXTLEN];
572 ptr2 = strrchr(path, '/');
574 // Search for first 0 after last /.
576 ptr = strchr(ptr2, '0');
578 if( ptr && isdigit(*ptr) ) {
579 number_start = ptr - path;
581 // Store the first number
582 char *ptr2 = number_text;
583 while( isdigit(*ptr) ) *ptr2++ = *ptr++;
585 current_number = atol(number_text);
586 total_digits = strlen(number_text);
590 // No number found or number not long enough
591 if( total_digits < min_digits ) {
594 total_digits = min_digits;
599 int Render::load_defaults(Asset *asset)
601 use_labels = mwindow->defaults->get("RENDER_FILE_PER_LABEL", 0);
602 load_mode = mwindow->defaults->get("RENDER_LOADMODE", LOADMODE_NEW_TRACKS);
603 range_type = mwindow->defaults->get("RENDER_RANGE_TYPE", RANGE_PROJECT);
605 // some defaults which work
606 asset->video_data = 1;
607 asset->audio_data = 1;
608 asset->format = FILE_FFMPEG;
609 strcpy(asset->acodec, "mp4.qt");
610 strcpy(asset->vcodec, "mp4.qt");
612 asset->load_defaults(mwindow->defaults,
613 "RENDER_", 1, 1, 1, 1, 1);
617 int Render::load_profile(int profile_slot, Asset *asset)
619 char string_name[100];
620 sprintf(string_name, "RENDER_%i_FILE_PER_LABEL", profile_slot);
621 use_labels = mwindow->defaults->get(string_name, 0);
622 // Load mode is not part of the profile
623 // printf(string_name, "RENDER_%i_LOADMODE", profile_slot);
624 // load_mode = mwindow->defaults->get(string_name, LOADMODE_NEW_TRACKS);
625 sprintf(string_name, "RENDER_%i_RANGE_TYPE", profile_slot);
626 range_type = mwindow->defaults->get(string_name, RANGE_PROJECT);
628 sprintf(string_name, "RENDER_%i_", profile_slot);
629 asset->load_defaults(mwindow->defaults,
630 string_name, 1, 1, 1, 1, 1);
635 int Render::save_defaults(Asset *asset)
637 mwindow->defaults->update("RENDER_FILE_PER_LABEL", use_labels);
638 mwindow->defaults->update("RENDER_LOADMODE", load_mode);
639 mwindow->defaults->update("RENDER_RANGE_TYPE", range_type);
641 asset->save_defaults(mwindow->defaults,
642 "RENDER_", 1, 1, 1, 1, 1);
646 void Render::update_assets()
649 packages->get_asset_list(assets);
652 static void run_script(const char *script, const char *arg)
654 char *const argv[] = { (char*)script, (char*)arg, 0 };
655 execvp(script ,&argv[0]);
656 perror("execvp script failed");
660 RenderThread::RenderThread(MWindow *mwindow, Render *render)
663 this->mwindow = mwindow;
664 this->render = render;
668 RenderThread::~RenderThread()
673 void RenderThread::render_single(int test_overwrite, Asset *asset, EDL *edl,
674 int strategy, int range_type)
676 // Total length in seconds
677 double total_length = 0;
678 RenderFarmServer *farm_server = 0;
680 render->in_progress = 1;
681 render->default_asset = asset;
682 render->progress = 0;
685 // Create rendering command
686 TransportCommand *command = new TransportCommand;
687 command->command = NORMAL_FWD;
688 command->get_edl()->copy_all(edl);
689 command->change_type = CHANGE_ALL;
691 switch( range_type ) {
692 case RANGE_BACKCOMPAT:
693 // Get highlighted playback range
694 command->set_playback_range();
695 // Adjust playback range with in/out points
696 command->playback_range_adjust_inout();
699 command->playback_range_project();
701 case RANGE_SELECTION:
702 command->set_playback_range();
705 command->playback_range_inout();
708 command->playback_range_1frame();
712 render->packages = new PackageDispatcher;
715 CICache *audio_cache = new CICache(render->preferences);
716 CICache *video_cache = new CICache(render->preferences);
718 render->default_asset->frame_rate = command->get_edl()->session->frame_rate;
719 render->default_asset->sample_rate = command->get_edl()->session->sample_rate;
721 // Conform asset to EDL. Find out if any tracks are playable.
722 render->result = render->check_asset(command->get_edl(),
723 *render->default_asset);
725 if( !render->result ) {
726 // Get total range to render
727 render->total_start = command->start_position;
728 render->total_end = command->end_position;
729 total_length = render->total_end - render->total_start;
732 if( EQUIV(total_length, 0) ) {
737 render_frames = render->default_asset->frame_rate * total_length;
740 if( !render->result ) {
741 // Stop background rendering
742 if( mwindow ) mwindow->stop_brender();
745 fs.complete_path(render->default_asset->path);
747 render->result = render->packages->create_packages(mwindow, command->get_edl(),
748 render->preferences, strategy, render->default_asset,
749 render->total_start, render->total_end, test_overwrite);
752 render->total_rendered = 0;
754 if( !render->result &&
755 ( strategy == SINGLE_PASS_FARM || strategy == FILE_PER_LABEL_FARM ) ) {
756 // Start dispatching external jobs
758 mwindow->gui->lock_window("Render::render 1");
759 mwindow->gui->show_message(_("Starting render farm"));
760 mwindow->gui->start_hourglass();
761 mwindow->gui->unlock_window();
764 printf("Render::render: starting render farm\n");
767 farm_server = new RenderFarmServer(mwindow, render->packages,
768 render->preferences, 1, &render->result,
769 &render->total_rendered, render->counter_lock,
770 render->default_asset, command->get_edl(), 0);
771 render->result = farm_server->start_clients();
773 if( render->result ) {
775 mwindow->gui->lock_window("Render::render 2");
776 mwindow->gui->show_message(_("Failed to start render farm"),
777 mwindow->theme->message_error);
778 mwindow->gui->stop_hourglass();
779 mwindow->gui->unlock_window();
782 printf("Render::render: Failed to start render farm\n");
787 // Perform local rendering
789 render->assets.clear();
790 if( !render->result ) {
791 render->start_progress();
793 MainPackageRenderer package_renderer(render);
794 render->result = package_renderer.initialize(mwindow,
795 command->get_edl(), // Copy of master EDL
797 render->default_asset);
799 while( !render->result ) {
800 int fps = strategy == SINGLE_PASS_FARM ?
801 package_renderer.frames_per_second : 0;
802 // Get unfinished job
803 RenderPackage *package = render->packages->get_package(fps, -1, 1);
805 if( !package ) break;
807 if( package_renderer.render_package(package) )
811 printf("Render::render_single: Session finished.\n");
813 if( strategy == SINGLE_PASS_FARM ||
814 strategy == FILE_PER_LABEL_FARM ) {
815 if( !render->progress ) {
816 while( farm_server->active_clients() > 0 ) {
818 render->show_progress();
821 farm_server->wait_clients();
822 render->result |= render->packages->packages_are_done();
826 if( render->result && !render->batch_cancelled &&
827 (!render->progress || !render->progress->is_cancelled()) ) {
830 mwindow->gui->get_abs_cursor(cx, cy, 1);
831 ErrorBox error_box(_(PROGRAM_NAME ": Error"), cx, cy);
832 error_box.create_objects(_("Error rendering data."));
833 error_box.raise_window();
834 error_box.run_window();
837 printf("Render::render: Error rendering data\n");
841 // Delete the progress box
842 render->stop_progress();
843 render->update_assets();
846 // Paste all packages into timeline if desired
848 if( !render->result && mwindow &&
849 render->load_mode != LOADMODE_NOTHING &&
850 render->mode != Render::BATCH ) {
851 mwindow->gui->lock_window("Render::render 3");
853 mwindow->undo->update_undo_before();
854 if( render->load_mode == LOADMODE_PASTE )
856 mwindow->load_assets(&render->assets,
857 -1, render->load_mode, 0, 0,
858 mwindow->edl->session->labels_follow_edits,
859 mwindow->edl->session->plugins_follow_edits,
860 mwindow->edl->session->autos_follow_edits,
862 mwindow->save_backup();
863 mwindow->undo->update_undo_after(_("render"), LOAD_ALL);
864 mwindow->update_plugin_guis();
865 mwindow->gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
866 mwindow->sync_parameters(CHANGE_ALL);
867 mwindow->gui->unlock_window();
869 mwindow->awindow->gui->async_update_assets();
874 mwindow->gui->lock_window("Render::render 3");
875 mwindow->gui->stop_hourglass();
876 mwindow->gui->unlock_window();
879 //printf("Render::render 110\n");
880 // Need to restart because brender always stops before render.
882 mwindow->restart_brender();
883 if( farm_server ) delete farm_server;
887 // Must delete packages after server
888 delete render->packages;
890 render->packages = 0;
891 render->in_progress = 0;
894 void RenderThread::run()
900 render->preferences->copy_from(mwindow->preferences);
902 if( render->mode == Render::INTERACTIVE ) {
903 render_single(1, render->asset, mwindow->edl,
904 render->get_strategy(), render->range_type);
907 if( render->mode == Render::BATCH ) {
908 for( int i=0; i<render->jobs->total && !render->result; ++i ) {
909 BatchRenderJob *job = render->jobs->values[i];
910 if( !job->enabled ) continue;
912 mwindow->batch_render->update_active(i);
914 printf("Render::run: %s\n", job->edl_path);
916 FileXML *file = new FileXML;
918 edl->create_objects();
919 file->read_from_file(job->edl_path);
920 edl->load_xml(file, LOAD_ALL);
923 render_single(0, job->asset, edl, job->get_strategy(), RANGE_BACKCOMPAT);
924 if( !render->result ) {
926 script = job->create_script(edl, &render->assets);
928 mwindow->batch_render->update_done(i, 1, render->elapsed_time);
930 char string[BCTEXTLEN];
931 render->elapsed_time =
932 (double)render->progress_timer->get_scaled_difference(1);
933 Units::totext(string, render->elapsed_time, TIME_HMS2);
934 printf("Render::run: done in %s\n", string);
939 mwindow->batch_render->update_active(-1);
941 printf("Render::run: failed\n");
945 mwindow->batch_render->update_active(-1);
946 mwindow->batch_render->update_done(-1, 0, 0);
949 render->completion->unlock();
951 if( !render->result ) {
952 double render_time = render_timer.get_difference() / 1000.0;
953 double render_rate = render_time > 0 ? render_frames / render_time : 0;
954 printf("** rendered %jd frames in %0.3f secs, %0.3f fps\n",
955 render_frames, render_time, render_rate);
958 if( render->mode == Render::INTERACTIVE && render->beep > 0 )
959 mwindow->beep(3000., 1.5, render->beep);
962 if( !render->result )
963 run_script(script, 0);
969 #define WIDTH xS(480)
970 #define HEIGHT yS(480)
973 RenderWindow::RenderWindow(MWindow *mwindow,
978 : BC_Window(_(PROGRAM_NAME ": Render"), x, y,
979 WIDTH, HEIGHT, WIDTH, HEIGHT, 0, 0, 1)
981 this->mwindow = mwindow;
982 this->render = render;
993 RenderWindow::~RenderWindow()
995 lock_window("RenderWindow::~RenderWindow");
996 delete render_format;
998 delete renderprofile;
1003 void RenderWindow::load_profile(int profile_slot)
1005 render->load_profile(profile_slot, asset);
1006 update_range_type(render->range_type);
1007 render_format->update(asset, &render->use_labels);
1011 void RenderWindow::create_objects()
1013 int xs10 = xS(10), xs20 = xS(20);
1014 int ys10 = yS(10), ys20 = yS(20), ys25 = yS(25), ys30 = yS(30);
1015 int x = xs10, y = ys10;
1016 lock_window("RenderWindow::create_objects");
1017 add_subwindow(file_format = new BC_Title(x, y,
1018 (render->use_labels ?
1019 _("Select the first file to render to:") :
1020 _("Select a file to render to:"))));
1023 render_format = new RenderFormat(mwindow, this, asset);
1024 render_format->create_objects(x, y,
1025 1, 1, 1, 1, 0, 1, 0, 0, &render->use_labels, 0);
1028 add_subwindow(title = new BC_Title(x, y, _("Render range:")));
1030 int is_image = File::is_image_render(asset->format);
1032 render->range_type = RANGE_1FRAME;
1034 int x1 = x + title->get_w() + xs20, y1 = y;
1035 add_subwindow(rangeproject = new RenderRangeProject(this,
1036 render->range_type == RANGE_PROJECT, x1, y));
1037 int x2 = x1 + rangeproject->get_w();
1039 add_subwindow(rangeselection = new RenderRangeSelection(this,
1040 render->range_type == RANGE_SELECTION, x1, y));
1041 int x3 = x1 + rangeselection->get_w();
1042 if( x2 < x3 ) x2 = x3;
1044 add_subwindow(rangeinout = new RenderRangeInOut(this,
1045 render->range_type == RANGE_INOUT, x1, y));
1046 x3 = x1 + rangeinout->get_w();
1047 if( x2 < x3 ) x2 = x3;
1049 add_subwindow(range1frame = new RenderRange1Frame(this,
1050 render->range_type == RANGE_1FRAME, x1, y));
1051 x3 = x1 + range1frame->get_w();
1052 if( x2 < x3 ) x2 = x3;
1055 enable_render_range(0);
1058 render->beep = mwindow->edl->session->render_beep;
1059 add_subwindow(beep_on_done = new RenderBeepOnDone(this, x1, y1));
1060 y1 += beep_on_done->get_h();
1061 add_subwindow(new BC_Title(x1, y1, _("Beep on done volume")));
1063 renderprofile = new RenderProfile(mwindow, this, x, y, 1);
1064 renderprofile->create_objects();
1067 loadmode = new LoadMode(mwindow, this, x, y, &render->load_mode);
1068 loadmode->create_objects();
1070 add_subwindow(new BC_OKButton(this));
1071 add_subwindow(new BC_CancelButton(this));
1077 void RenderWindow::update_range_type(int range_type)
1079 if( render->range_type == range_type ) return;
1080 render->range_type = range_type;
1081 rangeproject->update(range_type == RANGE_PROJECT);
1082 rangeselection->update(range_type == RANGE_SELECTION);
1083 rangeinout->update(range_type == RANGE_INOUT);
1084 range1frame->update(range_type == RANGE_1FRAME);
1087 void RenderWindow::enable_render_range(int v)
1090 rangeproject->enable();
1091 rangeselection->enable();
1092 rangeinout->enable();
1093 range1frame->enable();
1096 rangeproject->disable();
1097 rangeselection->disable();
1098 rangeinout->disable();
1099 range1frame->disable();
1104 RenderRangeProject::RenderRangeProject(RenderWindow *rwindow, int value, int x, int y)
1105 : BC_Radial(x, y, value, _("Project"))
1107 this->rwindow = rwindow;
1109 int RenderRangeProject::handle_event()
1111 rwindow->update_range_type(RANGE_PROJECT);
1115 RenderRangeSelection::RenderRangeSelection(RenderWindow *rwindow, int value, int x, int y)
1116 : BC_Radial(x, y, value, _("Selection"))
1118 this->rwindow = rwindow;
1120 int RenderRangeSelection::handle_event()
1122 rwindow->update_range_type(RANGE_SELECTION);
1127 RenderRangeInOut::RenderRangeInOut(RenderWindow *rwindow, int value, int x, int y)
1128 : BC_Radial(x, y, value, _("In/Out Points"))
1130 this->rwindow = rwindow;
1132 int RenderRangeInOut::handle_event()
1134 rwindow->update_range_type(RANGE_INOUT);
1138 RenderRange1Frame::RenderRange1Frame(RenderWindow *rwindow, int value, int x, int y)
1139 : BC_Radial(x, y, value, _("One Frame"))
1141 this->rwindow = rwindow;
1143 int RenderRange1Frame::handle_event()
1145 rwindow->update_range_type(RANGE_1FRAME);
1149 double Render::get_render_range()
1151 EDL *edl = mwindow->edl;
1152 double last = edl->tracks->total_playable_length();
1153 double framerate = edl->session->frame_rate;
1154 if( framerate <= 0 ) framerate = 1;
1155 double start = 0, end = last;
1156 switch( range_type ) {
1158 case RANGE_BACKCOMPAT:
1159 start = edl->local_session->get_selectionstart(1);
1160 end = edl->local_session->get_selectionend(1);
1161 if( EQUIV(start, end) ) end = last;
1165 case RANGE_SELECTION:
1166 start = edl->local_session->get_selectionstart(1);
1167 end = edl->local_session->get_selectionend(1);
1170 start = edl->local_session->inpoint_valid() ?
1171 edl->local_session->get_inpoint() : 0;
1172 end = edl->local_session->outpoint_valid() ?
1173 edl->local_session->get_outpoint() : last;
1176 start = end = edl->local_session->get_selectionstart(1);
1177 if( edl->session->frame_rate > 0 ) end += 1./edl->session->frame_rate;
1180 if( start < 0 ) start = 0;
1181 if( end > last ) end = last;
1185 RenderFormat::RenderFormat(MWindow *mwindow, BC_WindowBase *window, Asset *asset)
1186 : FormatTools(mwindow, window, asset)
1189 RenderFormat::~RenderFormat()
1193 void RenderFormat::update_format()
1195 FormatTools::update_format();
1196 RenderWindow *render_window = (RenderWindow *)window;
1197 if( render_window->is_hidden() ) return;
1198 int is_image = File::is_image_render(asset->format);
1200 render_window->update_range_type(RANGE_1FRAME);
1201 render_window->enable_render_range(0);
1204 render_window->enable_render_range(1);
1206 int RenderFormat::handle_event()
1208 RenderWindow *render_window = (RenderWindow *)window;
1209 render_window->file_format->update(
1210 (render_window->render->use_labels ?
1211 _("Select the first file to render to:") :
1212 _("Select a file to render to:")));
1216 RenderBeepOnDone::RenderBeepOnDone(RenderWindow *rwindow, int x, int y)
1217 : BC_FPot(x, y, rwindow->render->beep*100.f, 0.f, 100.f)
1219 this->rwindow = rwindow;
1222 int RenderBeepOnDone::handle_event()
1224 rwindow->render->beep = get_value()/100.f;