/[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 1481 - (show annotations) (download)
Wed Nov 14 23:42:15 2007 UTC (16 years, 6 months ago) by senoner
File size: 8008 byte(s)
* win32 port work in progress:
* - implemented win32 support in the following classes:
* Thread, Condition, Mutex, Path, LscpServer
* - lscp.y use DONTCARE instead of VOID
*  (a win32 symbol defined)
* - completed win32 editor plugin loader

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 namespace LinuxSampler {
44
45 std::map<String, AudioOutputDeviceFactory::InnerFactory*> AudioOutputDeviceFactory::InnerFactories;
46 std::map<String, DeviceParameterFactory*> AudioOutputDeviceFactory::ParameterFactories;
47
48 #if HAVE_ALSA
49 REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceAlsa);
50 /* Common parameters for now they'll have to be registered here. */
51 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterActive);
52 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterSampleRate);
53 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterChannels);
54 /* Driver specific parameters */
55 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterCard);
56 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragments);
57 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragmentSize);
58 #endif // HAVE_ALSA
59
60 #if HAVE_JACK
61 REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceJack);
62 /* Common parameters for now they'll have to be registered here. */
63 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterActive);
64 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterChannels);
65 /* Driver specific parameters */
66 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterName);
67 #endif // HAVE_JACK
68
69 #if HAVE_ARTS
70 REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceArts);
71 /* Common parameters for now they'll have to be registered here. */
72 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterActive);
73 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterSampleRate);
74 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterChannels);
75 /* Driver specific parameters */
76 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterName);
77 #endif // HAVE_ARTS
78
79 #if HAVE_ASIO
80 REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceAsio);
81 /* Common parameters for now they'll have to be registered here. */
82 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterActive);
83 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterSampleRate);
84 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterChannels);
85 /* Driver specific parameters */
86 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterCard);
87 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterFragmentSize);
88 #endif // HAVE_ASIO
89
90 AudioOutputDevice* AudioOutputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters) throw (Exception) {
91 if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
92 //Let's see if we need to create parameters
93 std::map<String,DeviceCreationParameter*> thisDeviceParams;
94 DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
95 if (pParamFactory) {
96 thisDeviceParams = pParamFactory->CreateAllParams(Parameters);
97 } else {
98 //No parameters are registered by the driver. Throw if any parameters were specified.
99 if (Parameters.size() != 0) throw Exception("Driver '" + DriverName + "' does not have any parameters.");
100 }
101 //Now create the device using those parameters
102 AudioOutputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams);
103 //Now attach all parameters to the newely created device.
104 for (std::map<String,DeviceCreationParameter*>::iterator iter = thisDeviceParams.begin(); iter != thisDeviceParams.end(); iter++) {
105 iter->second->Attach(pDevice);
106 }
107 return pDevice;
108 }
109
110 std::vector<String> AudioOutputDeviceFactory::AvailableDrivers() {
111 std::vector<String> result;
112 std::map<String, InnerFactory*>::iterator iter = InnerFactories.begin();
113 while (iter != InnerFactories.end()) {
114 result.push_back(iter->first);
115 iter++;
116 }
117 return result;
118 }
119
120 String AudioOutputDeviceFactory::AvailableDriversAsString() {
121 std::vector<String> drivers = AvailableDrivers();
122 String result;
123 std::vector<String>::iterator iter = drivers.begin();
124 for (; iter != drivers.end(); iter++) {
125 if (result != "") result += ",";
126 result += *iter;
127 }
128 return result;
129 }
130
131 std::map<String,DeviceCreationParameter*> AudioOutputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (Exception) {
132 if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
133 std::map<String,DeviceCreationParameter*> thisDeviceParams;
134 DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
135 if (pParamFactory) {
136 thisDeviceParams = pParamFactory->CreateAllParams();
137 }
138 return thisDeviceParams;
139 }
140
141 DeviceCreationParameter* AudioOutputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (Exception) {
142 std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName);
143 if (!parameters.count(ParameterName)) throw Exception("Audio output driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'.");
144 return parameters[ParameterName];
145 }
146
147 String AudioOutputDeviceFactory::GetDriverDescription(String DriverName) throw (Exception) {
148 if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
149 return InnerFactories[DriverName]->Description();
150 }
151
152 String AudioOutputDeviceFactory::GetDriverVersion(String DriverName) throw (Exception) {
153 if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
154 return InnerFactories[DriverName]->Version();
155 }
156
157 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC