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/delivery.h"
28 #include "ardour/route.h"
29 #include "ardour/session.h"
30 #include "ardour/auditioner.h"
31 #include "ardour/audioplaylist.h"
32 #include "ardour/audio_port.h"
33 #include "ardour/panner_shell.h"
34 #include "ardour/panner.h"
35 #include "ardour/data_type.h"
36 #include "ardour/region_factory.h"
39 using namespace ARDOUR;
44 Auditioner::Auditioner (Session& s)
45 : AudioTrack (s, "auditioner", Route::Hidden)
60 string left = _session.config.get_auditioner_output_left();
61 string right = _session.config.get_auditioner_output_right();
63 vector<string> outputs;
64 _session.engine().get_physical_outputs (DataType::AUDIO, outputs);
66 if (left == "default") {
67 if (_session.monitor_out()) {
68 left = _session.monitor_out()->input()->audio (0)->name();
71 if (outputs.size() > 0) {
77 if (right == "default") {
78 if (_session.monitor_out()) {
79 right = _session.monitor_out()->input()->audio (1)->name();
82 if (outputs.size() > 1) {
88 if ((left.length() == 0) && (right.length() == 0)) {
89 warning << _("no outputs available for auditioner - manual connection required") << endmsg;
93 _main_outs->defer_pan_reset ();
96 _output->add_port (left, this, DataType::AUDIO);
100 _output->add_port (right, this, DataType::AUDIO);
103 _main_outs->allow_pan_reset ();
104 _main_outs->reset_panner ();
106 _output->changed.connect_same_thread (*this, boost::bind (&Auditioner::output_changed, this, _1, _2));
111 Auditioner::~Auditioner ()
116 Auditioner::prepare_playlist ()
118 // FIXME auditioner is still audio-only
119 boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist>(_diskstream->playlist());
127 Auditioner::audition_current_playlist ()
129 if (g_atomic_int_get (&_auditioning)) {
130 /* don't go via session for this, because we are going
136 Glib::Mutex::Lock lm (lock);
137 _diskstream->seek (0);
138 length = _diskstream->playlist()->get_extent().second;
141 /* force a panner reset now that we have all channels */
143 _main_outs->panner_shell()->configure_io (ChanCount (DataType::AUDIO, _diskstream->n_channels().n_audio()),
144 ChanCount (DataType::AUDIO, n_outputs().n_audio()));
146 g_atomic_int_set (&_auditioning, 1);
150 Auditioner::audition_region (boost::shared_ptr<Region> region)
152 if (g_atomic_int_get (&_auditioning)) {
153 /* don't go via session for this, because we are going
159 if (boost::dynamic_pointer_cast<AudioRegion>(region) == 0) {
160 error << _("Auditioning of non-audio regions not yet supported") << endmsg;
164 Glib::Mutex::Lock lm (lock);
168 boost::shared_ptr<AudioRegion> the_region (boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (region)));
169 the_region->set_position (0);
171 _diskstream->playlist()->drop_regions ();
172 _diskstream->playlist()->add_region (the_region, 0, 1);
174 if (_diskstream->n_channels().n_audio() < the_region->n_channels()) {
175 audio_diskstream()->add_channel (the_region->n_channels() - _diskstream->n_channels().n_audio());
176 } else if (_diskstream->n_channels().n_audio() > the_region->n_channels()) {
177 audio_diskstream()->remove_channel (_diskstream->n_channels().n_audio() - the_region->n_channels());
182 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
184 if (configure_processors (&ps)) {
185 error << string_compose (_("Cannot setup auditioner processing flow for %1 channels"),
186 _diskstream->n_channels()) << endmsg;
191 /* force a panner reset now that we have all channels */
193 _main_outs->reset_panner();
195 length = the_region->length();
198 framecnt_t offset = the_region->sync_offset (dir);
200 /* can't audition from a negative sync point */
206 _diskstream->seek (offset);
207 current_frame = offset;
209 g_atomic_int_set (&_auditioning, 1);
213 Auditioner::play_audition (framecnt_t nframes)
215 bool need_butler = false;
216 framecnt_t this_nframes;
219 if (g_atomic_int_get (&_auditioning) == 0) {
224 this_nframes = min (nframes, length - current_frame);
226 if ((ret = roll (this_nframes, current_frame, current_frame + nframes, false, need_butler)) != 0) {
231 current_frame += this_nframes;
233 if (current_frame >= length) {
234 _session.cancel_audition ();
237 return need_butler ? 1 : 0;
242 Auditioner::output_changed (IOChange change, void* /*src*/)
244 if (change.type & IOChange::ConnectionsChanged) {
246 vector<string> connections;
247 vector<string> outputs;
248 _session.engine().get_physical_outputs (DataType::AUDIO, outputs);
249 if (_output->nth (0)->get_connections (connections)) {
250 if (outputs.size() > 0) {
253 if (phys != connections[0]) {
254 _session.config.set_auditioner_output_left (connections[0]);
256 _session.config.set_auditioner_output_left ("default");
259 _session.config.set_auditioner_output_left ("");
262 connections.clear ();
264 if (_output->nth (1)->get_connections (connections)) {
265 if (outputs.size() > 1) {
268 if (phys != connections[0]) {
269 _session.config.set_auditioner_output_right (connections[0]);
271 _session.config.set_auditioner_output_right ("default");
274 _session.config.set_auditioner_output_right ("");
280 Auditioner::input_streams () const
282 /* auditioner never has any inputs - its channel configuration
283 depends solely on the region we are auditioning.
286 if (audio_diskstream()) {
287 return audio_diskstream()->n_channels();
294 Auditioner::monitoring_state () const
296 return MonitoringDisk;