From fcbed9c1dcb8490d35eeb274d8ef417c15ee7deb Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 17 Jan 2017 20:20:34 +0100 Subject: [PATCH] Split metronome methods into re-usable parts (for count-in) --- libs/ardour/ardour/session.h | 2 ++ libs/ardour/session_click.cc | 46 ++++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index fbd5412d66..b62229a03c 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -1896,6 +1896,8 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop void setup_click_sounds (Sample**, Sample const *, framecnt_t*, framecnt_t, std::string const &); void clear_clicks (); void click (framepos_t start, framecnt_t nframes); + void run_click (framepos_t start, framecnt_t nframes); + void add_click (framepos_t pos, bool emphasis); std::vector master_outs; diff --git a/libs/ardour/session_click.cc b/libs/ardour/session_click.cc index 9c67ebef86..08aa0cc446 100644 --- a/libs/ardour/session_click.cc +++ b/libs/ardour/session_click.cc @@ -39,11 +39,24 @@ using namespace PBD; Pool Click::pool ("click", sizeof (Click), 1024); +void +Session::add_click (framepos_t pos, bool emphasis) +{ + if (emphasis) { + if (click_emphasis_data && Config->get_use_click_emphasis () == true) { + clicks.push_back (new Click (pos, click_emphasis_length, click_emphasis_data)); + } else if (click_data && Config->get_use_click_emphasis () == false) { + clicks.push_back (new Click (pos, click_length, click_data)); + } + } else if (click_data) { + clicks.push_back (new Click (pos, click_length, click_data)); + } +} + void Session::click (framepos_t start, framecnt_t nframes) { vector points; - Sample *buf; framecnt_t click_distance; if (_click_io == 0) { @@ -68,9 +81,6 @@ Session::click (framepos_t start, framecnt_t nframes) /* correct start, potentially */ start = max (start, (framepos_t) 0); - BufferSet& bufs = get_scratch_buffers(ChanCount(DataType::AUDIO, 1)); - buf = bufs.get_audio(0).data(); - _tempo_map->get_grid (points, start, end); if (distance (points.begin(), points.end()) == 0) { @@ -80,22 +90,34 @@ Session::click (framepos_t start, framecnt_t nframes) for (vector::iterator i = points.begin(); i != points.end(); ++i) { switch ((*i).beat) { case 1: - if (click_emphasis_data && Config->get_use_click_emphasis () == true) { - clicks.push_back (new Click ((*i).frame, click_emphasis_length, click_emphasis_data)); - } else if (click_data && Config->get_use_click_emphasis () == false) { - clicks.push_back (new Click ((*i).frame, click_length, click_data)); - } + add_click ((*i).frame, true); break; - default: - if (click_emphasis_data == 0 || (Config->get_use_click_emphasis () == false) || (click_emphasis_data && (*i).beat != 1)) { - clicks.push_back (new Click ((*i).frame, click_length, click_data)); + if (click_emphasis_data == 0 || (Config->get_use_click_emphasis () == false) || (click_emphasis_data && (*i).beat != 1)) { // XXX why is this check needed ?? + add_click ((*i).frame, false); } break; } } run_clicks: + clickm.release (); + run_click (start, nframes); +} + +void +Session::run_click (framepos_t start, framepos_t nframes) +{ + Glib::Threads::RWLock::ReaderLock clickm (click_lock, Glib::Threads::TRY_LOCK); + + if (!clickm.locked() || click_data == 0) { + _click_io->silence (nframes); + return; + } + + Sample *buf; + BufferSet& bufs = get_scratch_buffers(ChanCount(DataType::AUDIO, 1)); + buf = bufs.get_audio(0).data(); memset (buf, 0, sizeof (Sample) * nframes); for (list::iterator i = clicks.begin(); i != clicks.end(); ) { -- 2.30.2