X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fsession_click.cc;h=abfbaecfcd69f03b5da7e9ded5ad2df007722f60;hb=d54d26e822661e76a56fe7d8bb371f1b3944e066;hp=d5a3bc5e4213d54ce5e251addac1c8377c0077a6;hpb=355183f1abea75d8fab0926cd7e7130796574cb0;p=ardour.git diff --git a/libs/ardour/session_click.cc b/libs/ardour/session_click.cc index d5a3bc5e42..abfbaecfcd 100644 --- a/libs/ardour/session_click.cc +++ b/libs/ardour/session_click.cc @@ -20,13 +20,14 @@ #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 @@ -36,7 +37,7 @@ 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) @@ -44,6 +45,7 @@ Session::click (framepos_t start, framecnt_t nframes) TempoMap::BBTPointList::const_iterator points_begin; TempoMap::BBTPointList::const_iterator points_end; Sample *buf; + framecnt_t click_distance; if (_click_io == 0) { return; @@ -51,15 +53,25 @@ Session::click (framepos_t start, framecnt_t nframes) Glib::RWLock::WriterLock clickm (click_lock, Glib::TRY_LOCK); - if (!clickm.locked() || _transport_speed != 1.0 || !_clicking || click_data == 0) { + /* how far have we moved since the last time the clicks got cleared + */ + + click_distance = start - _clicks_cleared; + + if (!clickm.locked() || _transport_speed != 1.0 || !_clicking || click_data == 0 || ((click_distance + nframes) < _worst_track_latency)) { _click_io->silence (nframes); return; } + start -= _worst_track_latency; + /* start could be negative at this point */ const framepos_t end = start + 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_begin, points_end, start, end); if (distance (points_begin, points_end) == 0) { @@ -80,7 +92,6 @@ Session::click (framepos_t start, framecnt_t nframes) } break; } - } run_clicks: @@ -91,11 +102,8 @@ Session::click (framepos_t start, framecnt_t nframes) framecnt_t copy; framecnt_t internal_offset; Click *clk; - list::iterator next; clk = *i; - next = i; - ++next; if (clk->start < start) { internal_offset = 0; @@ -111,20 +119,20 @@ Session::click (framepos_t start, framecnt_t nframes) } copy = min (clk->duration - clk->offset, nframes - internal_offset); - + memcpy (buf + internal_offset, &clk->data[clk->offset], copy * sizeof (Sample)); - + clk->offset += copy; if (clk->offset >= clk->duration) { delete clk; - clicks.erase (i); + i = clicks.erase (i); + } else { + ++i; } - - - i = next; } + _click_gain->run (bufs, 0, 0, nframes, false); _click_io->copy_to_outputs (bufs, DataType::AUDIO, nframes, 0); } @@ -224,4 +232,5 @@ Session::clear_clicks () } clicks.clear (); + _clicks_cleared = _transport_frame; }