Change return type of Session::import_audiofiles to void as the int return value...
[ardour.git] / libs / ardour / session_click.cc
index d97d29cc1831e2d926da00fa324ad6f697ad6a01..7161de6d78fa6d2f84c6b823702ce79ebad3be40 100644 (file)
@@ -15,7 +15,6 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
 #include <list>
@@ -25,6 +24,7 @@
 #include <ardour/session.h>
 #include <ardour/tempo.h>
 #include <ardour/io.h>
+#include <ardour/buffer_set.h>
 
 #include <sndfile.h>
 
 
 using namespace std;
 using namespace ARDOUR;
+using namespace PBD;
 
 Pool Session::Click::pool ("click", sizeof (Click), 128);
 
 void
-Session::click (jack_nframes_t start, jack_nframes_t nframes, jack_nframes_t offset)
+Session::click (nframes_t start, nframes_t nframes, nframes_t offset)
 {
        TempoMap::BBTPointList *points;
-       jack_nframes_t end;
        Sample *buf;
-       vector<Sample*> bufs;
 
        if (_click_io == 0) {
                return;
        }
+
+       Glib::RWLock::WriterLock clickm (click_lock, Glib::TRY_LOCK);
        
-       if (_transport_speed != 1.0 || !_clicking || click_data == 0) {
+       if (!clickm.locked() || _transport_speed != 1.0 || !_clicking || click_data == 0) {
                _click_io->silence (nframes, offset);
                return;
        } 
 
-       end = start + nframes;
+       const nframes_t end = start + (nframes_t)floor(nframes * _transport_speed);
 
-       buf = _passthru_buffers[0];
+       BufferSet& bufs = get_scratch_buffers(ChanCount(DataType::AUDIO, 1));
+       buf = bufs.get_audio(0).data();
        points = _tempo_map->get_points (start, end);
 
        if (points == 0) {
@@ -81,29 +83,36 @@ Session::click (jack_nframes_t start, jack_nframes_t nframes, jack_nframes_t off
                        break;
                }
        }
-
+       
   run_clicks:
        memset (buf, 0, sizeof (Sample) * nframes);
 
        for (list<Click*>::iterator i = clicks.begin(); i != clicks.end(); ) {
 
-               jack_nframes_t copy;
-               jack_nframes_t internal_offset;
+               nframes_t copy;
+               nframes_t internal_offset;
                Click *clk;
                list<Click*>::iterator next;
 
                clk = *i;
                next = i;
                ++next;
-
+       
                if (clk->start < start) {
                        internal_offset = 0;
                } else {
                        internal_offset = clk->start - start;
                }
 
+               if (nframes < internal_offset) {
+                        /* we've just located or something.. 
+                           effectively going backwards.
+                           lets get the flock out of here */
+                       break;
+               }
+
                copy = min (clk->duration - clk->offset, nframes - internal_offset);
-               
+
                memcpy (buf + internal_offset, &clk->data[clk->offset], copy * sizeof (Sample));
 
                clk->offset += copy;
@@ -116,8 +125,8 @@ Session::click (jack_nframes_t start, jack_nframes_t nframes, jack_nframes_t off
 
                i = next;
        }
-
-       _click_io->deliver_output (_passthru_buffers, 1, nframes, offset);
+       
+       _click_io->deliver_output (bufs, start, end, nframes, offset);
 }
 
 void
@@ -135,17 +144,19 @@ Session::setup_click_sounds (int which)
                        click_data = 0;
                }
 
-               if (click_sound.length() == 0) {
+               string path = Config->get_click_sound();
+
+               if (path.empty()) {
 
                        click_data = const_cast<Sample*> (default_click);
                        click_length = default_click_length;
 
                } else {
 
-                       if ((sndfile = sf_open (click_sound.c_str(), SFM_READ, &info)) == 0) {
+                       if ((sndfile = sf_open (path.c_str(), SFM_READ, &info)) == 0) {
                                char errbuf[256];
                                sf_error_str (0, errbuf, sizeof (errbuf) - 1);
-                               warning << string_compose (_("cannot open click soundfile %1 (%2)"), click_sound, errbuf) << endmsg;
+                               warning << string_compose (_("cannot open click soundfile %1 (%2)"), path, errbuf) << endmsg;
                                _clicking = false;
                                return;
                        }
@@ -172,14 +183,16 @@ Session::setup_click_sounds (int which)
                        click_emphasis_data = 0;
                }
 
-               if (click_emphasis_sound.length() == 0) {
+               string path = Config->get_click_emphasis_sound();
+
+               if (path.empty()) {
                        click_emphasis_data = const_cast<Sample*> (default_click_emphasis);
                        click_emphasis_length = default_click_emphasis_length;
                } else {
-                       if ((sndfile = sf_open (click_emphasis_sound.c_str(), SFM_READ, &info)) == 0) {
+                       if ((sndfile = sf_open (path.c_str(), SFM_READ, &info)) == 0) {
                                char errbuf[256];
                                sf_error_str (0, errbuf, sizeof (errbuf) - 1);
-                               warning << string_compose (_("cannot open click emphasis soundfile %1 (%2)"), click_emphasis_sound, errbuf) << endmsg;
+                               warning << string_compose (_("cannot open click emphasis soundfile %1 (%2)"), path, errbuf) << endmsg;
                                return;
                        }
                        
@@ -200,7 +213,7 @@ Session::setup_click_sounds (int which)
 void
 Session::clear_clicks ()
 {
-       LockMonitor lm (route_lock, __LINE__, __FILE__);
+       Glib::RWLock::WriterLock lm (click_lock);
 
        for (Clicks::iterator i = clicks.begin(); i != clicks.end(); ++i) {
                delete *i;
@@ -208,46 +221,3 @@ Session::clear_clicks ()
 
        clicks.clear ();
 }
-
-void
-Session::set_click_sound (string path)
-{
-       if (path != click_sound) {
-               click_sound = path;
-               setup_click_sounds (1);
-       }
-}
-
-void
-Session::set_click_emphasis_sound (string path)
-{
-       if (path != click_emphasis_sound) {
-               click_emphasis_sound = path;
-               setup_click_sounds (-1);
-       }
-}
-
-void
-Session::set_clicking (bool yn)
-{
-       if (click_requested != yn) {
-               click_requested = yn;
-               
-               if (yn) {
-                       if (_click_io && click_data) {
-                               _clicking = true;
-                       }
-               } else {
-                       _clicking = false;
-               }
-
-                ControlChanged (Clicking); /* EMIT SIGNAL */
-       }
-}
-
-bool
-Session::get_clicking () const
-{
-       return click_requested;
-}
-