/[svn]/linuxsampler/trunk/src/drivers/audio/AudioOutputDeviceFactory.cpp
ViewVC logotype

Annotation of /linuxsampler/trunk/src/drivers/audio/AudioOutputDeviceFactory.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1481 - (hide 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 schoenebeck 200 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 1424 * Copyright (C) 2005 - 2007 Christian Schoenebeck *
7 schoenebeck 200 * *
8 schoenebeck 838 * This library is free software; you can redistribute it and/or modify *
9 schoenebeck 200 * 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 schoenebeck 838 * This library is distributed in the hope that it will be useful, *
14 schoenebeck 200 * 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 schoenebeck 838 * along with this library; if not, write to the Free Software *
20 schoenebeck 200 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21     * MA 02111-1307 USA *
22     ***************************************************************************/
23    
24     #include "AudioOutputDeviceFactory.h"
25    
26 schoenebeck 1424 #include "../../common/global_private.h"
27    
28 schoenebeck 289 #if HAVE_ALSA
29     # include "AudioOutputDeviceAlsa.h"
30     #endif // HAVE_ALSA
31 schoenebeck 288
32 schoenebeck 289 #if HAVE_JACK
33     # include "AudioOutputDeviceJack.h"
34     #endif // HAVE_JACK
35    
36 schoenebeck 838 #if HAVE_ARTS
37     # include "AudioOutputDeviceArts.h"
38     #endif // HAVE_ARTS
39    
40 senoner 1481 #if HAVE_ASIO
41     # include "AudioOutputDeviceAsio.h"
42     #endif // HAVE_ASIO
43 schoenebeck 200 namespace LinuxSampler {
44    
45     std::map<String, AudioOutputDeviceFactory::InnerFactory*> AudioOutputDeviceFactory::InnerFactories;
46     std::map<String, DeviceParameterFactory*> AudioOutputDeviceFactory::ParameterFactories;
47    
48 schoenebeck 289 #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 schoenebeck 288
60 schoenebeck 289 #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 schoenebeck 374 /* Driver specific parameters */
66     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterName);
67 schoenebeck 289 #endif // HAVE_JACK
68    
69 schoenebeck 838 #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 senoner 1481 #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 schoenebeck 880 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 schoenebeck 200 //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 schoenebeck 880 if (Parameters.size() != 0) throw Exception("Driver '" + DriverName + "' does not have any parameters.");
100 schoenebeck 200 }
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 schoenebeck 880 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 schoenebeck 200 std::map<String,DeviceCreationParameter*> thisDeviceParams;
134     DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
135     if (pParamFactory) {
136     thisDeviceParams = pParamFactory->CreateAllParams();
137     }
138     return thisDeviceParams;
139     }
140    
141 schoenebeck 880 DeviceCreationParameter* AudioOutputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (Exception) {
142 schoenebeck 200 std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName);
143 schoenebeck 880 if (!parameters.count(ParameterName)) throw Exception("Audio output driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'.");
144 schoenebeck 200 return parameters[ParameterName];
145     }
146    
147 schoenebeck 880 String AudioOutputDeviceFactory::GetDriverDescription(String DriverName) throw (Exception) {
148     if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
149 schoenebeck 200 return InnerFactories[DriverName]->Description();
150     }
151    
152 schoenebeck 880 String AudioOutputDeviceFactory::GetDriverVersion(String DriverName) throw (Exception) {
153     if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
154 schoenebeck 200 return InnerFactories[DriverName]->Version();
155     }
156    
157     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC