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

module.C

Go to the documentation of this file.
00001 #include "attachmentpoint.h"
00002 #include "bcsignals.h"
00003 #include "commonrender.h"
00004 #include "edl.h"
00005 #include "edlsession.h"
00006 #include "filexml.h"
00007 #include "module.h"
00008 #include "mwindow.h"
00009 #include "patch.h"
00010 #include "patchbay.h"
00011 #include "plugin.h"
00012 #include "pluginarray.h"
00013 #include "pluginserver.h"
00014 #include "renderengine.h"
00015 #include "sharedlocation.h"
00016 #include "track.h"
00017 #include "tracks.h"
00018 #include "transportque.h"
00019 
00020 
00021 Module::Module(RenderEngine *renderengine, 
00022         CommonRender *commonrender, 
00023         PluginArray *plugin_array,
00024         Track *track)
00025 {
00026         this->renderengine = renderengine;
00027         this->commonrender = commonrender;
00028         this->plugin_array = plugin_array;
00029         this->track = track;
00030         transition = 0;
00031         transition_server = 0;
00032         attachments = 0;
00033         total_attachments = 0;
00034         new_total_attachments = 0;
00035         new_attachments = 0;
00036 }
00037 
00038 Module::~Module()
00039 {
00040         if(attachments)
00041         {
00042                 for(int i = 0; i < track->plugin_set.total; i++)
00043                 {
00044                         if(attachments[i])
00045                         {
00046 // For some reason it isn't used here.
00047 //                              attachments[i]->render_stop(0);
00048                                 delete attachments[i];
00049                         }
00050                 }
00051                 delete [] attachments;
00052         }
00053         if(transition_server)
00054         {
00055                 transition_server->close_plugin();
00056                 delete transition_server;
00057         }
00058 }
00059 
00060 void Module::create_objects()
00061 {
00062         create_new_attachments();
00063         swap_attachments();
00064 }
00065 
00066 EDL* Module::get_edl()
00067 {
00068         if(renderengine) 
00069                 return renderengine->edl;
00070         else
00071                 return edl;
00072 }
00073 
00074 void Module::create_new_attachments()
00075 {
00076 // Not used in pluginarray
00077         if(commonrender)
00078         {
00079                 new_total_attachments = track->plugin_set.total;
00080                 if(new_total_attachments)
00081                 {
00082                         new_attachments = new AttachmentPoint*[new_total_attachments];
00083                         for(int i = 0; i < new_total_attachments; i++)
00084                         {
00085                                 Plugin *plugin = 
00086                                         track->get_current_plugin(commonrender->current_position, 
00087                                                 i, 
00088                                                 renderengine->command->get_direction(),
00089                                                 0,
00090                                                 1);
00091 
00092                                 if(plugin && plugin->plugin_type != PLUGIN_NONE && plugin->on)
00093                                         new_attachments[i] = new_attachment(plugin);
00094                                 else
00095                                         new_attachments[i] = 0;
00096                         }
00097                 }
00098                 else
00099                         new_attachments = 0;
00100 
00101 // Create plugin servers in virtual console expansion
00102         }
00103 }
00104 
00105 void Module::swap_attachments()
00106 {
00107 // None of this is used in a pluginarray
00108         for(int i = 0; 
00109                 i < new_total_attachments &&
00110                 i < total_attachments; 
00111                 i++)
00112         {
00113 // Delete new attachment which is identical to the old one and copy
00114 // old attachment.
00115                 if(new_attachments[i] &&
00116                         attachments[i] &&
00117                         new_attachments[i]->identical(attachments[i]))
00118                 {
00119                         delete new_attachments[i];
00120                         new_attachments[i] = attachments[i];
00121                         attachments[i] = 0;
00122                 }
00123         }
00124 
00125 // Delete old attachments which weren't identical to new ones
00126         for(int i = 0; i < total_attachments; i++)
00127         {
00128                 if(attachments[i]) delete attachments[i];
00129         }
00130 
00131         if(attachments)
00132         {
00133                 delete [] attachments;
00134         }
00135 
00136         attachments = new_attachments;
00137         total_attachments = new_total_attachments;
00138 }
00139 
00140 int Module::render_init()
00141 {
00142         for(int i = 0; i < total_attachments; i++)
00143         {
00144                 if(attachments[i])
00145                         attachments[i]->render_init();
00146         }
00147 
00148         return 0;
00149 }
00150 
00151 AttachmentPoint* Module::attachment_of(Plugin *plugin)
00152 {
00153 //printf("Module::attachment_of 1 %d\n", total_attachments);
00154         for(int i = 0; i < total_attachments; i++)
00155         {
00156 //printf("Module::attachment_of 2 %p\n", attachments[i]);
00157                 if(attachments[i] && 
00158                         attachments[i]->plugin == plugin) return attachments[i];
00159         }
00160         return 0;
00161 }
00162 
00163 AttachmentPoint* Module::get_attachment(int number)
00164 {
00165         if(number < total_attachments)
00166                 return attachments[number];
00167         else
00168                 return 0;
00169 }
00170 
00171 void Module::reset_attachments()
00172 {
00173 //printf("Module::reset_attachments 1 %d\n", total_attachments);
00174         for(int i = 0; i < total_attachments; i++)
00175         {
00176 //printf("Module::reset_attachments 2 %p\n", attachments[i]);
00177                 AttachmentPoint *attachment = attachments[i];
00178                 if(attachment) attachment->reset_status();
00179         }
00180 }
00181 
00182 // Test plugins for reconfiguration.
00183 // Used in playback
00184 int Module::test_plugins()
00185 {
00186         if(total_attachments != track->plugin_set.total) return 1;
00187 
00188         for(int i = 0; i < total_attachments; i++)
00189         {
00190                 AttachmentPoint *attachment = attachments[i];
00191                 Plugin *plugin = track->get_current_plugin(
00192                         commonrender->current_position, 
00193                         i, 
00194                         renderengine->command->get_direction(),
00195                         0,
00196                         1);
00197 // One exists and one doesn't
00198                 int use_plugin = plugin &&
00199                         plugin->plugin_type != PLUGIN_NONE &&
00200                         plugin->on;
00201 
00202                 if((attachment && !use_plugin) || 
00203                         (!attachment && use_plugin)) return 1;
00204 
00205 // Plugin not the same
00206                 if(plugin && 
00207                         attachment &&
00208                         attachment->plugin && 
00209                         !plugin->identical(attachment->plugin)) return 1;
00210         }
00211 
00212         return 0;
00213 }
00214 
00215 void Module::update_transition(int64_t current_position, 
00216         int direction)
00217 {
00218 SET_TRACE
00219         Plugin *transition = track->get_current_transition(current_position, 
00220                 direction,
00221                 0,
00222                 0); // position is already nudged in amodule.C and vmodule.C before calling update_transition!
00223 
00224 SET_TRACE
00225         if((!transition && this->transition) || 
00226                 (transition && this->transition && strcmp(transition->title, this->transition->title)))
00227         {
00228                 this->transition = 0;
00229 
00230                 transition_server->close_plugin();
00231                 delete transition_server;
00232                 transition_server = 0;
00233         }
00234 SET_TRACE
00235 
00236         if(transition && !this->transition)
00237         {
00238                 this->transition = transition;
00239 SET_TRACE
00240 
00241                 if(renderengine)
00242                 {
00243                         PluginServer *plugin_server = renderengine->scan_plugindb(transition->title,
00244                                 track->data_type);
00245                         transition_server = new PluginServer(*plugin_server);
00246                         transition_server->open_plugin(0, 
00247                                 renderengine->preferences, 
00248                                 get_edl(), 
00249                                 transition,
00250                                 -1);
00251                         transition_server->init_realtime(
00252                                 get_edl()->session->real_time_playback &&
00253                                 renderengine->command->realtime,
00254                                 1,
00255                                 get_buffer_size());
00256                 }
00257                 else
00258                 if(plugin_array)
00259                 {
00260 SET_TRACE
00261                         PluginServer *plugin_server = plugin_array->scan_plugindb(transition->title);
00262 SET_TRACE
00263                         transition_server = new PluginServer(*plugin_server);
00264 SET_TRACE
00265                         transition_server->open_plugin(0, 
00266                                 plugin_array->mwindow->preferences,
00267                                 get_edl(), 
00268                                 transition,
00269                                 -1);
00270 SET_TRACE
00271                         transition_server->init_realtime(
00272                                 0,
00273                                 1,
00274                                 get_buffer_size());
00275 SET_TRACE
00276                 }
00277         }
00278 }
00279 
00280 
00281 void Module::dump()
00282 {
00283         printf("  Module title=%s\n", track->title);
00284         printf("   Plugins total_attachments=%d\n", total_attachments);
00285         for(int i = 0; i < total_attachments; i++)
00286         {
00287                 attachments[i]->dump();
00288         }
00289 }
00290 
00291 
00292 
00293 
00294 
00295 

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