r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / pluginarray.C
blob8ec882fb9f32a7226b01aa16a443feb680e6c19d
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, mwindow->edl, 0);
80                                 if(i == 0) plugin->set_interactive();
81                                 plugin->start_loop(start, end, buffer_size, 1);
82 //printf("PluginArray::start_plugins 4\n");
83                         }
84                 }
85                 else
86                 {
87 // ============================ multichannel
88 // start 1 plugin for all tracks
89 //printf("PluginArray::start_plugins 5\n");
90                         append(plugin = new PluginServer(*plugin_server));
91 //printf("PluginArray::start_plugins 4\n");
92                         plugin->set_mwindow(mwindow);
93 //printf("PluginArray::start_plugins 4\n");
94                         plugin->set_keyframe(keyframe);
95 //printf("PluginArray::start_plugins 4\n");
96                         for(i = 0; i < total_tracks(); i++)
97                                 plugin->set_module(modules[i]);
98 //printf("PluginArray::start_plugins 4\n");
99                         plugin->open_plugin(0, mwindow->edl, 0);
100 // set one plugin for progress bars
101                         plugin->set_interactive();
102 //printf("PluginArray::start_plugins 4\n");
103                         plugin->start_loop(start, end, buffer_size, total_tracks());
104 //printf("PluginArray::start_plugins 6\n");
105                 }
107 //printf("PluginArray::start_plugins 5\n");
108         }
109         else
110         {
111                 PluginServer *plugin;
112                 int i;
114                 if(!plugin_server->multichannel)
115                 {
116 // single channel plugins
117 // start 1 plugin for each track
118                         for(i = 0; i < total_tracks(); i++)
119                         {
120                                 append(plugin = new PluginServer(*plugin_server));
121                                 plugin->set_mwindow(mwindow);
122                                 plugin->set_keyframe(keyframe);
123                                 plugin->open_plugin(0, mwindow->edl, 0);
124                                 plugin->init_realtime(0, 1, get_bufsize());
125 // Plugin loads configuration on its own
126 //                      plugin->get_configuration_change(plugin_data);                          
127                         }
128                 }
129                 else
130                 {
131 // multichannel
132 // start 1 plugin for all tracks
133                         append(plugin = new PluginServer(*plugin_server));
134                         plugin->set_mwindow(mwindow);
135                         plugin->set_keyframe(keyframe);
136                         plugin->open_plugin(0, mwindow->edl, 0);
137                         plugin->init_realtime(0, total_tracks(), get_bufsize());
138 // Plugin loads configuration on its own
139 //              plugin->get_configuration_change(plugin_data);                          
140                 }
141         }
142 //printf("PluginArray::start_plugins 8\n");
143         return 0;
150 int PluginArray::run_plugins()
152         int i, j, result;
153 // Length to write after process_loop
154         int64_t write_length;
156         done = 0;     // for when done
157         error = 0;
158 //printf("PluginArray::run_plugins 1\n");
159         if(plugin_server->realtime)
160         {
161                 int64_t len;
162                 MainProgressBar *progress;
163                 char string[BCTEXTLEN], string2[BCTEXTLEN];
165 //printf("PluginArray::run_plugins 2\n");
166                 sprintf(string, _("%s..."), plugin_server->title);
167                 progress = mwindow->mainprogress->start_progress(string, end - start);
169 //printf("PluginArray::run_plugins 3\n");
170                 for(int current_position = start; 
171                         current_position < end && !done && !error;
172                         current_position += len)
173                 {
174                         len = buffer_size;
175                         if(current_position + len > end) len = end - current_position;
177 //printf("PluginArray::run_plugins 4\n");
178 // Arm buffers
179                         for(i = 0; i < total_tracks(); i++)
180                         {
181                                 load_module(i, current_position, len);
182                         }
183 //printf("PluginArray::run_plugins 5\n");
185 // Process in plugin
186                         for(i = 0; i < total; i++)
187                         {
188                                 process_realtime(i, current_position, len);
189                         }
190 //printf("PluginArray::run_plugins 6 %d\n", len);
192 // Write to file
193                         error = write_buffers(len);
194                         done = progress->update(current_position - start + len);
195 //printf("PluginArray::run_plugins 7 %d %d %d %d\n", error, done, current_position, end);
196                 }
198                 progress->get_time(string2);
199                 progress->stop_progress();
200                 delete progress;
202                 sprintf(string, _("%s took %s"), plugin_server->title, string2);
203                 mwindow->gui->lock_window();
204                 mwindow->gui->show_message(string2, BLACK);
205                 mwindow->gui->unlock_window();
206 //printf("PluginArray::run_plugins 8\n");
207         }
208         else
209         {
210 // Run main loop once for multichannel plugins.
211 // Run multiple times for single channel plugins.
212 // Each write to the file must contain all the channels
213                 while(!done && !error)
214                 {
215                         for(i = 0; i < total; i++)
216                         {
217 //printf("PluginArray::run_plugins 9 %d\n", i);
218                                 write_length = 0;
219                                 done += process_loop(i, write_length);
220 //printf("PluginArray::run_plugins 10 %d\n", write_length);
221                         }
224                         if(write_length)
225                                 error = write_buffers(write_length);
226 //printf("PluginArray::run_plugins 11 %d\n", write_length);
227                 }
228         }
230         return error;
234 int PluginArray::stop_plugins()
236         if(plugin_server->realtime)
237         {
238                 for(int i = 0; i < total; i++)
239                 {
240                         values[i]->close_plugin();
241                 }
242         }
243         else
244         {
245                 for(int i = 0; i < total; i++)
246                 {
247                         values[i]->stop_loop();
248                         values[i]->close_plugin();
249                 }
250         }
252         delete cache;
253         return 0;