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>
29 #include <ardour/coreaudiosource.h>
34 using namespace ARDOUR;
38 sigc::signal<void,boost::shared_ptr<Source> > SourceFactory::SourceCreated;
41 SourceFactory::setup_peakfile (boost::shared_ptr<Source> s)
43 boost::shared_ptr<AudioSource> as (boost::dynamic_pointer_cast<AudioSource> (s));
45 if (as->setup_peakfile ()) {
46 error << string_compose("SourceFactory: could not set up peakfile for %1", as->name()) << endmsg;
54 boost::shared_ptr<Source>
55 SourceFactory::createSilent (Session& s, const XMLNode& node, nframes_t nframes, float sr)
57 boost::shared_ptr<Source> ret (new SilentFileSource (s, node, nframes, sr));
63 boost::shared_ptr<Source>
64 SourceFactory::create (Session& s, const XMLNode& node)
67 boost::shared_ptr<Source> ret (new CoreAudioSource (s, node));
68 if (setup_peakfile (ret)) {
69 return boost::shared_ptr<Source>();
76 catch (failed_constructor& err) {
78 /* this is allowed to throw */
80 boost::shared_ptr<Source> ret (new SndFileSource (s, node));
81 if (setup_peakfile (ret)) {
82 return boost::shared_ptr<Source>();
88 return boost::shared_ptr<Source>();
93 boost::shared_ptr<Source>
94 SourceFactory::create (Session& s, const XMLNode& node)
96 /* this is allowed to throw */
98 boost::shared_ptr<Source> ret (new SndFileSource (s, node));
100 if (setup_peakfile (ret)) {
101 return boost::shared_ptr<Source>();
108 #endif // HAVE_COREAUDIO
110 #ifdef HAVE_COREAUDIO
111 boost::shared_ptr<Source>
112 SourceFactory::createReadable (Session& s, string path, int chn, AudioFileSource::Flag flags, bool announce)
114 if (!(flags & Destructive)) {
117 boost::shared_ptr<Source> ret (new CoreAudioSource (s, path, chn, flags));
118 if (setup_peakfile (ret)) {
119 return boost::shared_ptr<Source>();
127 catch (failed_constructor& err) {
129 /* this is allowed to throw */
131 boost::shared_ptr<Source> ret (new SndFileSource (s, path, chn, flags));
132 if (setup_peakfile (ret)) {
133 return boost::shared_ptr<Source>();
143 boost::shared_ptr<Source> ret (new SndFileSource (s, path, chn, flags));
144 if (setup_peakfile (ret)) {
145 return boost::shared_ptr<Source>();
153 return boost::shared_ptr<Source>();
158 boost::shared_ptr<Source>
159 SourceFactory::createReadable (Session& s, string path, int chn, AudioFileSource::Flag flags, bool announce)
161 boost::shared_ptr<Source> ret (new SndFileSource (s, path, chn, flags));
163 if (setup_peakfile (ret)) {
164 return boost::shared_ptr<Source>();
174 #endif // HAVE_COREAUDIO
176 boost::shared_ptr<Source>
177 SourceFactory::createWritable (Session& s, std::string path, bool destructive, nframes_t rate, bool announce)
179 /* this might throw failed_constructor(), which is OK */
181 boost::shared_ptr<Source> ret (new SndFileSource
183 Config->get_native_file_data_format(),
184 Config->get_native_file_header_format(),
186 (destructive ? AudioFileSource::Flag (SndFileSource::default_writable_flags | AudioFileSource::Destructive) :
187 SndFileSource::default_writable_flags)));
189 if (setup_peakfile (ret)) {
190 return boost::shared_ptr<Source>();