2 Copyright (C) 2001 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.
21 #include <glibmm/thread.h>
23 #include <ardour/audio_diskstream.h>
24 #include <ardour/audioregion.h>
25 #include <ardour/route.h>
26 #include <ardour/session.h>
27 #include <ardour/auditioner.h>
28 #include <ardour/audioplaylist.h>
29 #include <ardour/panner.h>
30 #include <ardour/data_type.h>
33 using namespace ARDOUR;
35 Auditioner::Auditioner (Session& s)
36 : AudioTrack (s, "auditioner", Route::Hidden)
38 string left = Config->get_auditioner_output_left();
39 string right = Config->get_auditioner_output_right();
41 if ((left.length() == 0) && (right.length() == 0)) {
48 add_output_port (left, this, DataType::AUDIO);
52 audio_diskstream().add_channel();
53 add_output_port (right, this, DataType::AUDIO);
58 IO::output_changed.connect (mem_fun (*this, &Auditioner::output_changed));
61 g_atomic_int_set (&_active, 0);
64 Auditioner::~Auditioner ()
69 Auditioner::prepare_playlist ()
71 // FIXME auditioner is still audio-only
72 AudioPlaylist* const apl = dynamic_cast<AudioPlaylist*>(_diskstream->playlist());
75 apl->clear (false, false);
80 Auditioner::audition_current_playlist ()
82 if (g_atomic_int_get (&_active)) {
83 /* don't go via session for this, because we are going
89 Glib::Mutex::Lock lm (lock);
90 _diskstream->seek (0);
91 length = _diskstream->playlist()->get_maximum_extent();
94 /* force a panner reset now that we have all channels */
96 _panner->reset (n_outputs().get(DataType::AUDIO), _diskstream->n_channels());
98 g_atomic_int_set (&_active, 1);
102 Auditioner::audition_region (AudioRegion& region)
104 if (g_atomic_int_get (&_active)) {
105 /* don't go via session for this, because we are going
111 Glib::Mutex::Lock lm (lock);
113 the_region = new AudioRegion (region);
114 the_region->set_position (0, this);
116 _diskstream->playlist()->clear (true, false);
117 _diskstream->playlist()->add_region (*the_region, 0, 1, false);
119 while (_diskstream->n_channels() < the_region->n_channels()) {
120 audio_diskstream().add_channel ();
123 while (_diskstream->n_channels() > the_region->n_channels()) {
124 audio_diskstream().remove_channel ();
127 /* force a panner reset now that we have all channels */
129 _panner->reset (n_outputs().get(DataType::AUDIO), _diskstream->n_channels());
131 length = the_region->length();
132 _diskstream->seek (0);
134 g_atomic_int_set (&_active, 1);
138 Auditioner::play_audition (jack_nframes_t nframes)
141 jack_nframes_t this_nframes;
144 if (g_atomic_int_get (&_active) == 0) {
145 silence (nframes, 0);
149 this_nframes = min (nframes, length - current_frame);
151 _diskstream->prepare ();
153 if ((ret = roll (this_nframes, current_frame, current_frame + nframes, 0, false, false, false)) != 0) {
154 silence (nframes, 0);
158 need_butler = _diskstream->commit (this_nframes);
159 current_frame += this_nframes;
161 if (current_frame >= length) {
162 _session.cancel_audition ();
165 return need_butler ? 1 : 0;
170 Auditioner::output_changed (IOChange change, void* src)
172 if (change & ConnectionsChanged) {
173 const char ** connections;
174 connections = output (0)->get_connections ();
176 Config->set_auditioner_output_left (connections[0]);
180 connections = output (1)->get_connections ();
182 Config->set_auditioner_output_right (connections[0]);