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 * |
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 * |
33 |
#include "../../common/LinuxSamplerException.h" |
#include "../../common/LinuxSamplerException.h" |
34 |
#include "../Device.h" |
#include "../Device.h" |
35 |
#include "../DeviceParameter.h" |
#include "../DeviceParameter.h" |
36 |
#include "../../engines/common/Engine.h" |
#include "../../engines/common/EngineChannel.h" |
37 |
#include "AudioChannel.h" |
#include "AudioChannel.h" |
38 |
|
|
39 |
namespace LinuxSampler { |
namespace LinuxSampler { |
40 |
|
|
41 |
// just symbol prototyping |
// just symbol prototyping |
42 |
class Engine; |
class EngineChannel; |
43 |
|
|
44 |
/** Abstract base class for audio output drivers in LinuxSampler |
/** Abstract base class for audio output drivers in LinuxSampler |
45 |
* |
* |
59 |
*/ |
*/ |
60 |
class ParameterActive : public DeviceCreationParameterBool { |
class ParameterActive : public DeviceCreationParameterBool { |
61 |
public: |
public: |
62 |
ParameterActive( void ) : DeviceCreationParameterBool() { InitWithDefault(); } |
ParameterActive(); |
63 |
ParameterActive( String s ) : DeviceCreationParameterBool(s) {} |
ParameterActive(String s); |
64 |
virtual String Description() { return "Enable / disable device"; } |
virtual String Description(); |
65 |
virtual bool Fix() { return false; } |
virtual bool Fix(); |
66 |
virtual bool Mandatory() { return false; } |
virtual bool Mandatory(); |
67 |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() { return std::map<String,DeviceCreationParameter*>(); } |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters(); |
68 |
virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters) { return true; } |
virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters); |
69 |
virtual void OnSetValue(bool b) throw (LinuxSamplerException) { if (b) ((AudioOutputDevice*)pDevice)->Play(); else ((AudioOutputDevice*)pDevice)->Stop(); } |
virtual void OnSetValue(bool b) throw (LinuxSamplerException); |
70 |
static String Name() { return "ACTIVE"; } |
static String Name(); |
71 |
}; |
}; |
72 |
|
|
73 |
/** Device Parameter 'SAMPLERATE' |
/** Device Parameter 'SAMPLERATE' |
76 |
*/ |
*/ |
77 |
class ParameterSampleRate : public DeviceCreationParameterInt { |
class ParameterSampleRate : public DeviceCreationParameterInt { |
78 |
public: |
public: |
79 |
ParameterSampleRate() : DeviceCreationParameterInt() { InitWithDefault(); } |
ParameterSampleRate(); |
80 |
ParameterSampleRate( String s ) : DeviceCreationParameterInt(s) {} |
ParameterSampleRate(String s); |
81 |
virtual String Description() { return "Output sample rate"; } |
virtual String Description(); |
82 |
virtual bool Fix() { return true; } |
virtual bool Fix(); |
83 |
virtual bool Mandatory() { return false; } |
virtual bool Mandatory(); |
84 |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() { return std::map<String,DeviceCreationParameter*>(); } |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters(); |
85 |
virtual optional<int> DefaultAsInt(std::map<String,String> Parameters) { return 44100; } |
virtual optional<int> DefaultAsInt(std::map<String,String> Parameters); |
86 |
virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; } |
virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters); |
87 |
virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; } |
virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters); |
88 |
virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters) { return std::vector<int>(); } |
virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters); |
89 |
virtual void OnSetValue(int i) throw (LinuxSamplerException) { /* cannot happen, as parameter is fix */ } |
virtual void OnSetValue(int i) throw (LinuxSamplerException); |
90 |
static String Name() { return "SAMPLERATE"; } |
static String Name(); |
91 |
}; |
}; |
92 |
|
|
93 |
/** Device Parameters 'CHANNELS' |
/** Device Parameters 'CHANNELS' |
97 |
*/ |
*/ |
98 |
class ParameterChannels : public DeviceCreationParameterInt { |
class ParameterChannels : public DeviceCreationParameterInt { |
99 |
public: |
public: |
100 |
ParameterChannels() : DeviceCreationParameterInt() { InitWithDefault(); } |
ParameterChannels(); |
101 |
ParameterChannels( String s ) : DeviceCreationParameterInt(s) {} |
ParameterChannels(String s); |
102 |
virtual String Description() { return "Number of output channels"; } |
virtual String Description(); |
103 |
virtual bool Fix() { return false; } |
virtual bool Fix(); |
104 |
virtual bool Mandatory() { return false; } |
virtual bool Mandatory(); |
105 |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() { return std::map<String,DeviceCreationParameter*>(); } |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters(); |
106 |
virtual optional<int> DefaultAsInt(std::map<String,String> Parameters) { return 2; } |
virtual optional<int> DefaultAsInt(std::map<String,String> Parameters); |
107 |
virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; } |
virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters); |
108 |
virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; } |
virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters); |
109 |
virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters) { return std::vector<int>(); } |
virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters); |
110 |
virtual void OnSetValue(int i) throw (LinuxSamplerException) { ((AudioOutputDevice*)pDevice)->AcquireChannels(i); } |
virtual void OnSetValue(int i) throw (LinuxSamplerException); |
111 |
static String Name() { return "CHANNELS"; } |
static String Name(); |
112 |
}; |
}; |
113 |
|
|
114 |
|
|
147 |
virtual void Stop() = 0; |
virtual void Stop() = 0; |
148 |
|
|
149 |
/** |
/** |
|
* This method will usually be called by the sampler engines that |
|
|
* are connected to this audio device to inform the audio device |
|
|
* how much audio channels the engine(s) need. It's the |
|
|
* responsibility of the audio device to offer that amount of |
|
|
* audio channels - again: this is not an option this is a must! |
|
|
* The engines will assume to be able to access those audio |
|
|
* channels right after. If the audio driver is not able to offer |
|
|
* that much channels, it can simply create mix channels which |
|
|
* are then just mixed to the 'real' audio channels. See |
|
|
* AudioChannel.h for details about channels and mix channels. |
|
|
* |
|
|
* @param Channels - amount of output channels required by |
|
|
* a sampler engine |
|
|
* @throws AudioOutputException if desired amount of channels |
|
|
* cannot be offered |
|
|
* @see AudioChannel |
|
|
*/ |
|
|
virtual void AcquireChannels(uint Channels) = 0; |
|
|
|
|
|
/** |
|
150 |
* Maximum amount of sample points the implementing audio |
* Maximum amount of sample points the implementing audio |
151 |
* device will ever demand the sampler engines to write in one |
* device will ever demand the sampler engines to write in one |
152 |
* fragment cycle / period. Simple audio device drivers usually |
* fragment cycle / period. Simple audio device drivers usually |
167 |
virtual uint SampleRate() = 0; |
virtual uint SampleRate() = 0; |
168 |
|
|
169 |
/** |
/** |
170 |
* Return the audio output device driver type name. |
* Return the audio output device driver name. |
171 |
*/ |
*/ |
172 |
virtual String Driver() = 0; |
virtual String Driver() = 0; |
173 |
|
|
174 |
|
/** |
175 |
|
* Create new audio channel. This will be called by |
176 |
|
* AcquireChannels(). Each driver must implement it. |
177 |
|
*/ |
178 |
|
virtual AudioChannel* CreateChannel(uint ChannelNr) = 0; |
179 |
|
|
180 |
|
|
181 |
|
|
182 |
///////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////// |
183 |
// normal methods |
// normal methods |
184 |
// (usually not to be overriden by descendant) |
// (usually not to be overriden by descendant) |
189 |
* device and the engine will also automatically be informed |
* device and the engine will also automatically be informed |
190 |
* about the connection. |
* about the connection. |
191 |
* |
* |
192 |
* @param pEngine - sampler engine |
* @param pEngineChannel - sampler engine channel |
193 |
*/ |
*/ |
194 |
void Connect(Engine* pEngine); |
void Connect(EngineChannel* pEngineChannel); |
195 |
|
|
196 |
/** |
/** |
197 |
* Disconnect given sampler engine from this audio output device. |
* Disconnect given sampler engine from this audio output device. |
198 |
* Removes given sampler engine reference from the Engines |
* Removes given sampler engine reference from the Engines |
199 |
* container of this audio device. |
* container of this audio device. |
200 |
* |
* |
201 |
* @param pEngine - sampler engine |
* @param pEngineChannel - sampler engine channel |
202 |
*/ |
*/ |
203 |
void Disconnect(Engine* pEngine); |
void Disconnect(EngineChannel* pEngineChannel); |
204 |
|
|
205 |
/** |
/** |
206 |
* Returns audio channel with index \a ChannelIndex or NULL if |
* Returns audio channel with index \a ChannelIndex or NULL if |
209 |
AudioChannel* Channel(uint ChannelIndex); |
AudioChannel* Channel(uint ChannelIndex); |
210 |
|
|
211 |
/** |
/** |
212 |
|
* This method will usually be called by the sampler engines that |
213 |
|
* are connected to this audio device to inform the audio device |
214 |
|
* how much audio channels the engine(s) need. It's the |
215 |
|
* responsibility of the audio device to offer that amount of |
216 |
|
* audio channels - again: this is not an option this is a must! |
217 |
|
* The engines will assume to be able to access those audio |
218 |
|
* channels right after. If the audio driver is not able to offer |
219 |
|
* that much channels, it can simply create mix channels which |
220 |
|
* are then just mixed to the 'real' audio channels. See |
221 |
|
* AudioChannel.h for details about channels and mix channels. |
222 |
|
* |
223 |
|
* @param Channels - amount of output channels required by |
224 |
|
* a sampler engine |
225 |
|
* @throws AudioOutputException if desired amount of channels |
226 |
|
* cannot be offered |
227 |
|
* @see AudioChannel |
228 |
|
*/ |
229 |
|
void AcquireChannels(uint Channels); |
230 |
|
|
231 |
|
/** |
232 |
* Returns all device parameter settings. |
* Returns all device parameter settings. |
233 |
*/ |
*/ |
234 |
std::map<String,DeviceCreationParameter*> DeviceParameters(); |
std::map<String,DeviceCreationParameter*> DeviceParameters(); |
235 |
|
|
236 |
protected: |
protected: |
237 |
std::set<Engine*> Engines; ///< All sampler engines that are connected to the audio output device. |
std::set<EngineChannel*> EngineChannels; ///< All sampler engine channels that are connected to the audio output device. |
238 |
std::vector<AudioChannel*> Channels; ///< All audio channels of the audio output device. This is just a container; the descendant has to create channels by himself. |
std::vector<AudioChannel*> Channels; ///< All audio channels of the audio output device. This is just a container; the descendant has to create channels by himself. |
239 |
std::map<String,DeviceCreationParameter*> Parameters; ///< All device parameters. |
std::map<String,DeviceCreationParameter*> Parameters; ///< All device parameters. |
240 |
|
|