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>
31 #include <ardour/region_factory.h>
34 using namespace ARDOUR;
36 Auditioner::Auditioner (Session& s)
37 : AudioTrack (s, "auditioner", Route::Hidden)
39 string left = Config->get_auditioner_output_left();
40 string right = Config->get_auditioner_output_right();
42 if ((left.length() == 0) && (right.length() == 0)) {
49 add_output_port (left, this, DataType::AUDIO);
53 audio_diskstream()->add_channel();
54 add_output_port (right, this, DataType::AUDIO);
59 IO::output_changed.connect (mem_fun (*this, &Auditioner::output_changed));
61 the_region.reset ((AudioRegion*) 0);
62 g_atomic_int_set (&_active, 0);
65 Auditioner::~Auditioner ()
70 Auditioner::prepare_playlist ()
72 // FIXME auditioner is still audio-only
73 AudioPlaylist* const apl = dynamic_cast<AudioPlaylist*>(_diskstream->playlist());
81 Auditioner::audition_current_playlist ()
83 if (g_atomic_int_get (&_active)) {
84 /* don't go via session for this, because we are going
90 Glib::Mutex::Lock lm (lock);
91 _diskstream->seek (0);
92 length = _diskstream->playlist()->get_maximum_extent();
95 /* force a panner reset now that we have all channels */
97 _panner->reset (n_outputs(), _diskstream->n_channels());
99 g_atomic_int_set (&_active, 1);
103 Auditioner::audition_region (boost::shared_ptr<AudioRegion> region)
105 if (g_atomic_int_get (&_active)) {
106 /* don't go via session for this, because we are going
112 Glib::Mutex::Lock lm (lock);
116 boost::shared_ptr<AudioRegion> the_region (boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (region)));
117 the_region->set_position (0, this);
119 _diskstream->playlist()->clear (false);
120 _diskstream->playlist()->add_region (the_region, 0, 1, false);
122 while (_diskstream->n_channels() < the_region->n_channels()) {
123 audio_diskstream()->add_channel ();
126 while (_diskstream->n_channels() > the_region->n_channels()) {
127 audio_diskstream()->remove_channel ();
130 /* force a panner reset now that we have all channels */
132 _panner->reset (n_outputs(), _diskstream->n_channels());
134 length = the_region->length();
135 _diskstream->seek (0);
137 g_atomic_int_set (&_active, 1);
141 Auditioner::play_audition (jack_nframes_t nframes)
144 jack_nframes_t this_nframes;
147 if (g_atomic_int_get (&_active) == 0) {
148 silence (nframes, 0);
152 this_nframes = min (nframes, length - current_frame);
154 _diskstream->prepare ();
156 if ((ret = roll (this_nframes, current_frame, current_frame + nframes, 0, false, false, false)) != 0) {
157 silence (nframes, 0);
161 need_butler = _diskstream->commit (this_nframes);
162 current_frame += this_nframes;
164 if (current_frame >= length) {
165 _session.cancel_audition ();
168 return need_butler ? 1 : 0;
173 Auditioner::output_changed (IOChange change, void* src)
175 if (change & ConnectionsChanged) {
176 const char ** connections;
177 connections = output (0)->get_connections ();
179 Config->set_auditioner_output_left (connections[0]);
183 connections = output (1)->get_connections ();
185 Config->set_auditioner_output_right (connections[0]);