2 #include "edlsession.h"
6 #include "localsession.h"
10 #include "pluginpopup.h"
11 #include "pluginset.h"
12 #include "pluginserver.h"
13 #include "renderengine.h"
16 #include "virtualnode.h"
19 Plugin::Plugin(EDL *edl,
26 strcpy(this->title, title);
27 plugin_type = PLUGIN_NONE;
32 keyframes = new KeyFrames(edl, track);
33 keyframes->create_objects();
37 Plugin::Plugin(EDL *edl, PluginSet *plugin_set, char *title)
38 : Edit(edl, plugin_set)
40 this->track = plugin_set->track;
41 this->plugin_set = plugin_set;
42 strcpy(this->title, title);
43 plugin_type = PLUGIN_NONE;
48 keyframes = new KeyFrames(edl, track);
49 keyframes->create_objects();
54 while(keyframes->last) delete keyframes->last;
58 Edit& Plugin::operator=(Edit& edit)
64 Plugin& Plugin::operator=(Plugin& edit)
70 int Plugin::operator==(Plugin& that)
72 return identical(&that);
75 int Plugin::operator==(Edit& that)
77 return identical((Plugin*)&that);
82 if(plugin_type != PLUGIN_NONE)
88 void Plugin::clear_keyframes(int64_t start, int64_t end)
90 keyframes->clear(start, end, 0);
94 void Plugin::copy_from(Edit *edit)
96 Plugin *plugin = (Plugin*)edit;
98 this->startsource = edit->startsource;
99 this->startproject = edit->startproject;
100 this->length = edit->length;
103 this->plugin_type = plugin->plugin_type;
104 this->in = plugin->in;
105 this->out = plugin->out;
106 this->show = plugin->show;
107 this->on = plugin->on;
108 // Should reconfigure this based on where the first track is now.
109 this->shared_location = plugin->shared_location;
110 strcpy(this->title, plugin->title);
112 copy_keyframes(plugin);
115 void Plugin::copy_keyframes(Plugin *plugin)
117 keyframes->copy_from(plugin->keyframes);
120 void Plugin::copy_keyframes(int64_t start,
126 keyframes->copy(start, end, file, default_only, autos_only);
129 void Plugin::synchronize_params(Edit *edit)
131 Plugin *plugin = (Plugin*)edit;
132 this->in = plugin->in;
133 this->out = plugin->out;
134 this->show = plugin->show;
135 this->on = plugin->on;
136 strcpy(this->title, plugin->title);
137 copy_keyframes(plugin);
140 void Plugin::shift_keyframes(int64_t position)
142 for(KeyFrame *keyframe = (KeyFrame*)keyframes->first;
144 keyframe = (KeyFrame*)keyframe->next)
146 keyframe->position += position;
151 void Plugin::equivalent_output(Edit *edit, int64_t *result)
153 Plugin *plugin = (Plugin*)edit;
154 // End of plugin changed
155 if(startproject + length != plugin->startproject + plugin->length)
157 if(*result < 0 || startproject + length < *result)
158 *result = startproject + length;
161 // Start of plugin changed
163 startproject != plugin->startproject ||
164 plugin_type != plugin->plugin_type ||
166 !(shared_location == plugin->shared_location) ||
167 strcmp(title, plugin->title)
170 if(*result < 0 || startproject < *result)
171 *result = startproject;
175 keyframes->equivalent_output(plugin->keyframes, startproject, result);
180 int Plugin::is_synthesis(RenderEngine *renderengine,
186 case PLUGIN_STANDALONE:
188 PluginServer *plugin_server = renderengine->scan_plugindb(title);
189 return plugin_server->synthesis;
193 // Dereference real plugin and descend another level
194 case PLUGIN_SHAREDPLUGIN:
196 int real_module_number = shared_location.module;
197 int real_plugin_number = shared_location.plugin;
198 Track *track = edl->tracks->number(real_module_number);
199 Plugin *plugin = track->get_current_plugin(position,
203 // if plugin at the master track is not present at this position
204 if (!plugin) return 0;
205 return plugin->is_synthesis(renderengine, position, direction);
209 // Dereference the real track and descend
210 case PLUGIN_SHAREDMODULE:
212 int real_module_number = shared_location.module;
213 Track *track = edl->tracks->number(real_module_number);
214 return track->is_synthesis(renderengine, position, direction);
223 int Plugin::identical(Plugin *that)
225 char title1[BCTEXTLEN], title2[BCTEXTLEN];
227 calculate_title(title1);
228 that->calculate_title(title2);
230 // printf("Plugin::identical %s %s %d %d %s %s %d\n",
234 // that->plugin_type,
235 // ((KeyFrame*)keyframes->default_auto)->data,
236 // ((KeyFrame*)that->keyframes->default_auto)->data,
237 // ((KeyFrame*)keyframes->default_auto)->identical(((KeyFrame*)that->keyframes->default_auto)));
239 return (this->plugin_type == that->plugin_type &&
240 this->on == that->on &&
241 !strcasecmp(title1, title2) &&
242 ((KeyFrame*)keyframes->default_auto)->identical(
243 ((KeyFrame*)that->keyframes->default_auto)));
246 int Plugin::identical_location(Plugin *that)
248 //printf("Plugin::identical_location\n");
249 if(!plugin_set || !plugin_set->track) return 0;
250 if(!that->plugin_set || !that->plugin_set->track) return 0;
252 //printf("Plugin::identical_location %d %d %d %d %d %d\n",
253 //plugin_set->track->number_of(),
254 //that->plugin_set->track->number_of(),
255 //plugin_set->get_number(),
256 //that->plugin_set->get_number(),
258 //that->startproject);
259 if(plugin_set->track->number_of() == that->plugin_set->track->number_of() &&
260 plugin_set->get_number() == that->plugin_set->get_number() &&
261 startproject == that->startproject) return 1;
266 void Plugin::change_plugin(char *title,
267 SharedLocation *shared_location,
270 strcpy(this->title, title);
271 this->shared_location = *shared_location;
272 this->plugin_type = plugin_type;
277 KeyFrame* Plugin::get_prev_keyframe(int64_t position)
279 KeyFrame *current = 0;
281 //printf("Plugin::get_prev_keyframe 1 %p %p\n", this, edl);
282 // This doesn't work because edl->selectionstart doesn't change during
283 // playback at the same rate as PluginClient::source_position.
286 printf("Plugin::get_prev_keyframe position < 0\n");
287 position = track->to_units(edl->local_session->selectionstart, 0);
289 //printf("Plugin::get_prev_keyframe 1 %d\n", position);
291 for(current = (KeyFrame*)keyframes->last;
293 current = (KeyFrame*)PREVIOUS)
295 if(current->position <= position) break;
298 //printf("Plugin::get_prev_keyframe %p %p %ld\n", current, keyframes->first, keyframes->first->position);
299 if(!current && keyframes->first)
301 current = (KeyFrame*)keyframes->first;
306 current = (KeyFrame*)keyframes->default_auto;
309 //printf("Plugin::get_prev_keyframe 2 %ld %ld\n",
310 // position, current->position);
314 KeyFrame* Plugin::get_next_keyframe(int64_t position)
318 // This doesn't work because edl->selectionstart doesn't change during
319 // playback at the same rate as PluginClient::source_position.
322 printf("Plugin::get_next_keyframe position < 0\n");
323 position = track->to_units(edl->local_session->selectionstart, 0);
326 for(current = (KeyFrame*)keyframes->first;
328 current = (KeyFrame*)NEXT)
330 if(current->position > position) break;
333 if(!current && keyframes->last)
335 current = (KeyFrame*)keyframes->last;
340 current = (KeyFrame*)keyframes->default_auto;
343 //printf("Plugin::get_next_keyframe 2 %ld %ld\n",
344 // position, current->position);
348 KeyFrame* Plugin::get_keyframe()
350 // Search for keyframe on or before selection
352 get_prev_keyframe(track->to_units(edl->local_session->selectionstart, 0));
354 //printf("Plugin::get_keyframe %p %p %p\n", result, edl, edl->session);
355 // Return nearest keyframe if not in automatic keyframe generation
356 if(!edl->session->auto_keyframes)
361 // Return new keyframe
362 if(result == (KeyFrame*)keyframes->default_auto ||
363 result->position != track->to_units(edl->local_session->selectionstart, 0))
365 return (KeyFrame*)keyframes->insert_auto(track->to_units(edl->local_session->selectionstart, 0));
368 // Return existing keyframe
376 void Plugin::copy(int64_t start, int64_t end, FileXML *file)
378 int64_t endproject = startproject + length;
380 if((startproject >= start && startproject <= end) || // startproject in range
381 (endproject <= end && endproject >= start) || // endproject in range
382 (startproject <= start && endproject >= end)) // range in project
385 int64_t startproject_in_selection = startproject; // start of edit in selection in project
386 int64_t startsource_in_selection = startsource; // start of source in selection in source
387 int64_t endsource_in_selection = startsource + length; // end of source in selection
388 int64_t length_in_selection = length; // length of edit in selection
390 if(startproject < start)
391 { // start is after start of edit in project
392 int64_t length_difference = start - startproject;
394 startsource_in_selection += length_difference;
395 startproject_in_selection += length_difference;
396 length_in_selection -= length_difference;
399 // end is before end of edit in project
402 length_in_selection = end - startproject_in_selection;
405 // Plugins don't store silence
406 file->tag.set_title("PLUGIN");
407 // file->tag.set_property("STARTPROJECT", startproject_in_selection - start);
408 file->tag.set_property("LENGTH", length_in_selection);
409 file->tag.set_property("TYPE", plugin_type);
410 file->tag.set_property("TITLE", title);
412 file->append_newline();
415 if(plugin_type == PLUGIN_SHAREDPLUGIN ||
416 plugin_type == PLUGIN_SHAREDMODULE)
418 shared_location.save(file);
425 file->tag.set_title("IN");
430 file->tag.set_title("OUT");
435 file->tag.set_title("SHOW");
440 file->tag.set_title("ON");
443 file->append_newline();
446 keyframes->copy(start, end, file, 0, 0);
448 file->tag.set_title("/PLUGIN");
450 file->append_newline();
454 void Plugin::load(FileXML *file)
457 int first_keyframe = 1;
460 // Currently show is ignored when loading
463 while(keyframes->last) delete keyframes->last;
466 result = file->read_tag();
468 //printf("Plugin::load 1 %s\n", file->tag.get_title());
471 if(file->tag.title_is("/PLUGIN"))
476 if(file->tag.title_is("SHARED_LOCATION"))
478 shared_location.load(file);
481 if(file->tag.title_is("IN"))
486 if(file->tag.title_is("OUT"))
491 if(file->tag.title_is("SHOW"))
496 if(file->tag.title_is("ON"))
501 if(file->tag.title_is("KEYFRAME"))
506 keyframes->default_auto->load(file);
510 // Override default keyframe
512 KeyFrame *keyframe = (KeyFrame*)keyframes->append(new KeyFrame(edl, keyframes));
513 keyframe->position = file->tag.get_property("POSITION", (int64_t)0);
514 keyframe->load(file);
521 void Plugin::get_shared_location(SharedLocation *result)
523 if(plugin_type == PLUGIN_STANDALONE && plugin_set)
525 result->module = edl->tracks->number_of(track);
526 result->plugin = track->plugin_set.number_of(plugin_set);
530 *result = this->shared_location;
534 Track* Plugin::get_shared_track()
536 return edl->tracks->get_item_number(shared_location.module);
539 Plugin* Plugin::get_shared_plugin()
541 Track *track = get_shared_track();
544 shared_location.plugin >= 0)
546 return track->get_current_plugin(startproject,
547 shared_location.plugin,
556 void Plugin::calculate_title(char *string)
558 if(plugin_type == PLUGIN_STANDALONE || plugin_type == PLUGIN_NONE)
560 strcpy(string, title);
563 if(plugin_type == PLUGIN_SHAREDPLUGIN || plugin_type == PLUGIN_SHAREDMODULE)
565 shared_location.calculate_title(string, edl, startproject, 0, plugin_type);
570 void Plugin::paste(FileXML *file)
572 length = file->tag.get_property("LENGTH", (int64_t)0);
575 void Plugin::resample(double old_rate, double new_rate)
577 // Resample keyframes in here
578 keyframes->resample(old_rate, new_rate);
581 void Plugin::shift(int64_t difference)
583 Edit::shift(difference);
584 shift_keyframes(difference);
589 printf(" PLUGIN: type=%d title=\"%s\" on=%d track=%d plugin=%d\n",
593 shared_location.module,
594 shared_location.plugin);
595 printf(" startproject %ld length %ld\n", startproject, length);