r956: README.BUILD - add more library recommendations
[cinelerra_cv/ct.git] / cinelerra / attachmentpoint.C
blobba4c2e0b1a799820137f383a32d997f8dd306054
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 void AttachmentPoint::render_stop()
127         if(plugin_server && plugin->on)
128         {
129                 for(int i = 0; i < plugin_servers.total; i++)
130                 {
131                         plugin_servers.values[i]->render_stop();
132                 }
133         }
136 int AttachmentPoint::attach_virtual_plugin(VirtualNode *virtual_plugin)
138         if(!this) printf("AttachmentPoint::attach_virtual_plugin NULL\n");
139         int buffer_number = 0;
141         if(plugin_server && plugin->on)
142         {
143 // add virtual plugin to list of new virtual plugins
144                 new_virtual_plugins.append(virtual_plugin);
145 //printf("AttachmentPoint::attach_virtual_plugin 1 %d\n", new_virtual_plugins.total);
146 // Always increment buffer number since this also corresponds to what 
147 // plugin server to access if single channel.
148                 buffer_number = new_virtual_plugins.total - 1;
149         }
150         else
151         if(!plugin->on)
152         {
153                 printf("AttachmentPoint::attach_virtual_plugin attempt to attach plugin when off.\n");
154         }
155         else
156         if(!plugin_server)
157         {
158                 printf("AttachmentPoint::attach_virtual_plugin attempt to attach when no plugin_server.\n");
159         }
161         return buffer_number;
164 int AttachmentPoint::multichannel_shared(int search_new)
166         if(!this) printf("AttachmentPoint::multichannel_shared NULL\n");
167         if(search_new)
168         {
169                 if(new_virtual_plugins.total && 
170                         plugin_server && 
171                         plugin_server->multichannel) return 1;
172         }
173         else
174         {
175                 if(virtual_plugins.total && 
176                         plugin_server && 
177                         plugin_server->multichannel) return 1;
178         }
179         return 0;
182 int AttachmentPoint::singlechannel()
184         if(!this) printf("AttachmentPoint::singlechannel NULL\n");
185         if(plugin_server && !plugin_server->multichannel) return 1;
186         return 0;
190 void AttachmentPoint::render_gui(void *data)
192         if(!this) printf("AttachmentPoint::render_gui 1 NULL\n");
193         if(renderengine && renderengine->mwindow)
194                 renderengine->mwindow->render_plugin_gui(data, plugin);
197 void AttachmentPoint::render_gui(void *data, int size)
199         if(!this) printf("AttachmentPoint::render_gui 2 NULL\n");
200         if(renderengine && renderengine->mwindow)
201                 renderengine->mwindow->render_plugin_gui(data, size, plugin);
204 int AttachmentPoint::gui_open()
206         if(renderengine && renderengine->mwindow)
207                 return renderengine->mwindow->plugin_gui_open(plugin);
208         return 0;
221 int AttachmentPoint::dump()
223         if(this)
224         {
225                 printf("    Attachmentpoint %x virtual_plugins=%d\n", this, new_virtual_plugins.total);
226                 if(plugin_server) plugin_server->dump();
227         }
228         else
229         {
230                 printf("    No Plugin\n");
231         }