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));
64 boost::shared_ptr<Source>
65 SourceFactory::create (Session& s, const XMLNode& node)
67 DataType type = DataType::AUDIO;
68 const XMLProperty* prop = node.property("type");
70 type = DataType(prop->value());
73 if (type == DataType::AUDIO) {
76 boost::shared_ptr<Source> ret (new CoreAudioSource (s, node));
77 if (setup_peakfile (ret)) {
78 return boost::shared_ptr<Source>();
84 catch (failed_constructor& err) {
86 /* this is allowed to throw */
88 boost::shared_ptr<Source> ret (new SndFileSource (s, node));
89 if (setup_peakfile (ret)) {
90 return boost::shared_ptr<Source>();
96 } else if (type == DataType::MIDI) {
98 boost::shared_ptr<Source> ret (new SMFSource (node));
103 return boost::shared_ptr<Source>();
108 boost::shared_ptr<Source>
109 SourceFactory::create (Session& s, const XMLNode& node)
111 /* this is allowed to throw */
113 DataType type = DataType::AUDIO;
114 const XMLProperty* prop = node.property("type");
116 type = DataType(prop->value());
119 if (type == DataType::AUDIO) {
121 boost::shared_ptr<Source> ret (new SndFileSource (s, node));
123 if (setup_peakfile (ret)) {
124 return boost::shared_ptr<Source>();
130 } else if (type == DataType::MIDI) {
132 boost::shared_ptr<Source> ret (new SMFSource (s, node));
139 return boost::shared_ptr<Source> ();
142 #endif // HAVE_COREAUDIO
144 #ifdef HAVE_COREAUDIO
145 boost::shared_ptr<Source>
146 SourceFactory::createReadable (DataType type, Session& s, string path, int chn, AudioFileSource::Flag flags, bool announce)
148 if (type == DataType::AUDIO) {
149 if (!(flags & Destructive)) {
152 boost::shared_ptr<Source> ret (new CoreAudioSource (s, path, chn, flags));
153 if (setup_peakfile (ret)) {
154 return boost::shared_ptr<Source>();
162 catch (failed_constructor& err) {
163 boost::shared_ptr<Source> ret (new SndFileSource (s, path, chn, flags));
164 if (setup_peakfile (ret)) {
165 return boost::shared_ptr<Source>();
176 /* this is allowed to throw */
178 boost::shared_ptr<Source> ret (new SndFileSource (s, path, chn, flags));
179 if (setup_peakfile (ret)) {
180 return boost::shared_ptr<Source>();
188 return boost::shared_ptr<Source>();
189 } else if (type == DataType::MIDI) {
191 boost::shared_ptr<Source> ret (new SMFSource (s, node));
199 return boost::shared_ptr<Source>();
204 boost::shared_ptr<Source>
205 SourceFactory::createReadable (DataType type, Session& s, string path, int chn, AudioFileSource::Flag flags, bool announce)
207 if (type == DataType::AUDIO) {
209 boost::shared_ptr<Source> ret (new SndFileSource (s, path, chn, flags));
211 if (setup_peakfile (ret)) {
212 return boost::shared_ptr<Source>();
222 } else if (type == DataType::MIDI) {
225 boost::shared_ptr<Source> ret (new SMFSource (s, path, SMFSource::Flag(0)));
234 return boost::shared_ptr<Source>();
237 #endif // HAVE_COREAUDIO
239 boost::shared_ptr<Source>
240 SourceFactory::createWritable (DataType type, Session& s, std::string path, bool destructive, nframes_t rate, bool announce)
242 /* this might throw failed_constructor(), which is OK */
244 if (type == DataType::AUDIO) {
245 boost::shared_ptr<Source> ret (new SndFileSource
247 Config->get_native_file_data_format(),
248 Config->get_native_file_header_format(),
250 (destructive ? AudioFileSource::Flag (SndFileSource::default_writable_flags | AudioFileSource::Destructive) :
251 SndFileSource::default_writable_flags)));
253 if (setup_peakfile (ret)) {
254 return boost::shared_ptr<Source>();
261 } else if (type == DataType::MIDI) {
263 boost::shared_ptr<Source> ret (new SMFSource (s, path));
272 return boost::shared_ptr<Source> ();