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, Track *track, const char *title)
46 strcpy(this->title, title);
47 plugin_type = PLUGIN_NONE;
52 keyframes = new KeyFrames(edl, track);
53 keyframes->create_objects();
57 Plugin::Plugin(EDL *edl, PluginSet *plugin_set, const char *title)
58 : Edit(edl, plugin_set)
61 this->track = plugin_set->track;
62 this->plugin_set = plugin_set;
63 strcpy(this->title, title);
64 plugin_type = PLUGIN_NONE;
69 keyframes = new KeyFrames(edl, track);
70 keyframes->create_objects();
75 while(keyframes->last) delete keyframes->last;
79 Edit& Plugin::operator=(Edit& edit)
85 Plugin& Plugin::operator=(Plugin& edit)
91 int Plugin::operator==(Plugin& that)
93 return identical(&that);
96 int Plugin::operator==(Edit& that)
98 return identical((Plugin*)&that);
101 int Plugin::silence()
103 return plugin_type == PLUGIN_NONE ? 1 : 0;
106 void Plugin::clear_keyframes(int64_t start, int64_t end)
108 keyframes->clear(start, end, 0);
112 void Plugin::copy_base(Edit *edit)
114 Plugin *plugin = (Plugin*)edit;
116 this->startsource = edit->startsource;
117 this->startproject = edit->startproject;
118 this->length = edit->length;
121 this->plugin_type = plugin->plugin_type;
122 this->in = plugin->in;
123 this->out = plugin->out;
124 this->show = plugin->show;
125 this->on = plugin->on;
126 // Should reconfigure this based on where the first track is now.
127 this->shared_location = plugin->shared_location;
128 strcpy(this->title, plugin->title);
131 void Plugin::copy_from(Edit *edit)
134 copy_keyframes((Plugin*)edit);
137 void Plugin::copy_keyframes(Plugin *plugin)
140 keyframes->copy_from(plugin->keyframes);
143 void Plugin::copy_keyframes(int64_t start,
149 // Only 1 default is copied from where the start position is
150 int64_t endproject = startproject + length;
153 start < endproject &&
154 start >= startproject))
155 keyframes->copy(start, end, file, default_only, active_only);
158 void Plugin::synchronize_params(Edit *edit)
160 Plugin *plugin = (Plugin*)edit;
161 this->in = plugin->in;
162 this->out = plugin->out;
163 this->show = plugin->show;
164 this->on = plugin->on;
165 strcpy(this->title, plugin->title);
166 copy_keyframes(plugin);
169 void Plugin::shift_keyframes(int64_t position)
171 for(KeyFrame *keyframe = (KeyFrame*)keyframes->first;
173 keyframe = (KeyFrame*)keyframe->next)
175 keyframe->position += position;
180 void Plugin::equivalent_output(Edit *edit, int64_t *result)
182 Plugin *plugin = (Plugin*)edit;
183 // End of plugin changed
184 if(startproject + length != plugin->startproject + plugin->length)
186 if(*result < 0 || startproject + length < *result)
187 *result = startproject + length;
190 // Start of plugin changed
191 if( startproject != plugin->startproject || plugin_type != plugin->plugin_type ||
192 on != plugin->on || !(shared_location == plugin->shared_location) ||
193 strcmp(title, plugin->title) ) {
194 if( *result < 0 || startproject < *result )
195 *result = startproject;
199 keyframes->equivalent_output(plugin->keyframes, startproject, result);
204 int Plugin::is_synthesis(int64_t position,
209 case PLUGIN_STANDALONE:
213 printf("Plugin::is_synthesis track not defined\n");
218 PluginServer *plugin_server = MWindow::scan_plugindb(title,
220 //printf("Plugin::is_synthesis %d %p %d\n", __LINE__, plugin_server, plugin_server->get_synthesis());
221 //plugin_server->dump();
222 return plugin_server->get_synthesis();
226 // Dereference real plugin and descend another level
227 case PLUGIN_SHAREDPLUGIN:
229 int real_module_number = shared_location.module;
230 int real_plugin_number = shared_location.plugin;
231 Track *track = edl->tracks->number(real_module_number);
232 // Get shared plugin from master track
233 Plugin *plugin = track->get_current_plugin(position,
240 return plugin->is_synthesis(position, direction);
244 // Dereference the real track and descend
245 case PLUGIN_SHAREDMODULE:
247 int real_module_number = shared_location.module;
248 Track *track = edl->tracks->number(real_module_number);
249 return track->is_synthesis(position, direction);
258 int Plugin::identical(Plugin *that)
261 if(plugin_type != that->plugin_type) return 0;
263 // Test title or location
266 case PLUGIN_STANDALONE:
267 if(strcmp(title, that->title)) return 0;
269 case PLUGIN_SHAREDPLUGIN:
270 if(shared_location.module != that->shared_location.module ||
271 shared_location.plugin != that->shared_location.plugin) return 0;
273 case PLUGIN_SHAREDMODULE:
274 if(shared_location.module != that->shared_location.module) return 0;
278 // Test remaining fields
279 return (this->on == that->on &&
280 ((KeyFrame*)keyframes->default_auto)->identical(
281 ((KeyFrame*)that->keyframes->default_auto)));
284 int Plugin::identical_location(Plugin *that)
286 if(!plugin_set || !plugin_set->track) return 0;
287 if(!that->plugin_set || !that->plugin_set->track) return 0;
289 if(plugin_set->track->number_of() == that->plugin_set->track->number_of() &&
290 plugin_set->get_number() == that->plugin_set->get_number() &&
291 startproject == that->startproject) return 1;
297 int Plugin::keyframe_exists(KeyFrame *ptr)
299 for(KeyFrame *current = (KeyFrame*)keyframes->first;
301 current = (KeyFrame*)NEXT)
303 if(current == ptr) return 1;
309 void Plugin::change_plugin(char *title,
310 SharedLocation *shared_location,
313 strcpy(this->title, title);
314 this->shared_location = *shared_location;
315 this->plugin_type = plugin_type;
320 KeyFrame* Plugin::get_prev_keyframe(int64_t position,
323 return keyframes->get_prev_keyframe(position, direction);
326 KeyFrame* Plugin::get_next_keyframe(int64_t position,
331 // This doesn't work for playback because edl->selectionstart doesn't
332 // change during playback at the same rate as PluginClient::source_position.
335 //printf("Plugin::get_next_keyframe position < 0\n");
336 position = track->to_units(edl->local_session->get_selectionstart(1), 0);
339 // Get keyframe after current position
340 for(current = (KeyFrame*)keyframes->first;
342 current = (KeyFrame*)NEXT)
344 if(direction == PLAY_FORWARD && current->position > position) break;
346 if(direction == PLAY_REVERSE && current->position >= position) break;
349 // Nothing after current position
350 if(!current && keyframes->last)
352 current = (KeyFrame*)keyframes->last;
358 current = (KeyFrame*)keyframes->default_auto;
364 KeyFrame* Plugin::get_keyframe()
366 return keyframes->get_keyframe();
369 void Plugin::copy(int64_t start, int64_t end, FileXML *file)
371 int64_t endproject = startproject + length;
373 if((startproject >= start && startproject <= end) || // startproject in range
374 (endproject <= end && endproject >= start) || // endproject in range
375 (startproject <= start && endproject >= end)) // range in project
378 int64_t startproject_in_selection = startproject; // start of edit in selection in project
379 int64_t startsource_in_selection = startsource; // start of source in selection in source
380 //int64_t endsource_in_selection = startsource + length; // end of source in selection
381 int64_t length_in_selection = length; // length of edit in selection
383 if(startproject < start)
384 { // start is after start of edit in project
385 int64_t length_difference = start - startproject;
387 startsource_in_selection += length_difference;
388 startproject_in_selection += length_difference;
389 length_in_selection -= length_difference;
392 // end is before end of edit in project
395 length_in_selection = end - startproject_in_selection;
398 // Plugins don't store silence
399 file->tag.set_title("PLUGIN");
400 // file->tag.set_property("STARTPROJECT", startproject_in_selection - start);
401 file->tag.set_property("LENGTH", length_in_selection);
402 file->tag.set_property("TYPE", plugin_type);
403 file->tag.set_property("TITLE", title);
405 file->append_newline();
408 if(plugin_type == PLUGIN_SHAREDPLUGIN ||
409 plugin_type == PLUGIN_SHAREDMODULE)
411 shared_location.save(file);
418 file->tag.set_title("IN");
420 file->tag.set_title("/IN");
425 file->tag.set_title("OUT");
427 file->tag.set_title("/OUT");
432 file->tag.set_title("SHOW");
434 file->tag.set_title("/SHOW");
439 file->tag.set_title("ON");
441 file->tag.set_title("/ON");
444 file->append_newline();
447 keyframes->copy(start, end, file, 0, 0);
449 file->tag.set_title("/PLUGIN");
451 file->append_newline();
455 void Plugin::load(FileXML *file)
458 int first_keyframe = 1;
461 // Currently show is ignored when loading
464 while(keyframes->last) delete keyframes->last;
467 result = file->read_tag();
469 //printf("Plugin::load 1 %s\n", file->tag.get_title());
472 if(file->tag.title_is("/PLUGIN"))
477 if(file->tag.title_is("SHARED_LOCATION"))
479 shared_location.load(file);
482 if(file->tag.title_is("IN"))
487 if(file->tag.title_is("OUT"))
492 if(file->tag.title_is("SHOW"))
497 if(file->tag.title_is("ON"))
502 if(file->tag.title_is("KEYFRAME"))
507 keyframes->default_auto->load(file);
511 // Override default keyframe
513 KeyFrame *keyframe = (KeyFrame*)keyframes->append(new KeyFrame(edl, keyframes));
514 keyframe->position = file->tag.get_property("POSITION", (int64_t)0);
515 keyframe->load(file);
522 void Plugin::get_shared_location(SharedLocation *result)
524 if(plugin_type == PLUGIN_STANDALONE && plugin_set)
526 result->module = edl->tracks->number_of(track);
527 result->plugin = track->plugin_set.number_of(plugin_set);
531 *result = this->shared_location;
535 Track* Plugin::get_shared_track()
537 return edl->tracks->get_item_number(shared_location.module);
541 void Plugin::calculate_title(char *string, int use_nudge)
543 switch( plugin_type ) {
544 case PLUGIN_STANDALONE:
546 strcpy(string, _(title));
548 case PLUGIN_SHAREDPLUGIN:
549 case PLUGIN_SHAREDMODULE:
550 shared_location.calculate_title(string, edl,
551 startproject, 0, plugin_type, use_nudge);
556 void Plugin::fix_plugin_title(char *title)
558 MWindow::fix_plugin_title(title);
562 void Plugin::paste(FileXML *file)
564 length = file->tag.get_property("LENGTH", (int64_t)0);
567 void Plugin::resample(double old_rate, double new_rate)
569 // Resample keyframes in here
570 keyframes->resample(old_rate, new_rate);
573 void Plugin::shift(int64_t difference)
575 Edit::shift(difference);
577 if(edl->session->autos_follow_edits)
578 shift_keyframes(difference);
581 void Plugin::dump(FILE *fp)
583 fprintf(fp," PLUGIN: type=%d title=\"%s\" on=%d track=%d plugin=%d\n",
584 plugin_type, title, on, shared_location.module, shared_location.plugin);
585 fprintf(fp," startproject %jd length %jd\n", startproject, length);