Remove code related to capture-offset.
[ardour.git] / libs / ardour / session_click.cc
index 872828e57ecf64df2e481f2f31865508d0dfa9ae..b4b5283fd855d271532615f3aaf61e03625a73d7 100644 (file)
@@ -31,7 +31,7 @@
 
 #include <sndfile.h>
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -40,11 +40,24 @@ using namespace PBD;
 Pool Click::pool ("click", sizeof (Click), 1024);
 
 void
-Session::click (framepos_t start, framecnt_t nframes)
+Session::add_click (samplepos_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 (samplepos_t start, samplecnt_t nframes)
 {
        vector<TempoMap::BBTPoint> points;
-       Sample *buf;
-       framecnt_t click_distance;
+       samplecnt_t click_distance;
 
        if (_click_io == 0) {
                return;
@@ -62,14 +75,20 @@ Session::click (framepos_t start, framecnt_t nframes)
                return;
        }
 
+       if (_click_rec_only && !actively_recording()) {
+               return;
+       }
+
        start -= _worst_track_latency;
+#ifdef MIXBUS
+       if (_master_out) {
+               start -= _master_out->signal_latency (); // delay signal by mixbus' internal latency
+       }
+#endif
        /* start could be negative at this point */
-       const framepos_t end = start + nframes;
+       const samplepos_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();
+       start = max (start, (samplepos_t) 0);
 
        _tempo_map->get_grid (points, start, end);
 
@@ -80,28 +99,40 @@ Session::click (framepos_t start, framecnt_t nframes)
        for (vector<TempoMap::BBTPoint>::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).sample, 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).sample, false);
                        }
                        break;
                }
        }
 
   run_clicks:
+       clickm.release ();
+       run_click (start, nframes);
+}
+
+void
+Session::run_click (samplepos_t start, samplepos_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<Click*>::iterator i = clicks.begin(); i != clicks.end(); ) {
 
-               framecnt_t copy;
-               framecnt_t internal_offset;
+               samplecnt_t copy;
+               samplecnt_t internal_offset;
                Click *clk;
 
                clk = *i;
@@ -133,12 +164,12 @@ Session::click (framepos_t start, framecnt_t nframes)
                }
        }
 
-       _click_gain->run (bufs, 0, 0, nframes, false);
+       _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;
@@ -233,5 +264,5 @@ Session::clear_clicks ()
        }
 
        clicks.clear ();
-       _clicks_cleared = _transport_frame;
+       _clicks_cleared = _transport_sample;
 }