r136: This commit was manufactured by cvs2svn to create tag 'hv_1_1_8'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / pluginarray.C
blob9bfe1905cbdeb9cc2d45be114aac9b27f6f314ae
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 "mainprogress.h"
8 #include "mwindow.h"
9 #include "mwindowgui.h"
10 #include "pluginarray.h"
11 #include "pluginserver.h"
12 #include "preferences.h"
13 #include "bcprogressbox.h"
15 #include <libintl.h>
16 #define _(String) gettext(String)
17 #define gettext_noop(String) String
18 #define N_(String) gettext_noop (String)
22 PluginArray::PluginArray()
23  : ArrayList<PluginServer*>()
27 PluginArray::~PluginArray()
29         remove_all_objects();
30         delete [] modules;
34 PluginServer* PluginArray::scan_plugindb(char *title)
36         return mwindow->scan_plugindb(title);
39 int PluginArray::start_plugins(MWindow *mwindow, 
40         EDL *edl, 
41         PluginServer *plugin_server, 
42         KeyFrame *keyframe,
43         int64_t start,
44         int64_t end,
45         File *file)
47         this->mwindow = mwindow;
48         this->edl = edl;
49         this->plugin_server = plugin_server;
50         this->keyframe = keyframe;
51         this->start = start;
52         this->end = end;
53         this->file = file;
55         cache = new CICache(this->edl, mwindow->preferences, mwindow->plugindb);
56 //printf("PluginArray::start_plugins 1\n");     
57         buffer_size = get_bufsize();
58         get_recordable_tracks();
59         create_modules();
60         create_buffers();
62 //printf("PluginArray::start_plugins 2\n");
63         if(!plugin_server->realtime)
64         {
65                 PluginServer *plugin;
66                 int i;
68                 if(!plugin_server->multichannel)
69                 {
70 // ============================ single channel plugins
71 // start 1 plugin for each track
72                         for(i = 0; i < total_tracks(); i++)
73                         {
74 //printf("PluginArray::start_plugins 3 %d\n", i);
75                                 append(plugin = new PluginServer(*plugin_server));
76                                 plugin->set_mwindow(mwindow);
77                                 plugin->set_keyframe(keyframe);
78                                 plugin->set_module(modules[i]);
79                                 plugin->open_plugin(0, 
80                                         mwindow->preferences, 
81                                         mwindow->edl, 
82                                         0,
83                                         -1);
84                                 if(i == 0) plugin->set_interactive();
85                                 plugin->start_loop(start, end, buffer_size, 1);
86 //printf("PluginArray::start_plugins 4\n");
87                         }
88                 }
89                 else
90                 {
91 // ============================ multichannel
92 // start 1 plugin for all tracks
93 //printf("PluginArray::start_plugins 5\n");
94                         append(plugin = new PluginServer(*plugin_server));
95 //printf("PluginArray::start_plugins 4\n");
96                         plugin->set_mwindow(mwindow);
97 //printf("PluginArray::start_plugins 4\n");
98                         plugin->set_keyframe(keyframe);
99 //printf("PluginArray::start_plugins 4\n");
100                         for(i = 0; i < total_tracks(); i++)
101                                 plugin->set_module(modules[i]);
102 //printf("PluginArray::start_plugins 4\n");
103                         plugin->open_plugin(0, 
104                                 mwindow->preferences, 
105                                 mwindow->edl, 
106                                 0,
107                                 -1);
108 // set one plugin for progress bars
109                         plugin->set_interactive();
110 //printf("PluginArray::start_plugins 4\n");
111                         plugin->start_loop(start, end, buffer_size, total_tracks());
112 //printf("PluginArray::start_plugins 6\n");
113                 }
115 //printf("PluginArray::start_plugins 5\n");
116         }
117         else
118         {
119                 PluginServer *plugin;
120                 int i;
122                 if(!plugin_server->multichannel)
123                 {
124 // single channel plugins
125 // start 1 plugin for each track
126                         for(i = 0; i < total_tracks(); i++)
127                         {
128                                 append(plugin = new PluginServer(*plugin_server));
129                                 plugin->set_mwindow(mwindow);
130                                 plugin->set_keyframe(keyframe);
131                                 plugin->open_plugin(0, 
132                                         mwindow->preferences, 
133                                         mwindow->edl, 
134                                         0,
135                                         -1);
136                                 plugin->init_realtime(0, 1, get_bufsize());
137 // Plugin loads configuration on its own
138 //                      plugin->get_configuration_change(plugin_data);                          
139                         }
140                 }
141                 else
142                 {
143 // multichannel
144 // start 1 plugin for all tracks
145                         append(plugin = new PluginServer(*plugin_server));
146                         plugin->set_mwindow(mwindow);
147                         plugin->set_keyframe(keyframe);
148                         plugin->open_plugin(0, 
149                                 mwindow->preferences,
150                                 mwindow->edl, 
151                                 0,
152                                 -1);
153                         plugin->init_realtime(0, total_tracks(), get_bufsize());
154 // Plugin loads configuration on its own
155 //              plugin->get_configuration_change(plugin_data);                          
156                 }
157         }
158 //printf("PluginArray::start_plugins 8\n");
159         return 0;
166 int PluginArray::run_plugins()
168         int i, j, result;
169 // Length to write after process_loop
170         int64_t write_length;
172         done = 0;     // for when done
173         error = 0;
174 //printf("PluginArray::run_plugins 1\n");
175         if(plugin_server->realtime)
176         {
177                 int64_t len;
178                 MainProgressBar *progress;
179                 char string[BCTEXTLEN], string2[BCTEXTLEN];
181 //printf("PluginArray::run_plugins 2\n");
182                 sprintf(string, _("%s..."), plugin_server->title);
183                 progress = mwindow->mainprogress->start_progress(string, end - start);
185 //printf("PluginArray::run_plugins 3\n");
186                 for(int current_position = start; 
187                         current_position < end && !done && !error;
188                         current_position += len)
189                 {
190                         len = buffer_size;
191                         if(current_position + len > end) len = end - current_position;
193 //printf("PluginArray::run_plugins 4\n");
194 // Arm buffers
195                         for(i = 0; i < total_tracks(); i++)
196                         {
197                                 load_module(i, current_position, len);
198                         }
199 //printf("PluginArray::run_plugins 5\n");
201 // Process in plugin
202                         for(i = 0; i < total; i++)
203                         {
204                                 process_realtime(i, current_position, len);
205                         }
206 //printf("PluginArray::run_plugins 6 %d\n", len);
208 // Write to file
209                         error = write_buffers(len);
210                         done = progress->update(current_position - start + len);
211 //printf("PluginArray::run_plugins 7 %d %d %d %d\n", error, done, current_position, end);
212                 }
214                 progress->get_time(string2);
215                 progress->stop_progress();
216                 delete progress;
218                 sprintf(string, _("%s took %s"), plugin_server->title, string2);
219                 mwindow->gui->lock_window();
220                 mwindow->gui->show_message(string2, BLACK);
221                 mwindow->gui->unlock_window();
222 //printf("PluginArray::run_plugins 8\n");
223         }
224         else
225         {
226 // Run main loop once for multichannel plugins.
227 // Run multiple times for single channel plugins.
228 // Each write to the file must contain all the channels
229                 while(!done && !error)
230                 {
231                         for(i = 0; i < total; i++)
232                         {
233 //printf("PluginArray::run_plugins 9 %d\n", i);
234                                 write_length = 0;
235                                 done += process_loop(i, write_length);
236 //printf("PluginArray::run_plugins 10 %d\n", write_length);
237                         }
240                         if(write_length)
241                                 error = write_buffers(write_length);
242 //printf("PluginArray::run_plugins 11 %d\n", write_length);
243                 }
244         }
246         return error;
250 int PluginArray::stop_plugins()
252         if(plugin_server->realtime)
253         {
254                 for(int i = 0; i < total; i++)
255                 {
256                         values[i]->close_plugin();
257                 }
258         }
259         else
260         {
261                 for(int i = 0; i < total; i++)
262                 {
263                         values[i]->stop_loop();
264                         values[i]->close_plugin();
265                 }
266         }
268         delete cache;
269         return 0;