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;
70 for(int i = 0; i < track->plugin_set.total; i++)
74 // For some reason it isn't used here.
75 // attachments[i]->render_stop(0);
76 delete attachments[i];
79 delete [] attachments;
83 transition_server->close_plugin();
84 delete transition_server;
87 delete nested_renderengine;
88 delete nested_command;
89 if(private_cache) delete cache;
92 void Module::create_objects()
94 create_new_attachments();
98 EDL* Module::get_edl()
100 return renderengine ? renderengine->get_edl() : edl;
103 Preferences* Module::get_preferences()
105 if( renderengine ) return renderengine->preferences;
106 if( plugin_array ) return plugin_array->mwindow->preferences;
111 void Module::create_new_attachments()
113 // Not used in pluginarray
116 new_total_attachments = track->plugin_set.size();
117 if(new_total_attachments)
119 new_attachments = new AttachmentPoint*[new_total_attachments];
120 for(int i = 0; i < new_total_attachments; i++)
123 track->get_current_plugin(commonrender->current_position,
125 renderengine->command->get_direction(),
129 if(plugin && plugin->plugin_type != PLUGIN_NONE && plugin->on)
131 new_attachments[i] = new_attachment(plugin);
132 // printf("Module::create_new_attachments %d new_attachment=%p\n",
134 // new_attachments[i]->virtual_plugins.values);
138 new_attachments[i] = 0;
145 // Create plugin servers in virtual console expansion
149 void Module::swap_attachments()
151 // for(int i = 0; i < total_attachments; i++)
152 // printf("Module::swap_attachments %d attachment=%p\n", __LINE__, attachments[i] ? attachments[i]->virtual_plugins.values : 0);
153 // for(int i = 0; i < new_total_attachments; i++)
154 // printf("Module::swap_attachments %d new_attachment=%p\n", __LINE__, new_attachments[i] ? new_attachments[i]->virtual_plugins.values : 0);
156 // None of this is used in a pluginarray
158 i < new_total_attachments &&
159 i < total_attachments;
162 // Delete new attachment which is identical to the old one and copy
164 if(new_attachments[i] &&
166 new_attachments[i]->identical(attachments[i]))
168 // printf("Module::swap_attachments %d virtual_plugins=%p new_virtual_plugins=%p\n",
170 // new_attachments[i]->virtual_plugins.values,
171 // new_attachments[i]->new_virtual_plugins.values);
173 delete new_attachments[i];
174 new_attachments[i] = attachments[i];
179 // Delete old attachments which weren't identical to new ones
180 for(int i = 0; i < total_attachments; i++)
182 if(attachments[i]) delete attachments[i];
187 delete [] attachments;
190 attachments = new_attachments;
191 total_attachments = new_total_attachments;
194 new_total_attachments = 0;
196 // for(int i = 0; i < total_attachments; i++)
197 // printf("Module::swap_attachments %d final_attachment=%p\n", __LINE__, attachments[i] ? attachments[i]->virtual_plugins.values : 0);
200 int Module::render_init()
202 for(int i = 0; i < total_attachments; i++)
205 attachments[i]->render_init();
211 void Module::render_stop()
213 for(int i = 0; i < total_attachments; i++)
216 attachments[i]->render_stop();
220 AttachmentPoint* Module::attachment_of(Plugin *plugin)
222 //printf("Module::attachment_of 1 %d\n", total_attachments);
223 for(int i = 0; i < total_attachments; i++)
225 //printf("Module::attachment_of 2 %p\n", attachments[i]);
227 attachments[i]->plugin == plugin) return attachments[i];
232 AttachmentPoint* Module::get_attachment(int number)
234 if(number < total_attachments)
235 return attachments[number];
240 void Module::reset_attachments()
242 //printf("Module::reset_attachments 1 %d\n", total_attachments);
243 for(int i = 0; i < total_attachments; i++)
245 //printf("Module::reset_attachments 2 %p\n", attachments[i]);
246 AttachmentPoint *attachment = attachments[i];
247 if(attachment) attachment->reset_status();
251 // Test plugins for reconfiguration.
253 int Module::test_plugins()
255 if(total_attachments != track->plugin_set.total) return 1;
257 for(int i = 0; i < total_attachments; i++)
259 AttachmentPoint *attachment = attachments[i];
260 Plugin *plugin = track->get_current_plugin(
261 commonrender->current_position,
263 renderengine->command->get_direction(),
266 // One exists and one doesn't
267 int use_plugin = plugin &&
268 plugin->plugin_type != PLUGIN_NONE &&
271 if((attachment && !use_plugin) ||
272 (!attachment && use_plugin)) return 1;
274 // Plugin not the same
277 attachment->plugin &&
278 !plugin->identical(attachment->plugin)) return 1;
284 void Module::update_transition(int64_t current_position,
287 transition = track->get_current_transition(current_position,
290 // For situations where we had a transition but not anymore,
291 // keep the server open.
292 // Maybe the same transition will follow and we won't need to reinit.
293 // (happens a lot while scrubbing over transitions left and right)
296 // If the current transition differs from the previous transition, delete the
298 if (transition && transition_server) {
299 if (strcmp(transition->title, transition_server->plugin->title)) {
300 transition_server->close_plugin();
301 delete transition_server;
302 transition_server = 0;
305 transition_server->plugin = transition;
309 if(transition && !transition_server) {
311 PluginServer *plugin_server = MWindow::scan_plugindb(transition->title,
313 transition_server = new PluginServer(*plugin_server);
314 transition_server->open_plugin(0,
318 transition_server->init_realtime(
319 get_edl()->session->real_time_playback &&
320 renderengine->command->realtime,
326 PluginServer *plugin_server = MWindow::scan_plugindb(transition->title,
327 plugin_array->data_type);
328 transition_server = new PluginServer(*plugin_server);
329 transition_server->open_plugin(0,
333 transition_server->init_realtime(
344 printf(" Module title=%s\n", track->title);
345 printf(" Plugins total_attachments=%d\n", total_attachments);
346 for(int i = 0; i < total_attachments; i++)
348 attachments[i]->dump();