4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "edlsession.h"
29 #include "mainprogress.h"
31 #include "mwindowgui.h"
32 #include "pluginarray.h"
33 #include "pluginserver.h"
34 #include "preferences.h"
35 #include "bcprogressbox.h"
40 PluginArray::PluginArray(int data_type)
41 : ArrayList<PluginServer*>()
43 this->data_type = data_type;
58 PluginArray::~PluginArray()
65 PluginServer* PluginArray::scan_plugindb(char *title)
67 return mwindow->scan_plugindb(title, data_type);
70 int PluginArray::start_plugins(MWindow *mwindow,
72 PluginServer *plugin_server,
78 this->mwindow = mwindow;
80 this->plugin_server = plugin_server;
81 this->keyframe = keyframe;
86 cache = new CICache(mwindow->preferences);
87 buffer_size = get_bufsize();
88 get_recordable_tracks();
92 if(!plugin_server->realtime)
97 if(!plugin_server->multichannel)
99 // ============================ single channel plugins
100 // start 1 plugin for each track
101 for(i = 0; i < total_tracks(); i++)
103 append(plugin = new PluginServer(*plugin_server));
104 plugin->set_mwindow(mwindow);
105 plugin->set_keyframe(keyframe);
106 plugin->append_module(modules[i]);
107 plugin->open_plugin(0,
108 mwindow->preferences,
111 if(i == 0) plugin->set_interactive();
112 plugin->start_loop(start, end, buffer_size, 1);
117 // ============================ multichannel
118 // start 1 plugin for all tracks
119 append(plugin = new PluginServer(*plugin_server));
120 plugin->set_mwindow(mwindow);
121 plugin->set_keyframe(keyframe);
122 for(i = 0; i < total_tracks(); i++)
123 plugin->append_module(modules[i]);
124 plugin->open_plugin(0,
125 mwindow->preferences,
128 // set one plugin for progress bars
129 plugin->set_interactive();
130 plugin->start_loop(start, end, buffer_size, total_tracks());
133 //printf("PluginArray::start_plugins 5\n");
137 PluginServer *plugin;
140 if(!plugin_server->multichannel)
142 // single channel plugins
143 // start 1 plugin for each track
144 for(i = 0; i < total_tracks(); i++)
146 append(plugin = new PluginServer(*plugin_server));
147 plugin->set_mwindow(mwindow);
148 plugin->set_keyframe(keyframe);
149 plugin->append_module(modules[i]);
150 plugin->open_plugin(0,
151 mwindow->preferences,
154 plugin->get_parameters(start, end, 1);
155 plugin->init_realtime(0, 1, get_bufsize());
161 // start 1 plugin for all tracks
162 append(plugin = new PluginServer(*plugin_server));
163 plugin->set_mwindow(mwindow);
164 plugin->set_keyframe(keyframe);
165 for(i = 0; i < total_tracks(); i++)
166 plugin->append_module(modules[i]);
167 plugin->open_plugin(0,
168 mwindow->preferences,
171 plugin->get_parameters(start, end, total_tracks());
172 plugin->init_realtime(0, total_tracks(), get_bufsize());
175 //printf("PluginArray::start_plugins 8\n");
183 int PluginArray::run_plugins()
185 // Length to write after process_loop
186 int64_t write_length;
188 done = 0; // for when done
190 if(plugin_server->realtime)
193 MainProgressBar *progress;
194 char string[BCTEXTLEN], string2[BCTEXTLEN];
196 mwindow->gui->lock_window();
197 sprintf(string, "%s...", _(plugin_server->title));
198 progress = mwindow->mainprogress->start_progress(string, end - start);
199 mwindow->gui->unlock_window();
201 for(int64_t current_position = start;
202 current_position < end && !done && !error;
203 current_position += len)
206 if(current_position + len > end) len = end - current_position;
208 // Process in plugin. This pulls data from the modules
210 for(int i = 0; i < total; i++)
212 process_realtime(i, current_position, len);
216 error = write_buffers(len);
217 done = progress->update(current_position - start + len);
220 progress->get_time(string2);
221 progress->stop_progress();
224 sprintf(string, _("%s took %s"), _(plugin_server->title), string2);
225 mwindow->gui->lock_window();
226 mwindow->gui->show_message(string2);
227 mwindow->gui->unlock_window();
231 // Run main loop once for multichannel plugins.
232 // Run multiple times for single channel plugins.
233 // Each write to the file must contain all the channels
234 while(!done && !error)
236 for(int i = 0; i < total; i++)
239 done += process_loop(i, write_length);
244 error = write_buffers(write_length);
252 int PluginArray::stop_plugins()
254 if(plugin_server->realtime)
256 for(int i = 0; i < total; i++)
258 values[i]->close_plugin();
263 for(int i = 0; i < total; i++)
265 values[i]->stop_loop();
266 values[i]->close_plugin();
270 cache->remove_user();