r602: Fix baver's code... don't insert timecode when show_tc is not set
[cinelerra_cv/mob.git] / cinelerra / module.C
blob1fdeaa9b4e722e1ab33a22adf80373850fea5efa
1 #include "attachmentpoint.h"
2 #include "commonrender.h"
3 #include "edl.h"
4 #include "edlsession.h"
5 #include "filexml.h"
6 #include "module.h"
7 #include "mwindow.h"
8 #include "patch.h"
9 #include "patchbay.h"
10 #include "plugin.h"
11 #include "pluginarray.h"
12 #include "pluginserver.h"
13 #include "renderengine.h"
14 #include "sharedlocation.h"
15 #include "track.h"
16 #include "tracks.h"
17 #include "transportque.h"
20 Module::Module(RenderEngine *renderengine, 
21         CommonRender *commonrender, 
22         PluginArray *plugin_array,
23         Track *track)
25         this->renderengine = renderengine;
26         this->commonrender = commonrender;
27         this->plugin_array = plugin_array;
28         this->track = track;
29         transition = 0;
30         transition_server = 0;
31         attachments = 0;
32         total_attachments = 0;
33         new_total_attachments = 0;
34         new_attachments = 0;
37 Module::~Module()
39         if(attachments)
40         {
41                 for(int i = 0; i < track->plugin_set.total; i++)
42                 {
43                         if(attachments[i])
44                         {
45 // For some reason it isn't used here.
46 //                              attachments[i]->render_stop(0);
47                                 delete attachments[i];
48                         }
49                 }
50                 delete [] attachments;
51         }
52         if(transition_server)
53         {
54                 transition_server->close_plugin();
55                 delete transition_server;
56         }
59 void Module::create_objects()
61         create_new_attachments();
62         swap_attachments();
65 EDL* Module::get_edl()
67         if(renderengine) 
68                 return renderengine->edl;
69         else
70                 return edl;
73 void Module::create_new_attachments()
75 // Not used in pluginarray
76         if(commonrender)
77         {
78                 new_total_attachments = track->plugin_set.total;
79                 if(new_total_attachments)
80                 {
81                         new_attachments = new AttachmentPoint*[new_total_attachments];
82                         for(int i = 0; i < new_total_attachments; i++)
83                         {
84                                 Plugin *plugin = 
85                                         track->get_current_plugin(commonrender->current_position, 
86                                                 i, 
87                                                 renderengine->command->get_direction(),
88                                                 0,
89                                                 1);
91                                 if(plugin && plugin->plugin_type != PLUGIN_NONE && plugin->on)
92                                         new_attachments[i] = new_attachment(plugin);
93                                 else
94                                         new_attachments[i] = 0;
95                         }
96                 }
97                 else
98                         new_attachments = 0;
100 // Create plugin servers in virtual console expansion
101         }
104 void Module::swap_attachments()
106 // None of this is used in a pluginarray
107         for(int i = 0; 
108                 i < new_total_attachments &&
109                 i < total_attachments; 
110                 i++)
111         {
112 // Delete new attachment which is identical to the old one and copy
113 // old attachment.
114                 if(new_attachments[i] &&
115                         attachments[i] &&
116                         new_attachments[i]->identical(attachments[i]))
117                 {
118                         delete new_attachments[i];
119                         new_attachments[i] = attachments[i];
120                         attachments[i] = 0;
121                 }
122         }
124 // Delete old attachments which weren't identical to new ones
125         for(int i = 0; i < total_attachments; i++)
126         {
127                 if(attachments[i]) delete attachments[i];
128         }
130         if(attachments)
131         {
132                 delete [] attachments;
133         }
135         attachments = new_attachments;
136         total_attachments = new_total_attachments;
139 int Module::render_init()
141         for(int i = 0; i < total_attachments; i++)
142         {
143                 if(attachments[i])
144                         attachments[i]->render_init();
145         }
147         return 0;
150 AttachmentPoint* Module::attachment_of(Plugin *plugin)
152 //printf("Module::attachment_of 1 %d\n", total_attachments);
153         for(int i = 0; i < total_attachments; i++)
154         {
155 //printf("Module::attachment_of 2 %p\n", attachments[i]);
156                 if(attachments[i] && 
157                         attachments[i]->plugin == plugin) return attachments[i];
158         }
159         return 0;
162 void Module::reset_attachments()
164 //printf("Module::reset_attachments 1 %d\n", total_attachments);
165         for(int i = 0; i < total_attachments; i++)
166         {
167 //printf("Module::reset_attachments 2 %p\n", attachments[i]);
168                 AttachmentPoint *attachment = attachments[i];
169                 if(attachment) attachment->reset_status();
170         }
173 // Test plugins for reconfiguration.
174 // Used in playback
175 int Module::test_plugins()
177         if(total_attachments != track->plugin_set.total) return 1;
179         for(int i = 0; i < total_attachments; i++)
180         {
181                 AttachmentPoint *attachment = attachments[i];
182                 Plugin *plugin = track->get_current_plugin(
183                         commonrender->current_position, 
184                         i, 
185                         renderengine->command->get_direction(),
186                         0,
187                         1);
188 // One exists and one doesn't
189                 int use_plugin = plugin &&
190                         plugin->plugin_type != PLUGIN_NONE &&
191                         plugin->on;
193                 if((attachment && !use_plugin) || 
194                         (!attachment && use_plugin)) return 1;
196 // Plugin not the same
197                 if(plugin && 
198                         attachment &&
199                         attachment->plugin && 
200                         !plugin->identical(attachment->plugin)) return 1;
201         }
203         return 0;
206 void Module::update_transition(int64_t current_position, 
207         int direction)
209         Plugin *transition = track->get_current_transition(current_position, 
210                 direction,
211                 0,
212                 0); // position is already nudged in amodule.C and vmodule.C before calling update_transition!
214         if((!transition && this->transition) || 
215                 (transition && this->transition && strcmp(transition->title, this->transition->title)))
216         {
217                 this->transition = 0;
219                 transition_server->close_plugin();
220                 delete transition_server;
221                 transition_server = 0;
222         }
224         if(transition && !this->transition)
225         {
226                 this->transition = transition;
228                 if(renderengine)
229                 {
230                         PluginServer *plugin_server = renderengine->scan_plugindb(transition->title,
231                                 track->data_type);
232                         transition_server = new PluginServer(*plugin_server);
233                         transition_server->open_plugin(0, 
234                                 renderengine->preferences, 
235                                 get_edl(), 
236                                 transition,
237                                 -1);
238                         transition_server->init_realtime(
239                                 get_edl()->session->real_time_playback &&
240                                 renderengine->command->realtime,
241                                 1,
242                                 get_buffer_size());
243                 }
244                 else
245                 if(plugin_array)
246                 {
247                         PluginServer *plugin_server = plugin_array->scan_plugindb(transition->title);
248                         transition_server = new PluginServer(*plugin_server);
249                         transition_server->open_plugin(0, 
250                                 plugin_array->mwindow->preferences,
251                                 get_edl(), 
252                                 transition,
253                                 -1);
254                         transition_server->init_realtime(
255                                 0,
256                                 1,
257                                 get_buffer_size());
258                 }
259         }
263 void Module::dump()
265         printf("  Module title=%s\n", track->title);
266         printf("   Plugins total_attachments=%d\n", total_attachments);
267         for(int i = 0; i < total_attachments; i++)
268         {
269                 attachments[i]->dump();
270         }