r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / attachmentpoint.C
blob4abfef05a7e1fb00fe0e464a7268a5e9ff095415
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, Plugin *plugin)
16         reset_parameters();
17         this->plugin = plugin;
18         this->renderengine = renderengine;
19         plugin_server = renderengine->scan_plugindb(plugin->title);
20 //printf("AttachmentPoint::AttachmentPoint %s %p\n", plugin->title, plugin_server);
23 AttachmentPoint::~AttachmentPoint()
25         delete_buffer_vectors();
26         plugin_servers.remove_all_objects();
30 int AttachmentPoint::reset_parameters()
32         current_buffer = 0;
33 //      plugin_type = 0;
34         plugin_server = 0;
35 //      plugin_type = 0;
36         new_total_input_buffers = 0;
37         total_input_buffers = 0;
38         return 0;
41 int AttachmentPoint::render_init()
43 //printf("AttachmentPoint::render_init 1\n");
44         if(plugin_server && plugin->on)
45         {
46 // Start new plugins or continue existing plugins
47 // Create new plugin servers
48 //printf("AttachmentPoint::render_init 2 %d %d\n", virtual_plugins.total, new_virtual_plugins.total);
49                 if(virtual_plugins.total != new_virtual_plugins.total)
50                 {
51 //printf("AttachmentPoint::render_init 3\n");
52                         plugin_servers.remove_all_objects();
53 //printf("AttachmentPoint::render_init 4\n");
54                         for(int i = 0; i < new_virtual_plugins.total; i++)
55                         {
56 //printf("AttachmentPoint::render_init 5\n");
57                                 if(i == 0 || !plugin_server->multichannel)
58                                 {
59 //printf("AttachmentPoint::render_init 5.1\n");
60                                         PluginServer *new_server;
61                                         plugin_servers.append(new_server = new PluginServer(*plugin_server));
62                                         new_server->set_attachmentpoint(this);
63 //printf("AttachmentPoint::render_init 5.2 %p %p\n", plugin_servers.values[i], plugin);
64                                         plugin_servers.values[i]->open_plugin(0, renderengine->edl, plugin);
65 //printf("AttachmentPoint::render_init 5.3\n");
66                                         plugin_servers.values[i]->init_realtime(
67                                                 renderengine->edl->session->real_time_playback &&
68                                                         renderengine->command->realtime,
69                                                 new_total_input_buffers,
70                                                 get_buffer_size());
71 //printf("AttachmentPoint::render_init 5.4\n");
72                                 }
73 //printf("AttachmentPoint::render_init 6\n");
74                         }
75                 }
76         }
78 //printf("AttachmentPoint::render_init 7\n");
79         virtual_plugins.remove_all();
80         for(int i = 0; i < new_virtual_plugins.total; i++)
81                 virtual_plugins.append(new_virtual_plugins.values[i]);
82         new_virtual_plugins.remove_all();
83 //printf("AttachmentPoint::render_init 8\n");
85         total_input_buffers = new_total_input_buffers;
86         new_total_input_buffers = 0;
87 //printf("AttachmentPoint::render_init 9\n");
89         delete_buffer_vectors();
90         new_buffer_vectors();
91 //printf("AttachmentPoint::render_init 10\n");
92         return 0;
95 int AttachmentPoint::render_stop(int duplicate)
97 // stop plugins
98 // Can't use the on value here because it may have changed.
99 //printf("AttachmentPoint::render_stop 1\n");
100         if(plugin_server && plugin->on && virtual_plugins.total && !duplicate)
101         {
102 // close the plugins if not shared
103                 for(int i = 0; i < virtual_plugins.total; i++)
104                 {
105                         if(i == 0 || !plugin_server->multichannel)
106                         {
107 //printf("AttachmentPoint::render_stop 2\n");
108                                 plugin_servers.values[i]->close_plugin();
109                         }
110                 }
111 //printf("AttachmentPoint::render_stop 3\n");
112                 plugin_servers.remove_all_objects();
113         }
114         return 0;
117 int AttachmentPoint::attach_virtual_plugin(VirtualNode *virtual_plugin)
119         int in_buffer_number = 0;
121 // add virtual plugin to list of new virtual plugins
122         new_virtual_plugins.append(virtual_plugin);
124 // Increment input buffer counter
125         if(plugin_server && plugin->on)
126         {
127                 in_buffer_number = new_total_input_buffers++;
128         }
129 //printf("AttachmentPoint::attach_virtual_plugin %p %d %d %d\n", plugin_server, plugin->on, in_buffer_number, new_total_input_buffers);
131         return in_buffer_number;
134 int AttachmentPoint::sort(VirtualNode *virtual_plugin)
136         int result = 0;
138         for(int i = 0; i < new_virtual_plugins.total && !result; i++)
139         {
140 // if no virtual plugins attached to this are waiting return 1
141                 if(!new_virtual_plugins.values[i]->waiting_real_plugin) result = 1;
142         }
144         return result;
147 int AttachmentPoint::multichannel_shared(int search_new)
149         if(search_new)
150         {
151                 if(new_virtual_plugins.total && 
152                         plugin_server && 
153                         plugin_server->multichannel) return 1;
154         }
155         else
156         {
157                 if(virtual_plugins.total && 
158                         plugin_server && 
159                         plugin_server->multichannel) return 1;
160         }
161         return 0;
164 int AttachmentPoint::singlechannel()
166         if(plugin_server && !plugin_server->multichannel) return 1;
167         return 0;
170 void AttachmentPoint::render(long current_position, long fragment_size)
172 // All buffers must be armed before proceeding
173 //printf("AttachmentPoint::render 1 %p %s\n", plugin_server, plugin_server->title);
174         if(plugin_server)
175         {
176                 if(current_buffer == total_input_buffers - 1 ||
177                         !plugin_server->multichannel)
178                 {
179                                 dispatch_plugin_server(current_buffer, 
180                                         current_position, 
181                                         fragment_size);
182                 }
183         }
185         current_buffer++;
186         if(current_buffer >= total_input_buffers) current_buffer = 0;
187 //printf("AttachmentPoint::render 10\n");
191 void AttachmentPoint::render_gui(void *data)
193 //printf("AttachmentPoint::render_gui 1 %p %p\n", renderengine, renderengine->mwindow);
194         if(renderengine && renderengine->mwindow)
195                 renderengine->mwindow->render_plugin_gui(data, plugin);
198 void AttachmentPoint::render_gui(void *data, int size)
200         if(renderengine && renderengine->mwindow)
201                 renderengine->mwindow->render_plugin_gui(data, size, plugin);
216 int AttachmentPoint::dump()
218         printf("    Attachmentpoint %x\n", this);
219         if(plugin_server) plugin_server->dump();