/[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 838 - (show annotations) (download)
Fri Feb 10 14:57:40 2006 UTC (18 years, 2 months ago) by schoenebeck
File size: 7397 byte(s)
* added aRts audio output driver (by no means RT safe)

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005, 2006 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 #if HAVE_ALSA
27 # include "AudioOutputDeviceAlsa.h"
28 #endif // HAVE_ALSA
29
30 #if HAVE_JACK
31 # include "AudioOutputDeviceJack.h"
32 #endif // HAVE_JACK
33
34 #if HAVE_ARTS
35 # include "AudioOutputDeviceArts.h"
36 #endif // HAVE_ARTS
37
38 namespace LinuxSampler {
39
40 std::map<String, AudioOutputDeviceFactory::InnerFactory*> AudioOutputDeviceFactory::InnerFactories;
41 std::map<String, DeviceParameterFactory*> AudioOutputDeviceFactory::ParameterFactories;
42
43 #if HAVE_ALSA
44 REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceAlsa);
45 /* Common parameters for now they'll have to be registered here. */
46 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterActive);
47 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterSampleRate);
48 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterChannels);
49 /* Driver specific parameters */
50 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterCard);
51 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragments);
52 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragmentSize);
53 #endif // HAVE_ALSA
54
55 #if HAVE_JACK
56 REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceJack);
57 /* Common parameters for now they'll have to be registered here. */
58 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterActive);
59 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterChannels);
60 /* Driver specific parameters */
61 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterName);
62 #endif // HAVE_JACK
63
64 #if HAVE_ARTS
65 REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceArts);
66 /* Common parameters for now they'll have to be registered here. */
67 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterActive);
68 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterSampleRate);
69 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterChannels);
70 /* Driver specific parameters */
71 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterName);
72 #endif // HAVE_ARTS
73
74 AudioOutputDevice* AudioOutputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters) throw (LinuxSamplerException) {
75 if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no audio output driver '" + DriverName + "'.");
76 //Let's see if we need to create parameters
77 std::map<String,DeviceCreationParameter*> thisDeviceParams;
78 DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
79 if (pParamFactory) {
80 thisDeviceParams = pParamFactory->CreateAllParams(Parameters);
81 } else {
82 //No parameters are registered by the driver. Throw if any parameters were specified.
83 if (Parameters.size() != 0) throw LinuxSamplerException("Driver '" + DriverName + "' does not have any parameters.");
84 }
85 //Now create the device using those parameters
86 AudioOutputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams);
87 //Now attach all parameters to the newely created device.
88 for (std::map<String,DeviceCreationParameter*>::iterator iter = thisDeviceParams.begin(); iter != thisDeviceParams.end(); iter++) {
89 iter->second->Attach(pDevice);
90 }
91 return pDevice;
92 }
93
94 std::vector<String> AudioOutputDeviceFactory::AvailableDrivers() {
95 std::vector<String> result;
96 std::map<String, InnerFactory*>::iterator iter = InnerFactories.begin();
97 while (iter != InnerFactories.end()) {
98 result.push_back(iter->first);
99 iter++;
100 }
101 return result;
102 }
103
104 String AudioOutputDeviceFactory::AvailableDriversAsString() {
105 std::vector<String> drivers = AvailableDrivers();
106 String result;
107 std::vector<String>::iterator iter = drivers.begin();
108 for (; iter != drivers.end(); iter++) {
109 if (result != "") result += ",";
110 result += *iter;
111 }
112 return result;
113 }
114
115 std::map<String,DeviceCreationParameter*> AudioOutputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (LinuxSamplerException) {
116 if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no audio output driver '" + DriverName + "'.");
117 std::map<String,DeviceCreationParameter*> thisDeviceParams;
118 DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
119 if (pParamFactory) {
120 thisDeviceParams = pParamFactory->CreateAllParams();
121 }
122 return thisDeviceParams;
123 }
124
125 DeviceCreationParameter* AudioOutputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (LinuxSamplerException) {
126 std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName);
127 if (!parameters.count(ParameterName)) throw LinuxSamplerException("Audio output driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'.");
128 return parameters[ParameterName];
129 }
130
131 String AudioOutputDeviceFactory::GetDriverDescription(String DriverName) throw (LinuxSamplerException) {
132 if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no audio output driver '" + DriverName + "'.");
133 return InnerFactories[DriverName]->Description();
134 }
135
136 String AudioOutputDeviceFactory::GetDriverVersion(String DriverName) throw (LinuxSamplerException) {
137 if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no audio output driver '" + DriverName + "'.");
138 return InnerFactories[DriverName]->Version();
139 }
140
141 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC