Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

pluginarray.C

Go to the documentation of this file.
00001 #include "atrack.h"
00002 #include "cache.h"
00003 #include "edl.h"
00004 #include "edlsession.h"
00005 #include "file.h"
00006 #include "keyframe.h"
00007 #include "language.h"
00008 #include "mainprogress.h"
00009 #include "mwindow.h"
00010 #include "mwindowgui.h"
00011 #include "pluginarray.h"
00012 #include "pluginserver.h"
00013 #include "preferences.h"
00014 #include "bcprogressbox.h"
00015 
00016 
00017 
00018 
00019 PluginArray::PluginArray(int data_type)
00020  : ArrayList<PluginServer*>()
00021 {
00022         this->data_type = data_type;
00023 }
00024 
00025 PluginArray::~PluginArray()
00026 {
00027         remove_all_objects();
00028         delete [] modules;
00029 }
00030 
00031 
00032 PluginServer* PluginArray::scan_plugindb(char *title)
00033 {
00034         return mwindow->scan_plugindb(title, data_type);
00035 }
00036 
00037 int PluginArray::start_plugins(MWindow *mwindow, 
00038         EDL *edl, 
00039         PluginServer *plugin_server, 
00040         KeyFrame *keyframe,
00041         int64_t start,
00042         int64_t end,
00043         File *file)
00044 {
00045         this->mwindow = mwindow;
00046         this->edl = edl;
00047         this->plugin_server = plugin_server;
00048         this->keyframe = keyframe;
00049         this->start = start;
00050         this->end = end;
00051         this->file = file;
00052 
00053         cache = new CICache(this->edl, mwindow->preferences, mwindow->plugindb);
00054         buffer_size = get_bufsize();
00055         get_recordable_tracks();
00056         create_modules();
00057         create_buffers();
00058 
00059         if(!plugin_server->realtime)
00060         {
00061                 PluginServer *plugin;
00062                 int i;
00063 
00064                 if(!plugin_server->multichannel)
00065                 {
00066 // ============================ single channel plugins
00067 // start 1 plugin for each track
00068                         for(i = 0; i < total_tracks(); i++)
00069                         {
00070                                 append(plugin = new PluginServer(*plugin_server));
00071                                 plugin->set_mwindow(mwindow);
00072                                 plugin->set_keyframe(keyframe);
00073                                 plugin->append_module(modules[i]);
00074                                 plugin->open_plugin(0, 
00075                                         mwindow->preferences, 
00076                                         mwindow->edl, 
00077                                         0,
00078                                         -1);
00079                                 if(i == 0) plugin->set_interactive();
00080                                 plugin->start_loop(start, end, buffer_size, 1);
00081                         }
00082                 }
00083                 else
00084                 {
00085 // ============================ multichannel
00086 // start 1 plugin for all tracks
00087                         append(plugin = new PluginServer(*plugin_server));
00088                         plugin->set_mwindow(mwindow);
00089                         plugin->set_keyframe(keyframe);
00090                         for(i = 0; i < total_tracks(); i++)
00091                                 plugin->append_module(modules[i]);
00092                         plugin->open_plugin(0, 
00093                                 mwindow->preferences, 
00094                                 mwindow->edl, 
00095                                 0,
00096                                 -1);
00097 // set one plugin for progress bars
00098                         plugin->set_interactive();
00099                         plugin->start_loop(start, end, buffer_size, total_tracks());
00100                 }
00101 
00102 //printf("PluginArray::start_plugins 5\n");
00103         }
00104         else
00105         {
00106                 PluginServer *plugin;
00107                 int i;
00108 
00109                 if(!plugin_server->multichannel)
00110                 {
00111 // single channel plugins
00112 // start 1 plugin for each track
00113                         for(i = 0; i < total_tracks(); i++)
00114                         {
00115                                 append(plugin = new PluginServer(*plugin_server));
00116                                 plugin->set_mwindow(mwindow);
00117                                 plugin->set_keyframe(keyframe);
00118                                 plugin->append_module(modules[i]);
00119                                 plugin->open_plugin(0, 
00120                                         mwindow->preferences, 
00121                                         mwindow->edl, 
00122                                         0,
00123                                         -1);
00124                                 plugin->get_parameters(start, end, 1);
00125                                 plugin->init_realtime(0, 1, get_bufsize());
00126                         }
00127                 }
00128                 else
00129                 {
00130 // multichannel
00131 // start 1 plugin for all tracks
00132                         append(plugin = new PluginServer(*plugin_server));
00133                         plugin->set_mwindow(mwindow);
00134                         plugin->set_keyframe(keyframe);
00135                         for(i = 0; i < total_tracks(); i++)
00136                                 plugin->append_module(modules[i]);
00137                         plugin->open_plugin(0, 
00138                                 mwindow->preferences,
00139                                 mwindow->edl, 
00140                                 0,
00141                                 -1);
00142                         plugin->get_parameters(start, end, total_tracks());
00143                         plugin->init_realtime(0, total_tracks(), get_bufsize());
00144                 }
00145         }
00146 //printf("PluginArray::start_plugins 8\n");
00147         return 0;
00148 }
00149 
00150 
00151 
00152 
00153 
00154 int PluginArray::run_plugins()
00155 {
00156         int i, j, result;
00157 // Length to write after process_loop
00158         int64_t write_length;
00159 
00160         done = 0;     // for when done
00161         error = 0;
00162         if(plugin_server->realtime)
00163         {
00164                 int64_t len;
00165                 MainProgressBar *progress;
00166                 char string[BCTEXTLEN], string2[BCTEXTLEN];
00167 
00168                 sprintf(string, _("%s..."), plugin_server->title);
00169                 progress = mwindow->mainprogress->start_progress(string, end - start);
00170 
00171                 for(int current_position = start; 
00172                         current_position < end && !done && !error;
00173                         current_position += len)
00174                 {
00175                         len = buffer_size;
00176                         if(current_position + len > end) len = end - current_position;
00177 
00178 // Process in plugin.  This pulls data from the modules
00179                         get_buffers();
00180                         for(i = 0; i < total; i++)
00181                         {
00182                                 process_realtime(i, current_position, len);
00183                         }
00184 
00185 // Write to file
00186                         error = write_buffers(len);
00187                         done = progress->update(current_position - start + len);
00188                 }
00189 
00190                 progress->get_time(string2);
00191                 progress->stop_progress();
00192                 delete progress;
00193 
00194                 sprintf(string, _("%s took %s"), plugin_server->title, string2);
00195                 mwindow->gui->lock_window();
00196                 mwindow->gui->show_message(string2);
00197                 mwindow->gui->unlock_window();
00198         }
00199         else
00200         {
00201 // Run main loop once for multichannel plugins.
00202 // Run multiple times for single channel plugins.
00203 // Each write to the file must contain all the channels
00204                 while(!done && !error)
00205                 {
00206                         for(i = 0; i < total; i++)
00207                         {
00208                                 write_length = 0;
00209                                 done += process_loop(i, write_length);
00210                         }
00211 
00212 
00213                         if(write_length)
00214                                 error = write_buffers(write_length);
00215                 }
00216         }
00217 
00218         return error;
00219 }
00220 
00221 
00222 int PluginArray::stop_plugins()
00223 {
00224         if(plugin_server->realtime)
00225         {
00226                 for(int i = 0; i < total; i++)
00227                 {
00228                         values[i]->close_plugin();
00229                 }
00230         }
00231         else
00232         {
00233                 for(int i = 0; i < total; i++)
00234                 {
00235                         values[i]->stop_loop();
00236                         values[i]->close_plugin();
00237                 }
00238         }
00239 
00240         delete cache;
00241         return 0;
00242 }
00243 

Generated on Sun Jan 8 13:38:58 2006 for Cinelerra-svn by  doxygen 1.4.4