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 <pbd/error.h>
25 #include <ardour/audio_diskstream.h>
26 #include <ardour/audioregion.h>
27 #include <ardour/route.h>
28 #include <ardour/session.h>
29 #include <ardour/auditioner.h>
30 #include <ardour/audioplaylist.h>
31 #include <ardour/panner.h>
32 #include <ardour/data_type.h>
33 #include <ardour/region_factory.h>
36 using namespace ARDOUR;
41 Auditioner::Auditioner (Session& s)
42 : AudioTrack (s, "auditioner", Route::Hidden)
44 string left = Config->get_auditioner_output_left();
45 string right = Config->get_auditioner_output_right();
47 if ((left.length() == 0) && (right.length() == 0)) {
54 add_output_port (left, this, DataType::AUDIO);
58 audio_diskstream()->add_channel();
59 add_output_port (right, this, DataType::AUDIO);
64 IO::output_changed.connect (mem_fun (*this, &Auditioner::output_changed));
66 the_region.reset ((AudioRegion*) 0);
67 g_atomic_int_set (&_active, 0);
70 Auditioner::~Auditioner ()
75 Auditioner::prepare_playlist ()
77 // FIXME auditioner is still audio-only
78 AudioPlaylist* const apl = dynamic_cast<AudioPlaylist*>(_diskstream->playlist());
86 Auditioner::audition_current_playlist ()
88 if (g_atomic_int_get (&_active)) {
89 /* don't go via session for this, because we are going
95 Glib::Mutex::Lock lm (lock);
96 _diskstream->seek (0);
97 length = _diskstream->playlist()->get_maximum_extent();
100 /* force a panner reset now that we have all channels */
102 _panner->reset (n_outputs(), _diskstream->n_channels());
104 g_atomic_int_set (&_active, 1);
108 Auditioner::audition_region (boost::shared_ptr<Region> region)
110 if (g_atomic_int_get (&_active)) {
111 /* don't go via session for this, because we are going
117 if (boost::dynamic_pointer_cast<AudioRegion>(region) == 0) {
118 error << _("Auditioning of non-audio regions not yet supported") << endmsg;
122 Glib::Mutex::Lock lm (lock);
126 boost::shared_ptr<AudioRegion> the_region (boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (region)));
127 the_region->set_position (0, this);
129 _diskstream->playlist()->clear (false);
130 _diskstream->playlist()->add_region (the_region, 0, 1, false);
132 while (_diskstream->n_channels() < the_region->n_channels()) {
133 audio_diskstream()->add_channel ();
136 while (_diskstream->n_channels() > the_region->n_channels()) {
137 audio_diskstream()->remove_channel ();
140 /* force a panner reset now that we have all channels */
142 _panner->reset (n_outputs(), _diskstream->n_channels());
144 length = the_region->length();
145 _diskstream->seek (0);
147 g_atomic_int_set (&_active, 1);
151 Auditioner::play_audition (nframes_t nframes)
154 nframes_t this_nframes;
157 if (g_atomic_int_get (&_active) == 0) {
158 silence (nframes, 0);
162 this_nframes = min (nframes, length - current_frame);
164 _diskstream->prepare ();
166 if ((ret = roll (this_nframes, current_frame, current_frame + nframes, 0, false, false, false)) != 0) {
167 silence (nframes, 0);
171 need_butler = _diskstream->commit (this_nframes);
172 current_frame += this_nframes;
174 if (current_frame >= length) {
175 _session.cancel_audition ();
178 return need_butler ? 1 : 0;
183 Auditioner::output_changed (IOChange change, void* src)
185 if (change & ConnectionsChanged) {
186 const char ** connections;
187 connections = output (0)->get_connections ();
189 Config->set_auditioner_output_left (connections[0]);
193 connections = output (1)->get_connections ();
195 Config->set_auditioner_output_right (connections[0]);