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

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

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

revision 554 by schoenebeck, Thu May 19 19:25:14 2005 UTC revision 1599 by schoenebeck, Fri Dec 28 15:47:33 2007 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 Christian Schoenebeck                              *   *   Copyright (C) 2005 - 2007 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program 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  *
# Line 23  Line 23 
23    
24  #include "AudioOutputDeviceFactory.h"  #include "AudioOutputDeviceFactory.h"
25  #include "AudioOutputDevice.h"  #include "AudioOutputDevice.h"
26    #include "../../common/global_private.h"
27    
28  namespace LinuxSampler {  namespace LinuxSampler {
29    
# Line 56  namespace LinuxSampler { Line 57  namespace LinuxSampler {
57          return true;          return true;
58      }      }
59    
60      void AudioOutputDevice::ParameterActive::OnSetValue(bool b) throw (LinuxSamplerException) {      void AudioOutputDevice::ParameterActive::OnSetValue(bool b) throw (Exception) {
61          if (b) ((AudioOutputDevice*)pDevice)->Play();          if (b) ((AudioOutputDevice*)pDevice)->Play();
62          else ((AudioOutputDevice*)pDevice)->Stop();          else ((AudioOutputDevice*)pDevice)->Stop();
63      }      }
# Line 109  namespace LinuxSampler { Line 110  namespace LinuxSampler {
110          return std::vector<int>();          return std::vector<int>();
111      }      }
112    
113      void AudioOutputDevice::ParameterSampleRate::OnSetValue(int i) throw (LinuxSamplerException) {      void AudioOutputDevice::ParameterSampleRate::OnSetValue(int i) throw (Exception) {
114          /* cannot happen, as parameter is fix */          /* cannot happen, as parameter is fix */
115      }      }
116    
# Line 150  namespace LinuxSampler { Line 151  namespace LinuxSampler {
151      }      }
152    
153      optional<int> AudioOutputDevice::ParameterChannels::RangeMinAsInt(std::map<String,String> Parameters) {      optional<int> AudioOutputDevice::ParameterChannels::RangeMinAsInt(std::map<String,String> Parameters) {
154          return optional<int>::nothing;          return 1;
155      }      }
156    
157      optional<int> AudioOutputDevice::ParameterChannels::RangeMaxAsInt(std::map<String,String> Parameters) {      optional<int> AudioOutputDevice::ParameterChannels::RangeMaxAsInt(std::map<String,String> Parameters) {
# Line 161  namespace LinuxSampler { Line 162  namespace LinuxSampler {
162          return std::vector<int>();          return std::vector<int>();
163      }      }
164    
165      void AudioOutputDevice::ParameterChannels::OnSetValue(int i) throw (LinuxSamplerException) {      void AudioOutputDevice::ParameterChannels::OnSetValue(int i) throw (Exception) {
166          ((AudioOutputDevice*)pDevice)->AcquireChannels(i);          ((AudioOutputDevice*)pDevice)->AcquireChannels(i);
167      }      }
168    
# Line 174  namespace LinuxSampler { Line 175  namespace LinuxSampler {
175  // *************** AudioOutputDevice ***************  // *************** AudioOutputDevice ***************
176  // *  // *
177    
178      AudioOutputDevice::AudioOutputDevice(std::map<String,DeviceCreationParameter*> DriverParameters) {      AudioOutputDevice::AudioOutputDevice(std::map<String,DeviceCreationParameter*> DriverParameters)
179            : EnginesReader(Engines) {
180          this->Parameters = DriverParameters;          this->Parameters = DriverParameters;
181      }      }
182    
# Line 183  namespace LinuxSampler { Line 185  namespace LinuxSampler {
185          {          {
186              std::vector<AudioChannel*>::iterator iter = Channels.begin();              std::vector<AudioChannel*>::iterator iter = Channels.begin();
187              while (iter != Channels.end()) {              while (iter != Channels.end()) {
                 Channels.erase(iter);  
188                  delete *iter;                  delete *iter;
189                  iter++;                  iter++;
190              }              }
191                Channels.clear();
192          }          }
193    
194          // delete all device parameters          // delete all device parameters
195          {          {
196              std::map<String,DeviceCreationParameter*>::iterator iter = Parameters.begin();              std::map<String,DeviceCreationParameter*>::iterator iter = Parameters.begin();
197              while (iter != Parameters.end()) {              while (iter != Parameters.end()) {
                 Parameters.erase(iter);  
198                  delete iter->second;                  delete iter->second;
199                  iter++;                  iter++;
200              }              }
201                Parameters.clear();
202          }          }
203      }      }
204    
205      void AudioOutputDevice::Connect(Engine* pEngine) {      void AudioOutputDevice::Connect(Engine* pEngine) {
206          if (Engines.find(pEngine) == Engines.end()) {          std::set<Engine*>& engines = Engines.GetConfigForUpdate();
207              Engines.insert(pEngine);          if (engines.find(pEngine) == engines.end()) {
208                engines.insert(pEngine);
209                Engines.SwitchConfig().insert(pEngine);
210              // make sure the engine knows about the connection              // make sure the engine knows about the connection
211              //pEngine->Connect(this);              //pEngine->Connect(this);
212          }          }
213      }      }
214    
215      void AudioOutputDevice::Disconnect(Engine* pEngine) {      void AudioOutputDevice::Disconnect(Engine* pEngine) {
216          if (Engines.find(pEngine) != Engines.end()) { // if clause to prevent disconnect loop          std::set<Engine*>& engines = Engines.GetConfigForUpdate();
217              Engines.erase(pEngine);          if (engines.find(pEngine) != engines.end()) { // if clause to prevent disconnect loop
218                engines.erase(pEngine);
219                Engines.SwitchConfig().erase(pEngine);
220              // make sure the engine knows about the disconnection              // make sure the engine knows about the disconnection
221              //pEngine->DisconnectAudioOutputDevice();              //pEngine->DisconnectAudioOutputDevice();
222          }          }
# Line 229  namespace LinuxSampler { Line 234  namespace LinuxSampler {
234          }          }
235      }      }
236    
237        uint AudioOutputDevice::ChannelCount() {
238            return Channels.size();
239        }
240    
241      std::map<String,DeviceCreationParameter*> AudioOutputDevice::DeviceParameters() {      std::map<String,DeviceCreationParameter*> AudioOutputDevice::DeviceParameters() {
242          return Parameters;          return Parameters;
243      }      }
# Line 247  namespace LinuxSampler { Line 256  namespace LinuxSampler {
256          int result = 0;          int result = 0;
257    
258          // let all connected engines render audio for the current audio fragment cycle          // let all connected engines render audio for the current audio fragment cycle
259            const std::set<Engine*>& engines = EnginesReader.Lock();
260          #if CONFIG_RT_EXCEPTIONS          #if CONFIG_RT_EXCEPTIONS
261          try          try
262          #endif // CONFIG_RT_EXCEPTIONS          #endif // CONFIG_RT_EXCEPTIONS
263          {          {
264              std::set<Engine*>::iterator iterEngine = Engines.begin();              std::set<Engine*>::iterator iterEngine = engines.begin();
265              std::set<Engine*>::iterator end        = Engines.end();              std::set<Engine*>::iterator end        = engines.end();
266              for (; iterEngine != end; iterEngine++) {              for (; iterEngine != end; iterEngine++) {
267                  int res = (*iterEngine)->RenderAudio(Samples);                  int res = (*iterEngine)->RenderAudio(Samples);
268                  if (res != 0) result = res;                  if (res != 0) result = res;
# Line 265  namespace LinuxSampler { Line 275  namespace LinuxSampler {
275          }          }
276          #endif // CONFIG_RT_EXCEPTIONS          #endif // CONFIG_RT_EXCEPTIONS
277    
278            EnginesReader.Unlock();
279          return result;          return result;
280      }      }
281    

Legend:
Removed from v.554  
changed lines
  Added in v.1599

  ViewVC Help
Powered by ViewVC