Fix code style
[ardour.git] / libs / ardour / plugin_insert.cc
index 21bc6b5d3d3d2b67cfb058bc7abfb31896add240..7ce8ea547f6524530aa2668e08ffce94345f8b8c 100644 (file)
@@ -236,24 +236,6 @@ PluginInsert::del_sidechain ()
        return true;
 }
 
-void
-PluginInsert::set_sidechain_latency (uint32_t capture, uint32_t playback)
-{
-       if (_sidechain &&
-                       (_sc_playback_latency != playback || _sc_capture_latency != capture)) {
-               _sc_capture_latency = capture;
-               _sc_playback_latency = playback;
-               LatencyRange pl; pl.min = pl.max = playback;
-               LatencyRange cl; cl.min = cl.max = capture;
-               DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: capture %2 playback; %3\n", _sidechain->name (), capture, playback));
-               PortSet& ps (_sidechain->input ()->ports ());
-               for (PortSet::iterator p = ps.begin(); p != ps.end(); ++p) {
-                       p->set_private_latency_range (pl, true);
-                       p->set_private_latency_range (cl, false);
-               }
-       }
-}
-
 void
 PluginInsert::control_list_automation_state_changed (Evoral::Parameter which, AutoState s)
 {
@@ -404,10 +386,7 @@ bool
 PluginInsert::is_instrument() const
 {
        PluginInfoPtr pip = _plugins[0]->get_info();
-       if (pip->is_instrument ()) {
-               return true;
-       }
-       return pip->n_inputs.n_midi () != 0 && pip->n_outputs.n_audio () > 0 && pip->n_inputs.n_audio () == 0;
+       return (pip->is_instrument ());
 }
 
 bool
@@ -588,9 +567,57 @@ PluginInsert::set_block_size (pframes_t nframes)
        return ret;
 }
 
+void
+PluginInsert::automation_run (samplepos_t start, pframes_t nframes)
+{
+       // XXX does not work when rolling backwards
+       if (_loop_location && nframes > 0) {
+               const samplepos_t loop_start = _loop_location->start ();
+               const samplepos_t loop_end   = _loop_location->end ();
+               const samplecnt_t looplen    = loop_end - loop_start;
+
+               samplecnt_t remain = nframes;
+               samplepos_t start_pos = start;
+
+               while (remain > 0) {
+                       if (start_pos >= loop_end) {
+                               sampleoffset_t start_off = (start_pos - loop_start) % looplen;
+                               start_pos = loop_start + start_off;
+                       }
+                       samplecnt_t move = std::min ((samplecnt_t)nframes, loop_end - start_pos);
+
+                       Automatable::automation_run (start_pos, move);
+                       remain -= move;
+                       start_pos += move;
+               }
+               return;
+       }
+       Automatable::automation_run (start, nframes);
+}
+
+bool
+PluginInsert::find_next_event (double now, double end, Evoral::ControlEvent& next_event, bool only_active) const
+{
+       bool rv = Automatable::find_next_event (now, end, next_event, only_active);
+
+       if (_loop_location && now < end) {
+               if (rv) {
+                       end = ceil (next_event.when);
+               }
+               const samplepos_t loop_end = _loop_location->end ();
+               assert (now < loop_end); // due to map_loop_range ()
+               if (end > loop_end) {
+                       next_event.when = loop_end;
+                       rv = true;
+               }
+       }
+       return rv;
+}
+
 void
 PluginInsert::activate ()
 {
+       _timing_stats.reset ();
        for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
                (*i)->activate ();
        }
@@ -612,6 +639,7 @@ PluginInsert::activate ()
 void
 PluginInsert::deactivate ()
 {
+       _timing_stats.reset ();
        Processor::deactivate ();
 
        for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
@@ -1178,6 +1206,7 @@ PluginInsert::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sa
        }
 
        if (_pending_active) {
+               _timing_stats.start ();
                /* run as normal if we are active or moving from inactive to active */
 
                if (_session.transport_rolling() || _session.bounce_processing()) {
@@ -1186,8 +1215,10 @@ 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());
                }
+               _timing_stats.update ();
 
        } 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);
@@ -1215,6 +1246,9 @@ PluginInsert::automate_and_run (BufferSet& bufs, samplepos_t start, samplepos_t
                return;
        }
 
+       /* map start back into loop-range, adjust end */
+       map_loop_range (start, end);
+
        if (!find_next_event (start, end, next_event) || _plugins.front()->requires_fixed_sized_buffers()) {
 
                /* no events have a time within the relevant range */
@@ -1233,6 +1267,8 @@ PluginInsert::automate_and_run (BufferSet& bufs, samplepos_t start, samplepos_t
                offset += cnt;
                start += cnt;
 
+               map_loop_range (start, end);
+
                if (!find_next_event (start, end, next_event)) {
                        break;
                }
@@ -3092,6 +3128,15 @@ PluginInsert::end_touch (uint32_t param_id)
        }
 }
 
+bool
+PluginInsert::get_stats (uint64_t& min, uint64_t& max, double& avg, double& dev) const
+{
+       /* TODO: consider taking a try/lock: Don't run concurrently with
+        * TimingStats::update, TimingStats::reset.
+        */
+       return _timing_stats.get_stats (min, max, avg, dev);
+}
+
 std::ostream& operator<<(std::ostream& o, const ARDOUR::PluginInsert::Match& m)
 {
        switch (m.method) {