2 |
* * |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003 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 * |
21 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
***************************************************************************/ |
23 |
|
|
24 |
|
#include <sstream> |
25 |
|
|
26 |
#include "Sampler.h" |
#include "Sampler.h" |
27 |
|
|
28 |
#include "audiodriver/AudioOutputDeviceAlsa.h" |
#include "engines/EngineFactory.h" |
29 |
#include "audiodriver/AudioOutputDeviceJack.h" |
#include "engines/EngineChannelFactory.h" |
30 |
#include "mididriver/MidiInputDeviceAlsa.h" |
#include "drivers/audio/AudioOutputDeviceFactory.h" |
31 |
#include "engines/gig/Engine.h" |
#include "drivers/midi/MidiInputDeviceFactory.h" |
32 |
|
#include "network/lscpserver.h" |
33 |
|
|
34 |
namespace LinuxSampler { |
namespace LinuxSampler { |
35 |
|
|
38 |
|
|
39 |
SamplerChannel::SamplerChannel(Sampler* pS) { |
SamplerChannel::SamplerChannel(Sampler* pS) { |
40 |
pSampler = pS; |
pSampler = pS; |
41 |
pEngine = NULL; |
pEngineChannel = NULL; |
|
pMidiInputDevice = NULL; |
|
42 |
pAudioOutputDevice = NULL; |
pAudioOutputDevice = NULL; |
43 |
|
pMidiInputDevice = NULL; |
44 |
|
iMidiPort = 0; |
45 |
|
midiChannel = midi_chan_all; |
46 |
iIndex = -1; |
iIndex = -1; |
47 |
} |
} |
48 |
|
|
49 |
SamplerChannel::~SamplerChannel() { |
SamplerChannel::~SamplerChannel() { |
50 |
if (pEngine) { |
if (pEngineChannel) { |
51 |
if (pMidiInputDevice) pMidiInputDevice->Disconnect(pEngine); |
MidiInputPort* pMidiInputPort = (pEngineChannel) ? pEngineChannel->GetMidiInputPort() : __GetMidiInputDevicePort(GetMidiInputChannel()); |
52 |
if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(pEngine); |
if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel); |
53 |
delete pEngine; |
if (pEngineChannel) { |
54 |
|
if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice(); |
55 |
|
EngineChannelFactory::Destroy(pEngineChannel); |
56 |
|
} |
57 |
} |
} |
58 |
} |
} |
59 |
|
|
60 |
void SamplerChannel::LoadEngine(engine_type_t EngineType) { |
void SamplerChannel::SetEngineType(String EngineType) throw (LinuxSamplerException) { |
61 |
dmsg(1,("SamplerChannel: Loading engine\n")); |
dmsg(2,("SamplerChannel: Assigning engine type...")); |
62 |
|
|
63 |
// create new engine |
// create new engine channel |
64 |
Engine* pNewEngine = NULL; |
EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType); |
65 |
switch (EngineType) { |
if (!pNewEngineChannel) throw LinuxSamplerException("Unknown engine type"); |
66 |
case engine_type_gig: |
|
67 |
pNewEngine = new gig::Engine; |
//FIXME: hack to allow fast retrieval of engine channel's sampler channel index |
68 |
break; |
pNewEngineChannel->iSamplerChannelIndex = Index(); |
69 |
default: |
|
70 |
throw LinuxSamplerException("Unknown engine type"); |
// dereference midi input port. |
71 |
|
MidiInputPort* pMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort()); |
72 |
|
// disconnect old engine channel |
73 |
|
if (pEngineChannel) { |
74 |
|
if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel); |
75 |
|
if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice(); |
76 |
|
EngineChannelFactory::Destroy(pEngineChannel); |
77 |
} |
} |
78 |
|
|
79 |
// disconnect old engine |
// connect new engine channel |
80 |
if (pEngine) { |
if (pMidiInputPort) pMidiInputPort->Connect(pNewEngineChannel, GetMidiInputChannel()); |
81 |
if (pMidiInputDevice) pMidiInputDevice->Disconnect(pEngine); |
if (pAudioOutputDevice) { |
82 |
if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(pEngine); |
pNewEngineChannel->Connect(pAudioOutputDevice); |
83 |
delete pEngine; |
pAudioOutputDevice->Connect(pNewEngineChannel->GetEngine()); |
84 |
} |
} |
85 |
|
pEngineChannel = pNewEngineChannel; |
86 |
|
|
87 |
// connect new engine |
// from now on get MIDI device and port from EngineChannel object |
88 |
pEngine = pNewEngine; |
this->pMidiInputDevice = NULL; |
89 |
if (pMidiInputDevice) pMidiInputDevice->Connect(pNewEngine, (MidiInputDevice::midi_chan_t) Index()); |
this->iMidiPort = 0; |
|
if (pAudioOutputDevice) pAudioOutputDevice->Connect(pNewEngine); |
|
|
dmsg(1,("SamplerChannel: Engine loaded.\n")); |
|
|
} |
|
90 |
|
|
91 |
void SamplerChannel::SetAudioOutputDevice(audio_output_type_t AudioType) { |
pEngineChannel->StatusChanged(true); |
|
// get / create desired audio device |
|
|
AudioOutputDevice* pDevice = pSampler->GetAudioOutputDevice(AudioType); |
|
|
if (!pDevice) pDevice = pSampler->CreateAudioOutputDevice(AudioType); |
|
92 |
|
|
93 |
// disconnect old device |
dmsg(2,("OK\n")); |
94 |
if (pAudioOutputDevice && pEngine) pAudioOutputDevice->Disconnect(pEngine); |
} |
95 |
|
|
96 |
|
void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) { |
97 |
|
// disconnect old device |
98 |
|
if (pAudioOutputDevice && pEngineChannel) pEngineChannel->DisconnectAudioOutputDevice(); |
99 |
// connect new device |
// connect new device |
100 |
pAudioOutputDevice = pDevice; |
pAudioOutputDevice = pDevice; |
101 |
if (pEngine) pAudioOutputDevice->Connect(pEngine); |
if (pEngineChannel) { |
102 |
|
pEngineChannel->Connect(pAudioOutputDevice); |
103 |
|
pAudioOutputDevice->Connect(pEngineChannel->GetEngine()); |
104 |
|
} |
105 |
} |
} |
106 |
|
|
107 |
void SamplerChannel::SetMidiInputDevice(midi_input_type_t MidiType, MidiInputDevice::midi_chan_t MidiChannel) { |
void SamplerChannel::SetMidiInputDevice(MidiInputDevice* pDevice) { |
108 |
// get / create desired midi device |
SetMidiInput(pDevice, 0, GetMidiInputChannel()); |
109 |
MidiInputDevice* pDevice = pSampler->GetMidiInputDevice(MidiType); |
} |
|
if (!pDevice) pDevice = pSampler->CreateMidiInputDevice(MidiType); |
|
110 |
|
|
111 |
// disconnect old device |
void SamplerChannel::SetMidiInputPort(int MidiPort) { |
112 |
if (pMidiInputDevice && pEngine) pMidiInputDevice->Disconnect(pEngine); |
SetMidiInput(GetMidiInputDevice(), MidiPort, GetMidiInputChannel()); |
113 |
|
} |
114 |
|
|
115 |
// connect new device |
void SamplerChannel::SetMidiInputChannel(midi_chan_t MidiChannel) { |
116 |
pMidiInputDevice = pDevice; |
SetMidiInput(GetMidiInputDevice(), GetMidiInputPort(), MidiChannel); |
|
if (pEngine) pMidiInputDevice->Connect(pEngine, MidiChannel); |
|
117 |
} |
} |
118 |
|
|
119 |
Engine* SamplerChannel::GetEngine() { |
void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel) { |
120 |
return pEngine; |
if (!pDevice) throw LinuxSamplerException("No MIDI input device assigned."); |
121 |
|
|
122 |
|
// get old and new midi input port |
123 |
|
MidiInputPort* pOldMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort()); |
124 |
|
MidiInputPort* pNewMidiInputPort = pDevice->GetPort(iMidiPort); |
125 |
|
|
126 |
|
// disconnect old device port |
127 |
|
if (pOldMidiInputPort && pEngineChannel) pOldMidiInputPort->Disconnect(pEngineChannel); |
128 |
|
// remember new device, port and channel if not engine channel yet created |
129 |
|
if (!pEngineChannel) { |
130 |
|
this->pMidiInputDevice = pDevice; |
131 |
|
this->iMidiPort = iMidiPort; |
132 |
|
this->midiChannel = MidiChannel; |
133 |
|
} |
134 |
|
|
135 |
|
// connect new device port |
136 |
|
if (pNewMidiInputPort && pEngineChannel) pNewMidiInputPort->Connect(pEngineChannel, MidiChannel); |
137 |
|
// Ooops. |
138 |
|
if (pNewMidiInputPort == NULL) |
139 |
|
throw LinuxSamplerException("There is no MIDI input port with index " + ToString(iMidiPort) + "."); |
140 |
} |
} |
141 |
|
|
142 |
MidiInputDevice* SamplerChannel::GetMidiInputDevice() { |
EngineChannel* SamplerChannel::GetEngineChannel() { |
143 |
return pMidiInputDevice; |
return pEngineChannel; |
144 |
|
} |
145 |
|
|
146 |
|
midi_chan_t SamplerChannel::GetMidiInputChannel() { |
147 |
|
if (pEngineChannel) this->midiChannel = pEngineChannel->MidiChannel(); |
148 |
|
return this->midiChannel; |
149 |
|
} |
150 |
|
|
151 |
|
int SamplerChannel::GetMidiInputPort() { |
152 |
|
MidiInputPort* pMidiInputPort = (pEngineChannel) ? pEngineChannel->GetMidiInputPort() : NULL; |
153 |
|
if (pMidiInputPort) this->iMidiPort = (int) pMidiInputPort->GetPortNumber(); |
154 |
|
return iMidiPort; |
155 |
} |
} |
156 |
|
|
157 |
AudioOutputDevice* SamplerChannel::GetAudioOutputDevice() { |
AudioOutputDevice* SamplerChannel::GetAudioOutputDevice() { |
158 |
return pAudioOutputDevice; |
return pAudioOutputDevice; |
159 |
} |
} |
160 |
|
|
161 |
|
MidiInputDevice* SamplerChannel::GetMidiInputDevice() { |
162 |
|
if (pEngineChannel) |
163 |
|
pMidiInputDevice = (pEngineChannel->GetMidiInputPort()) ? pEngineChannel->GetMidiInputPort()->GetDevice() : NULL; |
164 |
|
return pMidiInputDevice; |
165 |
|
} |
166 |
|
|
167 |
uint SamplerChannel::Index() { |
uint SamplerChannel::Index() { |
168 |
if (iIndex >= 0) return iIndex; |
if (iIndex >= 0) return iIndex; |
169 |
|
|
170 |
std::vector<SamplerChannel*>::iterator iter = pSampler->vSamplerChannels.begin(); |
Sampler::SamplerChannelMap::iterator iter = pSampler->mSamplerChannels.begin(); |
171 |
for (int i = 0; iter != pSampler->vSamplerChannels.end(); i++, iter++) { |
for (; iter != pSampler->mSamplerChannels.end(); iter++) { |
172 |
if (*iter == this) { |
if (iter->second == this) { |
173 |
iIndex = i; |
iIndex = iter->first; |
174 |
return i; |
return iIndex; |
175 |
} |
} |
176 |
} |
} |
177 |
|
|
178 |
throw LinuxSamplerException("SamplerChannel index not found"); |
throw LinuxSamplerException("Internal error: SamplerChannel index not found"); |
179 |
} |
} |
180 |
|
|
181 |
|
MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) { |
182 |
|
MidiInputPort* pMidiInputPort = NULL; |
183 |
|
MidiInputDevice* pMidiInputDevice = GetMidiInputDevice(); |
184 |
|
if (pMidiInputDevice) |
185 |
|
pMidiInputPort = pMidiInputDevice->GetPort(iMidiPort); |
186 |
|
return pMidiInputPort; |
187 |
|
} |
188 |
|
|
189 |
|
|
190 |
|
|
191 |
// ****************************************************************** |
// ****************************************************************** |
192 |
// * Sampler |
// * Sampler |
195 |
} |
} |
196 |
|
|
197 |
Sampler::~Sampler() { |
Sampler::~Sampler() { |
198 |
// delete sampler channels |
Reset(); |
|
{ |
|
|
std::vector<SamplerChannel*>::iterator iter = vSamplerChannels.begin(); |
|
|
for (; iter != vSamplerChannels.end(); iter++) delete *iter; |
|
|
} |
|
|
|
|
|
// delete midi input devices |
|
|
{ |
|
|
MidiInputDeviceMap::iterator iter = MidiInputDevices.begin(); |
|
|
for (; iter != MidiInputDevices.end(); iter++) { |
|
|
MidiInputDevice* pDevice = iter->second; |
|
|
pDevice->StopListen(); |
|
|
delete pDevice; |
|
|
} |
|
|
} |
|
|
|
|
|
// delete audio output devices |
|
|
{ |
|
|
AudioOutputDeviceMap::iterator iter = AudioOutputDevices.begin(); |
|
|
for (; iter != AudioOutputDevices.end(); iter++) { |
|
|
AudioOutputDevice* pDevice = iter->second; |
|
|
pDevice->Stop(); |
|
|
delete pDevice; |
|
|
} |
|
|
} |
|
199 |
} |
} |
200 |
|
|
201 |
uint Sampler::SamplerChannels() { |
uint Sampler::SamplerChannels() { |
202 |
vSamplerChannels.size(); |
return mSamplerChannels.size(); |
203 |
} |
} |
204 |
|
|
205 |
SamplerChannel* Sampler::AddSamplerChannel() { |
SamplerChannel* Sampler::AddSamplerChannel() { |
206 |
|
// if there's no sampler channel yet |
207 |
|
if (!mSamplerChannels.size()) { |
208 |
|
SamplerChannel* pChannel = new SamplerChannel(this); |
209 |
|
mSamplerChannels[0] = pChannel; |
210 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, 1)); |
211 |
|
return pChannel; |
212 |
|
} |
213 |
|
|
214 |
|
// get the highest used sampler channel index |
215 |
|
uint lastIndex = (--(mSamplerChannels.end()))->first; |
216 |
|
|
217 |
|
// check if we reached the index limit |
218 |
|
if (lastIndex + 1 < lastIndex) { |
219 |
|
// search for an unoccupied sampler channel index starting from 0 |
220 |
|
for (uint i = 0; i < lastIndex; i++) { |
221 |
|
if (mSamplerChannels.find(i) != mSamplerChannels.end()) continue; |
222 |
|
// we found an unused index, so insert the new channel there |
223 |
|
SamplerChannel* pChannel = new SamplerChannel(this); |
224 |
|
mSamplerChannels[i] = pChannel; |
225 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i)); |
226 |
|
return pChannel; |
227 |
|
} |
228 |
|
throw LinuxSamplerException("Internal error: could not find unoccupied sampler channel index."); |
229 |
|
} |
230 |
|
|
231 |
|
// we have not reached the index limit so we just add the channel past the highest index |
232 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
233 |
vSamplerChannels.push_back(pChannel); |
mSamplerChannels[lastIndex + 1] = pChannel; |
234 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, lastIndex + 1)); |
235 |
return pChannel; |
return pChannel; |
236 |
} |
} |
237 |
|
|
238 |
SamplerChannel* Sampler::GetSamplerChannel(uint uiSamplerChannel) { |
SamplerChannel* Sampler::GetSamplerChannel(uint uiSamplerChannel) { |
239 |
if (uiSamplerChannel >= SamplerChannels()) return NULL; |
return (mSamplerChannels.find(uiSamplerChannel) != mSamplerChannels.end()) ? mSamplerChannels[uiSamplerChannel] : NULL; |
240 |
return vSamplerChannels[uiSamplerChannel]; |
} |
241 |
|
|
242 |
|
std::map<uint, SamplerChannel*> Sampler::GetSamplerChannels() { |
243 |
|
return mSamplerChannels; |
244 |
} |
} |
245 |
|
|
246 |
void Sampler::RemoveSamplerChannel(SamplerChannel* pSamplerChannel) { |
void Sampler::RemoveSamplerChannel(SamplerChannel* pSamplerChannel) { |
247 |
std::vector<SamplerChannel*>::iterator iterChan = vSamplerChannels.begin(); |
SamplerChannelMap::iterator iterChan = mSamplerChannels.begin(); |
248 |
for (; iterChan != vSamplerChannels.end(); iterChan++) { |
for (; iterChan != mSamplerChannels.end(); iterChan++) { |
249 |
if (*iterChan == pSamplerChannel) { |
if (iterChan->second == pSamplerChannel) { |
250 |
vSamplerChannels.erase(iterChan); |
mSamplerChannels.erase(iterChan); |
251 |
delete pSamplerChannel; |
delete pSamplerChannel; |
252 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, mSamplerChannels.size())); |
253 |
return; |
return; |
254 |
} |
} |
255 |
} |
} |
261 |
RemoveSamplerChannel(pChannel); |
RemoveSamplerChannel(pChannel); |
262 |
} |
} |
263 |
|
|
264 |
AudioOutputDevice* Sampler::CreateAudioOutputDevice(audio_output_type_t AudioType) { |
std::vector<String> Sampler::AvailableAudioOutputDrivers() { |
265 |
// check if device already created |
return AudioOutputDeviceFactory::AvailableDrivers(); |
266 |
AudioOutputDevice* pDevice = GetAudioOutputDevice(AudioType); |
} |
|
if (pDevice) return pDevice; |
|
267 |
|
|
268 |
|
AudioOutputDevice* Sampler::CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) { |
269 |
// create new device |
// create new device |
270 |
switch (AudioType) { |
AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters); |
271 |
case audio_output_type_alsa: |
|
272 |
pDevice = new AudioOutputDeviceAlsa; |
// add new audio device to the audio device list |
273 |
break; |
for (uint i = 0; ; i++) { // seek for a free place starting from the beginning |
274 |
case audio_output_type_jack: |
if (!mAudioOutputDevices[i]) { |
275 |
pDevice = new AudioOutputDeviceJack; |
mAudioOutputDevices[i] = pDevice; |
276 |
break; |
break; |
277 |
default: |
} |
|
throw LinuxSamplerException("Unknown audio output device type"); |
|
278 |
} |
} |
279 |
|
|
|
// activate device |
|
|
pDevice->Play(); |
|
|
|
|
280 |
return pDevice; |
return pDevice; |
281 |
} |
} |
282 |
|
|
283 |
AudioOutputDevice* Sampler::GetAudioOutputDevice(audio_output_type_t AudioType) { |
uint Sampler::AudioOutputDevices() { |
284 |
AudioOutputDeviceMap::iterator iter = AudioOutputDevices.find(AudioType); |
return mAudioOutputDevices.size(); |
|
return (iter != AudioOutputDevices.end()) ? iter->second : NULL; |
|
285 |
} |
} |
286 |
|
|
287 |
MidiInputDevice* Sampler::CreateMidiInputDevice(midi_input_type_t MidiType) { |
uint Sampler::MidiInputDevices() { |
288 |
// check if device already created |
return mMidiInputDevices.size(); |
289 |
MidiInputDevice* pDevice = GetMidiInputDevice(MidiType); |
} |
|
if (pDevice) return pDevice; |
|
290 |
|
|
291 |
// create new device |
std::map<uint, AudioOutputDevice*> Sampler::GetAudioOutputDevices() { |
292 |
switch (MidiType) { |
return mAudioOutputDevices; |
293 |
case midi_input_type_alsa: |
} |
294 |
pDevice = new MidiInputDeviceAlsa; |
|
295 |
break; |
std::map<uint, MidiInputDevice*> Sampler::GetMidiInputDevices() { |
296 |
default: |
return mMidiInputDevices; |
297 |
throw LinuxSamplerException("Unknown audio output device type"); |
} |
298 |
|
|
299 |
|
void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException) { |
300 |
|
AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin(); |
301 |
|
for (; iter != mAudioOutputDevices.end(); iter++) { |
302 |
|
if (iter->second == pDevice) { |
303 |
|
// check if there are still sampler engines connected to this device |
304 |
|
for (uint i = 0; i < SamplerChannels(); i++) |
305 |
|
if (GetSamplerChannel(i)->GetAudioOutputDevice() == pDevice) throw LinuxSamplerException("Sampler channel " + ToString(i) + " is still connected to the audio output device."); |
306 |
|
|
307 |
|
// disable device |
308 |
|
pDevice->Stop(); |
309 |
|
|
310 |
|
// destroy and free device from memory |
311 |
|
delete pDevice; |
312 |
|
} |
313 |
|
} |
314 |
|
// remove devices from the device list |
315 |
|
mAudioOutputDevices.clear(); |
316 |
|
} |
317 |
|
|
318 |
|
void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (LinuxSamplerException) { |
319 |
|
MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin(); |
320 |
|
for (; iter != mMidiInputDevices.end(); iter++) { |
321 |
|
if (iter->second == pDevice) { |
322 |
|
// check if there are still sampler engines connected to this device |
323 |
|
for (uint i = 0; i < SamplerChannels(); i++) |
324 |
|
if (GetSamplerChannel(i)->GetMidiInputDevice() == pDevice) throw LinuxSamplerException("Sampler channel " + ToString(i) + " is still connected to the midi input device."); |
325 |
|
|
326 |
|
// disable device |
327 |
|
pDevice->StopListen(); |
328 |
|
|
329 |
|
// destroy and free device from memory |
330 |
|
delete pDevice; |
331 |
|
} |
332 |
} |
} |
333 |
|
// remove devices from the device list |
334 |
|
mMidiInputDevices.clear(); |
335 |
|
} |
336 |
|
|
337 |
// activate device |
MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) { |
338 |
pDevice->Listen(); |
// create new device |
339 |
|
MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this); |
340 |
|
|
341 |
|
// add new device to the midi device list |
342 |
|
for (uint i = 0; ; i++) { // seek for a free place starting from the beginning |
343 |
|
if (!mMidiInputDevices[i]) { |
344 |
|
mMidiInputDevices[i] = pDevice; |
345 |
|
break; |
346 |
|
} |
347 |
|
} |
348 |
|
|
349 |
return pDevice; |
return pDevice; |
350 |
} |
} |
351 |
|
|
352 |
MidiInputDevice* Sampler::GetMidiInputDevice(midi_input_type_t MidiType) { |
int Sampler::GetVoiceCount() { |
353 |
MidiInputDeviceMap::iterator iter = MidiInputDevices.find(MidiType); |
int count = 0; |
354 |
return (iter != MidiInputDevices.end()) ? iter->second : NULL; |
std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin(); |
355 |
|
|
356 |
|
for(; it != EngineFactory::EngineInstances().end(); it++) { |
357 |
|
count += (*it)->VoiceCount(); |
358 |
|
} |
359 |
|
|
360 |
|
return count; |
361 |
|
} |
362 |
|
|
363 |
|
void Sampler::Reset() { |
364 |
|
// delete sampler channels |
365 |
|
try { |
366 |
|
while (true) { |
367 |
|
SamplerChannelMap::iterator iter = mSamplerChannels.begin(); |
368 |
|
if (iter == mSamplerChannels.end()) break; |
369 |
|
RemoveSamplerChannel(iter->second); |
370 |
|
} |
371 |
|
} |
372 |
|
catch(...) { |
373 |
|
std::cerr << "Sampler::Reset(): Exception occured while trying to delete all sampler channels, exiting.\n" << std::flush; |
374 |
|
exit(EXIT_FAILURE); |
375 |
|
} |
376 |
|
|
377 |
|
// delete midi input devices |
378 |
|
try { |
379 |
|
while (true) { |
380 |
|
MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin(); |
381 |
|
if (iter == mMidiInputDevices.end()) break; |
382 |
|
DestroyMidiInputDevice(iter->second); |
383 |
|
} |
384 |
|
} |
385 |
|
catch(...) { |
386 |
|
std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI input devices, exiting.\n" << std::flush; |
387 |
|
exit(EXIT_FAILURE); |
388 |
|
} |
389 |
|
|
390 |
|
// delete audio output devices |
391 |
|
try { |
392 |
|
while (true) { |
393 |
|
AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin(); |
394 |
|
if (iter == mAudioOutputDevices.end()) break; |
395 |
|
DestroyAudioOutputDevice(iter->second); |
396 |
|
} |
397 |
|
} |
398 |
|
catch(...) { |
399 |
|
std::cerr << "Sampler::Reset(): Exception occured while trying to delete all audio output devices, exiting.\n" << std::flush; |
400 |
|
exit(EXIT_FAILURE); |
401 |
|
} |
402 |
} |
} |
403 |
|
|
404 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |