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"
25 #include "edlsession.h"
28 #include "pluginserver.h"
29 #include "renderengine.h"
30 #include "transportque.h"
31 #include "virtualnode.h"
35 AttachmentPoint::AttachmentPoint(RenderEngine *renderengine,
40 this->plugin = plugin;
41 this->plugin_id = plugin->id;
42 this->renderengine = renderengine;
43 this->data_type = data_type;
44 plugin_server = MWindow::scan_plugindb(plugin->title,
48 AttachmentPoint::~AttachmentPoint()
50 delete_buffer_vector();
51 plugin_servers.remove_all_objects();
55 int AttachmentPoint::reset_parameters()
63 void AttachmentPoint::reset_status()
65 if(!this) printf("AttachmentPoint::reset_status NULL\n");
74 int AttachmentPoint::identical(AttachmentPoint *old)
76 return plugin_id == old->plugin_id;
80 int AttachmentPoint::render_init()
82 if(!this) printf("AttachmentPoint::render_init NULL\n");
83 if(plugin_server && plugin->on)
85 // Start new plugin servers if the number of nodes changed.
86 // The number of nodes can change independantly of the module's
88 if(virtual_plugins.total != new_virtual_plugins.total)
90 plugin_servers.remove_all_objects();
91 for(int i = 0; i < new_virtual_plugins.total; i++)
93 if(i == 0 || !plugin_server->multichannel)
95 PluginServer *new_server;
96 plugin_servers.append(new_server = new PluginServer(*plugin_server));
97 new_server->set_attachmentpoint(this);
98 plugin_servers.values[i]->open_plugin(0,
99 renderengine->preferences,
100 renderengine->get_edl(),
102 plugin_servers.values[i]->init_realtime(
103 renderengine->get_edl()->session->real_time_playback &&
104 renderengine->command->realtime,
105 plugin_server->multichannel ? new_virtual_plugins.total : 1,
111 // Set new back pointers in the plugin servers
112 if(plugin_server->multichannel && plugin_servers.total)
114 PluginServer *new_server = plugin_servers.values[0];
115 new_server->reset_nodes();
116 for(int i = 0; i < new_virtual_plugins.total; i++)
118 new_server->append_node(new_virtual_plugins.values[i]);
123 for(int i = 0; i < new_virtual_plugins.total; i++)
125 PluginServer *new_server = plugin_servers.values[i];
126 new_server->reset_nodes();
127 new_server->append_node(new_virtual_plugins.values[i]);
132 // Delete old plugin servers
133 delete_buffer_vector();
134 virtual_plugins.remove_all();
136 // Set new plugin servers
137 for(int i = 0; i < new_virtual_plugins.total; i++)
138 virtual_plugins.append(new_virtual_plugins.values[i]);
139 new_virtual_plugins.remove_all();
145 void AttachmentPoint::render_stop()
147 if(plugin_server && plugin->on)
149 for(int i = 0; i < plugin_servers.total; i++)
151 plugin_servers.values[i]->render_stop();
156 int AttachmentPoint::attach_virtual_plugin(VirtualNode *virtual_plugin)
158 if(!this) printf("AttachmentPoint::attach_virtual_plugin NULL\n");
159 int buffer_number = 0;
161 if(plugin_server && plugin->on)
163 // add virtual plugin to list of new virtual plugins
164 new_virtual_plugins.append(virtual_plugin);
165 //printf("AttachmentPoint::attach_virtual_plugin 1 %d\n", new_virtual_plugins.total);
166 // Always increment buffer number since this also corresponds to what
167 // plugin server to access if single channel.
168 buffer_number = new_virtual_plugins.total - 1;
173 printf("AttachmentPoint::attach_virtual_plugin attempt to attach plugin when off.\n");
178 printf("AttachmentPoint::attach_virtual_plugin attempt to attach when no plugin_server.\n");
181 return buffer_number;
184 int AttachmentPoint::multichannel_shared(int search_new)
186 if(!this) printf("AttachmentPoint::multichannel_shared NULL\n");
189 if(new_virtual_plugins.total &&
191 plugin_server->multichannel) return 1;
195 if(virtual_plugins.total &&
197 plugin_server->multichannel) return 1;
202 int AttachmentPoint::singlechannel()
204 if(!this) printf("AttachmentPoint::singlechannel NULL\n");
205 if(plugin_server && !plugin_server->multichannel) return 1;
210 void AttachmentPoint::render_gui(void *data, PluginServer *server)
212 //printf("AttachmentPoint::render_gui 1 %p %p\n", server, plugin_servers.get(0));
213 if(!this) printf("AttachmentPoint::render_gui 1 NULL\n");
215 // Discard if not 1st plugin server, so single channel plugins don't get double GUI updates
216 if(server != plugin_servers.get(0)) return;
218 if(renderengine && renderengine->mwindow)
219 renderengine->mwindow->render_plugin_gui(data, plugin);
222 void AttachmentPoint::render_gui(void *data, int size, PluginServer *server)
224 if(!this) printf("AttachmentPoint::render_gui 2 NULL\n");
226 // Discard if not 1st plugin server, so single channel plugins don't get double GUI updates
227 if(server != plugin_servers.get(0)) return;
229 if(renderengine && renderengine->mwindow)
230 renderengine->mwindow->render_plugin_gui(data, size, plugin);
233 int AttachmentPoint::gui_open()
235 if(renderengine && renderengine->mwindow)
236 return renderengine->mwindow->plugin_gui_open(plugin);
240 int AttachmentPoint::dump(FILE *fp)
244 fprintf(fp," Attachmentpoint this=%p virtual_plugins=%d\n", this, new_virtual_plugins.total);
245 if(plugin_server) plugin_server->dump(fp);
249 fprintf(fp," No Plugin\n");