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>
29 using namespace ARDOUR;
32 sigc::signal<void,boost::shared_ptr<Source> > SourceFactory::SourceCreated;
37 boost::shared_ptr<Source>
38 SourceFactory::create (const XMLNode& node)
40 DataType type = DataType::AUDIO;
41 const XMLProperty* prop = node.property("type");
43 type = DataType(prop->value());
46 if (type == DataType::AUDIO) {
48 if (node.property (X_("destructive")) != 0) {
50 boost::shared_ptr<Source> ret (new DestructiveFileSource (node));
57 boost::shared_ptr<Source> ret (new CoreAudioSource (node));
63 catch (failed_constructor& err) {
64 boost::shared_ptr<Source> ret (new SndFileSource (node));
70 } else if (type == DataType::MIDI) {
72 boost::shared_ptr<Source> ret (new SMFSource (node));
78 return boost::shared_ptr<Source>();
83 boost::shared_ptr<Source>
84 SourceFactory::create (const XMLNode& node)
86 DataType type = DataType::AUDIO;
87 const XMLProperty* prop = node.property("type");
89 type = DataType(prop->value());
92 if (type == DataType::AUDIO) {
94 if (node.property (X_("destructive")) != 0) {
96 boost::shared_ptr<Source> ret (new DestructiveFileSource (node));
102 boost::shared_ptr<Source> ret (new SndFileSource (node));
107 } else if (type == DataType::MIDI) {
109 boost::shared_ptr<Source> ret (new SMFSource (node));
115 return boost::shared_ptr<Source> ();
118 #endif // HAVE_COREAUDIO
120 #ifdef HAVE_COREAUDIO
121 boost::shared_ptr<Source>
122 SourceFactory::createReadable (string idstr, AudioFileSource::Flag flags, bool announce)
124 if (type == DataType::AUDIO) {
125 if (flags & Destructive) {
126 boost::shared_ptr<Source> ret (new DestructiveFileSource (idstr, flags));
134 boost::shared_ptr<Source> ret (new CoreAudioSource (idstr, flags));
141 catch (failed_constructor& err) {
142 boost::shared_ptr<Source> ret (new SndFileSource (idstr, flags));
148 } else if (type == DataType::MIDI) {
150 boost::shared_ptr<Source> ret (new SMFSource (node));
156 return boost::shared_ptr<Source>();
161 boost::shared_ptr<Source>
162 SourceFactory::createReadable (DataType type, string idstr, AudioFileSource::Flag flags, bool announce)
164 if (type == DataType::AUDIO) {
165 boost::shared_ptr<Source> ret (new SndFileSource (idstr, flags));
171 } else if (type == DataType::MIDI) {
173 boost::shared_ptr<Source> ret (new SMFSource (idstr, SMFSource::Flag(0))); // FIXME: flags?
179 return boost::shared_ptr<Source> ();
182 #endif // HAVE_COREAUDIO
184 boost::shared_ptr<Source>
185 SourceFactory::createWritable (DataType type, std::string path, bool destructive, jack_nframes_t rate, bool announce)
187 /* this might throw failed_constructor(), which is OK */
189 if (type == DataType::AUDIO) {
191 boost::shared_ptr<Source> ret (new DestructiveFileSource (path,
192 Config->get_native_file_data_format(),
193 Config->get_native_file_header_format(),
201 boost::shared_ptr<Source> ret (new SndFileSource (path,
202 Config->get_native_file_data_format(),
203 Config->get_native_file_header_format(),
210 } else if (type == DataType::MIDI) {
212 boost::shared_ptr<Source> ret (new SMFSource (path));
218 return boost::shared_ptr<Source> ();