/[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 1424 - (hide annotations) (download)
Sun Oct 14 22:00:17 2007 UTC (16 years, 7 months ago) by schoenebeck
File size: 7307 byte(s)
* code cleanup:
- global.h now only covers global definitions that are needed for the C++
  API header files, all implementation internal global definitions are now
  in global_private.h
- atomic.h is not exposed to the C++ API anymore (replaced the references
  in SynchronizedConfig.h for this with local definitions)
- no need to include config.h anymore for using LS's API header files
- DB instruments classes are not exposed to the C++ API
- POSIX callback functions of Thread.h are hidden
- the (optional) gig Engine benchmark compiles again
- updated Doxyfile.in
- fixed warnings in API doc generation
* preparations for release 0.5.0

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

  ViewVC Help
Powered by ViewVC