2 Copyright (C) 20002 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <ardour/ardour.h>
25 #include <ardour/session.h>
26 #include <ardour/tempo.h>
27 #include <ardour/io.h>
34 using namespace ARDOUR;
36 Pool Session::Click::pool ("click", sizeof (Click), 128);
39 Session::click (jack_nframes_t start, jack_nframes_t nframes, jack_nframes_t offset)
41 TempoMap::BBTPointList *points;
50 if (_transport_speed != 1.0 || !_clicking || click_data == 0) {
51 _click_io->silence (nframes, offset);
55 end = start + nframes;
57 buf = _passthru_buffers[0];
58 points = _tempo_map->get_points (start, end);
64 if (points->empty()) {
69 for (TempoMap::BBTPointList::iterator i = points->begin(); i != points->end(); ++i) {
72 if (click_emphasis_data == 0 || (click_emphasis_data && (*i).beat != 1)) {
73 clicks.push_back (new Click ((*i).frame, click_length, click_data));
78 if (click_emphasis_data) {
79 clicks.push_back (new Click ((*i).frame, click_emphasis_length, click_emphasis_data));
86 memset (buf, 0, sizeof (Sample) * nframes);
88 for (list<Click*>::iterator i = clicks.begin(); i != clicks.end(); ) {
91 jack_nframes_t internal_offset;
93 list<Click*>::iterator next;
99 if (clk->start < start) {
102 internal_offset = clk->start - start;
105 copy = min (clk->duration - clk->offset, nframes - internal_offset);
107 memcpy (buf + internal_offset, &clk->data[clk->offset], copy * sizeof (Sample));
111 if (clk->offset >= clk->duration) {
120 _click_io->deliver_output (_passthru_buffers, 1, nframes, offset);
124 Session::setup_click_sounds (int which)
131 if ((which == 0 || which == 1)) {
133 if (click_data && click_data != default_click) {
134 delete [] click_data;
138 if (click_sound.length() == 0) {
140 click_data = const_cast<Sample*> (default_click);
141 click_length = default_click_length;
145 if ((sndfile = sf_open (click_sound.c_str(), SFM_READ, &info)) == 0) {
147 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
148 warning << string_compose (_("cannot open click soundfile %1 (%2)"), click_sound, errbuf) << endmsg;
153 click_data = new Sample[info.frames];
154 click_length = info.frames;
156 if (sf_read_float (sndfile, click_data, info.frames) != info.frames) {
157 warning << _("cannot read data from click soundfile") << endmsg;
168 if ((which == 0 || which == -1)) {
170 if (click_emphasis_data && click_emphasis_data != default_click_emphasis) {
171 delete [] click_emphasis_data;
172 click_emphasis_data = 0;
175 if (click_emphasis_sound.length() == 0) {
176 click_emphasis_data = const_cast<Sample*> (default_click_emphasis);
177 click_emphasis_length = default_click_emphasis_length;
179 if ((sndfile = sf_open (click_emphasis_sound.c_str(), SFM_READ, &info)) == 0) {
181 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
182 warning << string_compose (_("cannot open click emphasis soundfile %1 (%2)"), click_emphasis_sound, errbuf) << endmsg;
186 click_emphasis_data = new Sample[info.frames];
187 click_emphasis_length = info.frames;
189 if (sf_read_float (sndfile, click_emphasis_data, info.frames) != info.frames) {
190 warning << _("cannot read data from click emphasis soundfile") << endmsg;
191 delete click_emphasis_data;
192 click_emphasis_data = 0;
201 Session::clear_clicks ()
203 LockMonitor lm (route_lock, __LINE__, __FILE__);
205 for (Clicks::iterator i = clicks.begin(); i != clicks.end(); ++i) {
213 Session::set_click_sound (string path)
215 if (path != click_sound) {
217 setup_click_sounds (1);
222 Session::set_click_emphasis_sound (string path)
224 if (path != click_emphasis_sound) {
225 click_emphasis_sound = path;
226 setup_click_sounds (-1);
231 Session::set_clicking (bool yn)
233 if (click_requested != yn) {
234 click_requested = yn;
237 if (_click_io && click_data) {
244 ControlChanged (Clicking); /* EMIT SIGNAL */
249 Session::get_clicking () const
251 return click_requested;