Optimize plugin-processing for non-automated params
[ardour.git] / libs / ardour / plugin_insert.cc
index b24d065b5bc3ad275334d3e49244bbb449d12c1a..d7ae4da711fd1ce9a71f026b6b686d699617fc11 100644 (file)
@@ -589,7 +589,7 @@ PluginInsert::set_block_size (pframes_t nframes)
 }
 
 void
-PluginInsert::automation_run (samplepos_t start, pframes_t nframes)
+PluginInsert::automation_run (samplepos_t start, pframes_t nframes, bool only_active)
 {
        // XXX does not work when rolling backwards
        if (_loop_location && nframes > 0) {
@@ -607,13 +607,13 @@ PluginInsert::automation_run (samplepos_t start, pframes_t nframes)
                        }
                        samplecnt_t move = std::min ((samplecnt_t)nframes, loop_end - start_pos);
 
-                       Automatable::automation_run (start_pos, move);
+                       Automatable::automation_run (start_pos, move, only_active);
                        remain -= move;
                        start_pos += move;
                }
                return;
        }
-       Automatable::automation_run (start, nframes);
+       Automatable::automation_run (start, nframes, only_active);
 }
 
 bool
@@ -860,11 +860,11 @@ PluginInsert::connect_and_run (BufferSet& bufs, samplepos_t start, samplepos_t e
                                continue;
                        }
                        bool valid;
-                       uint32_t first_idx = in_map.at(0).get (*t, 0, &valid);
+                       uint32_t first_idx = in_map.p(0).get (*t, 0, &valid);
                        assert (valid && first_idx == 0); // check_inplace ensures this
                        /* copy the first stream's buffer contents to the others */
                        for (uint32_t i = 1; i < natural_input_streams ().get (*t); ++i) {
-                               uint32_t idx = in_map.at(0).get (*t, i, &valid);
+                               uint32_t idx = in_map.p(0).get (*t, i, &valid);
                                if (valid) {
                                        assert (idx == 0);
                                        bufs.get (*t, i).read_from (bufs.get (*t, first_idx), nframes, offset, offset);
@@ -880,6 +880,7 @@ PluginInsert::connect_and_run (BufferSet& bufs, samplepos_t start, samplepos_t e
 
        if (with_auto) {
 
+#if 0
                uint32_t n = 0;
 
                for (Controls::const_iterator li = controls().begin(); li != controls().end(); ++li, ++n) {
@@ -898,6 +899,21 @@ PluginInsert::connect_and_run (BufferSet& bufs, samplepos_t start, samplepos_t e
                                }
                        }
                }
+#else
+               boost::shared_ptr<ControlList> cl = _automated_controls.reader ();
+               for (ControlList::const_iterator ci = cl->begin(); ci != cl->end(); ++ci) {
+                       AutomationControl& c = *(ci->get());
+                       boost::shared_ptr<const Evoral::ControlList> clist (c.list());
+                       /* we still need to check for Touch and Latch */
+                       if (clist && (static_cast<AutomationList const&> (*clist)).automation_playback ()) {
+                               bool valid;
+                               const float val = c.list()->rt_safe_eval (start, valid);
+                               if (valid) {
+                                       c.set_value_unchecked(val);
+                               }
+                       }
+               }
+#endif
        }
 
        /* Calculate if, and how many samples we need to collect for analysis */
@@ -913,7 +929,7 @@ PluginInsert::connect_and_run (BufferSet& bufs, samplepos_t start, samplepos_t e
                //std::cerr << "               streams " << internal_input_streams().n_audio() << std::endl;
                //std::cerr << "filling buffer with " << collect_signal_nframes << " samples at " << _signal_analysis_collected_nframes << std::endl;
 
-               _signal_analysis_inputs.set_count(input_streams());
+               _signal_analysis_inputs.set_count (ChanCount (DataType::AUDIO, input_streams().n_audio()));
 
                for (uint32_t i = 0; i < input_streams().n_audio(); ++i) {
                        _signal_analysis_inputs.get_audio(i).read_from (
@@ -950,7 +966,7 @@ PluginInsert::connect_and_run (BufferSet& bufs, samplepos_t start, samplepos_t e
                        for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
                                for (uint32_t out = 0; out < natural_output_streams().get (*t); ++out) {
                                        bool valid;
-                                       uint32_t out_idx = out_map.at(pc).get (*t, out, &valid);
+                                       uint32_t out_idx = out_map.p(pc).get (*t, out, &valid);
                                        if (valid) {
                                                used_outputs.set (*t, out_idx, 1); // mark as used
                                        }
@@ -982,14 +998,14 @@ PluginInsert::connect_and_run (BufferSet& bufs, samplepos_t start, samplepos_t e
                for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
 
                        ARDOUR::ChanMapping i_in_map (natural_input_streams());
-                       ARDOUR::ChanMapping i_out_map (out_map.at(pc));
+                       ARDOUR::ChanMapping i_out_map (out_map.p(pc));
                        ARDOUR::ChanCount mapped;
 
                        /* map inputs sequentially */
                        for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
                                for (uint32_t in = 0; in < natural_input_streams().get (*t); ++in) {
                                        bool valid;
-                                       uint32_t in_idx = in_map.at(pc).get (*t, in, &valid);
+                                       uint32_t in_idx = in_map.p(pc).get (*t, in, &valid);
                                        uint32_t m = mapped.get (*t);
                                        if (valid) {
                                                inplace_bufs.get (*t, m).read_from (bufs.get (*t, in_idx), nframes, offset, offset);
@@ -1035,7 +1051,7 @@ PluginInsert::connect_and_run (BufferSet& bufs, samplepos_t start, samplepos_t e
                /* in-place processing */
                uint32_t pc = 0;
                for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
-                       if ((*i)->connect_and_run(bufs, start, end, speed, in_map.at(pc), out_map.at(pc), nframes, offset)) {
+                       if ((*i)->connect_and_run(bufs, start, end, speed, in_map.p(pc), out_map.p(pc), nframes, offset)) {
                                deactivate ();
                        }
                }
@@ -1048,7 +1064,7 @@ PluginInsert::connect_and_run (BufferSet& bufs, samplepos_t start, samplepos_t e
                //std::cerr << "       output, bufs " << bufs.count().n_audio() << " count,  " << bufs.available().n_audio() << " available" << std::endl;
                //std::cerr << "               streams " << internal_output_streams().n_audio() << std::endl;
 
-               _signal_analysis_outputs.set_count(output_streams());
+               _signal_analysis_outputs.set_count (ChanCount (DataType::AUDIO, output_streams().n_audio()));
 
                for (uint32_t i = 0; i < output_streams().n_audio(); ++i) {
                        _signal_analysis_outputs.get_audio(i).read_from(
@@ -1188,7 +1204,7 @@ PluginInsert::bypass (BufferSet& bufs, pframes_t nframes)
 void
 PluginInsert::silence (samplecnt_t nframes, samplepos_t start_sample)
 {
-       automation_run (start_sample, nframes); // evaluate automation only
+       automation_run (start_sample, nframes, true); // evaluate automation only
 
        if (!active ()) {
                // XXX delaybuffers need to be offset by nframes
@@ -1226,7 +1242,13 @@ PluginInsert::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sa
        }
 
        if (_pending_active) {
+#if defined MIXBUS && defined NDEBUG
+               if (!is_channelstrip ()) {
+                       _timing_stats.start ();
+               }
+#else
                _timing_stats.start ();
+#endif
                /* run as normal if we are active or moving from inactive to active */
 
                if (_session.transport_rolling() || _session.bounce_processing()) {
@@ -1235,14 +1257,20 @@ PluginInsert::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sa
                        Glib::Threads::Mutex::Lock lm (control_lock(), Glib::Threads::TRY_LOCK);
                        connect_and_run (bufs, start_sample, end_sample, speed, nframes, 0, lm.locked());
                }
+#if defined MIXBUS && defined NDEBUG
+               if (!is_channelstrip ()) {
+                       _timing_stats.update ();
+               }
+#else
                _timing_stats.update ();
+#endif
 
        } else {
                _timing_stats.reset ();
                // XXX should call ::silence() to run plugin(s) for consistent load.
                // We'll need to change this anyway when bypass can be automated
                bypass (bufs, nframes);
-               automation_run (start_sample, nframes); // evaluate automation only
+               automation_run (start_sample, nframes, true); // evaluate automation only
                _delaybuffers.flush ();
        }
 
@@ -2063,15 +2091,20 @@ PluginInsert::configure_io (ChanCount in, ChanCount out)
        _delaybuffers.configure (_configured_out, _plugins.front ()->max_latency ());
        _latency_changed = true;
 
-       // we don't know the analysis window size, so we must work with the
-       // current buffer size here. each request for data fills in these
-       // buffers and the analyser makes sure it gets enough data for the
-       // analysis window
-       session().ensure_buffer_set (_signal_analysis_inputs, in);
-       _signal_analysis_inputs.set_count (in);
+       /* we don't know the analysis window size, so we must work with the
+        * current buffer size here. each request for data fills in these
+        * buffers and the analyser makes sure it gets enough data for the
+        * analysis window. We also only analyze audio, so we can ignore
+        * MIDI buffers.
+        */
+       ChanCount cc_analysis_in (DataType::AUDIO, in.n_audio());
+       ChanCount cc_analysis_out (DataType::AUDIO, out.n_audio());
+
+       session().ensure_buffer_set (_signal_analysis_inputs, cc_analysis_in);
+       _signal_analysis_inputs.set_count (cc_analysis_in);
 
-       session().ensure_buffer_set (_signal_analysis_outputs, out);
-       _signal_analysis_outputs.set_count (out);
+       session().ensure_buffer_set (_signal_analysis_outputs, cc_analysis_out);
+       _signal_analysis_outputs.set_count (cc_analysis_out);
 
        // std::cerr << "set counts to i" << in.n_audio() << "/o" << out.n_audio() << std::endl;
 
@@ -3194,6 +3227,17 @@ PluginInsert::end_touch (uint32_t param_id)
        }
 }
 
+bool
+PluginInsert::provides_stats () const
+{
+#if defined MIXBUS && defined NDEBUG
+       if (is_channelstrip () || !display_to_user ()) {
+               return false;
+       }
+#endif
+       return true;
+}
+
 bool
 PluginInsert::get_stats (uint64_t& min, uint64_t& max, double& avg, double& dev) const
 {