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
00045 }
00046
00047 VirtualNode::~VirtualNode()
00048 {
00049 subnodes.remove_all_objects();
00050
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 real_module=%p %s\n",
00059 this,
00060 track->title,
00061 real_module,
00062 is_exit ? "*" : " ");
00063 if(real_module)
00064 {
00065 PRINT_INDENT
00066 printf(" Plugins total=%d\n", subnodes.total);
00067 for(int i = 0; i < subnodes.total; i++)
00068 {
00069 subnodes.values[i]->dump(indent + 2);
00070 }
00071 }
00072 else
00073 if(real_plugin)
00074 {
00075 printf(" Plugin %s\n", real_plugin->title);
00076 }
00077 }
00078
00079 int VirtualNode::expand(int persistent_plugins, int64_t current_position)
00080 {
00081
00082 if(real_module)
00083 {
00084 expand_as_module(persistent_plugins, current_position);
00085 }
00086 else
00087 if(real_plugin)
00088 {
00089
00090
00091 expand_as_plugin(persistent_plugins);
00092 }
00093
00094 return 0;
00095 }
00096
00097 int VirtualNode::expand_as_module(int duplicate, int64_t current_position)
00098 {
00099 Transition *transition = 0;
00100
00101
00102 for(int i = 0; i < track->plugin_set.total; i++)
00103 {
00104 Plugin *plugin = track->get_current_plugin(current_position,
00105 i,
00106 renderengine->command->get_direction(),
00107 0,
00108 1);
00109
00110
00111 if(plugin == real_plugin) continue;
00112
00113
00114 if(plugin && plugin->on)
00115 {
00116 int plugin_type = plugin->plugin_type;
00117 if(plugin_type == PLUGIN_SHAREDMODULE)
00118 {
00119
00120 attach_virtual_module(plugin,
00121 i,
00122 duplicate,
00123 current_position);
00124 }
00125 else
00126 if(plugin_type == PLUGIN_SHAREDPLUGIN ||
00127 plugin_type == PLUGIN_STANDALONE)
00128 {
00129
00130 attach_virtual_plugin(plugin,
00131 i,
00132 duplicate,
00133 current_position);
00134 }
00135 }
00136 }
00137
00138
00139 if(!parent_node) vconsole->append_exit_node(this);
00140
00141 return 0;
00142 }
00143
00144 int VirtualNode::expand_as_plugin(int duplicate)
00145 {
00146 plugin_type = real_plugin->plugin_type;
00147
00148 if(plugin_type == PLUGIN_SHAREDPLUGIN)
00149 {
00150
00151
00152
00153
00154 int real_module_number = real_plugin->shared_location.module;
00155 int real_plugin_number = real_plugin->shared_location.plugin;
00156 Module *real_module = vconsole->module_number(real_module_number);
00157 real_plugin = 0;
00158
00159 if(real_module)
00160 {
00161 attachment = real_module->get_attachment(real_plugin_number);
00162
00163 if(attachment)
00164 {
00165 real_plugin = attachment->plugin;
00166
00167
00168 if(!real_plugin || !real_plugin->on) real_plugin = 0;
00169 }
00170 }
00171 }
00172
00173
00174
00175
00176
00177
00178 if(plugin_type == PLUGIN_STANDALONE)
00179 {
00180
00181 Module *module = vconsole->module_of(track);
00182
00183 attachment = module->attachment_of(real_plugin);
00184 }
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 if(real_plugin && attachment)
00196 {
00197 if(attachment)
00198 plugin_buffer_number = attachment->attach_virtual_plugin(this);
00199 }
00200
00201
00202
00203
00204 return 0;
00205 }
00206
00207 int VirtualNode::attach_virtual_module(Plugin *plugin,
00208 int plugin_number,
00209 int duplicate,
00210 int64_t current_position)
00211 {
00212 if(plugin->on)
00213 {
00214 int real_module_number = plugin->shared_location.module;
00215 Module *real_module = vconsole->module_number(real_module_number);
00216
00217 if(!real_module) return 1;
00218
00219 Track *track = real_module->track;
00220
00221
00222 if(this->real_module && track == this->real_module->track) return 1;
00223
00224
00225
00226
00227 VirtualNode *virtual_module = create_module(plugin,
00228 real_module,
00229 track);
00230
00231 subnodes.append(virtual_module);
00232 virtual_module->expand(duplicate, current_position);
00233 }
00234
00235 return 0;
00236 }
00237
00238 int VirtualNode::attach_virtual_plugin(Plugin *plugin,
00239 int plugin_number,
00240 int duplicate,
00241 int64_t current_position)
00242 {
00243
00244 int is_on = 1;
00245 if(plugin->plugin_type == PLUGIN_SHAREDPLUGIN)
00246 {
00247 int real_module_number = plugin->shared_location.module;
00248 int real_plugin_number = plugin->shared_location.plugin;
00249 Module *real_module = vconsole->module_number(real_module_number);
00250 if(real_module)
00251 {
00252 AttachmentPoint *attachment = real_module->get_attachment(real_plugin_number);
00253 if(attachment)
00254 {
00255 Plugin *real_plugin = attachment->plugin;
00256 if(!real_plugin || !real_plugin->on)
00257 is_on = 0;
00258 }
00259 else
00260 is_on = 0;
00261 }
00262 else
00263 is_on = 0;
00264 }
00265
00266 if(is_on)
00267 {
00268 VirtualNode *virtual_plugin = create_plugin(plugin);
00269 subnodes.append(virtual_plugin);
00270 virtual_plugin->expand(duplicate, current_position);
00271 }
00272 return 0;
00273 }
00274
00275 VirtualNode* VirtualNode::get_previous_plugin(VirtualNode *current_node)
00276 {
00277 for(int i = 0; i < subnodes.total; i++)
00278 {
00279
00280 if(subnodes.values[i] == current_node)
00281 {
00282 if(i > 0)
00283 return subnodes.values[i - 1];
00284 else
00285 return 0;
00286 }
00287 }
00288 return 0;
00289 }
00290
00291
00292
00293 void VirtualNode::get_mute_fragment(int64_t input_position,
00294 int &mute_constant,
00295 int &fragment_len,
00296 Autos *autos,
00297 int direction,
00298 int use_nudge)
00299 {
00300 if(use_nudge) input_position += track->nudge;
00301
00302 IntAuto *prev_keyframe = 0;
00303 IntAuto *next_keyframe = 0;
00304 prev_keyframe = (IntAuto*)autos->get_prev_auto(input_position,
00305 direction,
00306 (Auto* &)prev_keyframe);
00307 next_keyframe = (IntAuto*)autos->get_next_auto(input_position,
00308 direction,
00309 (Auto* &)next_keyframe);
00310
00311 if(direction == PLAY_FORWARD)
00312 {
00313
00314 if(next_keyframe->position > prev_keyframe->position)
00315 {
00316 mute_constant = prev_keyframe->value;
00317
00318 if(next_keyframe->position < input_position + fragment_len)
00319 fragment_len = next_keyframe->position - input_position;
00320 }
00321 else
00322
00323 {
00324 mute_constant = prev_keyframe->value;
00325 }
00326 }
00327 else
00328 {
00329
00330 if(next_keyframe->position < prev_keyframe->position)
00331 {
00332 mute_constant = next_keyframe->value;
00333
00334 if(next_keyframe->position > input_position - fragment_len)
00335 fragment_len = input_position - next_keyframe->position;
00336 }
00337 else
00338
00339 {
00340 mute_constant = next_keyframe->value;
00341 }
00342 }
00343 }
00344
00345
00346
00347
00348
00349