Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / cinelerra / pluginarray.C
blob3d19aa5f60bab81d73abd74cb939831b660bb19b
1 #include "atrack.h"
2 #include "cache.h"
3 #include "edl.h"
4 #include "edlsession.h"
5 #include "file.h"
6 #include "keyframe.h"
7 #include "language.h"
8 #include "mainprogress.h"
9 #include "mwindow.h"
10 #include "mwindowgui.h"
11 #include "pluginarray.h"
12 #include "pluginserver.h"
13 #include "preferences.h"
14 #include "bcprogressbox.h"
19 PluginArray::PluginArray(int data_type)
20  : ArrayList<PluginServer*>()
22         this->data_type = data_type;
25 PluginArray::~PluginArray()
27         remove_all_objects();
28         delete [] modules;
32 PluginServer* PluginArray::scan_plugindb(char *title)
34         return mwindow->scan_plugindb(title, data_type);
37 int PluginArray::start_plugins(MWindow *mwindow, 
38         EDL *edl, 
39         PluginServer *plugin_server, 
40         KeyFrame *keyframe,
41         int64_t start,
42         int64_t end,
43         File *file)
45         this->mwindow = mwindow;
46         this->edl = edl;
47         this->plugin_server = plugin_server;
48         this->keyframe = keyframe;
49         this->start = start;
50         this->end = end;
51         this->file = file;
53         cache = new CICache(mwindow->preferences, mwindow->plugindb);
54         buffer_size = get_bufsize();
55         get_recordable_tracks();
56         create_modules();
57         create_buffers();
59         if(!plugin_server->realtime)
60         {
61                 PluginServer *plugin;
62                 int i;
64                 if(!plugin_server->multichannel)
65                 {
66 // ============================ single channel plugins
67 // start 1 plugin for each track
68                         for(i = 0; i < total_tracks(); i++)
69                         {
70                                 append(plugin = new PluginServer(*plugin_server));
71                                 plugin->set_mwindow(mwindow);
72                                 plugin->set_keyframe(keyframe);
73                                 plugin->append_module(modules[i]);
74                                 plugin->open_plugin(0, 
75                                         mwindow->preferences, 
76                                         mwindow->edl, 
77                                         0,
78                                         -1);
79                                 if(i == 0) plugin->set_interactive();
80                                 plugin->start_loop(start, end, buffer_size, 1);
81                         }
82                 }
83                 else
84                 {
85 // ============================ multichannel
86 // start 1 plugin for all tracks
87                         append(plugin = new PluginServer(*plugin_server));
88                         plugin->set_mwindow(mwindow);
89                         plugin->set_keyframe(keyframe);
90                         for(i = 0; i < total_tracks(); i++)
91                                 plugin->append_module(modules[i]);
92                         plugin->open_plugin(0, 
93                                 mwindow->preferences, 
94                                 mwindow->edl, 
95                                 0,
96                                 -1);
97 // set one plugin for progress bars
98                         plugin->set_interactive();
99                         plugin->start_loop(start, end, buffer_size, total_tracks());
100                 }
102 //printf("PluginArray::start_plugins 5\n");
103         }
104         else
105         {
106                 PluginServer *plugin;
107                 int i;
109                 if(!plugin_server->multichannel)
110                 {
111 // single channel plugins
112 // start 1 plugin for each track
113                         for(i = 0; i < total_tracks(); i++)
114                         {
115                                 append(plugin = new PluginServer(*plugin_server));
116                                 plugin->set_mwindow(mwindow);
117                                 plugin->set_keyframe(keyframe);
118                                 plugin->append_module(modules[i]);
119                                 plugin->open_plugin(0, 
120                                         mwindow->preferences, 
121                                         mwindow->edl, 
122                                         0,
123                                         -1);
124                                 plugin->get_parameters(start, end, 1);
125                                 plugin->init_realtime(0, 1, get_bufsize());
126                         }
127                 }
128                 else
129                 {
130 // multichannel
131 // start 1 plugin for all tracks
132                         append(plugin = new PluginServer(*plugin_server));
133                         plugin->set_mwindow(mwindow);
134                         plugin->set_keyframe(keyframe);
135                         for(i = 0; i < total_tracks(); i++)
136                                 plugin->append_module(modules[i]);
137                         plugin->open_plugin(0, 
138                                 mwindow->preferences,
139                                 mwindow->edl, 
140                                 0,
141                                 -1);
142                         plugin->get_parameters(start, end, total_tracks());
143                         plugin->init_realtime(0, total_tracks(), get_bufsize());
144                 }
145         }
146 //printf("PluginArray::start_plugins 8\n");
147         return 0;
154 int PluginArray::run_plugins()
156         int i, j, result;
157 // Length to write after process_loop
158         int64_t write_length;
160         done = 0;     // for when done
161         error = 0;
162         if(plugin_server->realtime)
163         {
164                 int64_t len;
165                 MainProgressBar *progress;
166                 char string[BCTEXTLEN], string2[BCTEXTLEN];
168                 sprintf(string, _("%s..."), plugin_server->title);
169                 progress = mwindow->mainprogress->start_progress(string, end - start);
171                 for(int current_position = start; 
172                         current_position < end && !done && !error;
173                         current_position += len)
174                 {
175                         len = buffer_size;
176                         if(current_position + len > end) len = end - current_position;
178 // Process in plugin.  This pulls data from the modules
179                         get_buffers();
180                         for(i = 0; i < total; i++)
181                         {
182                                 process_realtime(i, current_position, len);
183                         }
185 // Write to file
186                         error = write_buffers(len);
187                         done = progress->update(current_position - start + len);
188                 }
190                 progress->get_time(string2);
191                 progress->stop_progress();
192                 delete progress;
194                 sprintf(string, _("%s took %s"), plugin_server->title, string2);
195                 mwindow->gui->lock_window();
196                 mwindow->gui->show_message(string2);
197                 mwindow->gui->unlock_window();
198         }
199         else
200         {
201 // Run main loop once for multichannel plugins.
202 // Run multiple times for single channel plugins.
203 // Each write to the file must contain all the channels
204                 while(!done && !error)
205                 {
206                         for(i = 0; i < total; i++)
207                         {
208                                 write_length = 0;
209                                 done += process_loop(i, write_length);
210                         }
213                         if(write_length)
214                                 error = write_buffers(write_length);
215                 }
216         }
218         return error;
222 int PluginArray::stop_plugins()
224         if(plugin_server->realtime)
225         {
226                 for(int i = 0; i < total; i++)
227                 {
228                         values[i]->close_plugin();
229                 }
230         }
231         else
232         {
233                 for(int i = 0; i < total; i++)
234                 {
235                         values[i]->stop_loop();
236                         values[i]->close_plugin();
237                 }
238         }
240         delete cache;
241         return 0;
245 //      Local Variables:
246 //      mode: C++
247 //      c-file-style: "linux"
248 //      End: