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, 2006 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 * |
30 |
#include <stdexcept> |
#include <stdexcept> |
31 |
|
|
32 |
#include "../../common/global.h" |
#include "../../common/global.h" |
33 |
#include "../../common/LinuxSamplerException.h" |
#include "../../common/Exception.h" |
34 |
#include "../InputOutputDevice.h" |
#include "../Device.h" |
35 |
#include "../DeviceParameter.h" |
#include "../DeviceParameter.h" |
36 |
#include "../../engines/common/Engine.h" |
#include "../../engines/Engine.h" |
37 |
#include "AudioChannel.h" |
#include "AudioChannel.h" |
38 |
|
#include "../../common/SynchronizedConfig.h" |
39 |
|
|
40 |
namespace LinuxSampler { |
namespace LinuxSampler { |
41 |
|
|
48 |
* connection to a specific audio output system (e.g. Alsa, Jack, |
* connection to a specific audio output system (e.g. Alsa, Jack, |
49 |
* CoreAudio). |
* CoreAudio). |
50 |
*/ |
*/ |
51 |
class AudioOutputDevice : public InputOutputDevice { |
class AudioOutputDevice : public Device { |
52 |
public: |
public: |
53 |
|
|
54 |
///////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////// |
55 |
// Device parameters |
// Device parameters |
56 |
|
|
57 |
|
/** Device Parameter 'ACTIVE' |
58 |
|
* |
59 |
|
* Used to activate / deactivate the audio output device. |
60 |
|
*/ |
61 |
class ParameterActive : public DeviceCreationParameterBool { |
class ParameterActive : public DeviceCreationParameterBool { |
62 |
public: |
public: |
63 |
ParameterActive( void ) : DeviceCreationParameterBool() { InitWithDefault(); } |
ParameterActive(); |
64 |
ParameterActive( String s ) : DeviceCreationParameterBool(s) {} |
ParameterActive(String s); |
65 |
virtual String Description() { return "Enable / disable device"; } |
virtual String Description(); |
66 |
virtual bool Fix() { return false; } |
virtual bool Fix(); |
67 |
virtual bool Mandatory() { return false; } |
virtual bool Mandatory(); |
68 |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() { return std::map<String,DeviceCreationParameter*>(); } |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters(); |
69 |
virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters) { return true; } |
virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters); |
70 |
virtual void OnSetValue(bool b) throw (LinuxSamplerException) { if (b) ((AudioOutputDevice*)pDevice)->Play(); else ((AudioOutputDevice*)pDevice)->Stop(); } |
virtual void OnSetValue(bool b) throw (Exception); |
71 |
static String Name( void ) { return "active"; } |
static String Name(); |
72 |
}; |
}; |
73 |
|
|
74 |
|
/** Device Parameter 'SAMPLERATE' |
75 |
|
* |
76 |
|
* Used to set the sample rate of the audio output device. |
77 |
|
*/ |
78 |
class ParameterSampleRate : public DeviceCreationParameterInt { |
class ParameterSampleRate : public DeviceCreationParameterInt { |
79 |
public: |
public: |
80 |
ParameterSampleRate() : DeviceCreationParameterInt() { InitWithDefault(); } |
ParameterSampleRate(); |
81 |
ParameterSampleRate( String s ) : DeviceCreationParameterInt(s) {} |
ParameterSampleRate(String s); |
82 |
virtual String Description() { return "Output sample rate"; } |
virtual String Description(); |
83 |
virtual bool Fix() { return true; } |
virtual bool Fix(); |
84 |
virtual bool Mandatory() { return false; } |
virtual bool Mandatory(); |
85 |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() { return std::map<String,DeviceCreationParameter*>(); } |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters(); |
86 |
virtual optional<int> DefaultAsInt(std::map<String,String> Parameters) { return 44100; } |
virtual optional<int> DefaultAsInt(std::map<String,String> Parameters); |
87 |
virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; } |
virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters); |
88 |
virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; } |
virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters); |
89 |
virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters) { return std::vector<int>(); } |
virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters); |
90 |
virtual void OnSetValue(int i) throw (LinuxSamplerException) { /* cannot happen, as parameter is fix */ } |
virtual void OnSetValue(int i) throw (Exception); |
91 |
static String Name( void ) { return "samplerate"; } |
static String Name(); |
92 |
}; |
}; |
93 |
|
|
94 |
|
/** Device Parameters 'CHANNELS' |
95 |
|
* |
96 |
|
* Used to increase / decrease the number of audio channels of |
97 |
|
* audio output device. |
98 |
|
*/ |
99 |
class ParameterChannels : public DeviceCreationParameterInt { |
class ParameterChannels : public DeviceCreationParameterInt { |
100 |
public: |
public: |
101 |
ParameterChannels() : DeviceCreationParameterInt() { InitWithDefault(); } |
ParameterChannels(); |
102 |
ParameterChannels( String s ) : DeviceCreationParameterInt(s) {} |
ParameterChannels(String s); |
103 |
virtual String Description() { return "Number of output channels"; } |
virtual String Description(); |
104 |
virtual bool Fix() { return false; } |
virtual bool Fix(); |
105 |
virtual bool Mandatory() { return false; } |
virtual bool Mandatory(); |
106 |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() { return std::map<String,DeviceCreationParameter*>(); } |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters(); |
107 |
virtual optional<int> DefaultAsInt(std::map<String,String> Parameters) { return 2; } |
virtual optional<int> DefaultAsInt(std::map<String,String> Parameters); |
108 |
virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; } |
virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters); |
109 |
virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; } |
virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters); |
110 |
virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters) { return std::vector<int>(); } |
virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters); |
111 |
virtual void OnSetValue(int i) throw (LinuxSamplerException) { ((AudioOutputDevice*)pDevice)->AcquireChannels(i); } |
virtual void OnSetValue(int i) throw (Exception); |
112 |
static String Name( void ) { return "channels"; } |
static String Name(); |
113 |
}; |
}; |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
///////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////// |
118 |
// abstract methods |
// abstract methods |
119 |
// (these have to be implemented by the descendant) |
// (these have to be implemented by the descendant) |
148 |
virtual void Stop() = 0; |
virtual void Stop() = 0; |
149 |
|
|
150 |
/** |
/** |
|
* 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; |
|
|
|
|
|
/** |
|
151 |
* Maximum amount of sample points the implementing audio |
* Maximum amount of sample points the implementing audio |
152 |
* device will ever demand the sampler engines to write in one |
* device will ever demand the sampler engines to write in one |
153 |
* fragment cycle / period. Simple audio device drivers usually |
* fragment cycle / period. Simple audio device drivers usually |
168 |
virtual uint SampleRate() = 0; |
virtual uint SampleRate() = 0; |
169 |
|
|
170 |
/** |
/** |
171 |
* Return the audio output device driver type name. |
* Return the audio output device driver name. |
172 |
*/ |
*/ |
173 |
virtual String Driver() = 0; |
virtual String Driver() = 0; |
174 |
|
|
175 |
|
/** |
176 |
|
* Create new audio channel. This will be called by |
177 |
|
* AcquireChannels(). Each driver must implement it. |
178 |
|
*/ |
179 |
|
virtual AudioChannel* CreateChannel(uint ChannelNr) = 0; |
180 |
|
|
181 |
|
|
182 |
|
|
183 |
///////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////// |
184 |
// normal methods |
// normal methods |
185 |
// (usually not to be overriden by descendant) |
// (usually not to be overriden by descendant) |
209 |
*/ |
*/ |
210 |
AudioChannel* Channel(uint ChannelIndex); |
AudioChannel* Channel(uint ChannelIndex); |
211 |
|
|
212 |
std::map<String,DeviceCreationParameter*> DeviceParameters(); |
/** |
213 |
|
* This method will usually be called by the sampler engines that |
214 |
|
* are connected to this audio device to inform the audio device |
215 |
|
* how much audio channels the engine(s) need. It's the |
216 |
|
* responsibility of the audio device to offer that amount of |
217 |
|
* audio channels - again: this is not an option this is a must! |
218 |
|
* The engines will assume to be able to access those audio |
219 |
|
* channels right after. If the audio driver is not able to offer |
220 |
|
* that much channels, it can simply create mix channels which |
221 |
|
* are then just mixed to the 'real' audio channels. See |
222 |
|
* AudioChannel.h for details about channels and mix channels. |
223 |
|
* |
224 |
|
* @param Channels - amount of output channels required by |
225 |
|
* a sampler engine |
226 |
|
* @throws AudioOutputException if desired amount of channels |
227 |
|
* cannot be offered |
228 |
|
* @see AudioChannel |
229 |
|
*/ |
230 |
|
void AcquireChannels(uint Channels); |
231 |
|
|
232 |
|
/** |
233 |
|
* Returns the amount of audio channels (including the so called |
234 |
|
* "mix channels") the device is currently providing. |
235 |
|
*/ |
236 |
|
uint ChannelCount(); |
237 |
|
|
238 |
|
/** |
239 |
|
* Returns all device parameter settings. |
240 |
|
*/ |
241 |
|
std::map<String,DeviceCreationParameter*> DeviceParameters(); |
242 |
|
|
243 |
protected: |
protected: |
244 |
std::set<Engine*> Engines; ///< All sampler engines that are connected to the audio output device. |
SynchronizedConfig<std::set<Engine*> > Engines; ///< All sampler engines that are connected to the audio output device. |
245 |
|
SynchronizedConfig<std::set<Engine*> >::Reader EnginesReader; ///< Audio thread access to Engines. |
246 |
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. |
247 |
std::map<String,DeviceCreationParameter*> Parameters; ///< All device parameters. |
std::map<String,DeviceCreationParameter*> Parameters; ///< All device parameters. |
248 |
|
|
285 |
* (which should be done in the constructor of the AudioOutputDevice |
* (which should be done in the constructor of the AudioOutputDevice |
286 |
* descendant). |
* descendant). |
287 |
*/ |
*/ |
288 |
class AudioOutputException : public LinuxSamplerException { |
class AudioOutputException : public Exception { |
289 |
public: |
public: |
290 |
AudioOutputException(const std::string& msg) : LinuxSamplerException(msg) {} |
AudioOutputException(const std::string& msg) : Exception(msg) {} |
291 |
}; |
}; |
292 |
} |
} |
293 |
|
|