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 <ardour/source_factory.h>
22 #include <ardour/sndfilesource.h>
23 #include <ardour/smf_source.h>
24 #include <ardour/destructive_filesource.h>
25 #include <ardour/configuration.h>
28 #include <ardour/coreaudiosource.h>
33 using namespace ARDOUR;
36 sigc::signal<void,boost::shared_ptr<Source> > SourceFactory::SourceCreated;
39 boost::shared_ptr<Source>
40 SourceFactory::create (Session& s, const XMLNode& node)
42 DataType type = DataType::AUDIO;
43 const XMLProperty* prop = node.property("type");
45 type = DataType(prop->value());
48 if (type == DataType::AUDIO) {
50 if (node.property (X_("destructive")) != 0) {
52 boost::shared_ptr<Source> ret (new DestructiveFileSource (s, node));
59 boost::shared_ptr<Source> ret (new CoreAudioSource (s, node));
63 } catch (failed_constructor& err) {
66 boost::shared_ptr<Source> ret (new CoreAudioSource (node));
72 catch (failed_constructor& err) {
73 boost::shared_ptr<Source> ret (new SndFileSource (node));
79 } else if (type == DataType::MIDI) {
81 boost::shared_ptr<Source> ret (new SMFSource (node));
87 return boost::shared_ptr<Source>();
92 boost::shared_ptr<Source>
93 SourceFactory::create (Session& s, const XMLNode& node)
95 DataType type = DataType::AUDIO;
96 const XMLProperty* prop = node.property("type");
98 type = DataType(prop->value());
101 if (type == DataType::AUDIO) {
103 if (node.property (X_("destructive")) != 0) {
105 boost::shared_ptr<Source> ret (new DestructiveFileSource (s, node));
111 boost::shared_ptr<Source> ret (new SndFileSource (s, node));
116 } else if (type == DataType::MIDI) {
118 boost::shared_ptr<Source> ret (new SMFSource (s, node));
124 return boost::shared_ptr<Source> ();
127 #endif // HAVE_COREAUDIO
129 #ifdef HAVE_COREAUDIO
130 boost::shared_ptr<Source>
131 SourceFactory::createReadable (DataType type, Session& s, string idstr, AudioFileSource::Flag flags, bool announce)
133 if (type == DataType::AUDIO) {
134 if (flags & Destructive) {
135 boost::shared_ptr<Source> ret (new DestructiveFileSource (s, idstr, flags));
142 boost::shared_ptr<Source> ret (new CoreAudioSource (s, idstr, flags));
148 } catch (failed_constructor& err) {
149 boost::shared_ptr<Source> ret (new SndFileSource (s, idstr, flags));
156 } else if (type == DataType::MIDI) {
158 boost::shared_ptr<Source> ret (new SMFSource (s, node));
164 return boost::shared_ptr<Source>();
169 boost::shared_ptr<Source>
170 SourceFactory::createReadable (DataType type, Session& s, string idstr, AudioFileSource::Flag flags, bool announce)
172 if (type == DataType::AUDIO) {
174 boost::shared_ptr<Source> ret (new SndFileSource (s, idstr, flags));
180 } else if (type == DataType::MIDI) {
182 boost::shared_ptr<Source> ret (new SMFSource (s, idstr, SMFSource::Flag(0))); // FIXME: flags?
190 return boost::shared_ptr<Source> ();
193 #endif // HAVE_COREAUDIO
195 boost::shared_ptr<Source>
196 SourceFactory::createWritable (DataType type, Session& s, std::string path, bool destructive, jack_nframes_t rate, bool announce)
198 /* this might throw failed_constructor(), which is OK */
200 if (type == DataType::AUDIO) {
203 boost::shared_ptr<Source> ret (new DestructiveFileSource (s, path,
204 Config->get_native_file_data_format(),
205 Config->get_native_file_header_format(),
214 boost::shared_ptr<Source> ret (new SndFileSource (s, path,
215 Config->get_native_file_data_format(),
216 Config->get_native_file_header_format(),
225 } else if (type == DataType::MIDI) {
227 boost::shared_ptr<Source> ret (new SMFSource (s, path));
233 return boost::shared_ptr<Source> ();