2 Copyright (C) 2000-2006 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 <pbd/error.h>
23 #include <ardour/source_factory.h>
24 #include <ardour/sndfilesource.h>
25 #include <ardour/silentfilesource.h>
26 #include <ardour/configuration.h>
27 #include <ardour/smf_source.h>
30 #include <ardour/coreaudiosource.h>
35 using namespace ARDOUR;
39 sigc::signal<void,boost::shared_ptr<Source> > SourceFactory::SourceCreated;
42 SourceFactory::setup_peakfile (boost::shared_ptr<Source> s)
44 boost::shared_ptr<AudioSource> as (boost::dynamic_pointer_cast<AudioSource> (s));
46 if (as->setup_peakfile ()) {
47 error << string_compose("SourceFactory: could not set up peakfile for %1", as->name()) << endmsg;
55 boost::shared_ptr<Source>
56 SourceFactory::createSilent (Session& s, const XMLNode& node, nframes_t nframes, float sr)
58 boost::shared_ptr<Source> ret (new SilentFileSource (s, node, nframes, sr));
63 boost::shared_ptr<Source>
64 SourceFactory::create (Session& s, const XMLNode& node)
66 /* this is allowed to throw */
68 DataType type = DataType::AUDIO;
69 const XMLProperty* prop = node.property("type");
71 type = DataType(prop->value());
74 if (type == DataType::AUDIO) {
78 boost::shared_ptr<Source> ret (new CoreAudioSource (s, node));
79 if (setup_peakfile (ret)) {
80 return boost::shared_ptr<Source>();
86 catch (failed_constructor& err) {
88 /* this is allowed to throw */
90 boost::shared_ptr<Source> ret (new SndFileSource (s, node));
91 if (setup_peakfile (ret)) {
92 return boost::shared_ptr<Source>();
98 boost::shared_ptr<Source> ret (new SndFileSource (s, node));
100 if (setup_peakfile (ret)) {
101 return boost::shared_ptr<Source>();
108 } else if (type == DataType::MIDI) {
110 boost::shared_ptr<Source> ret (new SMFSource (s, node));
117 return boost::shared_ptr<Source> ();
120 boost::shared_ptr<Source>
121 SourceFactory::createReadable (DataType type, Session& s, string path, int chn, AudioFileSource::Flag flags, bool announce)
123 if (type == DataType::AUDIO) {
125 #ifdef HAVE_COREAUDIO
127 boost::shared_ptr<Source> ret (new CoreAudioSource (s, path, chn, flags));
128 if (setup_peakfile (ret)) {
129 return boost::shared_ptr<Source>();
137 catch (failed_constructor& err) {
138 boost::shared_ptr<Source> ret (new SndFileSource (s, path, chn, flags));
139 if (setup_peakfile (ret)) {
140 return boost::shared_ptr<Source>();
148 boost::shared_ptr<Source> ret (new SndFileSource (s, path, chn, flags));
150 if (setup_peakfile (ret)) {
151 return boost::shared_ptr<Source>();
161 } else if (type == DataType::MIDI) {
164 boost::shared_ptr<Source> ret (new SMFSource (s, path, SMFSource::Flag(0)));
173 return boost::shared_ptr<Source>();
176 boost::shared_ptr<Source>
177 SourceFactory::createWritable (DataType type, Session& s, std::string path, bool destructive, nframes_t rate, bool announce)
179 /* this might throw failed_constructor(), which is OK */
181 if (type == DataType::AUDIO) {
182 boost::shared_ptr<Source> ret (new SndFileSource
184 Config->get_native_file_data_format(),
185 Config->get_native_file_header_format(),
187 (destructive ? AudioFileSource::Flag (SndFileSource::default_writable_flags | AudioFileSource::Destructive) :
188 SndFileSource::default_writable_flags)));
190 if (setup_peakfile (ret)) {
191 return boost::shared_ptr<Source>();
198 } else if (type == DataType::MIDI) {
200 boost::shared_ptr<Source> ret (new SMFSource (s, path));
209 return boost::shared_ptr<Source> ();