/[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 288 - (hide annotations) (download)
Tue Oct 19 00:36:34 2004 UTC (19 years, 7 months ago) by schoenebeck
File size: 5852 byte(s)
* configure.in: added check for UNIX98 compatibility, check if there's at
  least one supported MIDI input and audio output system available, added
  conditionals for ALSA and JACK
* src/drivers/audio/Makefile.am: ALSA and JACK drivers are only compiled
  respectively if they're supported by the system
* MidiInputDeviceFactory.cpp, AudioOutputDeviceFactory.cpp: little
  workaround for reported linker problem
* removed autotools generated files from CVS

1 schoenebeck 200 /***************************************************************************
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 schoenebeck 288 // just to avoid linker problems
26     #include "AudioOutputDeviceAlsa.h"
27     #include "AudioOutputDeviceJack.h"
28    
29 schoenebeck 200 namespace LinuxSampler {
30    
31     std::map<String, AudioOutputDeviceFactory::InnerFactory*> AudioOutputDeviceFactory::InnerFactories;
32     std::map<String, DeviceParameterFactory*> AudioOutputDeviceFactory::ParameterFactories;
33    
34 schoenebeck 288 // just a little hack to avoid linker problems
35     static int ___init___foo___() {
36     #if HAVE_ALSA
37     AudioOutputDeviceAlsa::Name().c_str();
38     #endif // HAVE_ALSA
39     #if HAVE_JACK
40     AudioOutputDeviceJack::Name().c_str();
41     #endif // HAVE_JACK
42     return 0;
43     }
44     static int ___foo___ = ___init___foo___();
45    
46 schoenebeck 200 AudioOutputDevice* AudioOutputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters) throw (LinuxSamplerException) {
47     if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no audio output driver '" + DriverName + "'.");
48     //Let's see if we need to create parameters
49     std::map<String,DeviceCreationParameter*> thisDeviceParams;
50     DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
51     if (pParamFactory) {
52     thisDeviceParams = pParamFactory->CreateAllParams(Parameters);
53     } else {
54     //No parameters are registered by the driver. Throw if any parameters were specified.
55     if (Parameters.size() != 0) throw LinuxSamplerException("Driver '" + DriverName + "' does not have any parameters.");
56     }
57     //Now create the device using those parameters
58     AudioOutputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams);
59     //Now attach all parameters to the newely created device.
60     for (std::map<String,DeviceCreationParameter*>::iterator iter = thisDeviceParams.begin(); iter != thisDeviceParams.end(); iter++) {
61     iter->second->Attach(pDevice);
62     }
63     return pDevice;
64     }
65    
66     std::vector<String> AudioOutputDeviceFactory::AvailableDrivers() {
67     std::vector<String> result;
68     std::map<String, InnerFactory*>::iterator iter = InnerFactories.begin();
69     while (iter != InnerFactories.end()) {
70     result.push_back(iter->first);
71     iter++;
72     }
73     return result;
74     }
75    
76     String AudioOutputDeviceFactory::AvailableDriversAsString() {
77     std::vector<String> drivers = AvailableDrivers();
78     String result;
79     std::vector<String>::iterator iter = drivers.begin();
80     for (; iter != drivers.end(); iter++) {
81     if (result != "") result += ",";
82     result += *iter;
83     }
84     return result;
85     }
86    
87     std::map<String,DeviceCreationParameter*> AudioOutputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (LinuxSamplerException) {
88     if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no audio output driver '" + DriverName + "'.");
89     std::map<String,DeviceCreationParameter*> thisDeviceParams;
90     DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
91     if (pParamFactory) {
92     thisDeviceParams = pParamFactory->CreateAllParams();
93     }
94     return thisDeviceParams;
95     }
96    
97     DeviceCreationParameter* AudioOutputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (LinuxSamplerException) {
98     std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName);
99     if (!parameters.count(ParameterName)) throw LinuxSamplerException("Audio output driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'.");
100     return parameters[ParameterName];
101     }
102    
103     String AudioOutputDeviceFactory::GetDriverDescription(String DriverName) throw (LinuxSamplerException) {
104     if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no audio output driver '" + DriverName + "'.");
105     return InnerFactories[DriverName]->Description();
106     }
107    
108     String AudioOutputDeviceFactory::GetDriverVersion(String DriverName) throw (LinuxSamplerException) {
109     if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no audio output driver '" + DriverName + "'.");
110     return InnerFactories[DriverName]->Version();
111     }
112    
113     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC