4 * Copyright (C) 2008 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
22 #include "attachmentpoint.h"
23 #include "bcsignals.h"
25 #include "commonrender.h"
27 #include "edlsession.h"
34 #include "pluginarray.h"
35 #include "pluginserver.h"
36 #include "renderengine.h"
37 #include "sharedlocation.h"
40 #include "transportque.h"
41 #include "virtualconsole.h"
44 Module::Module(RenderEngine *renderengine,
45 CommonRender *commonrender,
46 PluginArray *plugin_array,
49 this->renderengine = renderengine;
50 this->commonrender = commonrender;
51 this->plugin_array = plugin_array;
54 transition_server = 0;
56 total_attachments = 0;
57 new_total_attachments = 0;
60 nested_renderengine = 0;
69 for(int i = 0; i < track->plugin_set.total; i++)
73 // For some reason it isn't used here.
74 // attachments[i]->render_stop(0);
75 delete attachments[i];
78 delete [] attachments;
82 transition_server->close_plugin();
83 delete transition_server;
86 delete nested_renderengine;
87 delete nested_command;
90 void Module::create_objects()
92 create_new_attachments();
96 EDL* Module::get_edl()
98 return renderengine ? renderengine->get_edl() : edl;
101 Preferences* Module::get_preferences()
103 if( renderengine ) return renderengine->preferences;
104 if( plugin_array ) return plugin_array->mwindow->preferences;
109 void Module::create_new_attachments()
111 // Not used in pluginarray
114 new_total_attachments = track->plugin_set.size();
115 if(new_total_attachments)
117 new_attachments = new AttachmentPoint*[new_total_attachments];
118 for(int i = 0; i < new_total_attachments; i++)
121 track->get_current_plugin(commonrender->current_position,
123 renderengine->command->get_direction(),
127 if(plugin && plugin->plugin_type != PLUGIN_NONE && plugin->on)
129 new_attachments[i] = new_attachment(plugin);
130 // printf("Module::create_new_attachments %d new_attachment=%p\n",
132 // new_attachments[i]->virtual_plugins.values);
136 new_attachments[i] = 0;
143 // Create plugin servers in virtual console expansion
147 void Module::swap_attachments()
149 // for(int i = 0; i < total_attachments; i++)
150 // printf("Module::swap_attachments %d attachment=%p\n", __LINE__, attachments[i] ? attachments[i]->virtual_plugins.values : 0);
151 // for(int i = 0; i < new_total_attachments; i++)
152 // printf("Module::swap_attachments %d new_attachment=%p\n", __LINE__, new_attachments[i] ? new_attachments[i]->virtual_plugins.values : 0);
154 // None of this is used in a pluginarray
156 i < new_total_attachments &&
157 i < total_attachments;
160 // Delete new attachment which is identical to the old one and copy
162 if(new_attachments[i] &&
164 new_attachments[i]->identical(attachments[i]))
166 // printf("Module::swap_attachments %d virtual_plugins=%p new_virtual_plugins=%p\n",
168 // new_attachments[i]->virtual_plugins.values,
169 // new_attachments[i]->new_virtual_plugins.values);
171 delete new_attachments[i];
172 new_attachments[i] = attachments[i];
177 // Delete old attachments which weren't identical to new ones
178 for(int i = 0; i < total_attachments; i++)
180 if(attachments[i]) delete attachments[i];
185 delete [] attachments;
188 attachments = new_attachments;
189 total_attachments = new_total_attachments;
192 new_total_attachments = 0;
194 // for(int i = 0; i < total_attachments; i++)
195 // printf("Module::swap_attachments %d final_attachment=%p\n", __LINE__, attachments[i] ? attachments[i]->virtual_plugins.values : 0);
198 int Module::render_init()
200 for(int i = 0; i < total_attachments; i++)
203 attachments[i]->render_init();
209 void Module::render_stop()
211 for(int i = 0; i < total_attachments; i++)
214 attachments[i]->render_stop();
218 AttachmentPoint* Module::attachment_of(Plugin *plugin)
220 //printf("Module::attachment_of 1 %d\n", total_attachments);
221 for(int i = 0; i < total_attachments; i++)
223 //printf("Module::attachment_of 2 %p\n", attachments[i]);
225 attachments[i]->plugin == plugin) return attachments[i];
230 AttachmentPoint* Module::get_attachment(int number)
232 if(number < total_attachments)
233 return attachments[number];
238 void Module::reset_attachments()
240 //printf("Module::reset_attachments 1 %d\n", total_attachments);
241 for(int i = 0; i < total_attachments; i++)
243 //printf("Module::reset_attachments 2 %p\n", attachments[i]);
244 AttachmentPoint *attachment = attachments[i];
245 if(attachment) attachment->reset_status();
249 // Test plugins for reconfiguration.
251 int Module::test_plugins()
253 if(total_attachments != track->plugin_set.total) return 1;
255 for(int i = 0; i < total_attachments; i++)
257 AttachmentPoint *attachment = attachments[i];
258 Plugin *plugin = track->get_current_plugin(
259 commonrender->current_position,
261 renderengine->command->get_direction(),
264 // One exists and one doesn't
265 int use_plugin = plugin &&
266 plugin->plugin_type != PLUGIN_NONE &&
269 if((attachment && !use_plugin) ||
270 (!attachment && use_plugin)) return 1;
272 // Plugin not the same
273 if( plugin && attachment && attachment->plugin && (
274 plugin->gui_id != attachment->plugin->gui_id ||
275 !plugin->identical(attachment->plugin) ) ) return 1;
281 void Module::update_transition(int64_t current_position,
284 Plugin *transition = track->get_current_transition(current_position,
286 transition_id = transition ? transition->orig_id : -1;
288 // For situations where we had a transition but not anymore,
289 // keep the server open.
290 // Maybe the same transition will follow and we won't need to reinit.
291 // (happens a lot while scrubbing over transitions left and right)
294 // If the current transition differs from the previous transition, delete the
296 if (transition && transition_server) {
297 Plugin *plugin = transition->edl->tracks->plugin_exists(transition_server->plugin_id);
298 if (!plugin || strcmp(transition->title, plugin->title)) {
299 transition_server->close_plugin();
300 delete transition_server;
301 transition_server = 0;
304 transition_server->plugin_id = transition_id;
308 if(transition && !transition_server) {
310 PluginServer *plugin_server = MWindow::scan_plugindb(transition->title,
312 if( plugin_server ) {
313 transition_server = new PluginServer(*plugin_server);
314 transition_server->open_plugin(0, get_preferences(), get_edl(),
316 transition_server->init_realtime(
317 get_edl()->session->real_time_playback &&
318 renderengine->command->realtime, 1, get_buffer_size());
323 PluginServer *plugin_server = MWindow::scan_plugindb(transition->title,
324 plugin_array->data_type);
325 if( plugin_server ) {
326 transition_server = new PluginServer(*plugin_server);
327 transition_server->open_plugin(0, get_preferences(), get_edl(),
329 transition_server->init_realtime( 0, 1, get_buffer_size());
338 printf(" Module title=%s\n", track->title);
339 printf(" Plugins total_attachments=%d\n", total_attachments);
340 for(int i = 0; i < total_attachments; i++)
342 attachments[i]->dump();