/[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 289 - (show annotations) (download)
Tue Oct 19 14:41:38 2004 UTC (19 years, 6 months ago) by schoenebeck
File size: 6589 byte(s)
* LinuxSampler was badly broken with last commit, fixed that
* using now James Klicman's proposol to fix the reported linker problem
* Mutex.cpp: try to force UNIX98 compatibility (if not already supported)
* Makefile.cvs: generate (and clean) all necessary autotools files

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

  ViewVC Help
Powered by ViewVC