update features5.pdf, fix intl titlebars, add sams icons
[goodguy/history.git] / cinelerra-5.1 / cinelerra / attachmentpoint.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "attachmentpoint.h"
23 #include "filexml.h"
24 #include "edl.h"
25 #include "edlsession.h"
26 #include "mwindow.h"
27 #include "plugin.h"
28 #include "pluginserver.h"
29 #include "renderengine.h"
30 #include "transportque.h"
31 #include "virtualnode.h"
32
33
34
35 AttachmentPoint::AttachmentPoint(RenderEngine *renderengine,
36         Plugin *plugin,
37         int data_type)
38 {
39         reset_parameters();
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,
45                 data_type);
46 }
47
48 AttachmentPoint::~AttachmentPoint()
49 {
50         delete_buffer_vector();
51         plugin_servers.remove_all_objects();
52 }
53
54
55 int AttachmentPoint::reset_parameters()
56 {
57         plugin_server = 0;
58         reset_status();
59         return 0;
60 }
61
62
63 void AttachmentPoint::reset_status()
64 {
65         void *This = this;
66         if(!This) printf("AttachmentPoint::reset_status NULL\n");
67         start_position = 0;
68         len = 0;
69         sample_rate = 0;
70         frame_rate = 0;
71         is_processed = 0;
72 }
73
74
75 int AttachmentPoint::identical(AttachmentPoint *old)
76 {
77         return plugin_id == old->plugin_id;
78 }
79
80
81 int AttachmentPoint::render_init()
82 {
83         void *This = this;
84         if(!This) printf("AttachmentPoint::render_init NULL\n");
85         if(plugin_server && plugin->on)
86         {
87 // Start new plugin servers if the number of nodes changed.
88 // The number of nodes can change independantly of the module's
89 // attachment count.
90                 if(virtual_plugins.total != new_virtual_plugins.total)
91                 {
92                         plugin_servers.remove_all_objects();
93                         for(int i = 0; i < new_virtual_plugins.total; i++)
94                         {
95                                 if(i == 0 || !plugin_server->multichannel)
96                                 {
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(),
103                                                 plugin);
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,
108                                                 get_buffer_size());
109                                 }
110                         }
111                 }
112
113 // Set new back pointers in the plugin servers
114                 if(plugin_server->multichannel && plugin_servers.total)
115                 {
116                         PluginServer *new_server = plugin_servers.values[0];
117                         new_server->reset_nodes();
118                         for(int i = 0; i < new_virtual_plugins.total; i++)
119                         {
120                                 new_server->append_node(new_virtual_plugins.values[i]);
121                         }
122                 }
123                 else
124                 {
125                         for(int i = 0; i < new_virtual_plugins.total; i++)
126                         {
127                                 PluginServer *new_server = plugin_servers.values[i];
128                                 new_server->reset_nodes();
129                                 new_server->append_node(new_virtual_plugins.values[i]);
130                         }
131                 }
132         }
133
134 // Delete old plugin servers
135         delete_buffer_vector();
136         virtual_plugins.remove_all();
137
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();
142
143
144         return 0;
145 }
146
147 void AttachmentPoint::render_stop()
148 {
149         if(plugin_server && plugin->on)
150         {
151                 for(int i = 0; i < plugin_servers.total; i++)
152                 {
153                         plugin_servers.values[i]->render_stop();
154                 }
155         }
156 }
157
158 int AttachmentPoint::attach_virtual_plugin(VirtualNode *virtual_plugin)
159 {
160         void *This = this;
161         if(!This) printf("AttachmentPoint::attach_virtual_plugin NULL\n");
162         int buffer_number = 0;
163
164         if(plugin_server && plugin->on)
165         {
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;
172         }
173         else
174         if(!plugin->on)
175         {
176                 printf("AttachmentPoint::attach_virtual_plugin attempt to attach plugin when off.\n");
177         }
178         else
179         if(!plugin_server)
180         {
181                 printf("AttachmentPoint::attach_virtual_plugin attempt to attach when no plugin_server.\n");
182         }
183
184         return buffer_number;
185 }
186
187 int AttachmentPoint::multichannel_shared(int search_new)
188 {
189         void *This = this;
190         if(!This) printf("AttachmentPoint::multichannel_shared NULL\n");
191         if(search_new)
192         {
193                 if(new_virtual_plugins.total &&
194                         plugin_server &&
195                         plugin_server->multichannel) return 1;
196         }
197         else
198         {
199                 if(virtual_plugins.total &&
200                         plugin_server &&
201                         plugin_server->multichannel) return 1;
202         }
203         return 0;
204 }
205
206 int AttachmentPoint::singlechannel()
207 {
208         void *This = this;
209         if(!This) printf("AttachmentPoint::singlechannel NULL\n");
210         if(plugin_server && !plugin_server->multichannel) return 1;
211         return 0;
212 }
213
214
215 void AttachmentPoint::render_gui(void *data, PluginServer *server)
216 {
217 //printf("AttachmentPoint::render_gui 1 %p %p\n", server, plugin_servers.get(0));
218         void *This = this;
219         if(!This) printf("AttachmentPoint::render_gui 1 NULL\n");
220
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;
223
224         if(renderengine && renderengine->mwindow)
225                 renderengine->mwindow->render_plugin_gui(data, plugin);
226 }
227
228 void AttachmentPoint::render_gui(void *data, int size, PluginServer *server)
229 {
230         void *This = this;
231         if(!This) printf("AttachmentPoint::render_gui 2 NULL\n");
232
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;
235
236         if(renderengine && renderengine->mwindow)
237                 renderengine->mwindow->render_plugin_gui(data, size, plugin);
238 }
239
240 int AttachmentPoint::gui_open()
241 {
242         if(renderengine && renderengine->mwindow)
243                 return renderengine->mwindow->plugin_gui_open(plugin);
244         return 0;
245 }
246
247 int AttachmentPoint::dump(FILE *fp)
248 {
249         void *This = this;
250         if(This)
251         {
252                 fprintf(fp,"    Attachmentpoint this=%p virtual_plugins=%d\n", this, new_virtual_plugins.total);
253                 if(plugin_server) plugin_server->dump(fp);
254         }
255         else
256         {
257                 fprintf(fp,"    No Plugin\n");
258         }
259         return 0;
260 }
261