X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fsession_click.cc;h=8e57d7578c107bfe3c8078b60fbb5a2d690526a2;hb=a473d630eb165272992e90f8d854b1d66ec0be63;hp=1d14fd4a80a77307365b0cb7369d0e5521377fe5;hpb=912da52a539981193941d8739fa6f103b5e406db;p=ardour.git diff --git a/libs/ardour/session_click.cc b/libs/ardour/session_click.cc index 1d14fd4a80..8e57d7578c 100644 --- a/libs/ardour/session_click.cc +++ b/libs/ardour/session_click.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 20002 Paul Davis + Copyright (C) 2002 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 @@ -34,30 +35,29 @@ using namespace std; using namespace ARDOUR; using namespace PBD; -Pool Session::Click::pool ("click", sizeof (Click), 128); +Pool Click::pool ("click", sizeof (Click), 128); void -Session::click (jack_nframes_t start, jack_nframes_t nframes, jack_nframes_t offset) +Session::click (framepos_t start, framecnt_t nframes) { TempoMap::BBTPointList *points; - jack_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 framepos_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) { @@ -80,7 +80,7 @@ Session::click (jack_nframes_t start, jack_nframes_t nframes, jack_nframes_t off case TempoMap::Bar: if (click_emphasis_data) { clicks.push_back (new Click ((*i).frame, click_emphasis_length, click_emphasis_data)); - } + } break; } } @@ -90,15 +90,15 @@ Session::click (jack_nframes_t start, jack_nframes_t nframes, jack_nframes_t off for (list::iterator i = clicks.begin(); i != clicks.end(); ) { - jack_nframes_t copy; - jack_nframes_t internal_offset; + framecnt_t copy; + framecnt_t internal_offset; Click *clk; list::iterator next; clk = *i; next = i; ++next; - + if (clk->start < start) { internal_offset = 0; } else { @@ -106,7 +106,7 @@ Session::click (jack_nframes_t start, jack_nframes_t nframes, jack_nframes_t off } 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; @@ -127,137 +127,103 @@ 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->copy_to_outputs (bufs, DataType::AUDIO, nframes, 0); } void -Session::setup_click_sounds (int which) +Session::setup_click_sounds (Sample** data, Sample const * default_data, framecnt_t* length, framecnt_t default_length, string const & path) { - SNDFILE *sndfile; - SF_INFO info; + if (*data != default_data) { + delete[] *data; + *data = 0; + } - clear_clicks(); + if (path.empty ()) { - if ((which == 0 || which == 1)) { - - if (click_data && click_data != default_click) { - delete [] click_data; - click_data = 0; - } + *data = const_cast (default_data); + *length = default_length; - if (click_sound.length() == 0) { + } else { - click_data = const_cast (default_click); - click_length = default_click_length; + SF_INFO info; + SNDFILE* sndfile; - } 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 soundfile %1 (%2)"), path, errbuf) << endmsg; + _clicking = false; + return; + } - if ((sndfile = sf_open (click_sound.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; - _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; - delete click_data; - click_data = 0; - _clicking = false; - } - - sf_close (sndfile); + /* read the (possibly multi-channel) click data into a temporary buffer */ - } - } - - if ((which == 0 || which == -1)) { + sf_count_t const samples = info.frames * info.channels; - if (click_emphasis_data && click_emphasis_data != default_click_emphasis) { - delete [] click_emphasis_data; - click_emphasis_data = 0; - } + Sample* tmp = new Sample[samples]; + + if (sf_readf_float (sndfile, tmp, info.frames) != info.frames) { + + warning << _("cannot read data from click soundfile") << endmsg; + *data = 0; + _clicking = false; - if (click_emphasis_sound.length() == 0) { - click_emphasis_data = const_cast (default_click_emphasis); - click_emphasis_length = default_click_emphasis_length; } else { - if ((sndfile = sf_open (click_emphasis_sound.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; - 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; - delete click_emphasis_data; - click_emphasis_data = 0; + + *data = new Sample[info.frames]; + *length = info.frames; + + /* mix down to mono */ + + for (int i = 0; i < info.frames; ++i) { + (*data)[i] = 0; + for (int j = 0; j < info.channels; ++j) { + (*data)[i] = tmp[i * info.channels + j]; + } + (*data)[i] /= info.channels; } - - sf_close (sndfile); } - } -} - -void -Session::clear_clicks () -{ - Glib::RWLock::WriterLock lm (click_lock); - for (Clicks::iterator i = clicks.begin(); i != clicks.end(); ++i) { - delete *i; + delete[] tmp; + sf_close (sndfile); } - - clicks.clear (); } void -Session::set_click_sound (string path) +Session::setup_click_sounds (int which) { - if (path != click_sound) { - click_sound = path; - setup_click_sounds (1); + clear_clicks (); + + if (which == 0 || which == 1) { + setup_click_sounds ( + &click_data, + default_click, + &click_length, + default_click_length, + Config->get_click_sound () + ); } -} -void -Session::set_click_emphasis_sound (string path) -{ - if (path != click_emphasis_sound) { - click_emphasis_sound = path; - setup_click_sounds (-1); + if (which == 0 || which == -1) { + setup_click_sounds ( + &click_emphasis_data, + default_click_emphasis, + &click_emphasis_length, + default_click_emphasis_length, + Config->get_click_emphasis_sound () + ); } } void -Session::set_clicking (bool yn) +Session::clear_clicks () { - if (click_requested != yn) { - click_requested = yn; - - if (yn) { - if (_click_io && click_data) { - _clicking = true; - } - } else { - _clicking = false; - } + Glib::RWLock::WriterLock lm (click_lock); - ControlChanged (Clicking); /* EMIT SIGNAL */ + for (Clicks::iterator i = clicks.begin(); i != clicks.end(); ++i) { + delete *i; } -} -bool -Session::get_clicking () const -{ - return click_requested; + clicks.clear (); } -