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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 289 by schoenebeck, Tue Oct 19 14:41:38 2004 UTC revision 1889 by persson, Sun Apr 26 12:19:00 2009 UTC
# Line 3  Line 3 
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 - 2009 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    #include "../../common/global_private.h"
27    
28  #if HAVE_ALSA  #if HAVE_ALSA
29  # include "AudioOutputDeviceAlsa.h"  # include "AudioOutputDeviceAlsa.h"
30  #endif // HAVE_ALSA  #endif // HAVE_ALSA
# Line 30  Line 33 
33  # include "AudioOutputDeviceJack.h"  # include "AudioOutputDeviceJack.h"
34  #endif // HAVE_JACK  #endif // HAVE_JACK
35    
36    #if HAVE_ARTS
37    # include "AudioOutputDeviceArts.h"
38    #endif // HAVE_ARTS
39    
40    #if HAVE_ASIO
41    # include "AudioOutputDeviceAsio.h"
42    #endif // HAVE_ASIO
43    
44    #if HAVE_COREAUDIO
45    # include "AudioOutputDeviceCoreAudio.h"
46    #endif // HAVE_COREAUDIO
47    
48  namespace LinuxSampler {  namespace LinuxSampler {
49    
50      std::map<String, AudioOutputDeviceFactory::InnerFactory*> AudioOutputDeviceFactory::InnerFactories;      std::map<String, AudioOutputDeviceFactory::InnerFactory*> AudioOutputDeviceFactory::InnerFactories;
# Line 51  namespace LinuxSampler { Line 66  namespace LinuxSampler {
66      REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceJack);      REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceJack);
67      /* Common parameters for now they'll have to be registered here. */      /* Common parameters for now they'll have to be registered here. */
68      REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterActive);      REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterActive);
69        REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterSampleRate);
70      REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterChannels);      REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterChannels);
71        /* Driver specific parameters */
72        REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterName);
73  #endif // HAVE_JACK  #endif // HAVE_JACK
74    
75      AudioOutputDevice* AudioOutputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters) throw (LinuxSamplerException) {  #if HAVE_ARTS
76          if (!InnerFactories.count(DriverName)) throw LinuxSamplerException("There is no audio output driver '" + DriverName + "'.");      REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceArts);
77        /* Common parameters for now they'll have to be registered here. */
78        REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterActive);
79        REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterSampleRate);
80        REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterChannels);
81        /* Driver specific parameters */
82        REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterName);
83    #endif // HAVE_ARTS
84    
85    #if HAVE_ASIO
86        REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceAsio);
87        /* Common parameters for now they'll have to be registered here. */
88        REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterActive);
89        REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterSampleRate);
90        REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterChannels);
91        /* Driver specific parameters */
92        REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterCard);
93        REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterFragmentSize);
94    #endif // HAVE_ASIO
95    
96    #if HAVE_COREAUDIO
97        REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceCoreAudio);
98        /* Common parameters for now they'll have to be registered here. */
99        REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterActive);
100        REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterSampleRate);
101        REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterChannels);
102        REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterDevice);
103        REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterBuffers);
104        REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterBufferSize);
105    #endif // HAVE_COREAUDIO
106    
107        AudioOutputDevice* AudioOutputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters) throw (Exception) {
108            if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
109          //Let's see if we need to create parameters          //Let's see if we need to create parameters
110          std::map<String,DeviceCreationParameter*> thisDeviceParams;          std::map<String,DeviceCreationParameter*> thisDeviceParams;
111          DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];          DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
# Line 63  namespace LinuxSampler { Line 113  namespace LinuxSampler {
113                  thisDeviceParams = pParamFactory->CreateAllParams(Parameters);                  thisDeviceParams = pParamFactory->CreateAllParams(Parameters);
114          } else {          } else {
115                  //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.
116                  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.");
117          }          }
118          //Now create the device using those parameters          //Now create the device using those parameters
119          AudioOutputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams);          AudioOutputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams);
# Line 95  namespace LinuxSampler { Line 145  namespace LinuxSampler {
145          return result;          return result;
146      }      }
147    
148      std::map<String,DeviceCreationParameter*> AudioOutputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (LinuxSamplerException) {      std::map<String,DeviceCreationParameter*> AudioOutputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (Exception) {
149          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 + "'.");
150          std::map<String,DeviceCreationParameter*> thisDeviceParams;          std::map<String,DeviceCreationParameter*> thisDeviceParams;
151          DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];          DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
152          if (pParamFactory) {          if (pParamFactory) {
# Line 105  namespace LinuxSampler { Line 155  namespace LinuxSampler {
155          return thisDeviceParams;          return thisDeviceParams;
156      }      }
157    
158      DeviceCreationParameter* AudioOutputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (LinuxSamplerException) {      DeviceCreationParameter* AudioOutputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (Exception) {
159          std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName);          if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
160          if (!parameters.count(ParameterName)) throw LinuxSamplerException("Audio output driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'.");          DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
161          return parameters[ParameterName];          if (pParamFactory) {
162                try { return pParamFactory->Create(ParameterName); }
163                catch(Exception e) { }
164            }
165            throw Exception("Audio output driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'.");
166      }      }
167    
168      String AudioOutputDeviceFactory::GetDriverDescription(String DriverName) throw (LinuxSamplerException) {      String AudioOutputDeviceFactory::GetDriverDescription(String DriverName) throw (Exception) {
169          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 + "'.");
170          return InnerFactories[DriverName]->Description();          return InnerFactories[DriverName]->Description();
171      }      }
172    
173      String AudioOutputDeviceFactory::GetDriverVersion(String DriverName) throw (LinuxSamplerException) {      String AudioOutputDeviceFactory::GetDriverVersion(String DriverName) throw (Exception) {
174          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 + "'.");
175          return InnerFactories[DriverName]->Version();          return InnerFactories[DriverName]->Version();
176      }      }
177    
178        void AudioOutputDeviceFactory::Unregister(String DriverName) {
179            std::map<String, InnerFactory*>::iterator iter = InnerFactories.find(DriverName);
180            if (iter != InnerFactories.end()) {
181                delete iter->second;
182                InnerFactories.erase(iter);
183            }
184    
185            std::map<String, DeviceParameterFactory*>::iterator iterpf = ParameterFactories.find(DriverName);
186            if (iterpf != ParameterFactories.end()) {
187                delete iterpf->second;
188                ParameterFactories.erase(iterpf);
189            }
190        }
191    
192  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.289  
changed lines
  Added in v.1889

  ViewVC Help
Powered by ViewVC