X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fplugin_insert.cc;h=205262ab4c56e0edac9af322c2295b148b8484ba;hb=736b6a3e573b59fd83eed8af6f86811a874449fb;hp=6b733ee1d139a49158a7c8946d212db88bab57cc;hpb=dee990103a1fb607ff401ec7c56e8c241074ffb5;p=ardour.git diff --git a/libs/ardour/plugin_insert.cc b/libs/ardour/plugin_insert.cc index 6b733ee1d1..205262ab4c 100644 --- a/libs/ardour/plugin_insert.cc +++ b/libs/ardour/plugin_insert.cc @@ -83,6 +83,7 @@ PluginInsert::PluginInsert (Session& s, boost::shared_ptr plug) , _maps_from_state (false) , _latency_changed (false) , _bypass_port (UINT32_MAX) + , _stat_reset (0) { /* the first is the master */ @@ -236,24 +237,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) { @@ -264,7 +247,7 @@ PluginInsert::control_list_automation_state_changed (Evoral::Parameter which, Au = boost::dynamic_pointer_cast(control (which)); if (c && s != Off) { - _plugins[0]->set_parameter (which.id(), c->list()->eval (_session.transport_frame())); + _plugins[0]->set_parameter (which.id(), c->list()->eval (_session.transport_sample())); } } @@ -395,7 +378,7 @@ PluginInsert::has_no_audio_inputs() const return _plugins[0]->get_info()->n_inputs.n_audio() == 0; } -framecnt_t +samplecnt_t PluginInsert::plugin_latency () const { return _plugins.front()->signal_latency (); } @@ -404,10 +387,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 @@ -492,7 +472,11 @@ PluginInsert::create_automatable_parameters () if (Variant::type_is_numeric(desc.datatype)) { list = boost::shared_ptr(new AutomationList(param, desc)); } - add_control (boost::shared_ptr (new PluginPropertyControl(this, param, desc, list))); + boost::shared_ptr c (new PluginPropertyControl(this, param, desc, list)); + if (!Variant::type_is_numeric(desc.datatype)) { + c->set_flags (Controllable::Flag ((int)c->flags() | Controllable::NotAutomatable)); + } + add_control (c); } } @@ -584,9 +568,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 (); } @@ -608,6 +640,12 @@ PluginInsert::activate () void PluginInsert::deactivate () { +#ifdef MIXBUS + if (is_nonbypassable ()) { + return; + } +#endif + _timing_stats.reset (); Processor::deactivate (); for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { @@ -701,6 +739,18 @@ PluginInsert::bypassable_changed () BypassableChanged (); } +bool +PluginInsert::write_immediate_event (size_t size, const uint8_t* buf) +{ + bool rv = true; + for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { + if (!(*i)->write_immediate_event (size, buf)) { + rv = false; + } + } + return rv; +} + void PluginInsert::preset_load_set_value (uint32_t p, float v) { @@ -719,7 +769,7 @@ PluginInsert::preset_load_set_value (uint32_t p, float v) } void -PluginInsert::inplace_silence_unconnected (BufferSet& bufs, const PinMappings& out_map, framecnt_t nframes, framecnt_t offset) const +PluginInsert::inplace_silence_unconnected (BufferSet& bufs, const PinMappings& out_map, samplecnt_t nframes, samplecnt_t offset) const { // TODO optimize: store "unconnected" in a fixed set. // it only changes on reconfiguration. @@ -752,7 +802,7 @@ PluginInsert::inplace_silence_unconnected (BufferSet& bufs, const PinMappings& o } void -PluginInsert::connect_and_run (BufferSet& bufs, framepos_t start, framepos_t end, double speed, pframes_t nframes, framecnt_t offset, bool with_auto) +PluginInsert::connect_and_run (BufferSet& bufs, samplepos_t start, samplepos_t end, double speed, pframes_t nframes, samplecnt_t offset, bool with_auto) { // TODO: atomically copy maps & _no_inplace PinMappings in_map (_in_map); @@ -839,10 +889,10 @@ PluginInsert::connect_and_run (BufferSet& bufs, framepos_t start, framepos_t end } } - /* Calculate if, and how many frames we need to collect for analysis */ - framecnt_t collect_signal_nframes = (_signal_analysis_collect_nframes_max - + /* Calculate if, and how many samples we need to collect for analysis */ + samplecnt_t collect_signal_nframes = (_signal_analysis_collect_nframes_max - _signal_analysis_collected_nframes); - if (nframes < collect_signal_nframes) { // we might not get all frames now + if (nframes < collect_signal_nframes) { // we might not get all samples now collect_signal_nframes = nframes; } @@ -850,7 +900,7 @@ PluginInsert::connect_and_run (BufferSet& bufs, framepos_t start, framepos_t end // collect input //std::cerr << "collect input, bufs " << bufs.count().n_audio() << " count, " << bufs.available().n_audio() << " available" << std::endl; //std::cerr << " streams " << internal_input_streams().n_audio() << std::endl; - //std::cerr << "filling buffer with " << collect_signal_nframes << " frames at " << _signal_analysis_collected_nframes << 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()); @@ -1126,9 +1176,12 @@ PluginInsert::bypass (BufferSet& bufs, pframes_t nframes) } void -PluginInsert::silence (framecnt_t nframes, framepos_t start_frame) +PluginInsert::silence (samplecnt_t nframes, samplepos_t start_sample) { + automation_run (start_sample, nframes); // evaluate automation only + if (!active ()) { + // XXX delaybuffers need to be offset by nframes return; } @@ -1140,37 +1193,46 @@ PluginInsert::silence (framecnt_t nframes, framepos_t start_frame) #ifdef MIXBUS if (is_channelstrip ()) { if (_configured_in.n_audio() > 0) { - _plugins.front()->connect_and_run (_session.get_scratch_buffers (maxbuf, true), start_frame, start_frame + nframes, 1.0, in_map, out_map, nframes, 0); + _plugins.front()->connect_and_run (_session.get_scratch_buffers (maxbuf, true), start_sample, start_sample + nframes, 1.0, in_map, out_map, nframes, 0); } } else #endif for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { - (*i)->connect_and_run (_session.get_scratch_buffers (maxbuf, true), start_frame, start_frame + nframes, 1.0, in_map, out_map, nframes, 0); + (*i)->connect_and_run (_session.get_scratch_buffers (maxbuf, true), start_sample, start_sample + nframes, 1.0, in_map, out_map, nframes, 0); } } void -PluginInsert::run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, double speed, pframes_t nframes, bool) +PluginInsert::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes, bool) { if (_sidechain) { // collect sidechain input for complete cycle (!) // TODO we need delaylines here for latency compensation - _sidechain->run (bufs, start_frame, end_frame, speed, nframes, true); + _sidechain->run (bufs, start_sample, end_sample, speed, nframes, true); + } + + if (g_atomic_int_compare_and_exchange (&_stat_reset, 1, 0)) { + _timing_stats.reset (); } 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()) { - automate_and_run (bufs, start_frame, end_frame, speed, nframes); + automate_and_run (bufs, start_sample, end_sample, speed, nframes); } else { Glib::Threads::Mutex::Lock lm (control_lock(), Glib::Threads::TRY_LOCK); - connect_and_run (bufs, start_frame, end_frame, speed, nframes, 0, lm.locked()); + 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); - automation_run (start_frame, nframes); + automation_run (start_sample, nframes); // evaluate automation only _delaybuffers.flush (); } @@ -1182,10 +1244,10 @@ PluginInsert::run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame } void -PluginInsert::automate_and_run (BufferSet& bufs, framepos_t start, framepos_t end, double speed, pframes_t nframes) +PluginInsert::automate_and_run (BufferSet& bufs, samplepos_t start, samplepos_t end, double speed, pframes_t nframes) { Evoral::ControlEvent next_event (0, 0.0f); - framecnt_t offset = 0; + samplecnt_t offset = 0; Glib::Threads::Mutex::Lock lm (control_lock(), Glib::Threads::TRY_LOCK); @@ -1194,6 +1256,9 @@ PluginInsert::automate_and_run (BufferSet& bufs, framepos_t start, framepos_t en 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 */ @@ -1204,7 +1269,7 @@ PluginInsert::automate_and_run (BufferSet& bufs, framepos_t start, framepos_t en while (nframes) { - framecnt_t cnt = min (((framecnt_t) ceil (next_event.when) - start), (framecnt_t) nframes); + samplecnt_t cnt = min (((samplecnt_t) ceil (next_event.when) - start), (samplecnt_t) nframes); connect_and_run (bufs, start, start + cnt, speed, cnt, offset, true); // XXX (start + cnt) * speed @@ -1212,6 +1277,8 @@ PluginInsert::automate_and_run (BufferSet& bufs, framepos_t start, framepos_t en offset += cnt; start += cnt; + map_loop_range (start, end); + if (!find_next_event (start, end, next_event)) { break; } @@ -1494,6 +1561,10 @@ bool PluginInsert::is_channelstrip () const { return _plugins.front()->is_channelstrip(); } +bool +PluginInsert::is_nonbypassable () const { + return _plugins.front()->is_nonbypassable (); +} #endif bool @@ -2337,15 +2408,9 @@ PluginInsert::automatic_can_support_io_configuration (ChanCount const & inx, Cha XMLNode& -PluginInsert::get_state () -{ - return state (true); -} - -XMLNode& -PluginInsert::state (bool full) +PluginInsert::state () { - XMLNode& node = Processor::state (full); + XMLNode& node = Processor::state (); node.set_property("type", _plugins[0]->state_node_name()); node.set_property("unique-id", _plugins[0]->unique_id()); @@ -2370,7 +2435,7 @@ PluginInsert::state (bool full) node.add_child_nocopy (* _thru_map.state ("ThruMap")); if (_sidechain) { - node.add_child_nocopy (_sidechain->state (full)); + node.add_child_nocopy (_sidechain->get_state ()); } _plugins[0]->set_insert_id(this->id()); @@ -2805,7 +2870,7 @@ PluginInsert::describe_parameter (Evoral::Parameter param) return Automatable::describe_parameter(param); } -ARDOUR::framecnt_t +ARDOUR::samplecnt_t PluginInsert::signal_latency() const { if (!_pending_active) { @@ -2964,7 +3029,7 @@ PluginInsert::get_impulse_analysis_plugin() } void -PluginInsert::collect_signal_for_analysis (framecnt_t nframes) +PluginInsert::collect_signal_for_analysis (samplecnt_t nframes) { // called from outside the audio thread, so this should be safe // only do audio as analysis is (currently) only for audio plugins @@ -3062,8 +3127,8 @@ PluginInsert::start_touch (uint32_t param_id) { boost::shared_ptr ac = automation_control (Evoral::Parameter (PluginAutomation, 0, param_id)); if (ac) { - // ToDo subtract _plugin_signal_latency from audible_frame() when rolling, assert > 0 - ac->start_touch (session().audible_frame()); + // ToDo subtract _plugin_signal_latency from audible_sample() when rolling, assert > 0 + ac->start_touch (session().audible_sample()); } } @@ -3072,11 +3137,26 @@ PluginInsert::end_touch (uint32_t param_id) { boost::shared_ptr ac = automation_control (Evoral::Parameter (PluginAutomation, 0, param_id)); if (ac) { - // ToDo subtract _plugin_signal_latency from audible_frame() when rolling, assert > 0 - ac->stop_touch (true, session().audible_frame()); + // ToDo subtract _plugin_signal_latency from audible_sample() when rolling, assert > 0 + ac->stop_touch (session().audible_sample()); } } +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); +} + +void +PluginInsert::clear_stats () +{ + g_atomic_int_set (&_stat_reset, 1); +} + std::ostream& operator<<(std::ostream& o, const ARDOUR::PluginInsert::Match& m) { switch (m.method) {