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

virtualnode.C

Go to the documentation of this file.
00001 #include "attachmentpoint.h"
00002 #include "auto.h"
00003 #include "automation.h"
00004 #include "autos.h"
00005 #include "floatauto.h"
00006 #include "floatautos.h"
00007 #include "intauto.h"
00008 #include "intautos.h"
00009 #include "mwindow.h"
00010 #include "module.h"
00011 #include "panauto.h"
00012 #include "panautos.h"
00013 #include "patchbay.h"
00014 #include "plugin.h"
00015 #include "pluginserver.h"
00016 #include "renderengine.h"
00017 #include "tracks.h"
00018 #include "transition.h"
00019 #include "transportque.h"
00020 #include "virtualconsole.h"
00021 #include "virtualnode.h"
00022 
00023 VirtualNode::VirtualNode(RenderEngine *renderengine, 
00024                 VirtualConsole *vconsole, 
00025                 Module *real_module, 
00026                 Plugin *real_plugin,
00027                 Track *track, 
00028                 VirtualNode *parent_node)
00029 {
00030         this->renderengine = renderengine;
00031         this->vconsole = vconsole;
00032         this->real_module = real_module;
00033         this->real_plugin = real_plugin;
00034         this->track = track;
00035         this->parent_node = parent_node;
00036         render_count = 0;
00037         plugin_type = 0;
00038         waiting_real_plugin = 0;
00039         plugin_buffer_number = 0;
00040         plugin_autos = 0;
00041         plugin_auto_before = plugin_auto_after = 0;
00042         attachment = 0;
00043         is_exit = 0;
00044 //printf("VirtualNode::VirtualNode 1\n");
00045 }
00046 
00047 VirtualNode::~VirtualNode()
00048 {
00049         subnodes.remove_all_objects();
00050 //printf("VirtualNode::VirtualNode 2\n");
00051 }
00052 
00053 #define PRINT_INDENT for(int j = 0; j < indent; j++) printf(" ");
00054 
00055 void VirtualNode::dump(int indent)
00056 {
00057         PRINT_INDENT
00058         printf("VirtualNode %p title=%s %s\n", 
00059                 this, 
00060                 track->title,
00061                 is_exit ? "*" : " ");
00062         if(real_module)
00063         {
00064                 PRINT_INDENT
00065                 printf(" Plugins total=%d\n", subnodes.total);
00066                 for(int i = 0; i < subnodes.total; i++)
00067                 {
00068                         subnodes.values[i]->dump(indent + 2);
00069                 }
00070         }
00071         else
00072         if(real_plugin)
00073         {
00074                 printf("    Plugin %s\n", real_plugin->title);
00075         }
00076 }
00077 
00078 int VirtualNode::expand(int persistent_plugins, int64_t current_position)
00079 {
00080 // module needs to know where the input data for the next process is
00081         if(real_module)
00082         {
00083                 expand_as_module(persistent_plugins, current_position);
00084         }
00085         else
00086         if(real_plugin)
00087         {
00088 // attach to a real plugin for a plugin
00089 // plugin always takes data from input to output
00090                 expand_as_plugin(persistent_plugins);
00091         }
00092 
00093         return 0;
00094 }
00095 
00096 int VirtualNode::expand_as_module(int duplicate, int64_t current_position)
00097 {
00098         Transition *transition = 0;
00099 
00100 // create the plugins for this module
00101         for(int i = 0; i < track->plugin_set.total; i++)
00102         {
00103                 Plugin *plugin = track->get_current_plugin(current_position, 
00104                         i, 
00105                         renderengine->command->get_direction(),
00106                         0,
00107                         1);
00108 
00109 // Switch off if circular reference.  This happens if a plugin set or a track is deleted.
00110                 if(plugin == real_plugin) continue;
00111 
00112 
00113                 if(plugin && plugin->on)
00114                 {
00115                         int plugin_type = plugin->plugin_type;
00116                         if(plugin_type == PLUGIN_SHAREDMODULE)
00117                         {
00118 // plugin is a module
00119                                 attach_virtual_module(plugin,
00120                                         i, 
00121                                         duplicate, 
00122                                         current_position);
00123                         }
00124                         else
00125                         if(plugin_type == PLUGIN_SHAREDPLUGIN ||
00126                                 plugin_type == PLUGIN_STANDALONE)
00127                         {
00128 // plugin is a plugin
00129                                 attach_virtual_plugin(plugin, 
00130                                         i, 
00131                                         duplicate, 
00132                                         current_position);
00133                         }
00134                 }
00135         }
00136 
00137 
00138         if(!parent_node) vconsole->append_exit_node(this);
00139 
00140         return 0;
00141 }
00142 
00143 int VirtualNode::expand_as_plugin(int duplicate)
00144 {
00145         plugin_type = real_plugin->plugin_type;
00146 
00147         if(plugin_type == PLUGIN_SHAREDPLUGIN)
00148         {
00149 // Attached to a shared plugin.
00150 // Get the real real plugin it's attached to.
00151 
00152 // Redirect the real_plugin to the shared plugin.
00153                 int real_module_number = real_plugin->shared_location.module;
00154                 int real_plugin_number = real_plugin->shared_location.plugin;
00155                 Module *real_module = vconsole->module_number(real_module_number);
00156                 real_plugin = 0;
00157 // module references are absolute so may get the wrong data type track.
00158                 if(real_module)
00159                 {
00160                         attachment = real_module->get_attachment(real_plugin_number);
00161 // Attachment is NULL if off
00162                         if(attachment)
00163                         {
00164                                 real_plugin = attachment->plugin;
00165 
00166 // Real plugin not on then null it.
00167                                 if(!real_plugin || !real_plugin->on) real_plugin = 0;
00168                         }
00169                 }
00170         }
00171 
00172 
00173 
00174 
00175 
00176 
00177         if(plugin_type == PLUGIN_STANDALONE)
00178         {
00179 // Get plugin server
00180                 Module *module = vconsole->module_of(track);
00181 
00182                 attachment = module->attachment_of(real_plugin);
00183         }
00184 
00185 
00186 
00187 
00188 
00189 // Add to real plugin's list of virtual plugins for configuration updates
00190 // and plugin_server initializations.
00191 // Input and output are taken care of when the parent module creates this plugin.
00192 // Get number for passing to render.
00193 // real_plugin may become NULL after shared plugin test.
00194         if(real_plugin && attachment)
00195         {
00196                 if(attachment)
00197                         plugin_buffer_number = attachment->attach_virtual_plugin(this);
00198         }
00199 
00200 
00201 
00202 
00203         return 0;
00204 }
00205 
00206 int VirtualNode::attach_virtual_module(Plugin *plugin, 
00207         int plugin_number, 
00208         int duplicate, 
00209         int64_t current_position)
00210 {
00211         if(plugin->on)
00212         {
00213                 int real_module_number = plugin->shared_location.module;
00214                 Module *real_module = vconsole->module_number(real_module_number);
00215 // If a track is deleted real_module is not found
00216                 if(!real_module) return 1;
00217 
00218                 Track *track = real_module->track;
00219 
00220 // Switch off if circular reference.  This happens if a track is deleted.
00221                 if(track == this->real_module->track) return 1;
00222 
00223 
00224 
00225 
00226                 VirtualNode *virtual_module = create_module(plugin,
00227                         real_module,
00228                         track);
00229 
00230                 subnodes.append(virtual_module);
00231                 virtual_module->expand(duplicate, current_position);
00232         }
00233 
00234         return 0;
00235 }
00236 
00237 int VirtualNode::attach_virtual_plugin(Plugin *plugin, 
00238         int plugin_number, 
00239         int duplicate, 
00240         int64_t current_position)
00241 {
00242 // Get real plugin and test if it is on.
00243         int is_on = 1;
00244         if(plugin->plugin_type == PLUGIN_SHAREDPLUGIN)
00245         {
00246                 int real_module_number = plugin->shared_location.module;
00247                 int real_plugin_number = plugin->shared_location.plugin;
00248                 Module *real_module = vconsole->module_number(real_module_number);
00249                 if(real_module)
00250                 {
00251                         AttachmentPoint *attachment = real_module->get_attachment(real_plugin_number);
00252                         if(attachment)
00253                         {
00254                                 Plugin *real_plugin = attachment->plugin;
00255                                 if(!real_plugin || !real_plugin->on)
00256                                         is_on = 0;
00257                         }
00258                         else
00259                                 is_on = 0;
00260                 }
00261                 else
00262                         is_on = 0;
00263         }
00264 
00265         if(is_on)
00266         {
00267                 VirtualNode *virtual_plugin = create_plugin(plugin);
00268                 subnodes.append(virtual_plugin);
00269                 virtual_plugin->expand(duplicate, current_position);
00270         }
00271         return 0;
00272 }
00273 
00274 VirtualNode* VirtualNode::get_previous_plugin(VirtualNode *current_node)
00275 {
00276         for(int i = 0; i < subnodes.total; i++)
00277         {
00278 // Assume plugin is on
00279                 if(subnodes.values[i] == current_node)
00280                 {
00281                         if(i > 0) 
00282                                 return subnodes.values[i - 1];
00283                         else
00284                                 return 0;
00285                 }
00286         }
00287         return 0;
00288 }
00289 
00290 
00291 
00292 void VirtualNode::get_mute_fragment(int64_t input_position,
00293                                 int &mute_constant, 
00294                                 int &fragment_len, 
00295                                 Autos *autos,
00296                                 int direction,
00297                                 int use_nudge)
00298 {
00299         if(use_nudge) input_position += track->nudge;
00300 
00301         IntAuto *prev_keyframe = 0;
00302         IntAuto *next_keyframe = 0;
00303         prev_keyframe = (IntAuto*)autos->get_prev_auto(input_position, 
00304                 direction, 
00305                 (Auto* &)prev_keyframe);
00306         next_keyframe = (IntAuto*)autos->get_next_auto(input_position, 
00307                 direction, 
00308                 (Auto* &)next_keyframe);
00309 
00310         if(direction == PLAY_FORWARD)
00311         {
00312 // Two distinct keyframes within range
00313                 if(next_keyframe->position > prev_keyframe->position)
00314                 {
00315                         mute_constant = prev_keyframe->value;
00316 
00317                         if(next_keyframe->position < input_position + fragment_len)
00318                                 fragment_len = next_keyframe->position - input_position;
00319                 }
00320                 else
00321 // One keyframe within range
00322                 {
00323                         mute_constant = prev_keyframe->value;
00324                 }
00325         }
00326         else
00327         {
00328 // Two distinct keyframes within range
00329                 if(next_keyframe->position < prev_keyframe->position)
00330                 {
00331                         mute_constant = next_keyframe->value;
00332 
00333                         if(next_keyframe->position > input_position - fragment_len)
00334                                 fragment_len = input_position - next_keyframe->position;
00335                 }
00336                 else
00337 // One keyframe within range
00338                 {
00339                         mute_constant = next_keyframe->value;
00340                 }
00341         }
00342 }
00343 
00344 
00345 
00346 
00347 
00348 

Generated on Sun Jan 8 13:39:02 2006 for Cinelerra-svn by  doxygen 1.4.4