2 #include "edlsession.h"
7 #include "pluginautos.h"
13 PluginSet::PluginSet(EDL *edl, Track *track)
19 PluginSet::~PluginSet()
21 while(last) delete last;
25 PluginSet& PluginSet::operator=(PluginSet& plugins)
27 //printf("PluginSet::operator= : you should call copy_from instead, to allow conditional copies.\n");
32 void PluginSet::copy_from(PluginSet *src)
34 while(last) delete last;
35 for(Plugin *current = (Plugin*)src->first; current; current = (Plugin*)NEXT)
38 append(new_plugin = (Plugin*)create_edit());
39 new_plugin->copy_from(current);
41 this->record = src->record;
44 Plugin* PluginSet::get_first_plugin()
46 // Called when a new pluginset is added.
47 // Get first non-silence plugin in the plugin set.
48 for(Plugin *current = (Plugin*)first; current; current = (Plugin*)NEXT)
50 if(current && current->plugin_type != PLUGIN_NONE)
58 int64_t PluginSet::plugin_change_duration(int64_t input_position,
62 int result = input_length;
67 int input_start = input_position - input_length;
68 for(current = last; current; current = PREVIOUS)
70 int start = current->startproject;
71 int end = start + current->length;
72 if(end > input_start && end < input_position)
74 result = input_position - end;
78 if(start > input_start && start < input_position)
80 result = input_position - start;
87 int input_end = input_position + input_length;
88 for(current = first; current; current = NEXT)
90 int start = current->startproject;
91 int end = start + current->length;
92 if(start > input_position && start < input_end)
94 result = start - input_position;
98 if(end > input_position && end < input_end)
100 result = end - input_position;
108 void PluginSet::synchronize_params(PluginSet *plugin_set)
110 for(Plugin *this_plugin = (Plugin*)first, *that_plugin = (Plugin*)plugin_set->first;
111 this_plugin && that_plugin;
112 this_plugin = (Plugin*)this_plugin->next, that_plugin = (Plugin*)that_plugin->next)
114 this_plugin->synchronize_params(that_plugin);
118 Plugin* PluginSet::insert_plugin(char *title,
119 int64_t unit_position,
122 SharedLocation *shared_location,
123 KeyFrame *default_keyframe,
126 Plugin *plugin = (Plugin*)paste_silence(unit_position,
127 unit_position + unit_length);
130 if(title) strcpy(plugin->title, title);
132 if(shared_location) plugin->shared_location = *shared_location;
134 plugin->plugin_type = plugin_type;
137 *plugin->keyframes->default_auto = *default_keyframe;
138 plugin->keyframes->default_auto->position = unit_position;
140 // May delete the plugin we just added so not desirable while loading.
141 if(do_optimize) optimize();
145 Edit* PluginSet::create_edit()
147 Plugin* result = new Plugin(edl, this, "");
151 Edit* PluginSet::insert_edit_after(Edit *previous_edit)
153 Plugin *current = new Plugin(edl, this, "");
154 List<Edit>::insert_after(previous_edit, current);
155 return (Edit*)current;
159 int PluginSet::get_number()
161 return track->plugin_set.number_of(this);
164 void PluginSet::clear(int64_t start, int64_t end)
167 for(Plugin *current = (Plugin*)first;
169 current = (Plugin*)NEXT)
171 current->keyframes->clear(start, end, 1);
175 Edits::clear(start, end);
178 void PluginSet::clear_recursive(int64_t start, int64_t end)
180 //printf("PluginSet::clear_recursive 1\n");
184 void PluginSet::shift_keyframes_recursive(int64_t position, int64_t length)
186 // Plugin keyframes are shifted in shift_effects
189 void PluginSet::shift_effects_recursive(int64_t position, int64_t length)
191 // Effects are shifted in length extension
192 // shift_effects(position, length);
196 void PluginSet::clear_keyframes(int64_t start, int64_t end)
198 for(Plugin *current = (Plugin*)first; current; current = (Plugin*)NEXT)
200 current->clear_keyframes(start, end);
204 void PluginSet::copy_keyframes(int64_t start,
210 file->tag.set_title("PLUGINSET");
212 file->append_newline();
214 for(Plugin *current = (Plugin*)first;
216 current = (Plugin*)NEXT)
218 current->copy_keyframes(start, end, file, default_only, autos_only);
221 file->tag.set_title("/PLUGINSET");
223 file->append_newline();
226 void PluginSet::paste_keyframes(int64_t start,
236 result = file->read_tag();
240 if(file->tag.title_is("/PLUGINSET"))
243 if(file->tag.title_is("KEYFRAME"))
245 int64_t position = file->tag.get_property("POSITION", 0);
248 // Get plugin owning keyframe
249 for(current = (Plugin*)last;
251 current = (Plugin*)PREVIOUS)
253 // We want keyframes to exist beyond the end of the last plugin to
254 // make editing intuitive, but it will always be possible to
255 // paste keyframes from one plugin into an incompatible plugin.
256 if(position >= current->startproject)
259 if(file->tag.get_property("DEFAULT", 0) || default_only)
261 keyframe = (KeyFrame*)current->keyframes->default_auto;
266 (KeyFrame*)current->keyframes->insert_auto(position);
268 keyframe->load(file);
269 keyframe->position = position;
279 void PluginSet::shift_effects(int64_t start, int64_t length)
281 for(Plugin *current = (Plugin*)first;
283 current = (Plugin*)NEXT)
285 // Shift beginning of this effect
286 if(current->startproject >= start)
288 current->startproject += length;
291 // Extend end of this effect
292 if(current->startproject + current->length >= start)
294 current->length += length;
297 // Shift keyframes in this effect
298 if(current->keyframes->default_auto->position >= start)
299 current->keyframes->default_auto->position += length;
300 current->keyframes->paste_silence(start, start + length);
304 void PluginSet::copy(int64_t start, int64_t end, FileXML *file)
306 file->tag.set_title("PLUGINSET");
307 file->tag.set_property("RECORD", record);
309 file->append_newline();
311 for(Plugin *current = (Plugin*)first; current; current = (Plugin*)NEXT)
313 current->copy(start, end, file);
316 file->tag.set_title("/PLUGINSET");
318 file->append_newline();
321 void PluginSet::save(FileXML *file)
323 copy(0, length(), file);
326 void PluginSet::load(FileXML *file, uint32_t load_flags)
329 // Current plugin being amended
330 Plugin *plugin = (Plugin*)first;
331 int64_t startproject = 0;
333 record = file->tag.get_property("RECORD", record);
335 result = file->read_tag();
340 if(file->tag.title_is("/PLUGINSET"))
345 if(file->tag.title_is("PLUGIN"))
347 int64_t length = file->tag.get_property("LENGTH", (int64_t)0);
348 int plugin_type = file->tag.get_property("TYPE", 1);
349 char title[BCTEXTLEN];
351 file->tag.get_property("TITLE", title);
352 SharedLocation shared_location;
353 shared_location.load(file);
356 if(load_flags & LOAD_EDITS)
358 plugin = insert_plugin(title,
366 startproject += length;
369 if(load_flags & LOAD_AUTOMATION)
374 plugin = (Plugin*)plugin->next;
384 int PluginSet::optimize()
387 Plugin *current_edit;
389 // Delete keyframes out of range
390 for(current_edit = (Plugin*)first;
392 current_edit = (Plugin*)current_edit->next)
394 for(KeyFrame *current_keyframe = (KeyFrame*)current_edit->keyframes->last;
397 KeyFrame *previous_keyframe = (KeyFrame*)current_keyframe->previous;
398 if(current_keyframe->position >=
399 current_edit->startproject + current_edit->length ||
400 current_keyframe->position < current_edit->startproject)
402 delete current_keyframe;
404 current_keyframe = previous_keyframe;
408 // Insert silence between plugins
409 for(Plugin *current = (Plugin*)last; current; current = (Plugin*)PREVIOUS)
411 if(current->previous)
413 Plugin *previous = (Plugin*)PREVIOUS;
415 if(current->startproject -
416 previous->startproject -
417 previous->length > 0)
419 Plugin *new_plugin = (Plugin*)create_edit();
420 insert_before(current, new_plugin);
421 new_plugin->startproject = previous->startproject +
423 new_plugin->length = current->startproject -
424 previous->startproject -
429 if(current->startproject > 0)
431 Plugin *new_plugin = (Plugin*)create_edit();
432 insert_before(current, new_plugin);
433 new_plugin->length = current->startproject;
438 // delete 0 length plugins
443 for(current_edit = (Plugin*)first;
444 current_edit && !result; )
446 if(current_edit->length == 0)
448 Plugin* next = (Plugin*)current_edit->next;
454 current_edit = (Plugin*)current_edit->next;
458 // merge identical plugins with same keyframes
459 for(current_edit = (Plugin*)first;
460 current_edit && current_edit->next && !result; )
462 Plugin *next_edit = (Plugin*)current_edit->next;
466 if(next_edit->identical(current_edit))
468 current_edit->length += next_edit->length;
470 for(KeyFrame *source = (KeyFrame*)next_edit->keyframes->first;
472 source = (KeyFrame*)source->next)
474 KeyFrame *dest = new KeyFrame(edl, current_edit->keyframes);
476 current_edit->keyframes->append(dest);
482 current_edit = (Plugin*)current_edit->next;
485 // delete last edit if 0 length or silence
488 if(last->silence() || !last->length)
503 void PluginSet::dump()
505 printf(" PLUGIN_SET:\n");
506 for(Plugin *current = (Plugin*)first; current; current = (Plugin*)NEXT)