/[svn]/linuxsampler/trunk/src/drivers/audio/AudioOutputDeviceFactory.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/drivers/audio/AudioOutputDeviceFactory.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1835 - (show annotations) (download)
Mon Feb 16 17:56:50 2009 UTC (15 years, 2 months ago) by iliev
File size: 9062 byte(s)
* Adapted drivers/Plugin class to be used as a base class for the
  AudioUnit plugin and fixed orphaned pointers when deleting PluginGlobal
* Fixed possible iterator invalidations when resetting the sampler
* Fixed memory leaks when issuing the following LSCP commands:
  GET AUDIO_OUTPUT_DRIVER INFO
  GET AUDIO_OUTPUT_DRIVER_PARAMETER INFO
  GET MIDI_INPUT_DRIVER INFO
  GET MIDI_INPUT_DRIVER_PARAMETER INFO
* Fixed possible compilation error when sqlite is not present

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 - 2007 Christian Schoenebeck *
7 * *
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21 * MA 02111-1307 USA *
22 ***************************************************************************/
23
24 #include "AudioOutputDeviceFactory.h"
25
26 #include "../../common/global_private.h"
27
28 #if HAVE_ALSA
29 # include "AudioOutputDeviceAlsa.h"
30 #endif // HAVE_ALSA
31
32 #if HAVE_JACK
33 # include "AudioOutputDeviceJack.h"
34 #endif // HAVE_JACK
35
36 #if HAVE_ARTS
37 # include "AudioOutputDeviceArts.h"
38 #endif // HAVE_ARTS
39
40 #if HAVE_ASIO
41 # include "AudioOutputDeviceAsio.h"
42 #endif // HAVE_ASIO
43
44 #if HAVE_COREAUDIO
45 # include "AudioOutputDeviceCoreAudio.h"
46 #endif // HAVE_COREAUDIO
47
48 namespace LinuxSampler {
49
50 std::map<String, AudioOutputDeviceFactory::InnerFactory*> AudioOutputDeviceFactory::InnerFactories;
51 std::map<String, DeviceParameterFactory*> AudioOutputDeviceFactory::ParameterFactories;
52
53 #if HAVE_ALSA
54 REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceAlsa);
55 /* Common parameters for now they'll have to be registered here. */
56 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterActive);
57 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterSampleRate);
58 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterChannels);
59 /* Driver specific parameters */
60 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterCard);
61 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragments);
62 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragmentSize);
63 #endif // HAVE_ALSA
64
65 #if HAVE_JACK
66 REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceJack);
67 /* Common parameters for now they'll have to be registered here. */
68 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterActive);
69 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterSampleRate);
70 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterChannels);
71 /* Driver specific parameters */
72 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterName);
73 #endif // HAVE_JACK
74
75 #if HAVE_ARTS
76 REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceArts);
77 /* Common parameters for now they'll have to be registered here. */
78 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterActive);
79 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterSampleRate);
80 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterChannels);
81 /* Driver specific parameters */
82 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterName);
83 #endif // HAVE_ARTS
84
85 #if HAVE_ASIO
86 REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceAsio);
87 /* Common parameters for now they'll have to be registered here. */
88 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterActive);
89 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterSampleRate);
90 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterChannels);
91 /* Driver specific parameters */
92 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterCard);
93 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterFragmentSize);
94 #endif // HAVE_ASIO
95
96 #if HAVE_COREAUDIO
97 REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceCoreAudio);
98 /* Common parameters for now they'll have to be registered here. */
99 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterActive);
100 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterSampleRate);
101 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterChannels);
102 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterDevice);
103 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterBuffers);
104 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterBufferSize);
105 #endif // HAVE_COREAUDIO
106
107 AudioOutputDevice* AudioOutputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters) throw (Exception) {
108 if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
109 //Let's see if we need to create parameters
110 std::map<String,DeviceCreationParameter*> thisDeviceParams;
111 DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
112 if (pParamFactory) {
113 thisDeviceParams = pParamFactory->CreateAllParams(Parameters);
114 } else {
115 //No parameters are registered by the driver. Throw if any parameters were specified.
116 if (Parameters.size() != 0) throw Exception("Driver '" + DriverName + "' does not have any parameters.");
117 }
118 //Now create the device using those parameters
119 AudioOutputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams);
120 //Now attach all parameters to the newely created device.
121 for (std::map<String,DeviceCreationParameter*>::iterator iter = thisDeviceParams.begin(); iter != thisDeviceParams.end(); iter++) {
122 iter->second->Attach(pDevice);
123 }
124 return pDevice;
125 }
126
127 std::vector<String> AudioOutputDeviceFactory::AvailableDrivers() {
128 std::vector<String> result;
129 std::map<String, InnerFactory*>::iterator iter = InnerFactories.begin();
130 while (iter != InnerFactories.end()) {
131 result.push_back(iter->first);
132 iter++;
133 }
134 return result;
135 }
136
137 String AudioOutputDeviceFactory::AvailableDriversAsString() {
138 std::vector<String> drivers = AvailableDrivers();
139 String result;
140 std::vector<String>::iterator iter = drivers.begin();
141 for (; iter != drivers.end(); iter++) {
142 if (result != "") result += ",";
143 result += *iter;
144 }
145 return result;
146 }
147
148 std::map<String,DeviceCreationParameter*> AudioOutputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (Exception) {
149 if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
150 std::map<String,DeviceCreationParameter*> thisDeviceParams;
151 DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
152 if (pParamFactory) {
153 thisDeviceParams = pParamFactory->CreateAllParams();
154 }
155 return thisDeviceParams;
156 }
157
158 DeviceCreationParameter* AudioOutputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (Exception) {
159 if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
160 DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
161 if (pParamFactory) {
162 try { return pParamFactory->Create(ParameterName); }
163 catch(Exception e) { }
164 }
165 throw Exception("Audio output driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'.");
166 }
167
168 String AudioOutputDeviceFactory::GetDriverDescription(String DriverName) throw (Exception) {
169 if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
170 return InnerFactories[DriverName]->Description();
171 }
172
173 String AudioOutputDeviceFactory::GetDriverVersion(String DriverName) throw (Exception) {
174 if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
175 return InnerFactories[DriverName]->Version();
176 }
177
178 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC