4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "bcsignals.h"
24 #include "edlsession.h"
27 #include "keyframes.h"
28 #include "localsession.h"
32 #include "pluginpopup.h"
33 #include "pluginset.h"
34 #include "pluginserver.h"
37 #include "virtualnode.h"
40 Plugin::Plugin(EDL *edl,
48 strcpy(this->title, title);
49 plugin_type = PLUGIN_NONE;
54 keyframes = new KeyFrames(edl, track);
55 keyframes->create_objects();
59 Plugin::Plugin(EDL *edl, PluginSet *plugin_set, const char *title)
60 : Edit(edl, plugin_set)
63 this->track = plugin_set->track;
64 this->plugin_set = plugin_set;
65 strcpy(this->title, title);
66 plugin_type = PLUGIN_NONE;
71 keyframes = new KeyFrames(edl, track);
72 keyframes->create_objects();
77 while(keyframes->last) delete keyframes->last;
81 Edit& Plugin::operator=(Edit& edit)
87 Plugin& Plugin::operator=(Plugin& edit)
93 int Plugin::operator==(Plugin& that)
95 return identical(&that);
98 int Plugin::operator==(Edit& that)
100 return identical((Plugin*)&that);
103 int Plugin::silence()
105 if(plugin_type != PLUGIN_NONE)
111 void Plugin::clear_keyframes(int64_t start, int64_t end)
113 keyframes->clear(start, end, 0);
117 void Plugin::copy_from(Edit *edit)
119 Plugin *plugin = (Plugin*)edit;
121 this->startsource = edit->startsource;
122 this->startproject = edit->startproject;
123 this->length = edit->length;
126 this->plugin_type = plugin->plugin_type;
127 this->in = plugin->in;
128 this->out = plugin->out;
129 this->show = plugin->show;
130 this->on = plugin->on;
131 // Should reconfigure this based on where the first track is now.
132 this->shared_location = plugin->shared_location;
133 strcpy(this->title, plugin->title);
135 copy_keyframes(plugin);
138 void Plugin::copy_keyframes(Plugin *plugin)
141 keyframes->copy_from(plugin->keyframes);
144 void Plugin::copy_keyframes(int64_t start,
150 // Only 1 default is copied from where the start position is
151 int64_t endproject = startproject + length;
154 start < endproject &&
155 start >= startproject))
156 keyframes->copy(start, end, file, default_only, active_only);
159 void Plugin::synchronize_params(Edit *edit)
161 Plugin *plugin = (Plugin*)edit;
162 this->in = plugin->in;
163 this->out = plugin->out;
164 this->show = plugin->show;
165 this->on = plugin->on;
166 strcpy(this->title, plugin->title);
167 copy_keyframes(plugin);
170 void Plugin::shift_keyframes(int64_t position)
172 for(KeyFrame *keyframe = (KeyFrame*)keyframes->first;
174 keyframe = (KeyFrame*)keyframe->next)
176 keyframe->position += position;
181 void Plugin::equivalent_output(Edit *edit, int64_t *result)
183 Plugin *plugin = (Plugin*)edit;
184 // End of plugin changed
185 if(startproject + length != plugin->startproject + plugin->length)
187 if(*result < 0 || startproject + length < *result)
188 *result = startproject + length;
191 // Start of plugin changed
193 startproject != plugin->startproject ||
194 plugin_type != plugin->plugin_type ||
196 !(shared_location == plugin->shared_location) ||
197 strcmp(title, plugin->title)
200 if(*result < 0 || startproject < *result)
201 *result = startproject;
205 keyframes->equivalent_output(plugin->keyframes, startproject, result);
210 int Plugin::is_synthesis(int64_t position,
215 case PLUGIN_STANDALONE:
219 printf("Plugin::is_synthesis track not defined\n");
224 PluginServer *plugin_server = MWindow::scan_plugindb(title,
226 //printf("Plugin::is_synthesis %d %p %d\n", __LINE__, plugin_server, plugin_server->get_synthesis());
227 //plugin_server->dump();
228 return plugin_server->get_synthesis();
232 // Dereference real plugin and descend another level
233 case PLUGIN_SHAREDPLUGIN:
235 int real_module_number = shared_location.module;
236 int real_plugin_number = shared_location.plugin;
237 Track *track = edl->tracks->number(real_module_number);
238 // Get shared plugin from master track
239 Plugin *plugin = track->get_current_plugin(position,
246 return plugin->is_synthesis(position, direction);
250 // Dereference the real track and descend
251 case PLUGIN_SHAREDMODULE:
253 int real_module_number = shared_location.module;
254 Track *track = edl->tracks->number(real_module_number);
255 return track->is_synthesis(position, direction);
264 int Plugin::identical(Plugin *that)
267 if(plugin_type != that->plugin_type) return 0;
269 // Test title or location
272 case PLUGIN_STANDALONE:
273 if(strcmp(title, that->title)) return 0;
275 case PLUGIN_SHAREDPLUGIN:
276 if(shared_location.module != that->shared_location.module ||
277 shared_location.plugin != that->shared_location.plugin) return 0;
279 case PLUGIN_SHAREDMODULE:
280 if(shared_location.module != that->shared_location.module) return 0;
284 // Test remaining fields
285 return (this->on == that->on &&
286 ((KeyFrame*)keyframes->default_auto)->identical(
287 ((KeyFrame*)that->keyframes->default_auto)));
290 int Plugin::identical_location(Plugin *that)
292 if(!plugin_set || !plugin_set->track) return 0;
293 if(!that->plugin_set || !that->plugin_set->track) return 0;
295 if(plugin_set->track->number_of() == that->plugin_set->track->number_of() &&
296 plugin_set->get_number() == that->plugin_set->get_number() &&
297 startproject == that->startproject) return 1;
303 int Plugin::keyframe_exists(KeyFrame *ptr)
305 for(KeyFrame *current = (KeyFrame*)keyframes->first;
307 current = (KeyFrame*)NEXT)
309 if(current == ptr) return 1;
315 void Plugin::change_plugin(char *title,
316 SharedLocation *shared_location,
319 strcpy(this->title, title);
320 this->shared_location = *shared_location;
321 this->plugin_type = plugin_type;
326 KeyFrame* Plugin::get_prev_keyframe(int64_t position,
329 return keyframes->get_prev_keyframe(position, direction);
332 KeyFrame* Plugin::get_next_keyframe(int64_t position,
337 // This doesn't work for playback because edl->selectionstart doesn't
338 // change during playback at the same rate as PluginClient::source_position.
341 //printf("Plugin::get_next_keyframe position < 0\n");
342 position = track->to_units(edl->local_session->get_selectionstart(1), 0);
345 // Get keyframe after current position
346 for(current = (KeyFrame*)keyframes->first;
348 current = (KeyFrame*)NEXT)
350 if(direction == PLAY_FORWARD && current->position > position) break;
352 if(direction == PLAY_REVERSE && current->position >= position) break;
355 // Nothing after current position
356 if(!current && keyframes->last)
358 current = (KeyFrame*)keyframes->last;
364 current = (KeyFrame*)keyframes->default_auto;
370 KeyFrame* Plugin::get_keyframe()
372 return keyframes->get_keyframe();
375 void Plugin::copy(int64_t start, int64_t end, FileXML *file)
377 int64_t endproject = startproject + length;
379 if((startproject >= start && startproject <= end) || // startproject in range
380 (endproject <= end && endproject >= start) || // endproject in range
381 (startproject <= start && endproject >= end)) // range in project
384 int64_t startproject_in_selection = startproject; // start of edit in selection in project
385 int64_t startsource_in_selection = startsource; // start of source in selection in source
386 //int64_t endsource_in_selection = startsource + length; // end of source in selection
387 int64_t length_in_selection = length; // length of edit in selection
389 if(startproject < start)
390 { // start is after start of edit in project
391 int64_t length_difference = start - startproject;
393 startsource_in_selection += length_difference;
394 startproject_in_selection += length_difference;
395 length_in_selection -= length_difference;
398 // end is before end of edit in project
401 length_in_selection = end - startproject_in_selection;
404 // Plugins don't store silence
405 file->tag.set_title("PLUGIN");
406 // file->tag.set_property("STARTPROJECT", startproject_in_selection - start);
407 file->tag.set_property("LENGTH", length_in_selection);
408 file->tag.set_property("TYPE", plugin_type);
409 file->tag.set_property("TITLE", title);
411 file->append_newline();
414 if(plugin_type == PLUGIN_SHAREDPLUGIN ||
415 plugin_type == PLUGIN_SHAREDMODULE)
417 shared_location.save(file);
424 file->tag.set_title("IN");
426 file->tag.set_title("/IN");
431 file->tag.set_title("OUT");
433 file->tag.set_title("/OUT");
438 file->tag.set_title("SHOW");
440 file->tag.set_title("/SHOW");
445 file->tag.set_title("ON");
447 file->tag.set_title("/ON");
450 file->append_newline();
453 keyframes->copy(start, end, file, 0, 0);
455 file->tag.set_title("/PLUGIN");
457 file->append_newline();
461 void Plugin::load(FileXML *file)
464 int first_keyframe = 1;
467 // Currently show is ignored when loading
470 while(keyframes->last) delete keyframes->last;
473 result = file->read_tag();
475 //printf("Plugin::load 1 %s\n", file->tag.get_title());
478 if(file->tag.title_is("/PLUGIN"))
483 if(file->tag.title_is("SHARED_LOCATION"))
485 shared_location.load(file);
488 if(file->tag.title_is("IN"))
493 if(file->tag.title_is("OUT"))
498 if(file->tag.title_is("SHOW"))
503 if(file->tag.title_is("ON"))
508 if(file->tag.title_is("KEYFRAME"))
513 keyframes->default_auto->load(file);
517 // Override default keyframe
519 KeyFrame *keyframe = (KeyFrame*)keyframes->append(new KeyFrame(edl, keyframes));
520 keyframe->position = file->tag.get_property("POSITION", (int64_t)0);
521 keyframe->load(file);
528 void Plugin::get_shared_location(SharedLocation *result)
530 if(plugin_type == PLUGIN_STANDALONE && plugin_set)
532 result->module = edl->tracks->number_of(track);
533 result->plugin = track->plugin_set.number_of(plugin_set);
537 *result = this->shared_location;
541 Track* Plugin::get_shared_track()
543 return edl->tracks->get_item_number(shared_location.module);
547 void Plugin::calculate_title(char *string, int use_nudge)
549 if(plugin_type == PLUGIN_STANDALONE || plugin_type == PLUGIN_NONE)
551 strcpy(string, _(title));
554 if(plugin_type == PLUGIN_SHAREDPLUGIN || plugin_type == PLUGIN_SHAREDMODULE)
556 shared_location.calculate_title(string,
566 void Plugin::paste(FileXML *file)
568 length = file->tag.get_property("LENGTH", (int64_t)0);
571 void Plugin::resample(double old_rate, double new_rate)
573 // Resample keyframes in here
574 keyframes->resample(old_rate, new_rate);
577 void Plugin::shift(int64_t difference)
579 Edit::shift(difference);
581 if(edl->session->autos_follow_edits)
582 shift_keyframes(difference);
585 void Plugin::dump(FILE *fp)
587 fprintf(fp," PLUGIN: type=%d title=\"%s\" on=%d track=%d plugin=%d\n",
591 shared_location.module,
592 shared_location.plugin);
593 fprintf(fp," startproject %jd length %jd\n", startproject, length);