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 * |
* Copyright (C) 2005 - 2007 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This library 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 * |
10 |
* the Free Software Foundation; either version 2 of the License, or * |
* the Free Software Foundation; either version 2 of the License, or * |
11 |
* (at your option) any later version. * |
* (at your option) any later version. * |
12 |
* * |
* * |
13 |
* This program is distributed in the hope that it will be useful, * |
* This library is distributed in the hope that it will be useful, * |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 |
* GNU General Public License for more details. * |
* GNU General Public License for more details. * |
17 |
* * |
* * |
18 |
* You should have received a copy of the GNU General Public License * |
* You should have received a copy of the GNU General Public License * |
19 |
* along with this program; if not, write to the Free Software * |
* along with this library; if not, write to the Free Software * |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
***************************************************************************/ |
29 |
#include "engines/EngineChannelFactory.h" |
#include "engines/EngineChannelFactory.h" |
30 |
#include "drivers/audio/AudioOutputDeviceFactory.h" |
#include "drivers/audio/AudioOutputDeviceFactory.h" |
31 |
#include "drivers/midi/MidiInputDeviceFactory.h" |
#include "drivers/midi/MidiInputDeviceFactory.h" |
32 |
#include "network/lscpserver.h" |
#include "drivers/midi/MidiInstrumentMapper.h" |
33 |
|
|
34 |
namespace LinuxSampler { |
namespace LinuxSampler { |
35 |
|
|
103 |
this->iMidiPort = 0; |
this->iMidiPort = 0; |
104 |
|
|
105 |
pEngineChannel->StatusChanged(true); |
pEngineChannel->StatusChanged(true); |
106 |
|
fireEngineChanged(); |
107 |
dmsg(2,("OK\n")); |
dmsg(2,("OK\n")); |
108 |
} |
} |
109 |
|
|
110 |
void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) { |
void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) { |
111 |
|
if(pAudioOutputDevice == pDevice) return; |
112 |
|
|
113 |
// disconnect old device |
// disconnect old device |
114 |
if (pAudioOutputDevice && pEngineChannel) { |
if (pAudioOutputDevice && pEngineChannel) { |
115 |
Engine* engine = pEngineChannel->GetEngine(); |
Engine* engine = pEngineChannel->GetEngine(); |
204 |
throw Exception("Internal error: SamplerChannel index not found"); |
throw Exception("Internal error: SamplerChannel index not found"); |
205 |
} |
} |
206 |
|
|
207 |
|
void SamplerChannel::AddEngineChangeListener(EngineChangeListener* l) { |
208 |
|
llEngineChangeListeners.AddListener(l); |
209 |
|
} |
210 |
|
|
211 |
|
void SamplerChannel::RemoveEngineChangeListener(EngineChangeListener* l) { |
212 |
|
llEngineChangeListeners.RemoveListener(l); |
213 |
|
} |
214 |
|
|
215 |
|
void SamplerChannel::RemoveAllEngineChangeListeners() { |
216 |
|
llEngineChangeListeners.RemoveAllListeners(); |
217 |
|
} |
218 |
|
|
219 |
|
void SamplerChannel::fireEngineChanged() { |
220 |
|
for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) { |
221 |
|
llEngineChangeListeners.GetListener(i)->EngineChanged(Index()); |
222 |
|
} |
223 |
|
} |
224 |
|
|
225 |
MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) { |
MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) { |
226 |
MidiInputPort* pMidiInputPort = NULL; |
MidiInputPort* pMidiInputPort = NULL; |
227 |
MidiInputDevice* pMidiInputDevice = GetMidiInputDevice(); |
MidiInputDevice* pMidiInputDevice = GetMidiInputDevice(); |
236 |
// * Sampler |
// * Sampler |
237 |
|
|
238 |
Sampler::Sampler() { |
Sampler::Sampler() { |
239 |
|
eventHandler.SetSampler(this); |
240 |
} |
} |
241 |
|
|
242 |
Sampler::~Sampler() { |
Sampler::~Sampler() { |
247 |
return mSamplerChannels.size(); |
return mSamplerChannels.size(); |
248 |
} |
} |
249 |
|
|
250 |
|
void Sampler::AddChannelCountListener(ChannelCountListener* l) { |
251 |
|
llChannelCountListeners.AddListener(l); |
252 |
|
} |
253 |
|
|
254 |
|
void Sampler::RemoveChannelCountListener(ChannelCountListener* l) { |
255 |
|
llChannelCountListeners.RemoveListener(l); |
256 |
|
} |
257 |
|
|
258 |
|
void Sampler::fireChannelCountChanged(int NewCount) { |
259 |
|
for (int i = 0; i < llChannelCountListeners.GetListenerCount(); i++) { |
260 |
|
llChannelCountListeners.GetListener(i)->ChannelCountChanged(NewCount); |
261 |
|
} |
262 |
|
} |
263 |
|
|
264 |
|
void Sampler::AddAudioDeviceCountListener(AudioDeviceCountListener* l) { |
265 |
|
llAudioDeviceCountListeners.AddListener(l); |
266 |
|
} |
267 |
|
|
268 |
|
void Sampler::RemoveAudioDeviceCountListener(AudioDeviceCountListener* l) { |
269 |
|
llAudioDeviceCountListeners.RemoveListener(l); |
270 |
|
} |
271 |
|
|
272 |
|
void Sampler::fireAudioDeviceCountChanged(int NewCount) { |
273 |
|
for (int i = 0; i < llAudioDeviceCountListeners.GetListenerCount(); i++) { |
274 |
|
llAudioDeviceCountListeners.GetListener(i)->AudioDeviceCountChanged(NewCount); |
275 |
|
} |
276 |
|
} |
277 |
|
|
278 |
|
void Sampler::AddMidiDeviceCountListener(MidiDeviceCountListener* l) { |
279 |
|
llMidiDeviceCountListeners.AddListener(l); |
280 |
|
} |
281 |
|
|
282 |
|
void Sampler::RemoveMidiDeviceCountListener(MidiDeviceCountListener* l) { |
283 |
|
llMidiDeviceCountListeners.RemoveListener(l); |
284 |
|
} |
285 |
|
|
286 |
|
void Sampler::fireMidiDeviceCountChanged(int NewCount) { |
287 |
|
for (int i = 0; i < llMidiDeviceCountListeners.GetListenerCount(); i++) { |
288 |
|
llMidiDeviceCountListeners.GetListener(i)->MidiDeviceCountChanged(NewCount); |
289 |
|
} |
290 |
|
} |
291 |
|
|
292 |
|
void Sampler::AddVoiceCountListener(VoiceCountListener* l) { |
293 |
|
llVoiceCountListeners.AddListener(l); |
294 |
|
} |
295 |
|
|
296 |
|
void Sampler::RemoveVoiceCountListener(VoiceCountListener* l) { |
297 |
|
llVoiceCountListeners.RemoveListener(l); |
298 |
|
} |
299 |
|
|
300 |
|
void Sampler::fireVoiceCountChanged(int ChannelId, int NewCount) { |
301 |
|
for (int i = 0; i < llVoiceCountListeners.GetListenerCount(); i++) { |
302 |
|
llVoiceCountListeners.GetListener(i)->VoiceCountChanged(ChannelId, NewCount); |
303 |
|
} |
304 |
|
} |
305 |
|
|
306 |
|
void Sampler::AddStreamCountListener(StreamCountListener* l) { |
307 |
|
llStreamCountListeners.AddListener(l); |
308 |
|
} |
309 |
|
|
310 |
|
void Sampler::RemoveStreamCountListener(StreamCountListener* l) { |
311 |
|
llStreamCountListeners.RemoveListener(l); |
312 |
|
} |
313 |
|
|
314 |
|
void Sampler::fireStreamCountChanged(int ChannelId, int NewCount) { |
315 |
|
for (int i = 0; i < llStreamCountListeners.GetListenerCount(); i++) { |
316 |
|
llStreamCountListeners.GetListener(i)->StreamCountChanged(ChannelId, NewCount); |
317 |
|
} |
318 |
|
} |
319 |
|
|
320 |
|
void Sampler::AddBufferFillListener(BufferFillListener* l) { |
321 |
|
llBufferFillListeners.AddListener(l); |
322 |
|
} |
323 |
|
|
324 |
|
void Sampler::RemoveBufferFillListener(BufferFillListener* l) { |
325 |
|
llBufferFillListeners.RemoveListener(l); |
326 |
|
} |
327 |
|
|
328 |
|
void Sampler::fireBufferFillChanged(int ChannelId, String FillData) { |
329 |
|
for (int i = 0; i < llBufferFillListeners.GetListenerCount(); i++) { |
330 |
|
llBufferFillListeners.GetListener(i)->BufferFillChanged(ChannelId, FillData); |
331 |
|
} |
332 |
|
} |
333 |
|
|
334 |
|
void Sampler::AddTotalVoiceCountListener(TotalVoiceCountListener* l) { |
335 |
|
llTotalVoiceCountListeners.AddListener(l); |
336 |
|
} |
337 |
|
|
338 |
|
void Sampler::RemoveTotalVoiceCountListener(TotalVoiceCountListener* l) { |
339 |
|
llTotalVoiceCountListeners.RemoveListener(l); |
340 |
|
} |
341 |
|
|
342 |
|
void Sampler::fireTotalVoiceCountChanged(int NewCount) { |
343 |
|
for (int i = 0; i < llTotalVoiceCountListeners.GetListenerCount(); i++) { |
344 |
|
llTotalVoiceCountListeners.GetListener(i)->TotalVoiceCountChanged(NewCount); |
345 |
|
} |
346 |
|
} |
347 |
|
|
348 |
|
void Sampler::AddFxSendCountListener(FxSendCountListener* l) { |
349 |
|
llFxSendCountListeners.AddListener(l); |
350 |
|
} |
351 |
|
|
352 |
|
void Sampler::RemoveFxSendCountListener(FxSendCountListener* l) { |
353 |
|
llFxSendCountListeners.RemoveListener(l); |
354 |
|
} |
355 |
|
|
356 |
|
void Sampler::fireFxSendCountChanged(int ChannelId, int NewCount) { |
357 |
|
for (int i = 0; i < llFxSendCountListeners.GetListenerCount(); i++) { |
358 |
|
llFxSendCountListeners.GetListener(i)->FxSendCountChanged(ChannelId, NewCount); |
359 |
|
} |
360 |
|
} |
361 |
|
|
362 |
|
void Sampler::EventHandler::EngineChanged(int ChannelId) { |
363 |
|
EngineChannel* engineChannel = pSampler->GetSamplerChannel(ChannelId)->GetEngineChannel(); |
364 |
|
if(engineChannel == NULL) return; |
365 |
|
engineChannel->AddFxSendCountListener(this); |
366 |
|
} |
367 |
|
|
368 |
|
void Sampler::EventHandler::FxSendCountChanged(int ChannelId, int NewCount) { |
369 |
|
pSampler->fireFxSendCountChanged(ChannelId, NewCount); |
370 |
|
} |
371 |
|
|
372 |
|
|
373 |
SamplerChannel* Sampler::AddSamplerChannel() { |
SamplerChannel* Sampler::AddSamplerChannel() { |
374 |
// if there's no sampler channel yet |
// if there's no sampler channel yet |
375 |
if (!mSamplerChannels.size()) { |
if (!mSamplerChannels.size()) { |
376 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
377 |
mSamplerChannels[0] = pChannel; |
mSamplerChannels[0] = pChannel; |
378 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, 1)); |
fireChannelCountChanged(1); |
379 |
|
pChannel->AddEngineChangeListener(&eventHandler); |
380 |
return pChannel; |
return pChannel; |
381 |
} |
} |
382 |
|
|
391 |
// we found an unused index, so insert the new channel there |
// we found an unused index, so insert the new channel there |
392 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
393 |
mSamplerChannels[i] = pChannel; |
mSamplerChannels[i] = pChannel; |
394 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i)); |
fireChannelCountChanged(SamplerChannels()); |
395 |
|
pChannel->AddEngineChangeListener(&eventHandler); |
396 |
return pChannel; |
return pChannel; |
397 |
} |
} |
398 |
throw Exception("Internal error: could not find unoccupied sampler channel index."); |
throw Exception("Internal error: could not find unoccupied sampler channel index."); |
401 |
// we have not reached the index limit so we just add the channel past the highest index |
// we have not reached the index limit so we just add the channel past the highest index |
402 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
403 |
mSamplerChannels[lastIndex + 1] = pChannel; |
mSamplerChannels[lastIndex + 1] = pChannel; |
404 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, lastIndex + 1)); |
fireChannelCountChanged(SamplerChannels()); |
405 |
|
pChannel->AddEngineChangeListener(&eventHandler); |
406 |
return pChannel; |
return pChannel; |
407 |
} |
} |
408 |
|
|
418 |
SamplerChannelMap::iterator iterChan = mSamplerChannels.begin(); |
SamplerChannelMap::iterator iterChan = mSamplerChannels.begin(); |
419 |
for (; iterChan != mSamplerChannels.end(); iterChan++) { |
for (; iterChan != mSamplerChannels.end(); iterChan++) { |
420 |
if (iterChan->second == pSamplerChannel) { |
if (iterChan->second == pSamplerChannel) { |
421 |
|
pSamplerChannel->RemoveAllEngineChangeListeners(); |
422 |
mSamplerChannels.erase(iterChan); |
mSamplerChannels.erase(iterChan); |
423 |
delete pSamplerChannel; |
delete pSamplerChannel; |
424 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, mSamplerChannels.size())); |
fireChannelCountChanged(SamplerChannels()); |
425 |
return; |
return; |
426 |
} |
} |
427 |
} |
} |
457 |
} |
} |
458 |
} |
} |
459 |
|
|
460 |
|
fireAudioDeviceCountChanged(AudioOutputDevices()); |
461 |
return pDevice; |
return pDevice; |
462 |
} |
} |
463 |
|
|
494 |
// destroy and free device from memory |
// destroy and free device from memory |
495 |
delete pDevice; |
delete pDevice; |
496 |
|
|
497 |
|
fireAudioDeviceCountChanged(AudioOutputDevices()); |
498 |
break; |
break; |
499 |
} |
} |
500 |
} |
} |
517 |
// destroy and free device from memory |
// destroy and free device from memory |
518 |
delete pDevice; |
delete pDevice; |
519 |
|
|
520 |
|
fireMidiDeviceCountChanged(MidiInputDevices()); |
521 |
break; |
break; |
522 |
} |
} |
523 |
} |
} |
535 |
} |
} |
536 |
} |
} |
537 |
|
|
538 |
|
fireMidiDeviceCountChanged(MidiInputDevices()); |
539 |
return pDevice; |
return pDevice; |
540 |
} |
} |
541 |
|
|
589 |
std::cerr << "Sampler::Reset(): Exception occured while trying to delete all audio output devices, exiting.\n" << std::flush; |
std::cerr << "Sampler::Reset(): Exception occured while trying to delete all audio output devices, exiting.\n" << std::flush; |
590 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
591 |
} |
} |
592 |
|
|
593 |
|
// delete MIDI instrument maps |
594 |
|
try { |
595 |
|
MidiInstrumentMapper::RemoveAllMaps(); |
596 |
|
} |
597 |
|
catch(...) { |
598 |
|
std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI instrument maps, exiting.\n" << std::flush; |
599 |
|
exit(EXIT_FAILURE); |
600 |
|
} |
601 |
} |
} |
602 |
|
|
603 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |