X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fsession_click.cc;h=3f3976a944508959353f9ccbcafa397f594a5249;hb=dec10f2f3c6fffe27e72243d9bf36713d8f084f9;hp=d5a3bc5e4213d54ce5e251addac1c8377c0077a6;hpb=355183f1abea75d8fab0926cd7e7130796574cb0;p=ardour.git diff --git a/libs/ardour/session_click.cc b/libs/ardour/session_click.cc index d5a3bc5e42..3f3976a944 100644 --- a/libs/ardour/session_click.cc +++ b/libs/ardour/session_click.cc @@ -20,82 +20,126 @@ #include #include -#include "ardour/ardour.h" +#include "ardour/amp.h" #include "ardour/audio_buffer.h" #include "ardour/buffer_set.h" #include "ardour/click.h" #include "ardour/io.h" #include "ardour/session.h" #include "ardour/tempo.h" +#include "ardour/types.h" #include -#include "i18n.h" +#include "pbd/i18n.h" using namespace std; using namespace ARDOUR; using namespace PBD; -Pool Click::pool ("click", sizeof (Click), 128); +Pool Click::pool ("click", sizeof (Click), 1024); void -Session::click (framepos_t start, framecnt_t nframes) +Session::add_click (samplepos_t pos, bool emphasis) { - TempoMap::BBTPointList::const_iterator points_begin; - TempoMap::BBTPointList::const_iterator points_end; - Sample *buf; + 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 (samplepos_t cycle_start, samplecnt_t nframes) +{ + vector points; // TODO use mempool allocator if (_click_io == 0) { return; } - Glib::RWLock::WriterLock clickm (click_lock, Glib::TRY_LOCK); + /* transport_frame is audible-frame (what you hear, + * incl output latency). So internally we're ahead, + * we need to prepare frames that the user will hear + * in "output latency's" worth of time. + */ + samplecnt_t offset = _click_io->connected_latency (true); + + Glib::Threads::RWLock::WriterLock clickm (click_lock, Glib::Threads::TRY_LOCK); + + /* how far have we moved since the last time the clicks got cleared */ + const samplecnt_t click_distance = cycle_start + offset - _clicks_cleared; - if (!clickm.locked() || _transport_speed != 1.0 || !_clicking || click_data == 0) { + if (!clickm.locked() || !_clicking || click_data == 0 || ((click_distance + nframes) < 0)) { _click_io->silence (nframes); return; } - const framepos_t end = start + nframes; + if (_click_rec_only && !actively_recording()) { + return; + } - BufferSet& bufs = get_scratch_buffers(ChanCount(DataType::AUDIO, 1)); - buf = bufs.get_audio(0).data(); - _tempo_map->get_grid (points_begin, points_end, start, end); + /* range to check for clicks */ + samplepos_t start = cycle_start + offset; + const samplepos_t end = start + nframes; + /* correct start, potentially */ + start = max (start, (samplepos_t) 0); - if (distance (points_begin, points_end) == 0) { + if (end > start) { + _tempo_map->get_grid (points, start, end); + } + + if (distance (points.begin(), points.end()) == 0) { goto run_clicks; } - for (TempoMap::BBTPointList::const_iterator i = points_begin; i != points_end; ++i) { + for (vector::iterator i = points.begin(); i != points.end(); ++i) { switch ((*i).beat) { case 1: - if (click_emphasis_data) { - clicks.push_back (new Click ((*i).frame, click_emphasis_length, click_emphasis_data)); - } + add_click ((*i).sample, true); break; - default: - if (click_emphasis_data == 0 || (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 ?? (*i).beat !=1 must be true here + add_click ((*i).sample, false); } break; } - } run_clicks: + clickm.release (); + run_click (cycle_start, nframes); +} + +void +Session::run_click (samplepos_t start, samplepos_t nframes) +{ + Glib::Threads::RWLock::ReaderLock clickm (click_lock, Glib::Threads::TRY_LOCK); + + /* align to output */ + start += _click_io->connected_latency (true); + + 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(); ) { - framecnt_t copy; - framecnt_t internal_offset; + samplecnt_t copy; + samplecnt_t internal_offset; Click *clk; - list::iterator next; clk = *i; - next = i; - ++next; if (clk->start < start) { internal_offset = 0; @@ -118,18 +162,18 @@ Session::click (framepos_t start, framecnt_t nframes) if (clk->offset >= clk->duration) { delete clk; - clicks.erase (i); + i = clicks.erase (i); + } else { + ++i; } - - - i = next; } + _click_gain->run (bufs, 0, 0, 1.0, nframes, false); _click_io->copy_to_outputs (bufs, DataType::AUDIO, nframes, 0); } void -Session::setup_click_sounds (Sample** data, Sample const * default_data, framecnt_t* length, framecnt_t default_length, string const & path) +Session::setup_click_sounds (Sample** data, Sample const * default_data, samplecnt_t* length, samplecnt_t default_length, string const & path) { if (*data != default_data) { delete[] *data; @@ -217,11 +261,12 @@ Session::setup_click_sounds (int which) void Session::clear_clicks () { - Glib::RWLock::WriterLock lm (click_lock); + Glib::Threads::RWLock::WriterLock lm (click_lock); for (Clicks::iterator i = clicks.begin(); i != clicks.end(); ++i) { delete *i; } clicks.clear (); + _clicks_cleared = _transport_sample; }