X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fsession_click.cc;h=2e7e077ce7fdf4aba411f9d5011aef393fbbd61c;hb=50131b3751e6ed5c9ed7450406049b2195ea9ecf;hp=38cc27be0bcf7d189ba65a92b0a451a8b9a755d3;hpb=34f4b98c349ac1cc0b6ba48f48418f1a3432dff7;p=ardour.git diff --git a/libs/ardour/session_click.cc b/libs/ardour/session_click.cc index 38cc27be0b..2e7e077ce7 100644 --- a/libs/ardour/session_click.cc +++ b/libs/ardour/session_click.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 20002 Paul Davis + Copyright (C) 20002 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,16 +15,17 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #include #include -#include -#include -#include -#include +#include "ardour/ardour.h" +#include "ardour/session.h" +#include "ardour/tempo.h" +#include "ardour/io.h" +#include "ardour/buffer_set.h" +#include "ardour/audio_buffer.h" #include @@ -37,56 +38,54 @@ using namespace PBD; Pool Session::Click::pool ("click", sizeof (Click), 128); void -Session::click (nframes_t start, nframes_t nframes, nframes_t offset) +Session::click (nframes_t start, nframes_t nframes) { TempoMap::BBTPointList *points; - nframes_t end; Sample *buf; - vector bufs; if (_click_io == 0) { return; } Glib::RWLock::WriterLock clickm (click_lock, Glib::TRY_LOCK); - + if (!clickm.locked() || _transport_speed != 1.0 || !_clicking || click_data == 0) { - _click_io->silence (nframes, offset); + _click_io->silence (nframes); return; - } + } - end = start + nframes; + const nframes_t end = start + nframes; - 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) { goto run_clicks; } - if (!points->empty()) { - - for (TempoMap::BBTPointList::iterator i = points->begin(); i != points->end(); ++i) { - switch ((*i).type) { - case TempoMap::Beat: - if (click_emphasis_data == 0 || (click_emphasis_data && (*i).beat != 1)) { - clicks.push_back (new Click ((*i).frame, click_length, click_data)); - } - break; - - case TempoMap::Bar: - if (click_emphasis_data) { - clicks.push_back (new Click ((*i).frame, click_emphasis_length, click_emphasis_data)); - } - break; + if (points->empty()) { + delete points; + goto run_clicks; + } + + for (TempoMap::BBTPointList::iterator i = points->begin(); i != points->end(); ++i) { + switch ((*i).type) { + case TempoMap::Beat: + if (click_emphasis_data == 0 || (click_emphasis_data && (*i).beat != 1)) { + clicks.push_back (new Click ((*i).frame, click_length, click_data)); } + break; + + case TempoMap::Bar: + if (click_emphasis_data) { + clicks.push_back (new Click ((*i).frame, click_emphasis_length, click_emphasis_data)); + } + break; } } - - delete points; - + run_clicks: - memset (buf, 0, sizeof (Sample) * nframes); for (list::iterator i = clicks.begin(); i != clicks.end(); ) { @@ -99,7 +98,7 @@ Session::click (nframes_t start, nframes_t nframes, nframes_t offset) clk = *i; next = i; ++next; - + if (clk->start < start) { internal_offset = 0; } else { @@ -107,7 +106,7 @@ Session::click (nframes_t start, nframes_t nframes, nframes_t offset) } if (nframes < internal_offset) { - /* we've just located or something.. + /* we've just located or something.. effectively going backwards. lets get the flock out of here */ break; @@ -128,7 +127,7 @@ Session::click (nframes_t start, nframes_t nframes, nframes_t offset) i = next; } - _click_io->deliver_output (_passthru_buffers, 1, nframes, offset); + _click_io->copy_to_outputs (bufs, DataType::AUDIO, nframes, 0); } void @@ -140,13 +139,13 @@ Session::setup_click_sounds (int which) clear_clicks(); if ((which == 0 || which == 1)) { - - if (click_data && click_data != default_click) { + + if (click_data != default_click) { delete [] click_data; click_data = 0; } - string path = Config->get_click_emphasis_sound(); + string path = Config->get_click_sound(); if (path.empty()) { @@ -155,6 +154,7 @@ Session::setup_click_sounds (int which) } else { + info.format = 0; if ((sndfile = sf_open (path.c_str(), SFM_READ, &info)) == 0) { char errbuf[256]; sf_error_str (0, errbuf, sizeof (errbuf) - 1); @@ -162,25 +162,25 @@ Session::setup_click_sounds (int which) _clicking = false; return; } - + click_data = new Sample[info.frames]; click_length = info.frames; - + if (sf_read_float (sndfile, click_data, info.frames) != info.frames) { - warning << _("cannot read data from click soundfile") << endmsg; + warning << _("cannot read data from click soundfile") << endmsg; delete click_data; click_data = 0; _clicking = false; } - + sf_close (sndfile); } } - + if ((which == 0 || which == -1)) { - if (click_emphasis_data && click_emphasis_data != default_click_emphasis) { + if (click_emphasis_data != default_click_emphasis) { delete [] click_emphasis_data; click_emphasis_data = 0; } @@ -191,26 +191,27 @@ Session::setup_click_sounds (int which) click_emphasis_data = const_cast (default_click_emphasis); click_emphasis_length = default_click_emphasis_length; } else { + info.format = 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)"), path, errbuf) << endmsg; return; } - + click_emphasis_data = new Sample[info.frames]; click_emphasis_length = info.frames; - + if (sf_read_float (sndfile, click_emphasis_data, info.frames) != info.frames) { - warning << _("cannot read data from click emphasis soundfile") << endmsg; + warning << _("cannot read data from click emphasis soundfile") << endmsg; delete click_emphasis_data; click_emphasis_data = 0; } - + sf_close (sndfile); } } -} +} void Session::clear_clicks ()