3 #include "edlsession.h"
7 #include "localsession.h"
11 #include "pluginpopup.h"
12 #include "pluginset.h"
13 #include "pluginserver.h"
14 #include "renderengine.h"
17 #include "virtualnode.h"
20 Plugin::Plugin(EDL *edl,
27 strcpy(this->title, title);
28 plugin_type = PLUGIN_NONE;
33 keyframes = new KeyFrames(edl, track);
34 keyframes->create_objects();
38 Plugin::Plugin(EDL *edl, PluginSet *plugin_set, char *title)
39 : Edit(edl, plugin_set)
41 this->track = plugin_set->track;
42 this->plugin_set = plugin_set;
43 strcpy(this->title, title);
44 plugin_type = PLUGIN_NONE;
49 keyframes = new KeyFrames(edl, track);
50 keyframes->create_objects();
55 while(keyframes->last) delete keyframes->last;
59 Edit& Plugin::operator=(Edit& edit)
65 Plugin& Plugin::operator=(Plugin& edit)
71 int Plugin::operator==(Plugin& that)
73 return identical(&that);
76 int Plugin::operator==(Edit& that)
78 return identical((Plugin*)&that);
83 if(plugin_type != PLUGIN_NONE)
89 void Plugin::clear_keyframes(int64_t start, int64_t end)
91 keyframes->clear(start, end, 0);
95 void Plugin::copy_from(Edit *edit)
97 Plugin *plugin = (Plugin*)edit;
99 this->startsource = edit->startsource;
100 this->startproject = edit->startproject;
101 this->length = edit->length;
104 this->plugin_type = plugin->plugin_type;
105 this->in = plugin->in;
106 this->out = plugin->out;
107 this->show = plugin->show;
108 this->on = plugin->on;
109 // Should reconfigure this based on where the first track is now.
110 this->shared_location = plugin->shared_location;
111 strcpy(this->title, plugin->title);
113 copy_keyframes(plugin);
116 void Plugin::copy_keyframes(Plugin *plugin)
118 keyframes->copy_from(plugin->keyframes);
121 void Plugin::copy_keyframes(int64_t start,
127 keyframes->copy(start, end, file, default_only, autos_only);
130 void Plugin::synchronize_params(Edit *edit)
132 Plugin *plugin = (Plugin*)edit;
133 this->in = plugin->in;
134 this->out = plugin->out;
135 this->show = plugin->show;
136 this->on = plugin->on;
137 strcpy(this->title, plugin->title);
138 copy_keyframes(plugin);
141 void Plugin::shift_keyframes(int64_t position)
143 for(KeyFrame *keyframe = (KeyFrame*)keyframes->first;
145 keyframe = (KeyFrame*)keyframe->next)
147 keyframe->position += position;
152 void Plugin::equivalent_output(Edit *edit, int64_t *result)
154 Plugin *plugin = (Plugin*)edit;
155 // End of plugin changed
156 if(startproject + length != plugin->startproject + plugin->length)
158 if(*result < 0 || startproject + length < *result)
159 *result = startproject + length;
162 // Start of plugin changed
164 startproject != plugin->startproject ||
165 plugin_type != plugin->plugin_type ||
167 !(shared_location == plugin->shared_location) ||
168 strcmp(title, plugin->title)
171 if(*result < 0 || startproject < *result)
172 *result = startproject;
176 keyframes->equivalent_output(plugin->keyframes, startproject, result);
181 int Plugin::is_synthesis(RenderEngine *renderengine,
187 case PLUGIN_STANDALONE:
191 printf("Plugin::is_synthesis track not defined\n");
194 PluginServer *plugin_server = renderengine->scan_plugindb(title,
196 return plugin_server->synthesis;
200 // Dereference real plugin and descend another level
201 case PLUGIN_SHAREDPLUGIN:
203 int real_module_number = shared_location.module;
204 int real_plugin_number = shared_location.plugin;
205 Track *track = edl->tracks->number(real_module_number);
206 // Get shared plugin from master track
207 Plugin *plugin = track->get_current_plugin(position,
214 return plugin->is_synthesis(renderengine, position, direction);
218 // Dereference the real track and descend
219 case PLUGIN_SHAREDMODULE:
221 int real_module_number = shared_location.module;
222 Track *track = edl->tracks->number(real_module_number);
223 return track->is_synthesis(renderengine, position, direction);
232 int Plugin::identical(Plugin *that)
235 if(plugin_type != that->plugin_type) return 0;
237 // Test title or location
240 case PLUGIN_STANDALONE:
241 if(strcmp(title, that->title)) return 0;
243 case PLUGIN_SHAREDPLUGIN:
244 if(shared_location.module != that->shared_location.module ||
245 shared_location.plugin != that->shared_location.plugin) return 0;
247 case PLUGIN_SHAREDMODULE:
248 if(shared_location.module != that->shared_location.module) return 0;
252 // Test remaining fields
253 return (this->on == that->on &&
254 ((KeyFrame*)keyframes->default_auto)->identical(
255 ((KeyFrame*)that->keyframes->default_auto)));
258 int Plugin::identical_location(Plugin *that)
260 if(!plugin_set || !plugin_set->track) return 0;
261 if(!that->plugin_set || !that->plugin_set->track) return 0;
263 if(plugin_set->track->number_of() == that->plugin_set->track->number_of() &&
264 plugin_set->get_number() == that->plugin_set->get_number() &&
265 startproject == that->startproject) return 1;
270 void Plugin::change_plugin(char *title,
271 SharedLocation *shared_location,
274 strcpy(this->title, title);
275 this->shared_location = *shared_location;
276 this->plugin_type = plugin_type;
281 KeyFrame* Plugin::get_prev_keyframe(int64_t position,
284 KeyFrame *current = 0;
286 // This doesn't work because edl->selectionstart doesn't change during
287 // playback at the same rate as PluginClient::source_position.
290 position = track->to_units(edl->local_session->selectionstart, 0);
293 // Get keyframe on or before current position
294 for(current = (KeyFrame*)keyframes->last;
296 current = (KeyFrame*)PREVIOUS)
298 if(direction == PLAY_FORWARD && current->position <= position) break;
300 if(direction == PLAY_REVERSE && current->position < position) break;
303 // Nothing before current position
304 if(!current && keyframes->first)
306 current = (KeyFrame*)keyframes->first;
312 current = (KeyFrame*)keyframes->default_auto;
318 KeyFrame* Plugin::get_next_keyframe(int64_t position,
323 // This doesn't work for playback because edl->selectionstart doesn't
324 // change during playback at the same rate as PluginClient::source_position.
327 //printf("Plugin::get_next_keyframe position < 0\n");
328 position = track->to_units(edl->local_session->selectionstart, 0);
331 // Get keyframe after current position
332 for(current = (KeyFrame*)keyframes->first;
334 current = (KeyFrame*)NEXT)
336 if(direction == PLAY_FORWARD && current->position > position) break;
338 if(direction == PLAY_REVERSE && current->position >= position) break;
341 // Nothing after current position
342 if(!current && keyframes->last)
344 current = (KeyFrame*)keyframes->last;
350 current = (KeyFrame*)keyframes->default_auto;
356 KeyFrame* Plugin::get_keyframe()
358 // Search for keyframe on or before selection
360 get_prev_keyframe(track->to_units(edl->local_session->selectionstart, 0),
363 // Return nearest keyframe if not in automatic keyframe generation
364 if(!edl->session->auto_keyframes)
369 // Return new keyframe
370 if(result == (KeyFrame*)keyframes->default_auto ||
371 result->position != track->to_units(edl->local_session->selectionstart, 0))
373 return (KeyFrame*)keyframes->insert_auto(track->to_units(edl->local_session->selectionstart, 0));
376 // Return existing keyframe
384 void Plugin::copy(int64_t start, int64_t end, FileXML *file)
386 int64_t endproject = startproject + length;
388 if((startproject >= start && startproject <= end) || // startproject in range
389 (endproject <= end && endproject >= start) || // endproject in range
390 (startproject <= start && endproject >= end)) // range in project
393 int64_t startproject_in_selection = startproject; // start of edit in selection in project
394 int64_t startsource_in_selection = startsource; // start of source in selection in source
395 int64_t endsource_in_selection = startsource + length; // end of source in selection
396 int64_t length_in_selection = length; // length of edit in selection
398 if(startproject < start)
399 { // start is after start of edit in project
400 int64_t length_difference = start - startproject;
402 startsource_in_selection += length_difference;
403 startproject_in_selection += length_difference;
404 length_in_selection -= length_difference;
407 // end is before end of edit in project
410 length_in_selection = end - startproject_in_selection;
413 // Plugins don't store silence
414 file->tag.set_title("PLUGIN");
415 // file->tag.set_property("STARTPROJECT", startproject_in_selection - start);
416 file->tag.set_property("LENGTH", length_in_selection);
417 file->tag.set_property("TYPE", plugin_type);
418 file->tag.set_property("TITLE", title);
420 file->append_newline();
423 if(plugin_type == PLUGIN_SHAREDPLUGIN ||
424 plugin_type == PLUGIN_SHAREDMODULE)
426 shared_location.save(file);
433 file->tag.set_title("IN");
438 file->tag.set_title("OUT");
443 file->tag.set_title("SHOW");
448 file->tag.set_title("ON");
451 file->append_newline();
454 keyframes->copy(start, end, file, 0, 0);
456 file->tag.set_title("/PLUGIN");
458 file->append_newline();
462 void Plugin::load(FileXML *file)
465 int first_keyframe = 1;
468 // Currently show is ignored when loading
471 while(keyframes->last) delete keyframes->last;
474 result = file->read_tag();
476 //printf("Plugin::load 1 %s\n", file->tag.get_title());
479 if(file->tag.title_is("/PLUGIN"))
484 if(file->tag.title_is("SHARED_LOCATION"))
486 shared_location.load(file);
489 if(file->tag.title_is("IN"))
494 if(file->tag.title_is("OUT"))
499 if(file->tag.title_is("SHOW"))
504 if(file->tag.title_is("ON"))
509 if(file->tag.title_is("KEYFRAME"))
514 keyframes->default_auto->load(file);
518 // Override default keyframe
520 KeyFrame *keyframe = (KeyFrame*)keyframes->append(new KeyFrame(edl, keyframes));
521 keyframe->position = file->tag.get_property("POSITION", (int64_t)0);
522 keyframe->load(file);
529 void Plugin::get_shared_location(SharedLocation *result)
531 if(plugin_type == PLUGIN_STANDALONE && plugin_set)
533 result->module = edl->tracks->number_of(track);
534 result->plugin = track->plugin_set.number_of(plugin_set);
538 *result = this->shared_location;
542 Track* Plugin::get_shared_track()
544 return edl->tracks->get_item_number(shared_location.module);
548 void Plugin::calculate_title(char *string, int use_nudge)
550 if(plugin_type == PLUGIN_STANDALONE || plugin_type == PLUGIN_NONE)
552 strcpy(string, _(title));
555 if(plugin_type == PLUGIN_SHAREDPLUGIN || plugin_type == PLUGIN_SHAREDMODULE)
557 shared_location.calculate_title(string,
567 void Plugin::paste(FileXML *file)
569 length = file->tag.get_property("LENGTH", (int64_t)0);
572 void Plugin::resample(double old_rate, double new_rate)
574 // Resample keyframes in here
575 keyframes->resample(old_rate, new_rate);
578 void Plugin::shift(int64_t difference)
580 Edit::shift(difference);
581 shift_keyframes(difference);
586 printf(" PLUGIN: type=%d title=\"%s\" on=%d track=%d plugin=%d\n",
590 shared_location.module,
591 shared_location.plugin);
592 printf(" startproject %lld length %lld\n", startproject, length);