Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / plugin.C
index 25023190bab85b6eb8dfcbb6e08a7189cc60e6a0..64b43072bb588432666fac3eeb0f9514119287a1 100644 (file)
@@ -2,6 +2,7 @@
 /*
  * CINELERRA
  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
+ * Copyright (C) 2003-2016 Cinelerra CV contributors
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -40,7 +41,6 @@
 Plugin::Plugin(EDL *edl, Track *track, const char *title)
  : Edit(edl, track)
 {
-       is_plugin = 1;
        this->track = track;
        this->plugin_set = 0;
        strcpy(this->title, title);
@@ -49,7 +49,8 @@ Plugin::Plugin(EDL *edl, Track *track, const char *title)
        out = 1;
        show = 0;
        on = 1;
-       keyframes = new KeyFrames(edl, track);
+       gui_id = -1;
+       keyframes = new KeyFrames(edl, this);
        keyframes->create_objects();
 }
 
@@ -57,7 +58,6 @@ Plugin::Plugin(EDL *edl, Track *track, const char *title)
 Plugin::Plugin(EDL *edl, PluginSet *plugin_set, const char *title)
  : Edit(edl, plugin_set)
 {
-       is_plugin = 1;
        this->track = plugin_set->track;
        this->plugin_set = plugin_set;
        strcpy(this->title, title);
@@ -66,7 +66,8 @@ Plugin::Plugin(EDL *edl, PluginSet *plugin_set, const char *title)
        out = 1;
        show = 0;
        on = 1;
-       keyframes = new KeyFrames(edl, track);
+       gui_id = -1;
+       keyframes = new KeyFrames(edl, this);
        keyframes->create_objects();
 }
 
@@ -100,10 +101,7 @@ int Plugin::operator==(Edit& that)
 
 int Plugin::silence()
 {
-       if(plugin_type != PLUGIN_NONE)
-               return 0;
-       else
-               return 1;
+       return plugin_type == PLUGIN_NONE ? 1 : 0;
 }
 
 void Plugin::clear_keyframes(int64_t start, int64_t end)
@@ -112,25 +110,44 @@ void Plugin::clear_keyframes(int64_t start, int64_t end)
 }
 
 
-void Plugin::copy_from(Edit *edit)
+void Plugin::init(const char *title,
+       int64_t unit_position, int64_t unit_length, int plugin_type,
+       SharedLocation *shared_location, KeyFrame *default_keyframe)
+{
+       if( title ) strcpy(this->title, title);
+       if( shared_location ) this->shared_location = *shared_location;
+       this->plugin_type = plugin_type;
+       if( default_keyframe )
+               *this->keyframes->default_auto = *default_keyframe;
+       this->keyframes->default_auto->position = unit_position;
+       this->startproject = unit_position;
+       this->length = unit_length;
+}
+
+void Plugin::copy_base(Edit *edit)
 {
        Plugin *plugin = (Plugin*)edit;
 
        this->startsource = edit->startsource;
        this->startproject = edit->startproject;
        this->length = edit->length;
-
+       this->orig_id = edit->orig_id;
 
        this->plugin_type = plugin->plugin_type;
        this->in = plugin->in;
        this->out = plugin->out;
        this->show = plugin->show;
        this->on = plugin->on;
+// dont copy gui_id, it will be a duplicate ref
 // Should reconfigure this based on where the first track is now.
        this->shared_location = plugin->shared_location;
        strcpy(this->title, plugin->title);
+}
 
-       copy_keyframes(plugin);
+void Plugin::copy_from(Edit *edit)
+{
+       copy_base(edit);
+       copy_keyframes((Plugin*)edit);
 }
 
 void Plugin::copy_keyframes(Plugin *plugin)
@@ -160,6 +177,7 @@ void Plugin::synchronize_params(Edit *edit)
        this->in = plugin->in;
        this->out = plugin->out;
        this->show = plugin->show;
+       this->gui_id = plugin->gui_id;
        this->on = plugin->on;
        strcpy(this->title, plugin->title);
        copy_keyframes(plugin);
@@ -198,56 +216,50 @@ void Plugin::equivalent_output(Edit *edit, int64_t *result)
        keyframes->equivalent_output(plugin->keyframes, startproject, result);
 }
 
-
-
-int Plugin::is_synthesis(int64_t position,
-               int direction)
+const char* Plugin::type_to_text(int type)
 {
-       switch(plugin_type)
-       {
-               case PLUGIN_STANDALONE:
-               {
-                       if(!track)
-                       {
-                               printf("Plugin::is_synthesis track not defined\n");
-                               return 0;
-                       }
-
+       switch( type ) {
+        case PLUGIN_STANDALONE:    return _("standalone");
+        case PLUGIN_SHAREDPLUGIN:  return _("shared plugin");
+        case PLUGIN_SHAREDMODULE:  return _("shared module");
+       }
+       return _("none");
+}
 
-                       PluginServer *plugin_server = MWindow::scan_plugindb(title,
-                               track->data_type);
-//printf("Plugin::is_synthesis %d %p %d\n", __LINE__, plugin_server, plugin_server->get_synthesis());
-//plugin_server->dump();
-                       return plugin_server->get_synthesis();
-                       break;
+int Plugin::is_synthesis(int64_t position, int direction, int depth)
+{
+       if( depth > 255 ) {
+               printf("Plugin::is_synthesis %d: depth range limit, type=%s, title=%s\n",
+                       __LINE__, type_to_text(plugin_type), title);
+               return 0;
+       }
+       switch( plugin_type ) {
+       case PLUGIN_STANDALONE: {
+               if( !track ) {
+                       printf("Plugin::is_synthesis track not defined\n");
+                       return 0;
                }
+               PluginServer *plugin_server = MWindow::scan_plugindb(title, track->data_type);
+               return plugin_server->get_synthesis(); }
 
 // Dereference real plugin and descend another level
-               case PLUGIN_SHAREDPLUGIN:
-               {
-                       int real_module_number = shared_location.module;
-                       int real_plugin_number = shared_location.plugin;
-                       Track *track = edl->tracks->number(real_module_number);
+       case PLUGIN_SHAREDPLUGIN: {
+               int real_module_number = shared_location.module;
+               int real_plugin_number = shared_location.plugin;
+               Track *track = edl->tracks->number(real_module_number);
 // Get shared plugin from master track
-                       Plugin *plugin = track->get_current_plugin(position,
-                               real_plugin_number,
-                               direction,
-                               0,
-                               0);
-
-                       if(plugin)
-                               return plugin->is_synthesis(position, direction);
-                       break;
-               }
+               Plugin *plugin = track->get_current_plugin(position,
+                       real_plugin_number, direction, 0, 0);
+
+               if(plugin)
+                       return plugin->is_synthesis(position, direction, depth+1);
+               break; }
 
 // Dereference the real track and descend
-               case PLUGIN_SHAREDMODULE:
-               {
-                       int real_module_number = shared_location.module;
-                       Track *track = edl->tracks->number(real_module_number);
-                       return track->is_synthesis(position, direction);
-                       break;
-               }
+       case PLUGIN_SHAREDMODULE: {
+               int real_module_number = shared_location.module;
+               Track *track = edl->tracks->number(real_module_number);
+               return track->is_synthesis(position, direction, depth+1); }
        }
        return 0;
 }
@@ -280,19 +292,6 @@ int Plugin::identical(Plugin *that)
                        ((KeyFrame*)that->keyframes->default_auto)));
 }
 
-int Plugin::identical_location(Plugin *that)
-{
-       if(!plugin_set || !plugin_set->track) return 0;
-       if(!that->plugin_set || !that->plugin_set->track) return 0;
-
-       if(plugin_set->track->number_of() == that->plugin_set->track->number_of() &&
-               plugin_set->get_number() == that->plugin_set->get_number() &&
-               startproject == that->startproject) return 1;
-
-       return 0;
-
-}
-
 int Plugin::keyframe_exists(KeyFrame *ptr)
 {
        for(KeyFrame *current = (KeyFrame*)keyframes->first;
@@ -579,8 +578,8 @@ void Plugin::shift(int64_t difference)
 
 void Plugin::dump(FILE *fp)
 {
-       fprintf(fp,"    PLUGIN: type=%d title=\"%s\" on=%d track=%d plugin=%d\n",
-               plugin_type, title, on, shared_location.module, shared_location.plugin);
+       fprintf(fp,"    PLUGIN: type=%d, id %d, orig_id %d, title=\"%s\" on=%d track=%d plugin=%d gui_id=%d\n",
+               plugin_type, id, orig_id, title, on, shared_location.module, shared_location.plugin, gui_id);
        fprintf(fp,"    startproject %jd length %jd\n", startproject, length);
 
        keyframes->dump(fp);