summaryrefslogtreecommitdiff
path: root/libs/ardour/source_factory.cc
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2006-08-29 21:21:48 +0000
committerDavid Robillard <d@drobilla.net>2006-08-29 21:21:48 +0000
commit82232f06ba3eea4a2b4342ad91fab552f4044402 (patch)
treed517cb47c017f51e2ecd9450624b86eb70d9f97b /libs/ardour/source_factory.cc
parent25d1670a61d19e795227b939a98be9cf5a050c67 (diff)
Merged with trunk R861
Possible new bugs - not very thoroughly tested, but at least functional at first glance git-svn-id: svn://localhost/ardour2/branches/midi@870 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/source_factory.cc')
-rw-r--r--libs/ardour/source_factory.cc219
1 files changed, 219 insertions, 0 deletions
diff --git a/libs/ardour/source_factory.cc b/libs/ardour/source_factory.cc
new file mode 100644
index 0000000000..2fcdd29033
--- /dev/null
+++ b/libs/ardour/source_factory.cc
@@ -0,0 +1,219 @@
+/*
+ Copyright (C) 2000-2006 Paul Davis
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+*/
+
+#include <ardour/source_factory.h>
+#include <ardour/sndfilesource.h>
+#include <ardour/smf_source.h>
+#include <ardour/destructive_filesource.h>
+#include <ardour/configuration.h>
+
+#include "i18n.h"
+
+using namespace ARDOUR;
+using namespace std;
+
+sigc::signal<void,boost::shared_ptr<Source> > SourceFactory::SourceCreated;
+
+#ifdef HAVE_COREAUDIO
+
+
+boost::shared_ptr<Source>
+SourceFactory::create (const XMLNode& node)
+{
+ DataType type = DataType::AUDIO;
+ const XMLProperty* prop = node.property("type");
+ if (prop) {
+ type = DataType(prop->value());
+ }
+
+ if (type == DataType::AUDIO) {
+
+ if (node.property (X_("destructive")) != 0) {
+
+ boost::shared_ptr<Source> ret (new DestructiveFileSource (node));
+ SourceCreated (ret);
+ return ret;
+
+ } else {
+
+ try {
+ boost::shared_ptr<Source> ret (new CoreAudioSource (node));
+ SourceCreated (ret);
+ return ret;
+ }
+
+
+ catch (failed_constructor& err) {
+ boost::shared_ptr<Source> ret (new SndFileSource (node));
+ SourceCreated (ret);
+ return ret;
+ }
+ }
+
+ } else if (type == DataType::MIDI) {
+
+ boost::shared_ptr<Source> ret (new SMFSource (node));
+ SourceCreated (ret);
+ return ret;
+
+ }
+
+ return boost::shared_ptr<Source>();
+}
+
+#else
+
+boost::shared_ptr<Source>
+SourceFactory::create (const XMLNode& node)
+{
+ DataType type = DataType::AUDIO;
+ const XMLProperty* prop = node.property("type");
+ if (prop) {
+ type = DataType(prop->value());
+ }
+
+ if (type == DataType::AUDIO) {
+
+ if (node.property (X_("destructive")) != 0) {
+
+ boost::shared_ptr<Source> ret (new DestructiveFileSource (node));
+ SourceCreated (ret);
+ return ret;
+
+ } else {
+
+ boost::shared_ptr<Source> ret (new SndFileSource (node));
+ SourceCreated (ret);
+ return ret;
+ }
+
+ } else if (type == DataType::MIDI) {
+
+ boost::shared_ptr<Source> ret (new SMFSource (node));
+ SourceCreated (ret);
+ return ret;
+
+ }
+
+ return boost::shared_ptr<Source> ();
+}
+
+#endif // HAVE_COREAUDIO
+
+#ifdef HAVE_COREAUDIO
+boost::shared_ptr<Source>
+SourceFactory::createReadable (string idstr, AudioFileSource::Flag flags, bool announce)
+{
+ if (type == DataType::AUDIO) {
+ if (flags & Destructive) {
+ boost::shared_ptr<Source> ret (new DestructiveFileSource (idstr, flags));
+ if (announce) {
+ SourceCreated (ret);
+ }
+ return ret;
+ }
+
+ try {
+ boost::shared_ptr<Source> ret (new CoreAudioSource (idstr, flags));
+ if (announce) {
+ SourceCreated (ret);
+ }
+ return ret;
+ }
+
+ catch (failed_constructor& err) {
+ boost::shared_ptr<Source> ret (new SndFileSource (idstr, flags));
+ if (announce) {
+ SourceCreated (ret);
+ }
+ return ret;
+ }
+ } else if (type == DataType::MIDI) {
+
+ boost::shared_ptr<Source> ret (new SMFSource (node));
+ SourceCreated (ret);
+ return ret;
+
+ }
+
+ return boost::shared_ptr<Source>();
+}
+
+#else
+
+boost::shared_ptr<Source>
+SourceFactory::createReadable (DataType type, string idstr, AudioFileSource::Flag flags, bool announce)
+{
+ if (type == DataType::AUDIO) {
+ boost::shared_ptr<Source> ret (new SndFileSource (idstr, flags));
+ if (announce) {
+ SourceCreated (ret);
+ }
+ return ret;
+
+ } else if (type == DataType::MIDI) {
+
+ boost::shared_ptr<Source> ret (new SMFSource (idstr, SMFSource::Flag(0))); // FIXME: flags?
+ SourceCreated (ret);
+ return ret;
+
+ }
+
+ return boost::shared_ptr<Source> ();
+}
+
+#endif // HAVE_COREAUDIO
+
+boost::shared_ptr<Source>
+SourceFactory::createWritable (DataType type, std::string path, bool destructive, jack_nframes_t rate, bool announce)
+{
+ /* this might throw failed_constructor(), which is OK */
+
+ if (type == DataType::AUDIO) {
+ if (destructive) {
+ boost::shared_ptr<Source> ret (new DestructiveFileSource (path,
+ Config->get_native_file_data_format(),
+ Config->get_native_file_header_format(),
+ rate));
+ if (announce) {
+ SourceCreated (ret);
+ }
+ return ret;
+
+ } else {
+ boost::shared_ptr<Source> ret (new SndFileSource (path,
+ Config->get_native_file_data_format(),
+ Config->get_native_file_header_format(),
+ rate));
+ if (announce) {
+ SourceCreated (ret);
+ }
+ return ret;
+ }
+ } else if (type == DataType::MIDI) {
+
+ boost::shared_ptr<Source> ret (new SMFSource (path));
+ SourceCreated (ret);
+ return ret;
+
+ }
+
+ return boost::shared_ptr<Source> ();
+}