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::init(const char *title,
113 int64_t unit_position, int64_t unit_length, int plugin_type,
114 SharedLocation *shared_location, KeyFrame *default_keyframe)
116 if( title ) strcpy(this->title, title);
117 if( shared_location ) this->shared_location = *shared_location;
118 this->plugin_type = plugin_type;
119 if( default_keyframe )
120 *this->keyframes->default_auto = *default_keyframe;
121 this->keyframes->default_auto->position = unit_position;
122 this->startproject = unit_position;
123 this->length = unit_length;
126 void Plugin::copy_base(Edit *edit)
128 Plugin *plugin = (Plugin*)edit;
130 this->startsource = edit->startsource;
131 this->startproject = edit->startproject;
132 this->length = edit->length;
135 this->plugin_type = plugin->plugin_type;
136 this->in = plugin->in;
137 this->out = plugin->out;
138 this->show = plugin->show;
139 this->on = plugin->on;
140 // Should reconfigure this based on where the first track is now.
141 this->shared_location = plugin->shared_location;
142 strcpy(this->title, plugin->title);
145 void Plugin::copy_from(Edit *edit)
148 copy_keyframes((Plugin*)edit);
151 void Plugin::copy_keyframes(Plugin *plugin)
154 keyframes->copy_from(plugin->keyframes);
157 void Plugin::copy_keyframes(int64_t start,
163 // Only 1 default is copied from where the start position is
164 int64_t endproject = startproject + length;
167 start < endproject &&
168 start >= startproject))
169 keyframes->copy(start, end, file, default_only, active_only);
172 void Plugin::synchronize_params(Edit *edit)
174 Plugin *plugin = (Plugin*)edit;
175 this->in = plugin->in;
176 this->out = plugin->out;
177 this->show = plugin->show;
178 this->on = plugin->on;
179 strcpy(this->title, plugin->title);
180 copy_keyframes(plugin);
183 void Plugin::shift_keyframes(int64_t position)
185 for(KeyFrame *keyframe = (KeyFrame*)keyframes->first;
187 keyframe = (KeyFrame*)keyframe->next)
189 keyframe->position += position;
194 void Plugin::equivalent_output(Edit *edit, int64_t *result)
196 Plugin *plugin = (Plugin*)edit;
197 // End of plugin changed
198 if(startproject + length != plugin->startproject + plugin->length)
200 if(*result < 0 || startproject + length < *result)
201 *result = startproject + length;
204 // Start of plugin changed
205 if( startproject != plugin->startproject || plugin_type != plugin->plugin_type ||
206 on != plugin->on || !(shared_location == plugin->shared_location) ||
207 strcmp(title, plugin->title) ) {
208 if( *result < 0 || startproject < *result )
209 *result = startproject;
213 keyframes->equivalent_output(plugin->keyframes, startproject, result);
218 int Plugin::is_synthesis(int64_t position,
223 case PLUGIN_STANDALONE:
227 printf("Plugin::is_synthesis track not defined\n");
232 PluginServer *plugin_server = MWindow::scan_plugindb(title,
234 //printf("Plugin::is_synthesis %d %p %d\n", __LINE__, plugin_server, plugin_server->get_synthesis());
235 //plugin_server->dump();
236 return plugin_server->get_synthesis();
240 // Dereference real plugin and descend another level
241 case PLUGIN_SHAREDPLUGIN:
243 int real_module_number = shared_location.module;
244 int real_plugin_number = shared_location.plugin;
245 Track *track = edl->tracks->number(real_module_number);
246 // Get shared plugin from master track
247 Plugin *plugin = track->get_current_plugin(position,
254 return plugin->is_synthesis(position, direction);
258 // Dereference the real track and descend
259 case PLUGIN_SHAREDMODULE:
261 int real_module_number = shared_location.module;
262 Track *track = edl->tracks->number(real_module_number);
263 return track->is_synthesis(position, direction);
272 int Plugin::identical(Plugin *that)
275 if(plugin_type != that->plugin_type) return 0;
277 // Test title or location
280 case PLUGIN_STANDALONE:
281 if(strcmp(title, that->title)) return 0;
283 case PLUGIN_SHAREDPLUGIN:
284 if(shared_location.module != that->shared_location.module ||
285 shared_location.plugin != that->shared_location.plugin) return 0;
287 case PLUGIN_SHAREDMODULE:
288 if(shared_location.module != that->shared_location.module) return 0;
292 // Test remaining fields
293 return (this->on == that->on &&
294 ((KeyFrame*)keyframes->default_auto)->identical(
295 ((KeyFrame*)that->keyframes->default_auto)));
298 int Plugin::identical_location(Plugin *that)
300 if(!plugin_set || !plugin_set->track) return 0;
301 if(!that->plugin_set || !that->plugin_set->track) return 0;
303 if(plugin_set->track->number_of() == that->plugin_set->track->number_of() &&
304 plugin_set->get_number() == that->plugin_set->get_number() &&
305 startproject == that->startproject) return 1;
311 int Plugin::keyframe_exists(KeyFrame *ptr)
313 for(KeyFrame *current = (KeyFrame*)keyframes->first;
315 current = (KeyFrame*)NEXT)
317 if(current == ptr) return 1;
323 void Plugin::change_plugin(char *title,
324 SharedLocation *shared_location,
327 strcpy(this->title, title);
328 this->shared_location = *shared_location;
329 this->plugin_type = plugin_type;
334 KeyFrame* Plugin::get_prev_keyframe(int64_t position,
337 return keyframes->get_prev_keyframe(position, direction);
340 KeyFrame* Plugin::get_next_keyframe(int64_t position,
345 // This doesn't work for playback because edl->selectionstart doesn't
346 // change during playback at the same rate as PluginClient::source_position.
349 //printf("Plugin::get_next_keyframe position < 0\n");
350 position = track->to_units(edl->local_session->get_selectionstart(1), 0);
353 // Get keyframe after current position
354 for(current = (KeyFrame*)keyframes->first;
356 current = (KeyFrame*)NEXT)
358 if(direction == PLAY_FORWARD && current->position > position) break;
360 if(direction == PLAY_REVERSE && current->position >= position) break;
363 // Nothing after current position
364 if(!current && keyframes->last)
366 current = (KeyFrame*)keyframes->last;
372 current = (KeyFrame*)keyframes->default_auto;
378 KeyFrame* Plugin::get_keyframe()
380 return keyframes->get_keyframe();
383 void Plugin::copy(int64_t start, int64_t end, FileXML *file)
385 int64_t endproject = startproject + length;
387 if((startproject >= start && startproject <= end) || // startproject in range
388 (endproject <= end && endproject >= start) || // endproject in range
389 (startproject <= start && endproject >= end)) // range in project
392 int64_t startproject_in_selection = startproject; // start of edit in selection in project
393 int64_t startsource_in_selection = startsource; // start of source in selection in source
394 //int64_t endsource_in_selection = startsource + length; // end of source in selection
395 int64_t length_in_selection = length; // length of edit in selection
397 if(startproject < start)
398 { // start is after start of edit in project
399 int64_t length_difference = start - startproject;
401 startsource_in_selection += length_difference;
402 startproject_in_selection += length_difference;
403 length_in_selection -= length_difference;
406 // end is before end of edit in project
409 length_in_selection = end - startproject_in_selection;
412 // Plugins don't store silence
413 file->tag.set_title("PLUGIN");
414 // file->tag.set_property("STARTPROJECT", startproject_in_selection - start);
415 file->tag.set_property("LENGTH", length_in_selection);
416 file->tag.set_property("TYPE", plugin_type);
417 file->tag.set_property("TITLE", title);
419 file->append_newline();
422 if(plugin_type == PLUGIN_SHAREDPLUGIN ||
423 plugin_type == PLUGIN_SHAREDMODULE)
425 shared_location.save(file);
432 file->tag.set_title("IN");
434 file->tag.set_title("/IN");
439 file->tag.set_title("OUT");
441 file->tag.set_title("/OUT");
446 file->tag.set_title("SHOW");
448 file->tag.set_title("/SHOW");
453 file->tag.set_title("ON");
455 file->tag.set_title("/ON");
458 file->append_newline();
461 keyframes->copy(start, end, file, 0, 0);
463 file->tag.set_title("/PLUGIN");
465 file->append_newline();
469 void Plugin::load(FileXML *file)
472 int first_keyframe = 1;
475 // Currently show is ignored when loading
478 while(keyframes->last) delete keyframes->last;
481 result = file->read_tag();
483 //printf("Plugin::load 1 %s\n", file->tag.get_title());
486 if(file->tag.title_is("/PLUGIN"))
491 if(file->tag.title_is("SHARED_LOCATION"))
493 shared_location.load(file);
496 if(file->tag.title_is("IN"))
501 if(file->tag.title_is("OUT"))
506 if(file->tag.title_is("SHOW"))
511 if(file->tag.title_is("ON"))
516 if(file->tag.title_is("KEYFRAME"))
521 keyframes->default_auto->load(file);
525 // Override default keyframe
527 KeyFrame *keyframe = (KeyFrame*)keyframes->append(new KeyFrame(edl, keyframes));
528 keyframe->position = file->tag.get_property("POSITION", (int64_t)0);
529 keyframe->load(file);
536 void Plugin::get_shared_location(SharedLocation *result)
538 if(plugin_type == PLUGIN_STANDALONE && plugin_set)
540 result->module = edl->tracks->number_of(track);
541 result->plugin = track->plugin_set.number_of(plugin_set);
545 *result = this->shared_location;
549 Track* Plugin::get_shared_track()
551 return edl->tracks->get_item_number(shared_location.module);
555 void Plugin::calculate_title(char *string, int use_nudge)
557 switch( plugin_type ) {
558 case PLUGIN_STANDALONE:
560 strcpy(string, _(title));
562 case PLUGIN_SHAREDPLUGIN:
563 case PLUGIN_SHAREDMODULE:
564 shared_location.calculate_title(string, edl,
565 startproject, 0, plugin_type, use_nudge);
570 void Plugin::fix_plugin_title(char *title)
572 MWindow::fix_plugin_title(title);
576 void Plugin::paste(FileXML *file)
578 length = file->tag.get_property("LENGTH", (int64_t)0);
581 void Plugin::resample(double old_rate, double new_rate)
583 // Resample keyframes in here
584 keyframes->resample(old_rate, new_rate);
587 void Plugin::shift(int64_t difference)
589 Edit::shift(difference);
591 if(edl->session->autos_follow_edits)
592 shift_keyframes(difference);
595 void Plugin::dump(FILE *fp)
597 fprintf(fp," PLUGIN: type=%d title=\"%s\" on=%d track=%d plugin=%d\n",
598 plugin_type, title, on, shared_location.module, shared_location.plugin);
599 fprintf(fp," startproject %jd length %jd\n", startproject, length);