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 int CommonRender::test_reconfigure(int64_t position, int64_t &length)
125 if(!vconsole) return 1;
126 if(!modules) return 1;
128 return vconsole->test_reconfigure(position, length, last_playback);
132 void CommonRender::build_virtual_console()
134 // Create new virtual console object
137 vconsole = new_vconsole_object();
141 vconsole->create_objects();
144 void CommonRender::start_command()
146 if(renderengine->command->realtime)
149 start_lock->lock("CommonRender::start_command");
153 int CommonRender::restart_playback()
157 build_virtual_console();
167 void CommonRender::delete_vconsole()
169 if(vconsole) delete vconsole;
173 int CommonRender::get_boundaries(int64_t ¤t_render_length)
175 int64_t loop_end = tounits(renderengine->edl->local_session->loop_end, 1);
176 int64_t loop_start = tounits(renderengine->edl->local_session->loop_start, 0);
177 int64_t start_position = tounits(renderengine->command->start_position, 0);
178 int64_t end_position = tounits(renderengine->command->end_position, 1);
181 // test absolute boundaries if no loop and not infinite
182 if(renderengine->command->single_frame() ||
183 (!renderengine->edl->local_session->loop_playback &&
184 !renderengine->command->infinite))
186 if(renderengine->command->get_direction() == PLAY_FORWARD)
188 if(current_position + current_render_length >= end_position)
191 current_render_length = end_position - current_position;
197 if(current_position - current_render_length <= start_position)
200 current_render_length = current_position - start_position;
205 // test against loop boundaries
206 if(!renderengine->command->single_frame() &&
207 renderengine->edl->local_session->loop_playback &&
208 !renderengine->command->infinite)
210 if(renderengine->command->get_direction() == PLAY_FORWARD)
212 int64_t segment_end = current_position + current_render_length;
213 if(segment_end > loop_end)
215 current_render_length = loop_end - current_position;
220 int64_t segment_end = current_position - current_render_length;
221 if(segment_end < loop_start)
223 current_render_length = current_position - loop_start;
228 if(renderengine->command->single_frame())
229 current_render_length = 1;
231 if(current_render_length < 0) current_render_length = 0;
235 void CommonRender::run()
237 start_lock->unlock();
260 CommonRender::CommonRender(MWindow *mwindow, RenderEngine *renderengine)
263 this->mwindow = mwindow;
264 this->renderengine = renderengine;
265 current_position = 0;
274 int CommonRender::wait_for_completion()
283 int CommonRender::advance_position(int64_t current_render_length)
285 int64_t loop_end = tounits(renderengine->edl->local_session->loop_end, 1);
286 int64_t loop_start = tounits(renderengine->edl->local_session->loop_start, 0);
288 // advance the playback position
289 if(renderengine->command->get_direction() == PLAY_REVERSE)
290 current_position -= current_render_length;
292 current_position += current_render_length;
295 if(renderengine->edl->local_session->loop_playback &&
296 !renderengine->command->infinite)
298 if(renderengine->command->get_direction() == PLAY_REVERSE)
300 if(current_position <= loop_start)
301 current_position = loop_end;
305 if(current_position >= loop_end)
306 current_position = loop_start + (current_position - loop_end);
312 int64_t CommonRender::tounits(double position, int round)
314 return (int64_t)position;
317 double CommonRender::fromunits(int64_t position)
319 return (double)position;