remove all duplicated _id members from children of PBD::Stateful.
[ardour.git] / libs / ardour / source_factory.cc
1 /*
2     Copyright (C) 2000-2006 Paul Davis 
3
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.
8
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.
13
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.
17
18     $Id$
19 */
20
21 #include <ardour/source_factory.h>
22 #include <ardour/sndfilesource.h>
23 #include <ardour/destructive_filesource.h>
24 #include <ardour/configuration.h>
25
26 #ifdef HAVE_COREAUDIO
27 #include <ardour/coreaudiosource.h>
28 #endif
29
30 #include "i18n.h"
31
32 using namespace ARDOUR;
33 using namespace std;
34
35 sigc::signal<void,boost::shared_ptr<Source> > SourceFactory::SourceCreated;
36
37 #ifdef HAVE_COREAUDIO
38 boost::shared_ptr<Source>
39 SourceFactory::create (Session& s, const XMLNode& node)
40 {
41         if (node.property (X_("destructive")) != 0) {
42                 
43                 boost::shared_ptr<Source> ret (new DestructiveFileSource (s, node));
44                 SourceCreated (ret);
45                 return ret;
46                 
47         } else {
48                 
49                 try {
50                         boost::shared_ptr<Source> ret (new CoreAudioSource (s, node));
51                         SourceCreated (ret);
52                         return ret;
53                 } 
54                 
55                 
56                 catch (failed_constructor& err) {
57                         boost::shared_ptr<Source> ret (new SndFileSource (s, node));
58                         SourceCreated (ret);
59                         return ret;
60                 }
61         }
62         
63         return boost::shared_ptr<Source>();
64 }
65
66 #else
67
68 boost::shared_ptr<Source>
69 SourceFactory::create (Session& s, const XMLNode& node)
70 {
71         if (node.property (X_("destructive")) != 0) {
72                 
73                 boost::shared_ptr<Source> ret (new DestructiveFileSource (s, node));
74                 SourceCreated (ret);
75                 return ret;
76                 
77         } else {
78                 
79                 boost::shared_ptr<Source> ret (new SndFileSource (s, node));
80                 SourceCreated (ret);
81                 return ret;
82         }
83 }
84
85 #endif // HAVE_COREAUDIO
86
87 #ifdef HAVE_COREAUDIO
88 boost::shared_ptr<Source>
89 SourceFactory::createReadable (Session& s, string idstr, AudioFileSource::Flag flags, bool announce)
90 {
91         if (flags & Destructive) {
92                 boost::shared_ptr<Source> ret (new DestructiveFileSource (s, idstr, flags));
93                 if (announce) {
94                         SourceCreated (ret);
95                 }
96                 return ret;
97         }
98
99         try {
100                 boost::shared_ptr<Source> ret (new CoreAudioSource (s, idstr, flags));
101                 if (announce) {
102                         SourceCreated (ret);
103                 }
104                 return ret;
105         }
106
107         catch (failed_constructor& err) {
108                 boost::shared_ptr<Source> ret (new SndFileSource (s, idstr, flags));
109                 if (announce) {
110                         SourceCreated (ret);
111                 }
112                 return ret;
113         }
114
115         return boost::shared_ptr<Source>();
116 }
117
118 #else
119
120 boost::shared_ptr<Source>
121 SourceFactory::createReadable (Session& s, string idstr, AudioFileSource::Flag flags, bool announce)
122 {
123         boost::shared_ptr<Source> ret (new SndFileSource (s, idstr, flags));
124         if (announce) {
125                 SourceCreated (ret);
126         }
127         return ret;
128 }
129
130 #endif // HAVE_COREAUDIO
131
132 boost::shared_ptr<Source>
133 SourceFactory::createWritable (Session& s, std::string path, bool destructive, jack_nframes_t rate, bool announce)
134 {
135         /* this might throw failed_constructor(), which is OK */
136         
137         if (destructive) {
138                 boost::shared_ptr<Source> ret (new DestructiveFileSource (s, path,
139                                                                           Config->get_native_file_data_format(),
140                                                                           Config->get_native_file_header_format(),
141                                                                           rate));
142                 if (announce) {
143                         SourceCreated (ret);
144                 }
145                 return ret;
146                 
147         } else {
148                 boost::shared_ptr<Source> ret (new SndFileSource (s, path, 
149                                                                   Config->get_native_file_data_format(),
150                                                                   Config->get_native_file_header_format(),
151                                                                   rate));
152                 if (announce) {
153                         SourceCreated (ret);
154                 }
155                 return ret;
156         }
157 }