4 * Copyright (C) 1997-2011 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "awindowgui.h"
27 #include "batchrender.h"
28 #include "bcprogressbox.h"
29 #include "bcsignals.h"
32 #include "compresspopup.h"
33 #include "condition.h"
34 #include "confirmsave.h"
35 #include "cwindowgui.h"
40 #include "edlsession.h"
43 #include "filesystem.h"
45 #include "formatcheck.h"
46 #include "formatpopup.h"
47 #include "formattools.h"
48 #include "indexable.h"
52 #include "localsession.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");
108 RenderProgress::RenderProgress(MWindow *mwindow, Render *render)
111 this->mwindow = mwindow;
112 this->render = render;
114 Thread::set_synchronous(1);
117 RenderProgress::~RenderProgress()
124 void RenderProgress::run()
126 Thread::disable_cancel();
129 if(render->total_rendered != last_value)
131 render->progress->update(render->total_rendered);
132 last_value = render->total_rendered;
134 if(mwindow) mwindow->preferences_thread->update_rates();
137 Thread::enable_cancel();
139 Thread::disable_cancel();
145 MainPackageRenderer::MainPackageRenderer(Render *render)
148 this->render = render;
153 MainPackageRenderer::~MainPackageRenderer()
158 int MainPackageRenderer::get_master()
163 int MainPackageRenderer::get_result()
165 return render->result;
168 void MainPackageRenderer::set_result(int value)
171 render->result = value;
177 void MainPackageRenderer::set_progress(int64_t value)
179 render->counter_lock->lock("MainPackageRenderer::set_progress");
180 // Increase total rendered for all nodes
181 render->total_rendered += value;
183 // Update frames per second for master node
184 render->preferences->set_rate(frames_per_second, -1);
186 //printf("MainPackageRenderer::set_progress %d %ld %f\n", __LINE__, (long)value, frames_per_second);
188 // If non interactive, print progress out
189 if(!render->progress)
191 int64_t current_eta = render->progress_timer->get_scaled_difference(1000);
192 if(current_eta - render->last_eta > 1000)
197 if(render->total_rendered)
201 render->progress_max /
202 render->total_rendered -
207 char string[BCTEXTLEN];
208 Units::totext(string,
212 printf("\r%d%% %s: %s ",
213 (int)(100 * (float)render->total_rendered / render->progress_max),
216 render->last_eta = current_eta;
220 render->counter_lock->unlock();
222 // This locks the preferences
223 if(mwindow) mwindow->preferences->copy_rates_from(preferences);
226 int MainPackageRenderer::progress_cancelled()
228 return (render->progress && render->progress->is_cancelled()) ||
229 render->batch_cancelled;
233 Render::Render(MWindow *mwindow)
236 this->mwindow = mwindow;
241 package_lock = new Mutex("Render::package_lock");
242 counter_lock = new Mutex("Render::counter_lock");
243 completion = new Condition(0, "Render::completion");
244 progress_timer = new Timer;
245 range_type = RANGE_BACKCOMPAT;
246 thread = new RenderThread(mwindow, this);
258 // May be owned by someone else. This is owned by mwindow, so we don't care
260 // delete preferences;
261 delete progress_timer;
262 if( asset ) asset->Garbage::remove_user();
266 void Render::start_interactive()
268 if( !thread->running() ) {
269 mode = Render::INTERACTIVE;
270 BC_DialogThread::start();
272 else if( in_progress ) {
274 mwindow->gui->get_abs_cursor_xy(cx, cy, 1);
275 ErrorBox error_box(_(PROGRAM_NAME ": Error"), cx, cy);
276 error_box.create_objects(_("Already rendering"));
277 error_box.raise_window();
278 error_box.run_window();
280 else if( render_window ) {
281 render_window->raise_window();
286 void Render::start_batches(ArrayList<BatchRenderJob*> *jobs)
288 if(!thread->running())
290 mode = Render::BATCH;
296 else if( in_progress ) {
298 mwindow->gui->get_abs_cursor_xy(cx, cy, 1);
299 ErrorBox error_box(_(PROGRAM_NAME ": Error"), cx, cy);
300 error_box.create_objects("Already rendering");
301 error_box.raise_window();
302 error_box.run_window();
304 // raise the window if rendering hasn't started yet
305 else if( render_window ) {
306 render_window->raise_window();
310 void Render::start_batches(ArrayList<BatchRenderJob*> *jobs,
311 BC_Hash *boot_defaults,
312 Preferences *preferences)
314 mode = Render::BATCH;
317 this->preferences = preferences;
323 this->preferences = 0;
327 BC_Window* Render::new_gui()
333 if(mode == Render::INTERACTIVE) {
334 // Fix the asset for rendering
335 if(!asset) asset = new Asset;
336 load_defaults(asset);
337 check_asset(mwindow->edl, *asset);
338 int px = mwindow->gui->get_pop_cursor_x(1);
339 int py = mwindow->gui->get_pop_cursor_y(1);
340 // Get format from user
341 render_window = new RenderWindow(mwindow, this, asset, px, py);
342 render_window->create_objects();
345 return render_window;
348 void Render::handle_done_event(int result)
351 // add to recentlist only on OK
352 render_window->render_format->path_recent->
353 add_item(File::formattostr(asset->format), asset->path);
358 void Render::handle_close_event(int result)
361 double render_range = get_render_range();
362 const char *err_msg = 0;
364 if( !result && !render_range ) {
365 err_msg = _("zero render range");
368 if( !result && asset->video_data ) {
369 double frame_rate = mwindow->edl->session->frame_rate;
370 if( frame_rate > 0 && render_range+1e-3 < 1./frame_rate ) {
371 err_msg = _("Video data and range less than 1 frame");
375 if( !result && asset->audio_data ) {
376 double sample_rate = mwindow->edl->session->sample_rate;
377 if( sample_rate > 0 && render_range+1e-6 < 1./sample_rate ) {
378 err_msg = _("Audio data and range less than 1 sample");
382 if( !result && File::is_image_render(asset->format) ) {
383 if( asset->video_data ) {
384 double frames = render_range * mwindow->edl->session->frame_rate;
385 if( !EQUIV(frames, 1.) ) {
386 err_msg = _("Image format and not 1 frame");
391 err_msg = _("Image format and no video data");
397 mwindow->gui->get_abs_cursor_xy(cx, cy, 1);
398 ErrorBox error_box(_(PROGRAM_NAME ": Error"),cx, cy);
399 error_box.create_objects(err_msg);
400 error_box.raise_window();
401 error_box.run_window();
405 // Check the asset format for errors.
406 FormatCheck format_check(asset);
407 if( format_check.check_format() )
413 save_defaults(asset);
415 mwindow->save_defaults();
419 if(debug) printf("Render::handle_close_event %d\n", __LINE__);
420 if(!result) start_render();
421 if(debug) printf("Render::handle_close_event %d\n", __LINE__);
428 void Render::stop_operation()
430 if(thread->Thread::running())
433 // Wait for completion
434 completion->lock("Render::stop_operation");
441 int Render::check_asset(EDL *edl, Asset &asset)
443 if(asset.video_data &&
444 edl->tracks->playable_video_tracks() &&
445 File::renders_video(&asset))
447 asset.video_data = 1;
449 asset.width = edl->session->output_w;
450 asset.height = edl->session->output_h;
451 asset.interlace_mode = edl->session->interlace_mode;
455 asset.video_data = 0;
459 if(asset.audio_data &&
460 edl->tracks->playable_audio_tracks() &&
461 File::renders_audio(&asset))
463 asset.audio_data = 1;
464 asset.channels = edl->session->audio_channels;
468 asset.audio_data = 0;
472 if(!asset.audio_data &&
480 int Render::fix_strategy(int strategy, int use_renderfarm)
484 if(strategy == FILE_PER_LABEL)
485 strategy = FILE_PER_LABEL_FARM;
487 if(strategy == SINGLE_PASS)
488 strategy = SINGLE_PASS_FARM;
492 if(strategy == FILE_PER_LABEL_FARM)
493 strategy = FILE_PER_LABEL;
495 if(strategy == SINGLE_PASS_FARM)
496 strategy = SINGLE_PASS;
501 void Render::start_progress()
503 char filename[BCTEXTLEN];
504 char string[BCTEXTLEN];
507 progress_max = packages->get_progress_max();
509 progress_timer->update();
513 // Generate the progress box
514 fs.extract_name(filename, default_asset->path);
515 sprintf(string, _("Rendering %s..."), filename);
517 // Don't bother with the filename since renderfarm defeats the meaning
518 progress = mwindow->mainprogress->start_progress(_("Rendering..."),
520 render_progress = new RenderProgress(mwindow, this);
521 render_progress->start();
525 void Render::stop_progress()
529 char string[BCTEXTLEN], string2[BCTEXTLEN];
530 delete render_progress;
531 progress->get_time(string);
532 elapsed_time = progress->get_time();
533 progress->stop_progress();
536 sprintf(string2, _("Rendering took %s"), string);
537 mwindow->gui->lock_window("");
538 mwindow->gui->show_message(string2);
539 mwindow->gui->update_default_message();
540 mwindow->gui->stop_hourglass();
541 mwindow->gui->unlock_window();
548 void Render::start_render()
558 void Render::create_filename(char *path,
565 int len = strlen(default_path);
566 char printf_string[BCTEXTLEN];
568 for(i = 0, j = 0; i < number_start; i++, j++)
570 printf_string[j] = default_path[i];
574 sprintf(&printf_string[j], "%%0%dd", total_digits);
575 j = strlen(printf_string);
578 // Copy remainder of string
579 for( ; i < len; i++, j++)
581 printf_string[j] = default_path[i];
583 printf_string[j] = 0;
584 // Print the printf argument to the path
585 sprintf(path, printf_string, current_number);
588 void Render::get_starting_number(char *path,
594 int len = strlen(path);
595 char number_text[BCTEXTLEN];
603 ptr2 = strrchr(path, '/');
605 // Search for first 0 after last /.
607 ptr = strchr(ptr2, '0');
609 if(ptr && isdigit(*ptr))
611 number_start = ptr - path;
613 // Store the first number
614 char *ptr2 = number_text;
618 current_number = atol(number_text);
619 total_digits = strlen(number_text);
623 // No number found or number not long enough
624 if(total_digits < min_digits)
628 total_digits = min_digits;
633 int Render::load_defaults(Asset *asset)
635 strategy = mwindow->defaults->get("RENDER_STRATEGY", SINGLE_PASS);
636 load_mode = mwindow->defaults->get("RENDER_LOADMODE", LOADMODE_NEW_TRACKS);
637 range_type = mwindow->defaults->get("RENDER_RANGE_TYPE", RANGE_PROJECT);
639 // some defaults which work
640 asset->video_data = 1;
641 asset->audio_data = 1;
642 asset->format = FILE_FFMPEG;
643 strcpy(asset->acodec, "mp4.qt");
644 strcpy(asset->vcodec, "mp4.qt");
646 asset->load_defaults(mwindow->defaults,
647 "RENDER_", 1, 1, 1, 1, 1);
651 int Render::load_profile(int profile_slot, Asset *asset)
653 char string_name[100];
654 sprintf(string_name, "RENDER_%i_STRATEGY", profile_slot);
655 strategy = mwindow->defaults->get(string_name, SINGLE_PASS);
656 // Load mode is not part of the profile
657 // printf(string_name, "RENDER_%i_LOADMODE", profile_slot);
658 // load_mode = mwindow->defaults->get(string_name, LOADMODE_NEW_TRACKS);
659 sprintf(string_name, "RENDER_%i_RANGE_TYPE", profile_slot);
660 range_type = mwindow->defaults->get(string_name, RANGE_PROJECT);
662 sprintf(string_name, "RENDER_%i_", profile_slot);
663 asset->load_defaults(mwindow->defaults,
664 string_name, 1, 1, 1, 1, 1);
669 int Render::save_defaults(Asset *asset)
671 mwindow->defaults->update("RENDER_STRATEGY", strategy);
672 mwindow->defaults->update("RENDER_LOADMODE", load_mode);
673 mwindow->defaults->update("RENDER_RANGE_TYPE", range_type);
675 asset->save_defaults(mwindow->defaults,
676 "RENDER_", 1, 1, 1, 1, 1);
681 static void run_script(const char *script, const char *arg)
683 char *const argv[] = { (char*)script, (char*)arg, 0 };
684 execvp(script ,&argv[0]);
685 perror("execvp script failed");
689 RenderThread::RenderThread(MWindow *mwindow, Render *render)
692 this->mwindow = mwindow;
693 this->render = render;
696 RenderThread::~RenderThread()
701 void RenderThread::render_single(int test_overwrite, Asset *asset, EDL *edl,
702 int strategy, int range_type)
704 // Total length in seconds
706 RenderFarmServer *farm_server = 0;
711 render->in_progress = 1;
714 render->default_asset = asset;
715 render->progress = 0;
720 if(!render->preferences)
721 render->preferences = new Preferences;
723 render->preferences->copy_from(mwindow->preferences);
727 // Create rendering command
728 TransportCommand *command = new TransportCommand;
729 command->command = NORMAL_FWD;
730 command->get_edl()->copy_all(edl);
731 command->change_type = CHANGE_ALL;
733 switch( range_type ) {
734 case RANGE_BACKCOMPAT:
735 // Get highlighted playback range
736 command->set_playback_range();
737 // Adjust playback range with in/out points
738 command->playback_range_adjust_inout();
741 command->playback_range_project();
743 case RANGE_SELECTION:
744 command->set_playback_range();
747 command->playback_range_inout();
750 command->playback_range_1frame();
754 render->packages = new PackageDispatcher;
757 CICache *audio_cache = new CICache(render->preferences);
758 CICache *video_cache = new CICache(render->preferences);
760 render->default_asset->frame_rate = command->get_edl()->session->frame_rate;
761 render->default_asset->sample_rate = command->get_edl()->session->sample_rate;
763 // Conform asset to EDL. Find out if any tracks are playable.
764 render->result = render->check_asset(command->get_edl(),
765 *render->default_asset);
769 // Get total range to render
770 render->total_start = command->start_position;
771 render->total_end = command->end_position;
772 total_length = render->total_end - render->total_start;
775 if(EQUIV(total_length, 0))
784 // Stop background rendering
785 if(mwindow) mwindow->stop_brender();
787 fs.complete_path(render->default_asset->path);
788 strategy = Render::fix_strategy(strategy, render->preferences->use_renderfarm);
790 render->result = render->packages->create_packages(mwindow,
794 render->default_asset,
801 render->total_rendered = 0;
805 // Start dispatching external jobs
808 mwindow->gui->lock_window("Render::render 1");
809 mwindow->gui->show_message(_("Starting render farm"));
810 mwindow->gui->start_hourglass();
811 mwindow->gui->unlock_window();
815 printf("Render::render: starting render farm\n");
818 if(strategy == SINGLE_PASS_FARM || strategy == FILE_PER_LABEL_FARM)
820 farm_server = new RenderFarmServer(mwindow,
825 &render->total_rendered,
826 render->counter_lock,
827 render->default_asset,
830 render->result = farm_server->start_clients();
836 mwindow->gui->lock_window("Render::render 2");
837 mwindow->gui->show_message(_("Failed to start render farm"),
838 mwindow->theme->message_error);
839 mwindow->gui->stop_hourglass();
840 mwindow->gui->unlock_window();
844 printf("Render::render: Failed to start render farm\n");
850 // Perform local rendering
855 render->start_progress();
860 MainPackageRenderer package_renderer(render);
861 render->result = package_renderer.initialize(mwindow,
862 command->get_edl(), // Copy of master EDL
864 render->default_asset);
872 while(!render->result)
874 // Get unfinished job
875 RenderPackage *package;
877 if(strategy == SINGLE_PASS_FARM)
879 package = render->packages->get_package(
880 package_renderer.frames_per_second,
886 package = render->packages->get_package(0, -1, 1);
901 if(package_renderer.render_package(package))
909 printf("Render::render_single: Session finished.\n");
915 if(strategy == SINGLE_PASS_FARM || strategy == FILE_PER_LABEL_FARM)
917 farm_server->wait_clients();
918 render->result |= render->packages->packages_are_done();
921 if(debug) printf("Render::render %d\n", __LINE__);
925 (!render->progress || !render->progress->is_cancelled()) &&
926 !render->batch_cancelled)
928 if(debug) printf("Render::render %d\n", __LINE__);
931 if(debug) printf("Render::render %d\n", __LINE__);
933 mwindow->gui->get_abs_cursor_xy(cx, cy, 1);
934 ErrorBox error_box(_(PROGRAM_NAME ": Error"), cx, cy);
935 error_box.create_objects(_("Error rendering data."));
936 error_box.raise_window();
937 error_box.run_window();
938 if(debug) printf("Render::render %d\n", __LINE__);
942 printf("Render::render: Error rendering data\n");
945 if(debug) printf("Render::render %d\n", __LINE__);
947 // Delete the progress box
948 render->stop_progress();
950 if(debug) printf("Render::render %d\n", __LINE__);
954 // Paste all packages into timeline if desired
956 if(!render->result &&
957 render->load_mode != LOADMODE_NOTHING &&
959 render->mode != Render::BATCH)
961 if(debug) printf("Render::render %d\n", __LINE__);
962 mwindow->gui->lock_window("Render::render 3");
963 if(debug) printf("Render::render %d\n", __LINE__);
965 mwindow->undo->update_undo_before();
967 if(debug) printf("Render::render %d\n", __LINE__);
970 ArrayList<Indexable*> *assets = render->packages->get_asset_list();
971 if(debug) printf("Render::render %d\n", __LINE__);
972 if(render->load_mode == LOADMODE_PASTE)
973 mwindow->clear(0, 1);
974 if(debug) printf("Render::render %d\n", __LINE__);
975 mwindow->load_assets(assets, -1, render->load_mode, 0, 0,
976 mwindow->edl->session->labels_follow_edits,
977 mwindow->edl->session->plugins_follow_edits,
978 mwindow->edl->session->autos_follow_edits,
980 if(debug) printf("Render::render %d\n", __LINE__);
981 for(int i = 0; i < assets->size(); i++)
982 assets->get(i)->Garbage::remove_user();
984 if(debug) printf("Render::render %d\n", __LINE__);
987 mwindow->save_backup();
988 if(debug) printf("Render::render %d\n", __LINE__);
989 mwindow->undo->update_undo_after(_("render"), LOAD_ALL);
990 if(debug) printf("Render::render %d\n", __LINE__);
991 mwindow->update_plugin_guis();
992 if(debug) printf("Render::render %d\n", __LINE__);
993 mwindow->gui->update(1,
1000 if(debug) printf("Render::render %d\n", __LINE__);
1001 mwindow->sync_parameters(CHANGE_ALL);
1002 if(debug) printf("Render::render %d\n", __LINE__);
1003 mwindow->gui->unlock_window();
1006 mwindow->awindow->gui->async_update_assets();
1008 if(debug) printf("Render::render %d\n", __LINE__);
1011 if(debug) printf("Render::render %d\n", __LINE__);
1013 // Disable hourglass
1016 mwindow->gui->lock_window("Render::render 3");
1017 mwindow->gui->stop_hourglass();
1018 mwindow->gui->unlock_window();
1021 //printf("Render::render 110\n");
1022 // Need to restart because brender always stops before render.
1024 mwindow->restart_brender();
1025 if(farm_server) delete farm_server;
1029 // Must delete packages after server
1030 delete render->packages;
1032 render->packages = 0;
1033 render->in_progress = 0;
1034 if(debug) printf("Render::render %d\n", __LINE__);
1037 void RenderThread::run()
1039 if(render->mode == Render::INTERACTIVE)
1041 render_single(1, render->asset, mwindow->edl,
1042 render->strategy, render->range_type);
1045 if(render->mode == Render::BATCH)
1048 // printf("RenderThread::run %d %d %d\n",
1050 // render->jobs->total,
1052 for(int i = 0; i < render->jobs->total && !render->result; i++)
1055 BatchRenderJob *job = render->jobs->values[i];
1059 if( *job->edl_path == '@' )
1061 run_script(job->edl_path+1, job->asset->path);
1066 mwindow->batch_render->update_active(i);
1070 printf("Render::run: %s\n", job->edl_path);
1075 FileXML *file = new FileXML;
1077 edl->create_objects();
1078 file->read_from_file(job->edl_path);
1079 edl->load_xml(file, LOAD_ALL);
1082 render_single(0, job->asset, edl, job->strategy, RANGE_BACKCOMPAT);
1085 edl->Garbage::remove_user();
1090 mwindow->batch_render->update_done(i, 1, render->elapsed_time);
1093 char string[BCTEXTLEN];
1094 render->elapsed_time =
1095 (double)render->progress_timer->get_scaled_difference(1);
1096 Units::totext(string,
1097 render->elapsed_time,
1099 printf("Render::run: done in %s\n", string);
1105 mwindow->batch_render->update_active(-1);
1107 printf("Render::run: failed\n");
1115 mwindow->batch_render->update_active(-1);
1116 mwindow->batch_render->update_done(-1, 0, 0);
1119 render->completion->unlock();
1127 RenderWindow::RenderWindow(MWindow *mwindow,
1132 : BC_Window(_(PROGRAM_NAME ": Render"), x, y,
1133 WIDTH, HEIGHT, WIDTH, HEIGHT, 0, 0, 1)
1135 this->mwindow = mwindow;
1136 this->render = render;
1137 this->asset = asset;
1144 RenderWindow::~RenderWindow()
1147 lock_window("RenderWindow::~RenderWindow");
1149 delete render_format;
1158 void RenderWindow::load_profile(int profile_slot)
1160 render->load_profile(profile_slot, asset);
1161 update_range_type(render->range_type);
1162 render_format->update(asset, &render->strategy);
1166 void RenderWindow::create_objects()
1169 lock_window("RenderWindow::create_objects");
1170 add_subwindow(new BC_Title(x, y,
1171 (char*)((render->strategy == FILE_PER_LABEL ||
1172 render->strategy == FILE_PER_LABEL_FARM) ?
1173 _("Select the first file to render to:") :
1174 _("Select a file to render to:"))));
1177 render_format = new RenderFormat(mwindow, this, asset);
1178 render_format->create_objects(x, y,
1179 1, 1, 1, 1, 0, 1, 0, 0, &render->strategy, 0);
1182 add_subwindow(title = new BC_Title(x, y, _("Render range:")));
1184 int is_image = File::is_image_render(asset->format);
1186 render->range_type = RANGE_1FRAME;
1188 int x1 = x + title->get_w() + 20;
1189 add_subwindow(rangeproject = new RenderRangeProject(this,
1190 render->range_type == RANGE_PROJECT, x1, y));
1192 add_subwindow(rangeselection = new RenderRangeSelection(this,
1193 render->range_type == RANGE_SELECTION, x1, y));
1195 add_subwindow(rangeinout = new RenderRangeInOut(this,
1196 render->range_type == RANGE_INOUT, x1, y));
1198 add_subwindow(range1frame = new RenderRange1Frame(this,
1199 render->range_type == RANGE_1FRAME, x1, y));
1203 enable_render_range(0);
1205 renderprofile = new RenderProfile(mwindow, this, x, y, 1);
1206 renderprofile->create_objects();
1209 loadmode = new LoadMode(mwindow, this, x, y, &render->load_mode, 1);
1210 loadmode->create_objects();
1212 add_subwindow(new BC_OKButton(this));
1213 add_subwindow(new BC_CancelButton(this));
1219 void RenderWindow::update_range_type(int range_type)
1221 if( render->range_type == range_type ) return;
1222 render->range_type = range_type;
1223 rangeproject->update(range_type == RANGE_PROJECT);
1224 rangeselection->update(range_type == RANGE_SELECTION);
1225 rangeinout->update(range_type == RANGE_INOUT);
1226 range1frame->update(range_type == RANGE_1FRAME);
1229 void RenderWindow::enable_render_range(int v)
1232 rangeproject->enable();
1233 rangeselection->enable();
1234 rangeinout->enable();
1235 range1frame->enable();
1238 rangeproject->disable();
1239 rangeselection->disable();
1240 rangeinout->disable();
1241 range1frame->disable();
1246 RenderRangeProject::RenderRangeProject(RenderWindow *rwindow, int value, int x, int y)
1247 : BC_Radial(x, y, value, _("Project"))
1249 this->rwindow = rwindow;
1251 int RenderRangeProject::handle_event()
1253 rwindow->update_range_type(RANGE_PROJECT);
1257 RenderRangeSelection::RenderRangeSelection(RenderWindow *rwindow, int value, int x, int y)
1258 : BC_Radial(x, y, value, _("Selection"))
1260 this->rwindow = rwindow;
1262 int RenderRangeSelection::handle_event()
1264 rwindow->update_range_type(RANGE_SELECTION);
1269 RenderRangeInOut::RenderRangeInOut(RenderWindow *rwindow, int value, int x, int y)
1270 : BC_Radial(x, y, value, _("In/Out Points"))
1272 this->rwindow = rwindow;
1274 int RenderRangeInOut::handle_event()
1276 rwindow->update_range_type(RANGE_INOUT);
1280 RenderRange1Frame::RenderRange1Frame(RenderWindow *rwindow, int value, int x, int y)
1281 : BC_Radial(x, y, value, _("One Frame"))
1283 this->rwindow = rwindow;
1285 int RenderRange1Frame::handle_event()
1287 rwindow->update_range_type(RANGE_1FRAME);
1291 double Render::get_render_range()
1293 EDL *edl = mwindow->edl;
1294 double last = edl->tracks->total_playable_length();
1295 double framerate = edl->session->frame_rate;
1296 if( framerate <= 0 ) framerate = 1;
1297 double start = 0, end = last;
1298 switch( range_type ) {
1300 case RANGE_BACKCOMPAT:
1301 start = edl->local_session->get_selectionstart(1);
1302 end = edl->local_session->get_selectionend(1);
1303 if( EQUIV(start, end) ) end = last;
1307 case RANGE_SELECTION:
1308 start = edl->local_session->get_selectionstart(1);
1309 end = edl->local_session->get_selectionend(1);
1312 start = edl->local_session->inpoint_valid() ?
1313 edl->local_session->get_inpoint() : 0;
1314 end = edl->local_session->outpoint_valid() ?
1315 edl->local_session->get_outpoint() : last;
1318 start = end = edl->local_session->get_selectionstart(1);
1319 if( edl->session->frame_rate > 0 ) end += 1./edl->session->frame_rate;
1322 if( start < 0 ) start = 0;
1323 if( end > last ) end = last;
1327 RenderFormat::RenderFormat(MWindow *mwindow, BC_WindowBase *window, Asset *asset)
1328 : FormatTools(mwindow, window, asset)
1331 RenderFormat::~RenderFormat()
1335 void RenderFormat::update_format()
1337 FormatTools::update_format();
1338 RenderWindow *render_window = (RenderWindow *)window;
1339 if( render_window->is_hidden() ) return;
1341 int is_image = File::is_image_render(asset->format);
1343 render_window->update_range_type(RANGE_1FRAME);
1344 render_window->enable_render_range(0);
1347 render_window->enable_render_range(1);