midi-controller, support log parameters - fixes #5890
[ardour.git] / libs / ardour / plugin_insert.cc
index b191cf4890a8e2892d6ba29ee576e05693e90ba4..ae018fb2a3c53544c5e20034e4b13455b87d16ef 100644 (file)
@@ -346,9 +346,8 @@ PluginInsert::connect_and_run (BufferSet& bufs, pframes_t nframes, framecnt_t of
                /* XXX: audio only */
                uint32_t first_idx = in_map.get (DataType::AUDIO, 0, &valid);
                if (valid) {
-                       Sample const * mono = bufs.get_audio (first_idx).data (offset);
                        for (uint32_t i = in_streams.n_audio(); i < natural_input_streams().n_audio(); ++i) {
-                               memcpy (bufs.get_audio (in_map.get (DataType::AUDIO, i, &valid)).data (offset), mono, sizeof (Sample) * nframes);
+                               bufs.get_audio(in_map.get (DataType::AUDIO, i, &valid)).read_from(bufs.get_audio(first_idx), nframes, offset, offset);
                        }
                }
        }
@@ -465,38 +464,31 @@ PluginInsert::run (BufferSet& bufs, framepos_t /*start_frame*/, framepos_t /*end
                }
 
        } else {
-               if (has_no_audio_inputs()) {
+               uint32_t in = input_streams ().n_audio ();
+               uint32_t out = output_streams().n_audio ();
+
+               if (has_no_audio_inputs() || in == 0) {
 
                        /* silence all (audio) outputs. Should really declick
                         * at the transitions of "active"
                         */
 
-                       uint32_t out = output_streams().n_audio ();
-
                        for (uint32_t n = 0; n < out; ++n) {
                                bufs.get_audio (n).silence (nframes);
                        }
 
-                       bufs.count().set_audio (out);
-
-               } else {
-
-                       /* does this need to be done with MIDI? it appears not */
+               } else if (out > in) {
 
-                       uint32_t in = input_streams ().n_audio ();
-                       uint32_t out = output_streams().n_audio ();
+                       /* not active, but something has make up for any channel count increase */
 
-                       if (out > in) {
-
-                               /* not active, but something has make up for any channel count increase */
-                               
-                               for (uint32_t n = out - in; n < out; ++n) {
-                                       memcpy (bufs.get_audio (n).data(), bufs.get_audio(in - 1).data(), sizeof (Sample) * nframes);
-                               }
+                       // TODO: option round-robin (n % in) or silence additional buffers ??
+                       // for now , simply replicate last buffer
+                       for (uint32_t n = in; n < out; ++n) {
+                               bufs.get_audio(n).read_from(bufs.get_audio(in - 1), nframes);
                        }
-
-                       bufs.count().set_audio (out);
                }
+
+               bufs.count().set_audio (out);
        }
 
        _active = _pending_active;
@@ -505,7 +497,6 @@ PluginInsert::run (BufferSet& bufs, framepos_t /*start_frame*/, framepos_t /*end
         * all buffers appropriately.
         */
 
-       bufs.set_is_silent (false);
 }
 
 void
@@ -651,6 +642,8 @@ bool
 PluginInsert::configure_io (ChanCount in, ChanCount out)
 {
        Match old_match = _match;
+       ChanCount old_in = input_streams ();
+       ChanCount old_out = output_streams ();
 
        /* set the matching method and number of plugins that we will use to meet this configuration */
        _match = private_can_support_io_configuration (in, out);
@@ -658,9 +651,12 @@ PluginInsert::configure_io (ChanCount in, ChanCount out)
                return false;
        }
 
-       /* a signal needs emitting if we start or stop splitting */
-       if (old_match.method != _match.method && (old_match.method == Split || _match.method == Split)) {
-               SplittingChanged (); /* EMIT SIGNAL */
+       if (  (old_match.method != _match.method && (old_match.method == Split || _match.method == Split))
+                       || old_in != in
+                       || old_out != out
+                       )
+       {
+               PluginIoReConfigure (); /* EMIT SIGNAL */
        }
 
        /* configure plugins */
@@ -715,6 +711,10 @@ PluginInsert::can_support_io_configuration (const ChanCount& in, ChanCount& out)
 PluginInsert::Match
 PluginInsert::private_can_support_io_configuration (ChanCount const & inx, ChanCount& out)
 {
+       if (_plugins.empty()) {
+               return Match();
+       }
+
        PluginInfoPtr info = _plugins.front()->get_info();
        ChanCount in; in += inx;
        midi_bypass.reset();
@@ -1184,6 +1184,10 @@ PluginInsert::PluginControl::PluginControl (PluginInsert* p, const Evoral::Param
        _logarithmic = desc.logarithmic;
        _sr_dependent = desc.sr_dependent;
        _toggled = desc.toggled;
+
+       if (desc.toggled) {
+               set_flags(Controllable::Toggle);
+       }
 }
 
 /** @param val `user' value */
@@ -1208,10 +1212,23 @@ double
 PluginInsert::PluginControl::internal_to_interface (double val) const
 {
        if (_logarithmic) {
+               /* some plugins have a log-scale range "0.."
+                * ideally we'd map the range down to infinity somehow :)
+                *
+                * one solution could be to use
+                *   val = exp(lower + log(range) * value);
+                *   (log(val) - lower) / range)
+                * This approach would require access to the actual range (ie
+                * Plugin::ParameterDescriptor) and also require handling
+                * of unbound ranges..
+                *
+                * currently an arbitrarly low number is assumed to represnt
+                * log(0) as hot-fix solution.
+                */
                if (val > 0) {
                        val = log (val);
                } else {
-                       val = 0;
+                       val = -8; // ~ -70dB = 20 * log10(exp(-8))
                }
        }
 
@@ -1222,7 +1239,12 @@ double
 PluginInsert::PluginControl::interface_to_internal (double val) const
 {
        if (_logarithmic) {
-               val = exp (val);
+               if (val <= -8) {
+                       /* see note in PluginInsert::PluginControl::internal_to_interface() */
+                       val= 0;
+               } else {
+                       val = exp (val);
+               }
        }
 
        return val;