3 #include "commonrender.h"
5 #include "edlsession.h"
7 #include "localsession.h"
8 #include "mainsession.h"
13 #include "playabletracks.h"
14 #include "preferences.h"
15 #include "renderengine.h"
18 #include "transportque.h"
19 #include "virtualconsole.h"
21 CommonRender::CommonRender(RenderEngine *renderengine)
24 this->renderengine = renderengine;
28 CommonRender::~CommonRender()
33 for(int i = 0; i < total_modules; i++)
39 void CommonRender::reset_parameters()
52 void CommonRender::arm_command()
54 int64_t temp_length = 1;
56 //printf("CommonRender::arm_command 1 %f\n", renderengine->command->playbackstart);
57 current_position = tounits(renderengine->command->playbackstart, 0);
58 //printf("CommonRender::arm_command 2 %d\n", renderengine->command->playbackstart);
60 init_output_buffers();
62 //printf("CommonRender::arm_command 3 %d\n", renderengine->command->playbackstart);
64 if(test_reconfigure(current_position, temp_length))
66 //printf("CommonRender::arm_command 3.1 %d\n", renderengine->command->playbackstart);
71 vconsole->start_playback();
73 //printf("CommonRender::arm_command 4 %d\n", renderengine->command->playbackstart);
80 //printf("CommonRender::arm_command 5\n");
85 void CommonRender::create_modules()
87 //printf("CommonRender::create_modules 1\n");
88 // Create a module for every track, playable or not
89 Track *current = renderengine->edl->tracks->first;
92 //printf("CommonRender::create_modules 1\n");
95 total_modules = get_total_tracks();
96 modules = new Module*[total_modules];
97 //printf("CommonRender::create_modules 1 %d\n", total_modules);
99 for(module = 0; module < total_modules && current; current = NEXT)
101 //printf("CommonRender::create_modules 2 %d %p\n", total_modules, current);
102 if(current->data_type == data_type)
104 modules[module] = new_module(current);
105 modules[module]->create_objects();
111 // Update changes in plugins for existing modules
113 //printf("CommonRender::create_modules 3 %d\n", total_modules);
114 for(module = 0; module < total_modules; module++)
116 modules[module]->create_objects();
118 //printf("CommonRender::create_modules 4\n");
122 void CommonRender::start_plugins()
124 //printf("CommonRender::start_plugins 1\n");
125 // Only start if virtual console was created
128 for(int i = 0; i < total_modules; i++)
130 modules[i]->render_init();
133 //printf("CommonRender::start_plugins 2\n");
136 int CommonRender::test_reconfigure(int64_t position, int64_t &length)
138 if(!vconsole) return 1;
139 if(!modules) return 1;
141 return vconsole->test_reconfigure(position, length, last_playback);
145 void CommonRender::build_virtual_console()
147 // Create new virtual console object
148 //printf("CommonRender::build_virtual_console 1 %p\n", vconsole);
151 vconsole = new_vconsole_object();
152 //printf("CommonRender::build_virtual_console 2\n");
156 vconsole->create_objects();
157 //printf("CommonRender::build_virtual_console 3\n");
160 void CommonRender::start_command()
162 if(renderengine->command->realtime)
171 int CommonRender::restart_playback()
175 build_virtual_console();
176 vconsole->start_playback();
186 void CommonRender::delete_vconsole()
188 if(vconsole) delete vconsole;
192 int CommonRender::get_boundaries(int64_t ¤t_render_length)
194 int64_t loop_end = tounits(renderengine->edl->local_session->loop_end, 1);
195 int64_t loop_start = tounits(renderengine->edl->local_session->loop_start, 0);
196 int64_t start_position = tounits(renderengine->command->start_position, 0);
197 int64_t end_position = tounits(renderengine->command->end_position, 1);
200 //printf("CommonRender::get_boundaries 1 %d %d %d %d\n",
201 //current_render_length,
205 // test absolute boundaries if no loop and not infinite
206 if(renderengine->command->single_frame() ||
207 (!renderengine->edl->local_session->loop_playback &&
208 !renderengine->command->infinite))
210 //printf("CommonRender::get_boundaries 1.1 %d\n", current_render_length);
211 if(renderengine->command->get_direction() == PLAY_FORWARD)
213 //printf("CommonRender::get_boundaries 1.2 %d\n", current_render_length);
214 if(current_position + current_render_length >= end_position)
217 current_render_length = end_position - current_position;
218 //printf("CommonRender::get_boundaries 1.3 %d\n", current_render_length);
224 //printf("CommonRender::get_boundaries 1.4 %d\n", current_render_length);
225 if(current_position - current_render_length <= start_position)
228 current_render_length = current_position - start_position;
229 //printf("CommonRender::get_boundaries 1.5 %d\n", current_render_length);
233 //printf("CommonRender::get_boundaries 2 %d\n", current_render_length);
235 // test against loop boundaries
236 if(!renderengine->command->single_frame() &&
237 renderengine->edl->local_session->loop_playback &&
238 !renderengine->command->infinite)
241 if(renderengine->command->get_direction() == PLAY_FORWARD)
243 int64_t segment_end = current_position + current_render_length;
244 if(segment_end > loop_end)
246 current_render_length = loop_end - current_position;
251 int64_t segment_end = current_position - current_render_length;
252 if(segment_end < loop_start)
254 current_render_length = current_position - loop_start;
259 //printf("CommonRender::get_boundaries 3 %d\n", current_render_length);
260 if(renderengine->command->single_frame())
261 current_render_length = 1;
263 //printf("CommonRender::get_boundaries 4 %d\n", current_render_length);
268 void CommonRender::run()
293 CommonRender::CommonRender(MWindow *mwindow, RenderEngine *renderengine)
296 this->mwindow = mwindow;
297 this->renderengine = renderengine;
298 current_position = 0;
307 int CommonRender::wait_for_completion()
316 int CommonRender::advance_position(int64_t current_render_length)
318 int64_t loop_end = tounits(renderengine->edl->local_session->loop_end, 1);
319 int64_t loop_start = tounits(renderengine->edl->local_session->loop_start, 0);
321 // advance the playback position
322 if(renderengine->command->get_direction() == PLAY_REVERSE)
323 current_position -= current_render_length;
325 current_position += current_render_length;
327 //printf("CommonRender::advance_position 1 %d\n", current_render_length);
329 if(renderengine->edl->local_session->loop_playback &&
330 !renderengine->command->infinite)
332 if(renderengine->command->get_direction() == PLAY_REVERSE)
334 if(current_position <= loop_start)
335 current_position = loop_end;
339 if(current_position >= loop_end)
340 current_position = loop_start + (current_position - loop_end);
346 int64_t CommonRender::tounits(double position, int round)
348 return (int64_t)position;
351 double CommonRender::fromunits(int64_t position)
353 return (double)position;