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.
20 #include <glibmm/thread.h>
22 #include <pbd/error.h>
24 #include <ardour/audio_diskstream.h>
25 #include <ardour/audioregion.h>
26 #include <ardour/audioengine.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 == "default") {
48 left = _session.engine().get_nth_physical_audio_output (0);
51 if (right == "default") {
52 right = _session.engine().get_nth_physical_audio_output (1);
55 if ((left.length() == 0) && (right.length() == 0)) {
56 warning << _("no outputs available for auditioner - manual connection required") << endmsg;
63 add_output_port (left, this, DataType::AUDIO);
67 audio_diskstream()->add_channel (1);
68 add_output_port (right, this, DataType::AUDIO);
73 IO::output_changed.connect (mem_fun (*this, &Auditioner::output_changed));
75 the_region.reset ((AudioRegion*) 0);
76 g_atomic_int_set (&_active, 0);
79 Auditioner::~Auditioner ()
84 Auditioner::prepare_playlist ()
86 // FIXME auditioner is still audio-only
87 boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist>(_diskstream->playlist());
95 Auditioner::audition_current_playlist ()
97 if (g_atomic_int_get (&_active)) {
98 /* don't go via session for this, because we are going
104 Glib::Mutex::Lock lm (lock);
105 _diskstream->seek (0);
106 length = _diskstream->playlist()->get_maximum_extent();
109 /* force a panner reset now that we have all channels */
111 _panner->reset (n_outputs(), _diskstream->n_channels());
113 g_atomic_int_set (&_active, 1);
117 Auditioner::audition_region (boost::shared_ptr<Region> region)
119 if (g_atomic_int_get (&_active)) {
120 /* don't go via session for this, because we are going
126 if (boost::dynamic_pointer_cast<AudioRegion>(region) == 0) {
127 error << _("Auditioning of non-audio regions not yet supported") << endmsg;
131 Glib::Mutex::Lock lm (lock);
135 boost::shared_ptr<AudioRegion> the_region (boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (region)));
136 the_region->set_position (0, this);
138 _diskstream->playlist()->drop_regions ();
139 _diskstream->playlist()->add_region (the_region, 0, 1);
141 if (_diskstream->n_channels() < the_region->n_channels()) {
142 audio_diskstream()->add_channel (the_region->n_channels() - _diskstream->n_channels());
143 } else if (_diskstream->n_channels() > the_region->n_channels()) {
144 audio_diskstream()->remove_channel (_diskstream->n_channels() - the_region->n_channels());
147 /* force a panner reset now that we have all channels */
149 _panner->reset (n_outputs(), _diskstream->n_channels());
151 length = the_region->length();
154 nframes_t offset = the_region->sync_offset (dir);
156 /* can't audition from a negative sync point */
162 _diskstream->seek (offset);
163 current_frame = offset;
165 g_atomic_int_set (&_active, 1);
169 Auditioner::play_audition (nframes_t nframes)
172 nframes_t this_nframes;
175 if (g_atomic_int_get (&_active) == 0) {
180 this_nframes = min (nframes, length - current_frame);
182 _diskstream->prepare ();
184 if ((ret = roll (this_nframes, current_frame, current_frame + nframes, false, false, false)) != 0) {
189 need_butler = _diskstream->commit (this_nframes);
191 current_frame += this_nframes;
193 if (current_frame >= length) {
194 _session.cancel_audition ();
197 return need_butler ? 1 : 0;
202 Auditioner::output_changed (IOChange change, void* src)
206 if (change & ConnectionsChanged) {
207 const char ** connections;
208 connections = output (0)->get_connections ();
210 phys = _session.engine().get_nth_physical_audio_output (0);
211 if (phys != connections[0]) {
212 Config->set_auditioner_output_left (connections[0]);
214 Config->set_auditioner_output_left ("default");
218 Config->set_auditioner_output_left ("");
221 connections = output (1)->get_connections ();
223 phys = _session.engine().get_nth_physical_audio_output (1);
224 if (phys != connections[0]) {
225 Config->set_auditioner_output_right (connections[0]);
227 Config->set_auditioner_output_right ("default");
231 Config->set_auditioner_output_right ("");