linuxsampler 1.0.0
|
00001 /*************************************************************************** 00002 * * 00003 * LinuxSampler - modular, streaming capable sampler * 00004 * * 00005 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * 00006 * Copyright (C) 2005 - 2009 Christian Schoenebeck * 00007 * * 00008 * This program is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation; either version 2 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * 00021 * MA 02111-1307 USA * 00022 ***************************************************************************/ 00023 00024 #ifndef __LS_AUDIOOUTPUTDEVICE_H__ 00025 #define __LS_AUDIOOUTPUTDEVICE_H__ 00026 00027 #include <set> 00028 #include <map> 00029 #include <vector> 00030 #include <stdexcept> 00031 00032 #include "../../common/global.h" 00033 #include "../../common/Exception.h" 00034 #include "../Device.h" 00035 #include "../DeviceParameter.h" 00036 #include "../../engines/Engine.h" 00037 #include "AudioChannel.h" 00038 #include "../../common/SynchronizedConfig.h" 00039 #include "../../effects/EffectChain.h" 00040 00041 namespace LinuxSampler { 00042 00043 // just symbol prototyping 00044 class Engine; 00045 class AudioOutputDeviceFactory; 00046 00053 class AudioOutputDevice : public Device { 00054 public: 00055 00057 // Device parameters 00058 00063 class ParameterActive : public DeviceCreationParameterBool { 00064 public: 00065 ParameterActive(); 00066 ParameterActive(String s); 00067 virtual String Description(); 00068 virtual bool Fix(); 00069 virtual bool Mandatory(); 00070 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters(); 00071 virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters); 00072 virtual void OnSetValue(bool b) throw (Exception); 00073 static String Name(); 00074 }; 00075 00080 class ParameterSampleRate : public DeviceCreationParameterInt { 00081 public: 00082 ParameterSampleRate(); 00083 ParameterSampleRate(String s); 00084 virtual String Description(); 00085 virtual bool Fix(); 00086 virtual bool Mandatory(); 00087 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters(); 00088 virtual optional<int> DefaultAsInt(std::map<String,String> Parameters); 00089 virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters); 00090 virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters); 00091 virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters); 00092 virtual int ValueAsInt(); 00093 virtual void OnSetValue(int i) throw (Exception); 00094 static String Name(); 00095 }; 00096 00102 class ParameterChannels : public DeviceCreationParameterInt { 00103 public: 00104 ParameterChannels(); 00105 ParameterChannels(String s); 00106 virtual String Description(); 00107 virtual bool Fix(); 00108 virtual bool Mandatory(); 00109 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters(); 00110 virtual optional<int> DefaultAsInt(std::map<String,String> Parameters); 00111 virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters); 00112 virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters); 00113 virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters); 00114 virtual void OnSetValue(int i) throw (Exception); 00115 static String Name(); 00116 }; 00117 00118 00119 00121 // abstract methods 00122 // (these have to be implemented by the descendant) 00123 00138 virtual void Play() = 0; 00139 00143 virtual bool IsPlaying() = 0; 00144 00151 virtual void Stop() = 0; 00152 00162 virtual uint MaxSamplesPerCycle() = 0; 00163 00171 virtual uint SampleRate() = 0; 00172 00176 virtual String Driver() = 0; 00177 00182 virtual AudioChannel* CreateChannel(uint ChannelNr) = 0; 00183 00184 00185 00187 // normal methods 00188 // (usually not to be overriden by descendant) 00189 00198 void Connect(Engine* pEngine); 00199 00207 void Disconnect(Engine* pEngine); 00208 00213 AudioChannel* Channel(uint ChannelIndex); 00214 00233 void AcquireChannels(uint Channels); 00234 00239 uint ChannelCount(); 00240 00244 std::map<String,DeviceCreationParameter*> DeviceParameters(); 00245 00250 EffectChain* AddMasterEffectChain(); 00251 00257 void RemoveMasterEffectChain(uint iChain) throw (Exception); 00258 00263 EffectChain* MasterEffectChain(uint iChain) const; 00264 00269 uint MasterEffectChainCount() const; 00270 00271 protected: 00272 SynchronizedConfig<std::set<Engine*> > Engines; 00273 SynchronizedConfig<std::set<Engine*> >::Reader EnginesReader; 00274 std::vector<AudioChannel*> Channels; 00275 std::map<String,DeviceCreationParameter*> Parameters; 00276 std::vector<EffectChain*> vEffectChains; 00277 00278 AudioOutputDevice(std::map<String,DeviceCreationParameter*> DriverParameters); 00279 00280 virtual ~AudioOutputDevice(); 00281 00294 int RenderAudio(uint Samples); 00295 00305 int RenderSilence(uint Samples); 00306 00307 friend class AudioOutputDeviceFactory; // allow AudioOutputDeviceFactory class to destroy audio devices 00308 00309 }; 00310 00317 class AudioOutputException : public Exception { 00318 public: 00319 AudioOutputException(const std::string& msg) : Exception(msg) {} 00320 }; 00321 } 00322 00323 #endif // __LS_AUDIOOUTPUTDEVICE_H__