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()
66 if(!This) printf("AttachmentPoint::reset_status NULL\n");
75 int AttachmentPoint::identical(AttachmentPoint *old)
77 return plugin_id == old->plugin_id;
81 int AttachmentPoint::render_init()
84 if(!This) printf("AttachmentPoint::render_init NULL\n");
85 if(plugin_server && plugin->on)
87 // Start new plugin servers if the number of nodes changed.
88 // The number of nodes can change independantly of the module's
90 if(virtual_plugins.total != new_virtual_plugins.total)
92 plugin_servers.remove_all_objects();
93 for(int i = 0; i < new_virtual_plugins.total; i++)
95 if(i == 0 || !plugin_server->multichannel)
97 PluginServer *new_server;
98 plugin_servers.append(new_server = new PluginServer(*plugin_server));
99 new_server->set_attachmentpoint(this);
100 plugin_servers.values[i]->open_plugin(0,
101 renderengine->preferences,
102 renderengine->get_edl(),
104 plugin_servers.values[i]->init_realtime(
105 renderengine->get_edl()->session->real_time_playback &&
106 renderengine->command->realtime,
107 plugin_server->multichannel ? new_virtual_plugins.total : 1,
113 // Set new back pointers in the plugin servers
114 if(plugin_server->multichannel && plugin_servers.total)
116 PluginServer *new_server = plugin_servers.values[0];
117 new_server->reset_nodes();
118 for(int i = 0; i < new_virtual_plugins.total; i++)
120 new_server->append_node(new_virtual_plugins.values[i]);
125 for(int i = 0; i < new_virtual_plugins.total; i++)
127 PluginServer *new_server = plugin_servers.values[i];
128 new_server->reset_nodes();
129 new_server->append_node(new_virtual_plugins.values[i]);
134 // Delete old plugin servers
135 delete_buffer_vector();
136 virtual_plugins.remove_all();
138 // Set new plugin servers
139 for(int i = 0; i < new_virtual_plugins.total; i++)
140 virtual_plugins.append(new_virtual_plugins.values[i]);
141 new_virtual_plugins.remove_all();
147 void AttachmentPoint::render_stop()
149 if(plugin_server && plugin->on)
151 for(int i = 0; i < plugin_servers.total; i++)
153 plugin_servers.values[i]->render_stop();
158 int AttachmentPoint::attach_virtual_plugin(VirtualNode *virtual_plugin)
161 if(!This) printf("AttachmentPoint::attach_virtual_plugin NULL\n");
162 int buffer_number = 0;
164 if(plugin_server && plugin->on)
166 // add virtual plugin to list of new virtual plugins
167 new_virtual_plugins.append(virtual_plugin);
168 //printf("AttachmentPoint::attach_virtual_plugin 1 %d\n", new_virtual_plugins.total);
169 // Always increment buffer number since this also corresponds to what
170 // plugin server to access if single channel.
171 buffer_number = new_virtual_plugins.total - 1;
176 printf("AttachmentPoint::attach_virtual_plugin attempt to attach plugin when off.\n");
181 printf("AttachmentPoint::attach_virtual_plugin attempt to attach when no plugin_server.\n");
184 return buffer_number;
187 int AttachmentPoint::multichannel_shared(int search_new)
190 if(!This) printf("AttachmentPoint::multichannel_shared NULL\n");
193 if(new_virtual_plugins.total &&
195 plugin_server->multichannel) return 1;
199 if(virtual_plugins.total &&
201 plugin_server->multichannel) return 1;
206 int AttachmentPoint::singlechannel()
209 if(!This) printf("AttachmentPoint::singlechannel NULL\n");
210 if(plugin_server && !plugin_server->multichannel) return 1;
215 void AttachmentPoint::render_gui(void *data, PluginServer *server)
217 //printf("AttachmentPoint::render_gui 1 %p %p\n", server, plugin_servers.get(0));
219 if(!This) printf("AttachmentPoint::render_gui 1 NULL\n");
221 // Discard if not 1st plugin server, so single channel plugins don't get double GUI updates
222 if(server != plugin_servers.get(0)) return;
224 if(renderengine && renderengine->mwindow)
225 renderengine->mwindow->render_plugin_gui(data, plugin);
228 void AttachmentPoint::render_gui(void *data, int size, PluginServer *server)
231 if(!This) printf("AttachmentPoint::render_gui 2 NULL\n");
233 // Discard if not 1st plugin server, so single channel plugins don't get double GUI updates
234 if(server != plugin_servers.get(0)) return;
236 if(renderengine && renderengine->mwindow)
237 renderengine->mwindow->render_plugin_gui(data, size, plugin);
240 int AttachmentPoint::gui_open()
242 if(renderengine && renderengine->mwindow)
243 return renderengine->mwindow->plugin_gui_open(plugin);
247 int AttachmentPoint::dump(FILE *fp)
252 fprintf(fp," Attachmentpoint this=%p virtual_plugins=%d\n", this, new_virtual_plugins.total);
253 if(plugin_server) plugin_server->dump(fp);
257 fprintf(fp," No Plugin\n");