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;
53 keyframes = new KeyFrames(edl, track);
54 keyframes->create_objects();
58 Plugin::Plugin(EDL *edl, PluginSet *plugin_set, const char *title)
59 : Edit(edl, plugin_set)
62 this->track = plugin_set->track;
63 this->plugin_set = plugin_set;
64 strcpy(this->title, title);
65 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 return plugin_type == PLUGIN_NONE ? 1 : 0;
108 void Plugin::clear_keyframes(int64_t start, int64_t end)
110 keyframes->clear(start, end, 0);
114 void Plugin::init(const char *title,
115 int64_t unit_position, int64_t unit_length, int plugin_type,
116 SharedLocation *shared_location, KeyFrame *default_keyframe)
118 if( title ) strcpy(this->title, title);
119 if( shared_location ) this->shared_location = *shared_location;
120 this->plugin_type = plugin_type;
121 if( default_keyframe )
122 *this->keyframes->default_auto = *default_keyframe;
123 this->keyframes->default_auto->position = unit_position;
124 this->startproject = unit_position;
125 this->length = unit_length;
128 void Plugin::copy_base(Edit *edit)
130 Plugin *plugin = (Plugin*)edit;
132 this->startsource = edit->startsource;
133 this->startproject = edit->startproject;
134 this->length = edit->length;
137 this->plugin_type = plugin->plugin_type;
138 this->in = plugin->in;
139 this->out = plugin->out;
140 this->show = plugin->show;
141 this->on = plugin->on;
142 // dont copy gui_id, it will be a duplicate ref
143 // Should reconfigure this based on where the first track is now.
144 this->shared_location = plugin->shared_location;
145 strcpy(this->title, plugin->title);
148 void Plugin::copy_from(Edit *edit)
151 copy_keyframes((Plugin*)edit);
154 void Plugin::copy_keyframes(Plugin *plugin)
157 keyframes->copy_from(plugin->keyframes);
160 void Plugin::copy_keyframes(int64_t start,
166 // Only 1 default is copied from where the start position is
167 int64_t endproject = startproject + length;
170 start < endproject &&
171 start >= startproject))
172 keyframes->copy(start, end, file, default_only, active_only);
175 void Plugin::synchronize_params(Edit *edit)
177 Plugin *plugin = (Plugin*)edit;
178 this->in = plugin->in;
179 this->out = plugin->out;
180 this->show = plugin->show;
181 this->gui_id = plugin->gui_id;
182 this->on = plugin->on;
183 strcpy(this->title, plugin->title);
184 copy_keyframes(plugin);
187 void Plugin::shift_keyframes(int64_t position)
189 for(KeyFrame *keyframe = (KeyFrame*)keyframes->first;
191 keyframe = (KeyFrame*)keyframe->next)
193 keyframe->position += position;
198 void Plugin::equivalent_output(Edit *edit, int64_t *result)
200 Plugin *plugin = (Plugin*)edit;
201 // End of plugin changed
202 if(startproject + length != plugin->startproject + plugin->length)
204 if(*result < 0 || startproject + length < *result)
205 *result = startproject + length;
208 // Start of plugin changed
209 if( startproject != plugin->startproject || plugin_type != plugin->plugin_type ||
210 on != plugin->on || !(shared_location == plugin->shared_location) ||
211 strcmp(title, plugin->title) ) {
212 if( *result < 0 || startproject < *result )
213 *result = startproject;
217 keyframes->equivalent_output(plugin->keyframes, startproject, result);
220 const char* Plugin::type_to_text(int type)
223 case PLUGIN_STANDALONE: return _("standalone");
224 case PLUGIN_SHAREDPLUGIN: return _("shared plugin");
225 case PLUGIN_SHAREDMODULE: return _("shared module");
230 int Plugin::is_synthesis(int64_t position, int direction, int depth)
233 printf("Plugin::is_synthesis %d: depth range limit, type=%s, title=%s\n",
234 __LINE__, type_to_text(plugin_type), title);
237 switch( plugin_type ) {
238 case PLUGIN_STANDALONE: {
240 printf("Plugin::is_synthesis track not defined\n");
243 PluginServer *plugin_server = MWindow::scan_plugindb(title, track->data_type);
244 return plugin_server->get_synthesis(); }
246 // Dereference real plugin and descend another level
247 case PLUGIN_SHAREDPLUGIN: {
248 int real_module_number = shared_location.module;
249 int real_plugin_number = shared_location.plugin;
250 Track *track = edl->tracks->number(real_module_number);
251 // Get shared plugin from master track
252 Plugin *plugin = track->get_current_plugin(position,
253 real_plugin_number, direction, 0, 0);
256 return plugin->is_synthesis(position, direction, depth+1);
259 // Dereference the real track and descend
260 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, depth+1); }
270 int Plugin::identical(Plugin *that)
273 if(plugin_type != that->plugin_type) return 0;
275 // Test title or location
278 case PLUGIN_STANDALONE:
279 if(strcmp(title, that->title)) return 0;
281 case PLUGIN_SHAREDPLUGIN:
282 if(shared_location.module != that->shared_location.module ||
283 shared_location.plugin != that->shared_location.plugin) return 0;
285 case PLUGIN_SHAREDMODULE:
286 if(shared_location.module != that->shared_location.module) return 0;
290 // Test remaining fields
291 return (this->on == that->on &&
292 ((KeyFrame*)keyframes->default_auto)->identical(
293 ((KeyFrame*)that->keyframes->default_auto)));
296 int Plugin::keyframe_exists(KeyFrame *ptr)
298 for(KeyFrame *current = (KeyFrame*)keyframes->first;
300 current = (KeyFrame*)NEXT)
302 if(current == ptr) return 1;
308 void Plugin::change_plugin(char *title,
309 SharedLocation *shared_location,
312 strcpy(this->title, title);
313 this->shared_location = *shared_location;
314 this->plugin_type = plugin_type;
319 KeyFrame* Plugin::get_prev_keyframe(int64_t position,
322 return keyframes->get_prev_keyframe(position, direction);
325 KeyFrame* Plugin::get_next_keyframe(int64_t position,
330 // This doesn't work for playback because edl->selectionstart doesn't
331 // change during playback at the same rate as PluginClient::source_position.
334 //printf("Plugin::get_next_keyframe position < 0\n");
335 position = track->to_units(edl->local_session->get_selectionstart(1), 0);
338 // Get keyframe after current position
339 for(current = (KeyFrame*)keyframes->first;
341 current = (KeyFrame*)NEXT)
343 if(direction == PLAY_FORWARD && current->position > position) break;
345 if(direction == PLAY_REVERSE && current->position >= position) break;
348 // Nothing after current position
349 if(!current && keyframes->last)
351 current = (KeyFrame*)keyframes->last;
357 current = (KeyFrame*)keyframes->default_auto;
363 KeyFrame* Plugin::get_keyframe()
365 return keyframes->get_keyframe();
368 void Plugin::copy(int64_t start, int64_t end, FileXML *file)
370 int64_t endproject = startproject + length;
372 if((startproject >= start && startproject <= end) || // startproject in range
373 (endproject <= end && endproject >= start) || // endproject in range
374 (startproject <= start && endproject >= end)) // range in project
377 int64_t startproject_in_selection = startproject; // start of edit in selection in project
378 int64_t startsource_in_selection = startsource; // start of source in selection in source
379 //int64_t endsource_in_selection = startsource + length; // end of source in selection
380 int64_t length_in_selection = length; // length of edit in selection
382 if(startproject < start)
383 { // start is after start of edit in project
384 int64_t length_difference = start - startproject;
386 startsource_in_selection += length_difference;
387 startproject_in_selection += length_difference;
388 length_in_selection -= length_difference;
391 // end is before end of edit in project
394 length_in_selection = end - startproject_in_selection;
397 // Plugins don't store silence
398 file->tag.set_title("PLUGIN");
399 // file->tag.set_property("STARTPROJECT", startproject_in_selection - start);
400 file->tag.set_property("LENGTH", length_in_selection);
401 file->tag.set_property("TYPE", plugin_type);
402 file->tag.set_property("TITLE", title);
404 file->append_newline();
407 if(plugin_type == PLUGIN_SHAREDPLUGIN ||
408 plugin_type == PLUGIN_SHAREDMODULE)
410 shared_location.save(file);
417 file->tag.set_title("IN");
419 file->tag.set_title("/IN");
424 file->tag.set_title("OUT");
426 file->tag.set_title("/OUT");
431 file->tag.set_title("SHOW");
433 file->tag.set_title("/SHOW");
438 file->tag.set_title("ON");
440 file->tag.set_title("/ON");
443 file->append_newline();
446 keyframes->copy(start, end, file, 0, 0);
448 file->tag.set_title("/PLUGIN");
450 file->append_newline();
454 void Plugin::load(FileXML *file)
457 int first_keyframe = 1;
460 // Currently show is ignored when loading
463 while(keyframes->last) delete keyframes->last;
466 result = file->read_tag();
468 //printf("Plugin::load 1 %s\n", file->tag.get_title());
471 if(file->tag.title_is("/PLUGIN"))
476 if(file->tag.title_is("SHARED_LOCATION"))
478 shared_location.load(file);
481 if(file->tag.title_is("IN"))
486 if(file->tag.title_is("OUT"))
491 if(file->tag.title_is("SHOW"))
496 if(file->tag.title_is("ON"))
501 if(file->tag.title_is("KEYFRAME"))
506 keyframes->default_auto->load(file);
510 // Override default keyframe
512 KeyFrame *keyframe = (KeyFrame*)keyframes->append(new KeyFrame(edl, keyframes));
513 keyframe->position = file->tag.get_property("POSITION", (int64_t)0);
514 keyframe->load(file);
521 void Plugin::get_shared_location(SharedLocation *result)
523 if(plugin_type == PLUGIN_STANDALONE && plugin_set)
525 result->module = edl->tracks->number_of(track);
526 result->plugin = track->plugin_set.number_of(plugin_set);
530 *result = this->shared_location;
534 Track* Plugin::get_shared_track()
536 return edl->tracks->get_item_number(shared_location.module);
540 void Plugin::calculate_title(char *string, int use_nudge)
542 switch( plugin_type ) {
543 case PLUGIN_STANDALONE:
545 strcpy(string, _(title));
547 case PLUGIN_SHAREDPLUGIN:
548 case PLUGIN_SHAREDMODULE:
549 shared_location.calculate_title(string, edl,
550 startproject, 0, plugin_type, use_nudge);
555 void Plugin::fix_plugin_title(char *title)
557 MWindow::fix_plugin_title(title);
561 void Plugin::paste(FileXML *file)
563 length = file->tag.get_property("LENGTH", (int64_t)0);
566 void Plugin::resample(double old_rate, double new_rate)
568 // Resample keyframes in here
569 keyframes->resample(old_rate, new_rate);
572 void Plugin::shift(int64_t difference)
574 Edit::shift(difference);
576 if(edl->session->autos_follow_edits)
577 shift_keyframes(difference);
580 void Plugin::dump(FILE *fp)
582 fprintf(fp," PLUGIN: type=%d title=\"%s\" on=%d track=%d plugin=%d gui_id=%d\n",
583 plugin_type, title, on, shared_location.module, shared_location.plugin, gui_id);
584 fprintf(fp," startproject %jd length %jd\n", startproject, length);