r668: Configure.in and autogen.sh cleanup based on ideas by giskard.
[cinelerra_cv.git] / cinelerra / attachmentpoint.C
blobe18e7ea08e3f7201b4d038227198e21c78f6ad4e
1 #include "attachmentpoint.h"
2 #include "filexml.h"
3 #include "edl.h"
4 #include "edlsession.h"
5 #include "mwindow.h"
6 #include "plugin.h"
7 #include "pluginserver.h"
8 #include "renderengine.h"
9 #include "transportque.h"
10 #include "virtualnode.h"
14 AttachmentPoint::AttachmentPoint(RenderEngine *renderengine, 
15         Plugin *plugin,
16         int data_type)
18         reset_parameters();
19         this->plugin = plugin;
20         this->plugin_id = plugin->id;
21         this->renderengine = renderengine;
22         this->data_type = data_type;
23         plugin_server = renderengine->scan_plugindb(plugin->title,
24                 data_type);
27 AttachmentPoint::~AttachmentPoint()
29         delete_buffer_vector();
30         plugin_servers.remove_all_objects();
34 int AttachmentPoint::reset_parameters()
36         plugin_server = 0;
37         reset_status();
38         return 0;
42 void AttachmentPoint::reset_status()
44         if(!this) printf("AttachmentPoint::reset_status NULL\n");
45         start_position = 0;
46         len = 0;
47         sample_rate = 0;
48         frame_rate = 0;
49         is_processed = 0;
53 int AttachmentPoint::identical(AttachmentPoint *old)
55         return plugin_id == old->plugin_id;
59 int AttachmentPoint::render_init()
61         if(!this) printf("AttachmentPoint::render_init NULL\n");
62         if(plugin_server && plugin->on)
63         {
64 // Start new plugin servers if the number of nodes changed.
65 // The number of nodes can change independantly of the module's 
66 // attachment count.
67                 if(virtual_plugins.total != new_virtual_plugins.total)
68                 {
69                         plugin_servers.remove_all_objects();
70                         for(int i = 0; i < new_virtual_plugins.total; i++)
71                         {
72                                 if(i == 0 || !plugin_server->multichannel)
73                                 {
74                                         PluginServer *new_server;
75                                         plugin_servers.append(new_server = new PluginServer(*plugin_server));
76                                         new_server->set_attachmentpoint(this);
77                                         plugin_servers.values[i]->open_plugin(0, 
78                                                 renderengine->preferences,
79                                                 renderengine->edl, 
80                                                 plugin,
81                                                 -1);
82                                         plugin_servers.values[i]->init_realtime(
83                                                 renderengine->edl->session->real_time_playback &&
84                                                         renderengine->command->realtime,
85                                                 plugin_server->multichannel ? new_virtual_plugins.total : 1,
86                                                 get_buffer_size());
87                                 }
88                         }
89                 }
91 // Set new back pointers in the plugin servers
92                 if(plugin_server->multichannel && plugin_servers.total)
93                 {
94                         PluginServer *new_server = plugin_servers.values[0];
95                         new_server->reset_nodes();
96                         for(int i = 0; i < new_virtual_plugins.total; i++)
97                         {
98                                 new_server->append_node(new_virtual_plugins.values[i]);
99                         }
100                 }
101                 else
102                 {
103                         for(int i = 0; i < new_virtual_plugins.total; i++)
104                         {
105                                 PluginServer *new_server = plugin_servers.values[i];
106                                 new_server->reset_nodes();
107                                 new_server->append_node(new_virtual_plugins.values[i]);
108                         }
109                 }
110         }
112 // Delete old plugin servers
113         delete_buffer_vector();
114         virtual_plugins.remove_all();
116 // Set new plugin servers
117         for(int i = 0; i < new_virtual_plugins.total; i++)
118                 virtual_plugins.append(new_virtual_plugins.values[i]);
119         new_virtual_plugins.remove_all();
122         return 0;
125 int AttachmentPoint::render_stop(int duplicate)
127         if(!this) printf("AttachmentPoint::render_stop NULL\n");
128 // stop plugins
129 // Can't use the on value here because it may have changed.
130         if(plugin_server && plugin->on && virtual_plugins.total && !duplicate)
131         {
132 // close the plugins if not shared
133                 for(int i = 0; i < virtual_plugins.total; i++)
134                 {
135                         if(i == 0 || !plugin_server->multichannel)
136                         {
137                                 plugin_servers.values[i]->close_plugin();
138                         }
139                 }
140                 plugin_servers.remove_all_objects();
141         }
142         return 0;
145 int AttachmentPoint::attach_virtual_plugin(VirtualNode *virtual_plugin)
147         if(!this) printf("AttachmentPoint::attach_virtual_plugin NULL\n");
148         int buffer_number = 0;
150         if(plugin_server && plugin->on)
151         {
152 // add virtual plugin to list of new virtual plugins
153                 new_virtual_plugins.append(virtual_plugin);
154 //printf("AttachmentPoint::attach_virtual_plugin 1 %d\n", new_virtual_plugins.total);
155 // Always increment buffer number since this also corresponds to what 
156 // plugin server to access if single channel.
157                 buffer_number = new_virtual_plugins.total - 1;
158         }
159         else
160         if(!plugin->on)
161         {
162                 printf("AttachmentPoint::attach_virtual_plugin attempt to attach plugin when off.\n");
163         }
164         else
165         if(!plugin_server)
166         {
167                 printf("AttachmentPoint::attach_virtual_plugin attempt to attach when no plugin_server.\n");
168         }
170         return buffer_number;
173 int AttachmentPoint::multichannel_shared(int search_new)
175         if(!this) printf("AttachmentPoint::multichannel_shared NULL\n");
176         if(search_new)
177         {
178                 if(new_virtual_plugins.total && 
179                         plugin_server && 
180                         plugin_server->multichannel) return 1;
181         }
182         else
183         {
184                 if(virtual_plugins.total && 
185                         plugin_server && 
186                         plugin_server->multichannel) return 1;
187         }
188         return 0;
191 int AttachmentPoint::singlechannel()
193         if(!this) printf("AttachmentPoint::singlechannel NULL\n");
194         if(plugin_server && !plugin_server->multichannel) return 1;
195         return 0;
199 void AttachmentPoint::render_gui(void *data)
201         if(!this) printf("AttachmentPoint::render_gui 1 NULL\n");
202         if(renderengine && renderengine->mwindow)
203                 renderengine->mwindow->render_plugin_gui(data, plugin);
206 void AttachmentPoint::render_gui(void *data, int size)
208         if(!this) printf("AttachmentPoint::render_gui 2 NULL\n");
209         if(renderengine && renderengine->mwindow)
210                 renderengine->mwindow->render_plugin_gui(data, size, plugin);
225 int AttachmentPoint::dump()
227         if(this)
228         {
229                 printf("    Attachmentpoint %x virtual_plugins=%d\n", this, new_virtual_plugins.total);
230                 if(plugin_server) plugin_server->dump();
231         }
232         else
233         {
234                 printf("    No Plugin\n");
235         }