/[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 374 - (show annotations) (download)
Sat Feb 12 00:36:08 2005 UTC (19 years, 1 month ago) by schoenebeck
File size: 6708 byte(s)
* JACK audio driver: added device creation parameter 'NAME' which can be
  used to assign an arbitrary name to the JACK client, it's now possible to
  create multiple JACK audio output devices simultaniously for LS
* src/network/lscpserver.cpp: fixed little bug in
  'SET CHANNEL AUDIO_OUTPUT_CHANNEL' (altering of audio routing)
  implementation, cleanup of error messages

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 /* Driver specific parameters */
56 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterName);
57 #endif // HAVE_JACK
58
59 AudioOutputDevice* AudioOutputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters) throw (LinuxSamplerException) {
60 if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no audio output driver '" + DriverName + "'.");
61 //Let's see if we need to create parameters
62 std::map<String,DeviceCreationParameter*> thisDeviceParams;
63 DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
64 if (pParamFactory) {
65 thisDeviceParams = pParamFactory->CreateAllParams(Parameters);
66 } else {
67 //No parameters are registered by the driver. Throw if any parameters were specified.
68 if (Parameters.size() != 0) throw LinuxSamplerException("Driver '" + DriverName + "' does not have any parameters.");
69 }
70 //Now create the device using those parameters
71 AudioOutputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams);
72 //Now attach all parameters to the newely created device.
73 for (std::map<String,DeviceCreationParameter*>::iterator iter = thisDeviceParams.begin(); iter != thisDeviceParams.end(); iter++) {
74 iter->second->Attach(pDevice);
75 }
76 return pDevice;
77 }
78
79 std::vector<String> AudioOutputDeviceFactory::AvailableDrivers() {
80 std::vector<String> result;
81 std::map<String, InnerFactory*>::iterator iter = InnerFactories.begin();
82 while (iter != InnerFactories.end()) {
83 result.push_back(iter->first);
84 iter++;
85 }
86 return result;
87 }
88
89 String AudioOutputDeviceFactory::AvailableDriversAsString() {
90 std::vector<String> drivers = AvailableDrivers();
91 String result;
92 std::vector<String>::iterator iter = drivers.begin();
93 for (; iter != drivers.end(); iter++) {
94 if (result != "") result += ",";
95 result += *iter;
96 }
97 return result;
98 }
99
100 std::map<String,DeviceCreationParameter*> AudioOutputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (LinuxSamplerException) {
101 if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no audio output driver '" + DriverName + "'.");
102 std::map<String,DeviceCreationParameter*> thisDeviceParams;
103 DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
104 if (pParamFactory) {
105 thisDeviceParams = pParamFactory->CreateAllParams();
106 }
107 return thisDeviceParams;
108 }
109
110 DeviceCreationParameter* AudioOutputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (LinuxSamplerException) {
111 std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName);
112 if (!parameters.count(ParameterName)) throw LinuxSamplerException("Audio output driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'.");
113 return parameters[ParameterName];
114 }
115
116 String AudioOutputDeviceFactory::GetDriverDescription(String DriverName) throw (LinuxSamplerException) {
117 if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no audio output driver '" + DriverName + "'.");
118 return InnerFactories[DriverName]->Description();
119 }
120
121 String AudioOutputDeviceFactory::GetDriverVersion(String DriverName) throw (LinuxSamplerException) {
122 if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no audio output driver '" + DriverName + "'.");
123 return InnerFactories[DriverName]->Version();
124 }
125
126 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC