3 #include "commonrender.h"
6 #include "edlsession.h"
8 #include "localsession.h"
9 #include "mainsession.h"
14 #include "playabletracks.h"
15 #include "preferences.h"
16 #include "renderengine.h"
19 #include "transportque.h"
20 #include "virtualconsole.h"
22 CommonRender::CommonRender(RenderEngine *renderengine)
25 this->renderengine = renderengine;
27 start_lock = new Condition(0, "CommonRender::start_lock");
30 CommonRender::~CommonRender()
35 for(int i = 0; i < total_modules; i++)
42 void CommonRender::reset_parameters()
54 void CommonRender::arm_command()
56 int64_t temp_length = 1;
58 current_position = tounits(renderengine->command->playbackstart, 0);
60 init_output_buffers();
63 if(test_reconfigure(current_position, temp_length))
69 vconsole->start_playback();
80 void CommonRender::create_modules()
82 // Create a module for every track, playable or not
83 Track *current = renderengine->edl->tracks->first;
88 total_modules = get_total_tracks();
89 modules = new Module*[total_modules];
91 for(module = 0; module < total_modules && current; current = NEXT)
93 if(current->data_type == data_type)
95 modules[module] = new_module(current);
96 modules[module]->create_objects();
102 // Update changes in plugins for existing modules
104 for(module = 0; module < total_modules; module++)
106 modules[module]->create_objects();
111 void CommonRender::start_plugins()
113 // Only start if virtual console was created
116 for(int i = 0; i < total_modules; i++)
118 modules[i]->render_init();
123 void CommonRender::stop_plugins()
125 for(int i = 0; i < total_modules; i++)
127 modules[i]->render_stop();
131 int CommonRender::test_reconfigure(int64_t position, int64_t &length)
133 if(!vconsole) return 1;
134 if(!modules) return 1;
136 return vconsole->test_reconfigure(position, length, last_playback);
140 void CommonRender::build_virtual_console()
142 // Create new virtual console object
145 vconsole = new_vconsole_object();
149 vconsole->create_objects();
152 void CommonRender::start_command()
154 if(renderengine->command->realtime)
156 Thread::set_realtime(renderengine->edl->session->real_time_playback &&
157 data_type == TRACK_AUDIO);
159 start_lock->lock("CommonRender::start_command");
163 int CommonRender::restart_playback()
167 build_virtual_console();
177 void CommonRender::delete_vconsole()
179 if(vconsole) delete vconsole;
183 int CommonRender::get_boundaries(int64_t ¤t_render_length)
185 int64_t loop_end = tounits(renderengine->edl->local_session->loop_end, 1);
186 int64_t loop_start = tounits(renderengine->edl->local_session->loop_start, 0);
187 int64_t start_position = tounits(renderengine->command->start_position, 0);
188 int64_t end_position = tounits(renderengine->command->end_position, 1);
191 // test absolute boundaries if no loop and not infinite
192 if(renderengine->command->single_frame() ||
193 (!renderengine->edl->local_session->loop_playback &&
194 !renderengine->command->infinite))
196 if(renderengine->command->get_direction() == PLAY_FORWARD)
198 if(current_position + current_render_length >= end_position)
201 current_render_length = end_position - current_position;
207 if(current_position - current_render_length <= start_position)
210 current_render_length = current_position - start_position;
215 // test against loop boundaries
216 if(!renderengine->command->single_frame() &&
217 renderengine->edl->local_session->loop_playback &&
218 !renderengine->command->infinite)
220 if(renderengine->command->get_direction() == PLAY_FORWARD)
222 int64_t segment_end = current_position + current_render_length;
223 if(segment_end > loop_end)
225 current_render_length = loop_end - current_position;
230 int64_t segment_end = current_position - current_render_length;
231 if(segment_end < loop_start)
233 current_render_length = current_position - loop_start;
238 if(renderengine->command->single_frame())
239 current_render_length = 1;
241 if(current_render_length < 0) current_render_length = 0;
245 void CommonRender::run()
247 start_lock->unlock();
270 CommonRender::CommonRender(MWindow *mwindow, RenderEngine *renderengine)
273 this->mwindow = mwindow;
274 this->renderengine = renderengine;
275 current_position = 0;
284 int CommonRender::wait_for_completion()
293 int CommonRender::advance_position(int64_t current_render_length)
295 int64_t loop_end = tounits(renderengine->edl->local_session->loop_end, 1);
296 int64_t loop_start = tounits(renderengine->edl->local_session->loop_start, 0);
298 // advance the playback position
299 if(renderengine->command->get_direction() == PLAY_REVERSE)
300 current_position -= current_render_length;
302 current_position += current_render_length;
305 if(renderengine->edl->local_session->loop_playback &&
306 !renderengine->command->infinite)
308 if(renderengine->command->get_direction() == PLAY_REVERSE)
310 if(current_position <= loop_start)
311 current_position = loop_end;
315 if(current_position >= loop_end)
316 current_position = loop_start + (current_position - loop_end);
322 int64_t CommonRender::tounits(double position, int round)
324 return (int64_t)position;
327 double CommonRender::fromunits(int64_t position)
329 return (double)position;