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/smf_source.h>
26 #include <ardour/destructive_filesource.h>
27 #include <ardour/configuration.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;
56 boost::shared_ptr<Source>
57 SourceFactory::create (Session& s, const XMLNode& node)
59 DataType type = DataType::AUDIO;
60 const XMLProperty* prop = node.property("type");
62 type = DataType(prop->value());
65 if (type == DataType::AUDIO) {
67 if (node.property (X_("destructive")) != 0) {
69 boost::shared_ptr<Source> ret (new DestructiveFileSource (s, node));
70 if (setup_peakfile (ret)) {
71 return boost::shared_ptr<Source>();
79 boost::shared_ptr<Source> ret (new CoreAudioSource (s, node));
80 if (setup_peakfile (ret)) {
81 return boost::shared_ptr<Source>();
86 } catch (failed_constructor& err) {
89 boost::shared_ptr<Source> ret (new CoreAudioSource (node));
95 catch (failed_constructor& err) {
97 boost::shared_ptr<Source> ret (new SndFileSource (s, node));
98 if (setup_peakfile (ret)) {
99 return boost::shared_ptr<Source>();
106 } else if (type == DataType::MIDI) {
108 boost::shared_ptr<Source> ret (new SMFSource (node));
114 return boost::shared_ptr<Source>();
119 boost::shared_ptr<Source>
120 SourceFactory::create (Session& s, const XMLNode& node)
122 DataType type = DataType::AUDIO;
123 const XMLProperty* prop = node.property("type");
125 type = DataType(prop->value());
128 if (type == DataType::AUDIO) {
130 if (node.property (X_("destructive")) != 0) {
132 boost::shared_ptr<Source> ret (new DestructiveFileSource (s, node));
133 if (setup_peakfile (ret)) {
134 return boost::shared_ptr<Source>();
141 boost::shared_ptr<Source> ret (new SndFileSource (s, node));
142 if (setup_peakfile (ret)) {
143 return boost::shared_ptr<Source>();
149 } else if (type == DataType::MIDI) {
151 boost::shared_ptr<Source> ret (new SMFSource (s, node));
157 return boost::shared_ptr<Source> ();
160 #endif // HAVE_COREAUDIO
162 #ifdef HAVE_COREAUDIO
163 boost::shared_ptr<Source>
164 SourceFactory::createReadable (DataType type, Session& s, string idstr, AudioFileSource::Flag flags, bool announce)
166 if (type == DataType::AUDIO) {
167 if (flags & Destructive) {
168 boost::shared_ptr<Source> ret (new DestructiveFileSource (s, idstr, flags));
169 if (setup_peakfile (ret)) {
170 return boost::shared_ptr<Source>();
178 boost::shared_ptr<Source> ret (new CoreAudioSource (s, idstr, flags));
184 } catch (failed_constructor& err) {
185 boost::shared_ptr<Source> ret (new SndFileSource (s, idstr, flags));
192 } else if (type == DataType::MIDI) {
194 boost::shared_ptr<Source> ret (new SMFSource (s, node));
200 return boost::shared_ptr<Source>();
205 boost::shared_ptr<Source>
206 SourceFactory::createReadable (DataType type, Session& s, string idstr, AudioFileSource::Flag flags, bool announce)
208 if (type == DataType::AUDIO) {
210 boost::shared_ptr<Source> ret (new SndFileSource (s, idstr, flags));
211 if (setup_peakfile (ret)) {
212 return boost::shared_ptr<Source>();
219 } else if (type == DataType::MIDI) {
221 boost::shared_ptr<Source> ret (new SMFSource (s, idstr, SMFSource::Flag(0))); // FIXME: flags?
229 return boost::shared_ptr<Source> ();
232 #endif // HAVE_COREAUDIO
234 boost::shared_ptr<Source>
235 SourceFactory::createWritable (DataType type, Session& s, std::string path, bool destructive, nframes_t rate, bool announce)
237 /* this might throw failed_constructor(), which is OK */
238 if (type == DataType::AUDIO) {
241 boost::shared_ptr<Source> ret (new DestructiveFileSource (s, path,
242 Config->get_native_file_data_format(),
243 Config->get_native_file_header_format(),
245 if (setup_peakfile (ret)) {
246 return boost::shared_ptr<Source>();
252 boost::shared_ptr<Source> ret (new SndFileSource (s, path,
253 Config->get_native_file_data_format(),
254 Config->get_native_file_header_format(),
256 if (setup_peakfile (ret)) {
257 return boost::shared_ptr<Source>();
265 } else if (type == DataType::MIDI) {
267 boost::shared_ptr<Source> ret (new SMFSource (s, path));
273 return boost::shared_ptr<Source> ();