Another not-quite-there-but-better commit.
[ardour.git] / libs / ardour / ladspa_plugin.cc
index ba944f3c08f3192f9e1fb93feacc210dc1bfa28c..42a593afd96da4389fca335f7af8ac1a71781ca4 100644 (file)
@@ -136,8 +136,6 @@ LadspaPlugin::init (void *mod, uint32_t index, nframes_t rate)
                }
        }
 
-       Plugin::setup_controls ();
-
        latency_compute_run ();
 }
 
@@ -195,6 +193,7 @@ LadspaPlugin::default_value (uint32_t port)
        float ret = 0.0f;
        bool bounds_given = false;
        bool sr_scaling = false;
+       bool earlier_hint = false;
 
        /* defaults - case 1 */
        
@@ -203,6 +202,7 @@ LadspaPlugin::default_value (uint32_t port)
                        ret = prh[port].LowerBound;
                        bounds_given = true;
                        sr_scaling = true;
+                       earlier_hint = true;
                }
                
                /* FIXME: add support for logarithmic defaults */
@@ -211,33 +211,41 @@ LadspaPlugin::default_value (uint32_t port)
                        ret = prh[port].LowerBound * 0.75f + prh[port].UpperBound * 0.25f;
                        bounds_given = true;
                        sr_scaling = true;
+                       earlier_hint = true;
                }
                else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(prh[port].HintDescriptor)) {
                        ret = prh[port].LowerBound * 0.50f + prh[port].UpperBound * 0.50f;
                        bounds_given = true;
                        sr_scaling = true;
+                       earlier_hint = true;
                }
                else if (LADSPA_IS_HINT_DEFAULT_HIGH(prh[port].HintDescriptor)) {
                        ret = prh[port].LowerBound * 0.25f + prh[port].UpperBound * 0.75f;
                        bounds_given = true;
                        sr_scaling = true;
+                       earlier_hint = true;
                }
                else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(prh[port].HintDescriptor)) {
                        ret = prh[port].UpperBound;
                        bounds_given = true;
                        sr_scaling = true;
+                       earlier_hint = true;
                }
                else if (LADSPA_IS_HINT_DEFAULT_0(prh[port].HintDescriptor)) {
                        ret = 0.0f;
+                       earlier_hint = true;
                }
                else if (LADSPA_IS_HINT_DEFAULT_1(prh[port].HintDescriptor)) {
                        ret = 1.0f;
+                       earlier_hint = true;
                }
                else if (LADSPA_IS_HINT_DEFAULT_100(prh[port].HintDescriptor)) {
                        ret = 100.0f;
+                       earlier_hint = true;
                }
                else if (LADSPA_IS_HINT_DEFAULT_440(prh[port].HintDescriptor)) {
                        ret = 440.0f;
+                       earlier_hint = true;
                }
                else {
                        /* no hint found */
@@ -290,7 +298,7 @@ LadspaPlugin::default_value (uint32_t port)
        
        /* defaults - case 5 */
                
-       if (LADSPA_IS_HINT_SAMPLE_RATE(prh[port].HintDescriptor)) {
+       if (LADSPA_IS_HINT_SAMPLE_RATE(prh[port].HintDescriptor) && !earlier_hint) {
                if (bounds_given) {
                        if (sr_scaling) {
                                ret *= sample_rate;
@@ -308,11 +316,13 @@ LadspaPlugin::set_parameter (uint32_t which, float val)
 {
        if (which < descriptor->PortCount) {
                shadow_data[which] = (LADSPA_Data) val;
-               ParameterChanged (which, val); /* EMIT SIGNAL */
+#if 0
+               ParameterChanged (ParamID(PluginAutomation, which), val); /* EMIT SIGNAL */
 
                if (which < parameter_count() && controls[which]) {
                        controls[which]->Changed ();
                }
+#endif
                
        } else {
                warning << string_compose (_("illegal parameter number used with plugin \"%1\". This may"
@@ -481,20 +491,23 @@ LadspaPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& des
        return 0;
 }
 
-
 string
-LadspaPlugin::describe_parameter (uint32_t which)
+LadspaPlugin::describe_parameter (ParamID which)
 {
-       if (which < parameter_count()) {
-               return port_names()[which];
+       if (which.type() == PluginAutomation && which.id() < parameter_count()) {
+               return port_names()[which.id()];
        } else {
                return "??";
        }
 }
 
 ARDOUR::nframes_t
-LadspaPlugin::latency () const
+LadspaPlugin::signal_latency () const
 {
+       if (_user_latency) {
+               return _user_latency;
+       }
+
        if (latency_control_port) {
                return (nframes_t) floor (*latency_control_port);
        } else {
@@ -502,16 +515,16 @@ LadspaPlugin::latency () const
        }
 }
 
-set<uint32_t>
+set<ParamID>
 LadspaPlugin::automatable () const
 {
-       set<uint32_t> ret;
+       set<ParamID> ret;
 
        for (uint32_t i = 0; i < parameter_count(); ++i){
                if (LADSPA_IS_PORT_INPUT(port_descriptor (i)) && 
                    LADSPA_IS_PORT_CONTROL(port_descriptor (i))){
                        
-                       ret.insert (ret.end(), i);
+                       ret.insert (ret.end(), ParamID(PluginAutomation, i));
                }
        }
 
@@ -526,7 +539,7 @@ LadspaPlugin::connect_and_run (BufferSet& bufs, uint32_t& in_index, uint32_t& ou
 
        then = get_cycles ();
 
-       const uint32_t nbufs = bufs.count().get(DataType::AUDIO);
+       const uint32_t nbufs = bufs.count().n_audio();
 
        while (port_index < parameter_count()) {
                if (LADSPA_IS_PORT_AUDIO (port_descriptor(port_index))) {