3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
|
* Copyright (C) 2005 - 2007 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* 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 * |
* 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 * |
* the Free Software Foundation; either version 2 of the License, or * |
11 |
* (at your option) any later version. * |
* (at your option) any later version. * |
12 |
* * |
* * |
13 |
* This program is distributed in the hope that it will be useful, * |
* This library is distributed in the hope that it will be useful, * |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 |
* GNU General Public License for more details. * |
* GNU General Public License for more details. * |
17 |
* * |
* * |
18 |
* You should have received a copy of the GNU General Public License * |
* You should have received a copy of the GNU General Public License * |
19 |
* along with this program; if not, write to the Free Software * |
* along with this library; if not, write to the Free Software * |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
***************************************************************************/ |
23 |
|
|
24 |
#include "AudioOutputDeviceFactory.h" |
#include "AudioOutputDeviceFactory.h" |
25 |
|
|
26 |
// just to avoid linker problems |
#include "../../common/global_private.h" |
27 |
#include "AudioOutputDeviceAlsa.h" |
|
28 |
#include "AudioOutputDeviceJack.h" |
#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 |
namespace LinuxSampler { |
namespace LinuxSampler { |
41 |
|
|
42 |
std::map<String, AudioOutputDeviceFactory::InnerFactory*> AudioOutputDeviceFactory::InnerFactories; |
std::map<String, AudioOutputDeviceFactory::InnerFactory*> AudioOutputDeviceFactory::InnerFactories; |
43 |
std::map<String, DeviceParameterFactory*> AudioOutputDeviceFactory::ParameterFactories; |
std::map<String, DeviceParameterFactory*> AudioOutputDeviceFactory::ParameterFactories; |
44 |
|
|
45 |
// just a little hack to avoid linker problems |
#if HAVE_ALSA |
46 |
static int ___init___foo___() { |
REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceAlsa); |
47 |
#if HAVE_ALSA |
/* Common parameters for now they'll have to be registered here. */ |
48 |
AudioOutputDeviceAlsa::Name().c_str(); |
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterActive); |
49 |
#endif // HAVE_ALSA |
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterSampleRate); |
50 |
#if HAVE_JACK |
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterChannels); |
51 |
AudioOutputDeviceJack::Name().c_str(); |
/* Driver specific parameters */ |
52 |
#endif // HAVE_JACK |
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterCard); |
53 |
return 0; |
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragments); |
54 |
} |
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragmentSize); |
55 |
static int ___foo___ = ___init___foo___(); |
#endif // HAVE_ALSA |
56 |
|
|
57 |
|
#if HAVE_JACK |
58 |
|
REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceJack); |
59 |
|
/* Common parameters for now they'll have to be registered here. */ |
60 |
|
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterActive); |
61 |
|
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterChannels); |
62 |
|
/* Driver specific parameters */ |
63 |
|
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterName); |
64 |
|
#endif // HAVE_JACK |
65 |
|
|
66 |
|
#if HAVE_ARTS |
67 |
|
REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceArts); |
68 |
|
/* Common parameters for now they'll have to be registered here. */ |
69 |
|
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterActive); |
70 |
|
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterSampleRate); |
71 |
|
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterChannels); |
72 |
|
/* Driver specific parameters */ |
73 |
|
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterName); |
74 |
|
#endif // HAVE_ARTS |
75 |
|
|
76 |
AudioOutputDevice* AudioOutputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters) throw (LinuxSamplerException) { |
AudioOutputDevice* AudioOutputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters) throw (Exception) { |
77 |
if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no audio output driver '" + DriverName + "'."); |
if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'."); |
78 |
//Let's see if we need to create parameters |
//Let's see if we need to create parameters |
79 |
std::map<String,DeviceCreationParameter*> thisDeviceParams; |
std::map<String,DeviceCreationParameter*> thisDeviceParams; |
80 |
DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName]; |
DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName]; |
82 |
thisDeviceParams = pParamFactory->CreateAllParams(Parameters); |
thisDeviceParams = pParamFactory->CreateAllParams(Parameters); |
83 |
} else { |
} else { |
84 |
//No parameters are registered by the driver. Throw if any parameters were specified. |
//No parameters are registered by the driver. Throw if any parameters were specified. |
85 |
if (Parameters.size() != 0) throw LinuxSamplerException("Driver '" + DriverName + "' does not have any parameters."); |
if (Parameters.size() != 0) throw Exception("Driver '" + DriverName + "' does not have any parameters."); |
86 |
} |
} |
87 |
//Now create the device using those parameters |
//Now create the device using those parameters |
88 |
AudioOutputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams); |
AudioOutputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams); |
114 |
return result; |
return result; |
115 |
} |
} |
116 |
|
|
117 |
std::map<String,DeviceCreationParameter*> AudioOutputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (LinuxSamplerException) { |
std::map<String,DeviceCreationParameter*> AudioOutputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (Exception) { |
118 |
if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no audio output driver '" + DriverName + "'."); |
if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'."); |
119 |
std::map<String,DeviceCreationParameter*> thisDeviceParams; |
std::map<String,DeviceCreationParameter*> thisDeviceParams; |
120 |
DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName]; |
DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName]; |
121 |
if (pParamFactory) { |
if (pParamFactory) { |
124 |
return thisDeviceParams; |
return thisDeviceParams; |
125 |
} |
} |
126 |
|
|
127 |
DeviceCreationParameter* AudioOutputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (LinuxSamplerException) { |
DeviceCreationParameter* AudioOutputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (Exception) { |
128 |
std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName); |
std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName); |
129 |
if (!parameters.count(ParameterName)) throw LinuxSamplerException("Audio output driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'."); |
if (!parameters.count(ParameterName)) throw Exception("Audio output driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'."); |
130 |
return parameters[ParameterName]; |
return parameters[ParameterName]; |
131 |
} |
} |
132 |
|
|
133 |
String AudioOutputDeviceFactory::GetDriverDescription(String DriverName) throw (LinuxSamplerException) { |
String AudioOutputDeviceFactory::GetDriverDescription(String DriverName) throw (Exception) { |
134 |
if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no audio output driver '" + DriverName + "'."); |
if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'."); |
135 |
return InnerFactories[DriverName]->Description(); |
return InnerFactories[DriverName]->Description(); |
136 |
} |
} |
137 |
|
|
138 |
String AudioOutputDeviceFactory::GetDriverVersion(String DriverName) throw (LinuxSamplerException) { |
String AudioOutputDeviceFactory::GetDriverVersion(String DriverName) throw (Exception) { |
139 |
if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no audio output driver '" + DriverName + "'."); |
if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'."); |
140 |
return InnerFactories[DriverName]->Version(); |
return InnerFactories[DriverName]->Version(); |
141 |
} |
} |
142 |
|
|