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 - 2007 Christian Schoenebeck * |
* Copyright (C) 2005 - 2009 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This library 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 * |
25 |
|
|
26 |
#include "Sampler.h" |
#include "Sampler.h" |
27 |
|
|
28 |
|
#include "common/global_private.h" |
29 |
#include "engines/EngineFactory.h" |
#include "engines/EngineFactory.h" |
30 |
#include "engines/EngineChannelFactory.h" |
#include "engines/EngineChannelFactory.h" |
31 |
#include "engines/InstrumentEditorFactory.h" |
#include "plugins/InstrumentEditorFactory.h" |
32 |
#include "drivers/audio/AudioOutputDeviceFactory.h" |
#include "drivers/audio/AudioOutputDeviceFactory.h" |
33 |
#include "drivers/midi/MidiInputDeviceFactory.h" |
#include "drivers/midi/MidiInputDeviceFactory.h" |
34 |
#include "drivers/midi/MidiInstrumentMapper.h" |
#include "drivers/midi/MidiInstrumentMapper.h" |
35 |
|
#include "common/Features.h" |
36 |
|
#include "network/lscpserver.h" |
37 |
|
|
38 |
namespace LinuxSampler { |
namespace LinuxSampler { |
39 |
|
|
71 |
void SamplerChannel::SetEngineType(String EngineType) throw (Exception) { |
void SamplerChannel::SetEngineType(String EngineType) throw (Exception) { |
72 |
dmsg(2,("SamplerChannel: Assigning engine type...")); |
dmsg(2,("SamplerChannel: Assigning engine type...")); |
73 |
|
|
74 |
|
if (pEngineChannel) { |
75 |
|
if (!strcasecmp(pEngineChannel->EngineName().c_str(), EngineType.c_str())) { |
76 |
|
dmsg(2,("OK\n")); |
77 |
|
return; |
78 |
|
} |
79 |
|
} |
80 |
|
|
81 |
|
fireEngineToBeChanged(); |
82 |
|
|
83 |
// create new engine channel |
// create new engine channel |
84 |
EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType); |
EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType); |
85 |
if (!pNewEngineChannel) throw Exception("Unknown engine type"); |
if (!pNewEngineChannel) throw Exception("Unknown engine type"); |
86 |
|
|
87 |
//FIXME: hack to allow fast retrieval of engine channel's sampler channel index |
pNewEngineChannel->SetSamplerChannel(this); |
|
pNewEngineChannel->iSamplerChannelIndex = Index(); |
|
88 |
|
|
89 |
// dereference midi input port. |
// dereference midi input port. |
90 |
MidiInputPort* pMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort()); |
MidiInputPort* pMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort()); |
216 |
throw Exception("Internal error: SamplerChannel index not found"); |
throw Exception("Internal error: SamplerChannel index not found"); |
217 |
} |
} |
218 |
|
|
219 |
|
Sampler* SamplerChannel::GetSampler() { |
220 |
|
return pSampler; |
221 |
|
} |
222 |
|
|
223 |
void SamplerChannel::AddEngineChangeListener(EngineChangeListener* l) { |
void SamplerChannel::AddEngineChangeListener(EngineChangeListener* l) { |
224 |
llEngineChangeListeners.AddListener(l); |
llEngineChangeListeners.AddListener(l); |
225 |
} |
} |
232 |
llEngineChangeListeners.RemoveAllListeners(); |
llEngineChangeListeners.RemoveAllListeners(); |
233 |
} |
} |
234 |
|
|
235 |
|
void SamplerChannel::fireEngineToBeChanged() { |
236 |
|
for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) { |
237 |
|
llEngineChangeListeners.GetListener(i)->EngineToBeChanged(Index()); |
238 |
|
} |
239 |
|
} |
240 |
|
|
241 |
void SamplerChannel::fireEngineChanged() { |
void SamplerChannel::fireEngineChanged() { |
242 |
for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) { |
for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) { |
243 |
llEngineChangeListeners.GetListener(i)->EngineChanged(Index()); |
llEngineChangeListeners.GetListener(i)->EngineChanged(Index()); |
259 |
|
|
260 |
Sampler::Sampler() { |
Sampler::Sampler() { |
261 |
eventHandler.SetSampler(this); |
eventHandler.SetSampler(this); |
262 |
|
uiOldTotalVoiceCount = uiOldTotalStreamCount = 0; |
263 |
} |
} |
264 |
|
|
265 |
Sampler::~Sampler() { |
Sampler::~Sampler() { |
284 |
} |
} |
285 |
} |
} |
286 |
|
|
287 |
|
void Sampler::fireChannelAdded(SamplerChannel* pChannel) { |
288 |
|
for (int i = 0; i < llChannelCountListeners.GetListenerCount(); i++) { |
289 |
|
llChannelCountListeners.GetListener(i)->ChannelAdded(pChannel); |
290 |
|
} |
291 |
|
} |
292 |
|
|
293 |
|
void Sampler::fireChannelToBeRemoved(SamplerChannel* pChannel) { |
294 |
|
for (int i = 0; i < llChannelCountListeners.GetListenerCount(); i++) { |
295 |
|
llChannelCountListeners.GetListener(i)->ChannelToBeRemoved(pChannel); |
296 |
|
} |
297 |
|
} |
298 |
|
|
299 |
void Sampler::AddAudioDeviceCountListener(AudioDeviceCountListener* l) { |
void Sampler::AddAudioDeviceCountListener(AudioDeviceCountListener* l) { |
300 |
llAudioDeviceCountListeners.AddListener(l); |
llAudioDeviceCountListeners.AddListener(l); |
301 |
} |
} |
324 |
} |
} |
325 |
} |
} |
326 |
|
|
327 |
|
void Sampler::fireMidiDeviceToBeDestroyed(MidiInputDevice* pDevice) { |
328 |
|
for (int i = 0; i < llMidiDeviceCountListeners.GetListenerCount(); i++) { |
329 |
|
llMidiDeviceCountListeners.GetListener(i)->MidiDeviceToBeDestroyed(pDevice); |
330 |
|
} |
331 |
|
} |
332 |
|
|
333 |
|
void Sampler::fireMidiDeviceCreated(MidiInputDevice* pDevice) { |
334 |
|
for (int i = 0; i < llMidiDeviceCountListeners.GetListenerCount(); i++) { |
335 |
|
llMidiDeviceCountListeners.GetListener(i)->MidiDeviceCreated(pDevice); |
336 |
|
} |
337 |
|
} |
338 |
|
|
339 |
void Sampler::AddVoiceCountListener(VoiceCountListener* l) { |
void Sampler::AddVoiceCountListener(VoiceCountListener* l) { |
340 |
llVoiceCountListeners.AddListener(l); |
llVoiceCountListeners.AddListener(l); |
341 |
} |
} |
345 |
} |
} |
346 |
|
|
347 |
void Sampler::fireVoiceCountChanged(int ChannelId, int NewCount) { |
void Sampler::fireVoiceCountChanged(int ChannelId, int NewCount) { |
348 |
|
std::map<uint, uint>::iterator it = mOldVoiceCounts.find(ChannelId); |
349 |
|
if (it != mOldVoiceCounts.end()) { |
350 |
|
uint oldCount = it->second; |
351 |
|
if (NewCount == oldCount) return; |
352 |
|
} |
353 |
|
|
354 |
|
mOldVoiceCounts[ChannelId] = NewCount; |
355 |
|
|
356 |
for (int i = 0; i < llVoiceCountListeners.GetListenerCount(); i++) { |
for (int i = 0; i < llVoiceCountListeners.GetListenerCount(); i++) { |
357 |
llVoiceCountListeners.GetListener(i)->VoiceCountChanged(ChannelId, NewCount); |
llVoiceCountListeners.GetListener(i)->VoiceCountChanged(ChannelId, NewCount); |
358 |
} |
} |
367 |
} |
} |
368 |
|
|
369 |
void Sampler::fireStreamCountChanged(int ChannelId, int NewCount) { |
void Sampler::fireStreamCountChanged(int ChannelId, int NewCount) { |
370 |
|
std::map<uint, uint>::iterator it = mOldStreamCounts.find(ChannelId); |
371 |
|
if (it != mOldStreamCounts.end()) { |
372 |
|
uint oldCount = it->second; |
373 |
|
if (NewCount == oldCount) return; |
374 |
|
} |
375 |
|
|
376 |
|
mOldStreamCounts[ChannelId] = NewCount; |
377 |
|
|
378 |
for (int i = 0; i < llStreamCountListeners.GetListenerCount(); i++) { |
for (int i = 0; i < llStreamCountListeners.GetListenerCount(); i++) { |
379 |
llStreamCountListeners.GetListener(i)->StreamCountChanged(ChannelId, NewCount); |
llStreamCountListeners.GetListener(i)->StreamCountChanged(ChannelId, NewCount); |
380 |
} |
} |
394 |
} |
} |
395 |
} |
} |
396 |
|
|
397 |
|
void Sampler::AddTotalStreamCountListener(TotalStreamCountListener* l) { |
398 |
|
llTotalStreamCountListeners.AddListener(l); |
399 |
|
} |
400 |
|
|
401 |
|
void Sampler::RemoveTotalStreamCountListener(TotalStreamCountListener* l) { |
402 |
|
llTotalStreamCountListeners.RemoveListener(l); |
403 |
|
} |
404 |
|
|
405 |
|
void Sampler::fireTotalStreamCountChanged(int NewCount) { |
406 |
|
if (NewCount == uiOldTotalStreamCount) return; |
407 |
|
uiOldTotalStreamCount = NewCount; |
408 |
|
|
409 |
|
for (int i = 0; i < llTotalStreamCountListeners.GetListenerCount(); i++) { |
410 |
|
llTotalStreamCountListeners.GetListener(i)->TotalStreamCountChanged(NewCount); |
411 |
|
} |
412 |
|
} |
413 |
|
|
414 |
void Sampler::AddTotalVoiceCountListener(TotalVoiceCountListener* l) { |
void Sampler::AddTotalVoiceCountListener(TotalVoiceCountListener* l) { |
415 |
llTotalVoiceCountListeners.AddListener(l); |
llTotalVoiceCountListeners.AddListener(l); |
416 |
} |
} |
420 |
} |
} |
421 |
|
|
422 |
void Sampler::fireTotalVoiceCountChanged(int NewCount) { |
void Sampler::fireTotalVoiceCountChanged(int NewCount) { |
423 |
|
if (NewCount == uiOldTotalVoiceCount) return; |
424 |
|
uiOldTotalVoiceCount = NewCount; |
425 |
|
|
426 |
for (int i = 0; i < llTotalVoiceCountListeners.GetListenerCount(); i++) { |
for (int i = 0; i < llTotalVoiceCountListeners.GetListenerCount(); i++) { |
427 |
llTotalVoiceCountListeners.GetListener(i)->TotalVoiceCountChanged(NewCount); |
llTotalVoiceCountListeners.GetListener(i)->TotalVoiceCountChanged(NewCount); |
428 |
} |
} |
442 |
} |
} |
443 |
} |
} |
444 |
|
|
445 |
|
void Sampler::EventHandler::EngineToBeChanged(int ChannelId) { |
446 |
|
// nothing to do here |
447 |
|
} |
448 |
|
|
449 |
void Sampler::EventHandler::EngineChanged(int ChannelId) { |
void Sampler::EventHandler::EngineChanged(int ChannelId) { |
450 |
EngineChannel* engineChannel = pSampler->GetSamplerChannel(ChannelId)->GetEngineChannel(); |
EngineChannel* engineChannel = pSampler->GetSamplerChannel(ChannelId)->GetEngineChannel(); |
451 |
if(engineChannel == NULL) return; |
if(engineChannel == NULL) return; |
462 |
if (!mSamplerChannels.size()) { |
if (!mSamplerChannels.size()) { |
463 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
464 |
mSamplerChannels[0] = pChannel; |
mSamplerChannels[0] = pChannel; |
465 |
|
fireChannelAdded(pChannel); |
466 |
fireChannelCountChanged(1); |
fireChannelCountChanged(1); |
467 |
pChannel->AddEngineChangeListener(&eventHandler); |
pChannel->AddEngineChangeListener(&eventHandler); |
468 |
return pChannel; |
return pChannel; |
479 |
// we found an unused index, so insert the new channel there |
// we found an unused index, so insert the new channel there |
480 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
481 |
mSamplerChannels[i] = pChannel; |
mSamplerChannels[i] = pChannel; |
482 |
|
fireChannelAdded(pChannel); |
483 |
fireChannelCountChanged(SamplerChannels()); |
fireChannelCountChanged(SamplerChannels()); |
484 |
pChannel->AddEngineChangeListener(&eventHandler); |
pChannel->AddEngineChangeListener(&eventHandler); |
485 |
return pChannel; |
return pChannel; |
490 |
// 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 |
491 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
492 |
mSamplerChannels[lastIndex + 1] = pChannel; |
mSamplerChannels[lastIndex + 1] = pChannel; |
493 |
|
fireChannelAdded(pChannel); |
494 |
fireChannelCountChanged(SamplerChannels()); |
fireChannelCountChanged(SamplerChannels()); |
495 |
pChannel->AddEngineChangeListener(&eventHandler); |
pChannel->AddEngineChangeListener(&eventHandler); |
496 |
return pChannel; |
return pChannel; |
508 |
SamplerChannelMap::iterator iterChan = mSamplerChannels.begin(); |
SamplerChannelMap::iterator iterChan = mSamplerChannels.begin(); |
509 |
for (; iterChan != mSamplerChannels.end(); iterChan++) { |
for (; iterChan != mSamplerChannels.end(); iterChan++) { |
510 |
if (iterChan->second == pSamplerChannel) { |
if (iterChan->second == pSamplerChannel) { |
511 |
|
fireChannelToBeRemoved(pSamplerChannel); |
512 |
|
mOldVoiceCounts.erase(pSamplerChannel->Index()); |
513 |
|
mOldStreamCounts.erase(pSamplerChannel->Index()); |
514 |
pSamplerChannel->RemoveAllEngineChangeListeners(); |
pSamplerChannel->RemoveAllEngineChangeListeners(); |
515 |
mSamplerChannels.erase(iterChan); |
mSamplerChannels.erase(iterChan); |
516 |
delete pSamplerChannel; |
delete pSamplerChannel; |
526 |
RemoveSamplerChannel(pChannel); |
RemoveSamplerChannel(pChannel); |
527 |
} |
} |
528 |
|
|
529 |
|
void Sampler::RemoveAllSamplerChannels() { |
530 |
|
/* |
531 |
|
* In maps iterator invalidation occurs when the iterator point |
532 |
|
* to the element that is being erased. So we need to copy the map |
533 |
|
* by calling GetSamplerChannels() to prevent that. |
534 |
|
*/ |
535 |
|
SamplerChannelMap chns = GetSamplerChannels(); |
536 |
|
SamplerChannelMap::iterator iter = chns.begin(); |
537 |
|
for(; iter != chns.end(); iter++) { |
538 |
|
RemoveSamplerChannel(iter->second); |
539 |
|
} |
540 |
|
} |
541 |
|
|
542 |
std::vector<String> Sampler::AvailableAudioOutputDrivers() { |
std::vector<String> Sampler::AvailableAudioOutputDrivers() { |
543 |
return AudioOutputDeviceFactory::AvailableDrivers(); |
return AudioOutputDeviceFactory::AvailableDrivers(); |
544 |
} |
} |
555 |
// create new device |
// create new device |
556 |
AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters); |
AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters); |
557 |
|
|
|
// add new audio device to the audio device list |
|
|
for (uint i = 0; ; i++) { // seek for a free place starting from the beginning |
|
|
if (!mAudioOutputDevices[i]) { |
|
|
mAudioOutputDevices[i] = pDevice; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
558 |
fireAudioDeviceCountChanged(AudioOutputDevices()); |
fireAudioDeviceCountChanged(AudioOutputDevices()); |
559 |
return pDevice; |
return pDevice; |
560 |
} |
} |
561 |
|
|
562 |
uint Sampler::AudioOutputDevices() { |
uint Sampler::AudioOutputDevices() { |
563 |
return mAudioOutputDevices.size(); |
return AudioOutputDeviceFactory::Devices().size(); |
564 |
} |
} |
565 |
|
|
566 |
uint Sampler::MidiInputDevices() { |
uint Sampler::MidiInputDevices() { |
567 |
return mMidiInputDevices.size(); |
return MidiInputDeviceFactory::Devices().size(); |
568 |
} |
} |
569 |
|
|
570 |
std::map<uint, AudioOutputDevice*> Sampler::GetAudioOutputDevices() { |
std::map<uint, AudioOutputDevice*> Sampler::GetAudioOutputDevices() { |
571 |
return mAudioOutputDevices; |
return AudioOutputDeviceFactory::Devices(); |
572 |
} |
} |
573 |
|
|
574 |
std::map<uint, MidiInputDevice*> Sampler::GetMidiInputDevices() { |
std::map<uint, MidiInputDevice*> Sampler::GetMidiInputDevices() { |
575 |
return mMidiInputDevices; |
return MidiInputDeviceFactory::Devices(); |
576 |
} |
} |
577 |
|
|
578 |
void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception) { |
void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception) { |
579 |
AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin(); |
if (pDevice) { |
580 |
for (; iter != mAudioOutputDevices.end(); iter++) { |
// check if there are still sampler engines connected to this device |
581 |
if (iter->second == pDevice) { |
for (SamplerChannelMap::iterator iterChan = mSamplerChannels.begin(); |
582 |
// check if there are still sampler engines connected to this device |
iterChan != mSamplerChannels.end(); iterChan++ |
583 |
for (uint i = 0; i < SamplerChannels(); i++) |
) if (iterChan->second->GetAudioOutputDevice() == pDevice) throw Exception("Sampler channel " + ToString(iterChan->first) + " is still connected to the audio output device."); |
584 |
if (GetSamplerChannel(i)->GetAudioOutputDevice() == pDevice) throw Exception("Sampler channel " + ToString(i) + " is still connected to the audio output device."); |
|
585 |
|
//TODO: should we add fireAudioDeviceToBeDestroyed() here ? |
586 |
// disable device |
AudioOutputDeviceFactory::Destroy(pDevice); |
587 |
pDevice->Stop(); |
fireAudioDeviceCountChanged(AudioOutputDevices()); |
588 |
|
} |
589 |
|
} |
590 |
|
|
591 |
// remove device from the device list |
void Sampler::DestroyAllAudioOutputDevices() throw (Exception) { |
592 |
mAudioOutputDevices.erase(iter); |
/* |
593 |
|
* In maps iterator invalidation occurs when the iterator point |
594 |
|
* to the element that is being erased. So we need to copy the map |
595 |
|
* by calling GetAudioOutputDevices() to prevent that. |
596 |
|
*/ |
597 |
|
std::map<uint, AudioOutputDevice*> devs = GetAudioOutputDevices(); |
598 |
|
std::map<uint, AudioOutputDevice*>::iterator iter = devs.begin(); |
599 |
|
for (; iter != devs.end(); iter++) { |
600 |
|
AudioOutputDevice* pDevice = iter->second; |
601 |
|
|
602 |
// destroy and free device from memory |
// skip non-autonomous devices |
603 |
delete pDevice; |
if (!pDevice->isAutonomousDevice()) continue; |
604 |
|
|
605 |
fireAudioDeviceCountChanged(AudioOutputDevices()); |
DestroyAudioOutputDevice(pDevice); |
|
break; |
|
|
} |
|
606 |
} |
} |
607 |
} |
} |
608 |
|
|
609 |
void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception) { |
void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception) { |
610 |
MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin(); |
if (pDevice) { |
611 |
for (; iter != mMidiInputDevices.end(); iter++) { |
// check if there are still sampler engines connected to this device |
612 |
if (iter->second == pDevice) { |
for (SamplerChannelMap::iterator iterChan = mSamplerChannels.begin(); |
613 |
// check if there are still sampler engines connected to this device |
iterChan != mSamplerChannels.end(); iterChan++ |
614 |
for (uint i = 0; i < SamplerChannels(); i++) |
) if (iterChan->second->GetMidiInputDevice() == pDevice) throw Exception("Sampler channel " + ToString(iterChan->first) + " is still connected to the midi input device."); |
615 |
if (GetSamplerChannel(i)->GetMidiInputDevice() == pDevice) throw Exception("Sampler channel " + ToString(i) + " is still connected to the midi input device."); |
|
616 |
|
fireMidiDeviceToBeDestroyed(pDevice); |
617 |
// disable device |
MidiInputDeviceFactory::Destroy(pDevice); |
618 |
pDevice->StopListen(); |
fireMidiDeviceCountChanged(MidiInputDevices()); |
619 |
|
} |
620 |
|
} |
621 |
|
|
622 |
// remove device from the device list |
void Sampler::DestroyAllMidiInputDevices() throw (Exception) { |
623 |
mMidiInputDevices.erase(iter); |
/* |
624 |
|
* In maps iterator invalidation occurs when the iterator point |
625 |
|
* to the element that is being erased. So we need to copy the map |
626 |
|
* by calling GetMidiInputDevices() to prevent that. |
627 |
|
*/ |
628 |
|
std::map<uint, MidiInputDevice*> devs = GetMidiInputDevices(); |
629 |
|
std::map<uint, MidiInputDevice*>::iterator iter = devs.begin(); |
630 |
|
for (; iter != devs.end(); iter++) { |
631 |
|
MidiInputDevice* pDevice = iter->second; |
632 |
|
|
633 |
// destroy and free device from memory |
// skip non-autonomous devices |
634 |
delete pDevice; |
if (!pDevice->isAutonomousDevice()) continue; |
635 |
|
|
636 |
fireMidiDeviceCountChanged(MidiInputDevices()); |
DestroyMidiInputDevice(pDevice); |
|
break; |
|
|
} |
|
637 |
} |
} |
638 |
} |
} |
639 |
|
|
641 |
// create new device |
// create new device |
642 |
MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this); |
MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this); |
643 |
|
|
644 |
// add new device to the midi device list |
fireMidiDeviceCreated(pDevice); |
|
for (uint i = 0; ; i++) { // seek for a free place starting from the beginning |
|
|
if (!mMidiInputDevices[i]) { |
|
|
mMidiInputDevices[i] = pDevice; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
645 |
fireMidiDeviceCountChanged(MidiInputDevices()); |
fireMidiDeviceCountChanged(MidiInputDevices()); |
646 |
return pDevice; |
return pDevice; |
647 |
} |
} |
648 |
|
|
649 |
|
int Sampler::GetDiskStreamCount() { |
650 |
|
int count = 0; |
651 |
|
std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin(); |
652 |
|
|
653 |
|
for(; it != EngineFactory::EngineInstances().end(); it++) { |
654 |
|
count += (*it)->DiskStreamCount(); |
655 |
|
} |
656 |
|
|
657 |
|
return count; |
658 |
|
} |
659 |
|
|
660 |
int Sampler::GetVoiceCount() { |
int Sampler::GetVoiceCount() { |
661 |
int count = 0; |
int count = 0; |
662 |
std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin(); |
std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin(); |
671 |
void Sampler::Reset() { |
void Sampler::Reset() { |
672 |
// delete sampler channels |
// delete sampler channels |
673 |
try { |
try { |
674 |
while (true) { |
RemoveAllSamplerChannels(); |
|
SamplerChannelMap::iterator iter = mSamplerChannels.begin(); |
|
|
if (iter == mSamplerChannels.end()) break; |
|
|
RemoveSamplerChannel(iter->second); |
|
|
} |
|
675 |
} |
} |
676 |
catch(...) { |
catch(...) { |
677 |
std::cerr << "Sampler::Reset(): Exception occured while trying to delete all sampler channels, exiting.\n" << std::flush; |
std::cerr << "Sampler::Reset(): Exception occured while trying to delete all sampler channels, exiting.\n" << std::flush; |
680 |
|
|
681 |
// delete midi input devices |
// delete midi input devices |
682 |
try { |
try { |
683 |
while (true) { |
DestroyAllMidiInputDevices(); |
|
MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin(); |
|
|
if (iter == mMidiInputDevices.end()) break; |
|
|
DestroyMidiInputDevice(iter->second); |
|
|
} |
|
684 |
} |
} |
685 |
catch(...) { |
catch(...) { |
686 |
std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI input devices, exiting.\n" << std::flush; |
std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI input devices, exiting.\n" << std::flush; |
689 |
|
|
690 |
// delete audio output devices |
// delete audio output devices |
691 |
try { |
try { |
692 |
while (true) { |
DestroyAllAudioOutputDevices(); |
|
AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin(); |
|
|
if (iter == mAudioOutputDevices.end()) break; |
|
|
DestroyAudioOutputDevice(iter->second); |
|
|
} |
|
693 |
} |
} |
694 |
catch(...) { |
catch(...) { |
695 |
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; |
709 |
InstrumentEditorFactory::ClosePlugins(); |
InstrumentEditorFactory::ClosePlugins(); |
710 |
} |
} |
711 |
|
|
712 |
|
bool Sampler::EnableDenormalsAreZeroMode() { |
713 |
|
Features::detect(); |
714 |
|
return Features::enableDenormalsAreZeroMode(); |
715 |
|
} |
716 |
|
|
717 |
|
void Sampler::fireStatistics() { |
718 |
|
static const LSCPEvent::event_t eventsArr[] = { |
719 |
|
LSCPEvent::event_voice_count, LSCPEvent::event_stream_count, |
720 |
|
LSCPEvent::event_buffer_fill, LSCPEvent::event_total_voice_count |
721 |
|
}; |
722 |
|
static const std::list<LSCPEvent::event_t> events(eventsArr, eventsArr + 4); |
723 |
|
|
724 |
|
if (LSCPServer::EventSubscribers(events)) |
725 |
|
{ |
726 |
|
LSCPServer::LockRTNotify(); |
727 |
|
std::map<uint,SamplerChannel*> channels = GetSamplerChannels(); |
728 |
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
729 |
|
for (; iter != channels.end(); iter++) { |
730 |
|
SamplerChannel* pSamplerChannel = iter->second; |
731 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
732 |
|
if (!pEngineChannel) continue; |
733 |
|
Engine* pEngine = pEngineChannel->GetEngine(); |
734 |
|
if (!pEngine) continue; |
735 |
|
fireVoiceCountChanged(iter->first, pEngineChannel->GetVoiceCount()); |
736 |
|
fireStreamCountChanged(iter->first, pEngineChannel->GetDiskStreamCount()); |
737 |
|
fireBufferFillChanged(iter->first, pEngine->DiskStreamBufferFillPercentage()); |
738 |
|
} |
739 |
|
|
740 |
|
fireTotalStreamCountChanged(GetDiskStreamCount()); |
741 |
|
fireTotalVoiceCountChanged(GetVoiceCount()); |
742 |
|
|
743 |
|
LSCPServer::UnlockRTNotify(); |
744 |
|
} |
745 |
|
} |
746 |
|
|
747 |
|
#if defined(WIN32) |
748 |
|
static HINSTANCE dllInstance = NULL; |
749 |
|
|
750 |
|
String Sampler::GetInstallDir() { |
751 |
|
char buf[MAX_PATH + 1]; |
752 |
|
if (GetModuleFileName(dllInstance, buf, MAX_PATH)) { |
753 |
|
String s(buf); |
754 |
|
size_t n = s.rfind('\\'); |
755 |
|
if (n != String::npos) { |
756 |
|
return s.substr(0, n); |
757 |
|
} |
758 |
|
} |
759 |
|
return ""; |
760 |
|
} |
761 |
|
#endif |
762 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |
763 |
|
|
764 |
|
#if defined(WIN32) |
765 |
|
extern "C" { |
766 |
|
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) |
767 |
|
{ |
768 |
|
switch (reason) { |
769 |
|
case DLL_PROCESS_ATTACH: |
770 |
|
LinuxSampler::dllInstance = instance; |
771 |
|
break; |
772 |
|
} |
773 |
|
return TRUE; |
774 |
|
} |
775 |
|
} |
776 |
|
#endif |