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)
148 Thread::set_realtime(renderengine->edl->session->real_time_playback &&
149 data_type == TRACK_AUDIO);
151 start_lock->lock("CommonRender::start_command");
155 int CommonRender::restart_playback()
159 build_virtual_console();
169 void CommonRender::delete_vconsole()
171 if(vconsole) delete vconsole;
175 int CommonRender::get_boundaries(int64_t ¤t_render_length)
177 int64_t loop_end = tounits(renderengine->edl->local_session->loop_end, 1);
178 int64_t loop_start = tounits(renderengine->edl->local_session->loop_start, 0);
179 int64_t start_position = tounits(renderengine->command->start_position, 0);
180 int64_t end_position = tounits(renderengine->command->end_position, 1);
183 // test absolute boundaries if no loop and not infinite
184 if(renderengine->command->single_frame() ||
185 (!renderengine->edl->local_session->loop_playback &&
186 !renderengine->command->infinite))
188 if(renderengine->command->get_direction() == PLAY_FORWARD)
190 if(current_position + current_render_length >= end_position)
193 current_render_length = end_position - current_position;
199 if(current_position - current_render_length <= start_position)
202 current_render_length = current_position - start_position;
207 // test against loop boundaries
208 if(!renderengine->command->single_frame() &&
209 renderengine->edl->local_session->loop_playback &&
210 !renderengine->command->infinite)
212 if(renderengine->command->get_direction() == PLAY_FORWARD)
214 int64_t segment_end = current_position + current_render_length;
215 if(segment_end > loop_end)
217 current_render_length = loop_end - current_position;
222 int64_t segment_end = current_position - current_render_length;
223 if(segment_end < loop_start)
225 current_render_length = current_position - loop_start;
230 if(renderengine->command->single_frame())
231 current_render_length = 1;
233 if(current_render_length < 0) current_render_length = 0;
237 void CommonRender::run()
239 start_lock->unlock();
262 CommonRender::CommonRender(MWindow *mwindow, RenderEngine *renderengine)
265 this->mwindow = mwindow;
266 this->renderengine = renderengine;
267 current_position = 0;
276 int CommonRender::wait_for_completion()
285 int CommonRender::advance_position(int64_t current_render_length)
287 int64_t loop_end = tounits(renderengine->edl->local_session->loop_end, 1);
288 int64_t loop_start = tounits(renderengine->edl->local_session->loop_start, 0);
290 // advance the playback position
291 if(renderengine->command->get_direction() == PLAY_REVERSE)
292 current_position -= current_render_length;
294 current_position += current_render_length;
297 if(renderengine->edl->local_session->loop_playback &&
298 !renderengine->command->infinite)
300 if(renderengine->command->get_direction() == PLAY_REVERSE)
302 if(current_position <= loop_start)
303 current_position = loop_end;
307 if(current_position >= loop_end)
308 current_position = loop_start + (current_position - loop_end);
314 int64_t CommonRender::tounits(double position, int round)
316 return (int64_t)position;
319 double CommonRender::fromunits(int64_t position)
321 return (double)position;