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 - 2008 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 * |
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" |
#include "common/Features.h" |
36 |
|
#include "network/lscpserver.h" |
37 |
|
|
38 |
namespace LinuxSampler { |
namespace LinuxSampler { |
39 |
|
|
70 |
|
|
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) { |
if (pEngineChannel) { |
75 |
if (!strcasecmp(pEngineChannel->EngineName().c_str(), EngineType.c_str())) { |
if (!strcasecmp(pEngineChannel->EngineName().c_str(), EngineType.c_str())) { |
76 |
dmsg(2,("OK\n")); |
dmsg(2,("OK\n")); |
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()); |
119 |
dmsg(2,("OK\n")); |
dmsg(2,("OK\n")); |
120 |
} |
} |
121 |
|
|
122 |
void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) { |
void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception) { |
123 |
if(pAudioOutputDevice == pDevice) return; |
if(pAudioOutputDevice == pDevice) return; |
124 |
|
|
125 |
// disconnect old device |
// disconnect old device |
126 |
if (pAudioOutputDevice && pEngineChannel) { |
if (pAudioOutputDevice && pEngineChannel) { |
127 |
|
if (!pAudioOutputDevice->isAutonomousDevice()) |
128 |
|
throw Exception("The audio output device '" + pAudioOutputDevice->Driver() + "' cannot be dropped from this sampler channel!"); |
129 |
|
|
130 |
Engine* engine = pEngineChannel->GetEngine(); |
Engine* engine = pEngineChannel->GetEngine(); |
131 |
pAudioOutputDevice->Disconnect(engine); |
pAudioOutputDevice->Disconnect(engine); |
132 |
|
|
145 |
} |
} |
146 |
} |
} |
147 |
|
|
148 |
void SamplerChannel::SetMidiInputDevice(MidiInputDevice* pDevice) { |
void SamplerChannel::SetMidiInputDevice(MidiInputDevice* pDevice) throw (Exception) { |
149 |
SetMidiInput(pDevice, 0, GetMidiInputChannel()); |
SetMidiInput(pDevice, 0, GetMidiInputChannel()); |
150 |
} |
} |
151 |
|
|
152 |
void SamplerChannel::SetMidiInputPort(int MidiPort) { |
void SamplerChannel::SetMidiInputPort(int MidiPort) throw (Exception) { |
153 |
SetMidiInput(GetMidiInputDevice(), MidiPort, GetMidiInputChannel()); |
SetMidiInput(GetMidiInputDevice(), MidiPort, GetMidiInputChannel()); |
154 |
} |
} |
155 |
|
|
157 |
SetMidiInput(GetMidiInputDevice(), GetMidiInputPort(), MidiChannel); |
SetMidiInput(GetMidiInputDevice(), GetMidiInputPort(), MidiChannel); |
158 |
} |
} |
159 |
|
|
160 |
void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel) { |
void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel) throw (Exception) { |
161 |
if (!pDevice) throw Exception("No MIDI input device assigned."); |
if (!pDevice) throw Exception("No MIDI input device assigned."); |
162 |
|
|
163 |
// get old and new midi input port |
// get old and new midi input port |
165 |
MidiInputPort* pNewMidiInputPort = pDevice->GetPort(iMidiPort); |
MidiInputPort* pNewMidiInputPort = pDevice->GetPort(iMidiPort); |
166 |
|
|
167 |
// disconnect old device port |
// disconnect old device port |
168 |
if (pOldMidiInputPort && pEngineChannel) pOldMidiInputPort->Disconnect(pEngineChannel); |
if (pOldMidiInputPort && pEngineChannel) { |
169 |
|
MidiInputDevice* pOldDevice = pOldMidiInputPort->GetDevice(); |
170 |
|
if (pOldMidiInputPort != pNewMidiInputPort && |
171 |
|
pOldDevice && !pOldDevice->isAutonomousDevice() |
172 |
|
) throw Exception("The MIDI input port '" + pOldDevice->Driver() + "' cannot be altered on this sampler channel!"); |
173 |
|
|
174 |
|
pOldMidiInputPort->Disconnect(pEngineChannel); |
175 |
|
} |
176 |
|
|
177 |
// remember new device, port and channel if not engine channel yet created |
// remember new device, port and channel if not engine channel yet created |
178 |
if (!pEngineChannel) { |
if (!pEngineChannel) { |
179 |
this->pMidiInputDevice = pDevice; |
this->pMidiInputDevice = pDevice; |
227 |
throw Exception("Internal error: SamplerChannel index not found"); |
throw Exception("Internal error: SamplerChannel index not found"); |
228 |
} |
} |
229 |
|
|
230 |
|
Sampler* SamplerChannel::GetSampler() { |
231 |
|
return pSampler; |
232 |
|
} |
233 |
|
|
234 |
void SamplerChannel::AddEngineChangeListener(EngineChangeListener* l) { |
void SamplerChannel::AddEngineChangeListener(EngineChangeListener* l) { |
235 |
llEngineChangeListeners.AddListener(l); |
llEngineChangeListeners.AddListener(l); |
236 |
} |
} |
270 |
|
|
271 |
Sampler::Sampler() { |
Sampler::Sampler() { |
272 |
eventHandler.SetSampler(this); |
eventHandler.SetSampler(this); |
273 |
|
uiOldTotalVoiceCount = uiOldTotalStreamCount = 0; |
274 |
} |
} |
275 |
|
|
276 |
Sampler::~Sampler() { |
Sampler::~Sampler() { |
356 |
} |
} |
357 |
|
|
358 |
void Sampler::fireVoiceCountChanged(int ChannelId, int NewCount) { |
void Sampler::fireVoiceCountChanged(int ChannelId, int NewCount) { |
359 |
|
std::map<uint, uint>::iterator it = mOldVoiceCounts.find(ChannelId); |
360 |
|
if (it != mOldVoiceCounts.end()) { |
361 |
|
uint oldCount = it->second; |
362 |
|
if (NewCount == oldCount) return; |
363 |
|
} |
364 |
|
|
365 |
|
mOldVoiceCounts[ChannelId] = NewCount; |
366 |
|
|
367 |
for (int i = 0; i < llVoiceCountListeners.GetListenerCount(); i++) { |
for (int i = 0; i < llVoiceCountListeners.GetListenerCount(); i++) { |
368 |
llVoiceCountListeners.GetListener(i)->VoiceCountChanged(ChannelId, NewCount); |
llVoiceCountListeners.GetListener(i)->VoiceCountChanged(ChannelId, NewCount); |
369 |
} |
} |
378 |
} |
} |
379 |
|
|
380 |
void Sampler::fireStreamCountChanged(int ChannelId, int NewCount) { |
void Sampler::fireStreamCountChanged(int ChannelId, int NewCount) { |
381 |
|
std::map<uint, uint>::iterator it = mOldStreamCounts.find(ChannelId); |
382 |
|
if (it != mOldStreamCounts.end()) { |
383 |
|
uint oldCount = it->second; |
384 |
|
if (NewCount == oldCount) return; |
385 |
|
} |
386 |
|
|
387 |
|
mOldStreamCounts[ChannelId] = NewCount; |
388 |
|
|
389 |
for (int i = 0; i < llStreamCountListeners.GetListenerCount(); i++) { |
for (int i = 0; i < llStreamCountListeners.GetListenerCount(); i++) { |
390 |
llStreamCountListeners.GetListener(i)->StreamCountChanged(ChannelId, NewCount); |
llStreamCountListeners.GetListener(i)->StreamCountChanged(ChannelId, NewCount); |
391 |
} |
} |
414 |
} |
} |
415 |
|
|
416 |
void Sampler::fireTotalStreamCountChanged(int NewCount) { |
void Sampler::fireTotalStreamCountChanged(int NewCount) { |
417 |
|
if (NewCount == uiOldTotalStreamCount) return; |
418 |
|
uiOldTotalStreamCount = NewCount; |
419 |
|
|
420 |
for (int i = 0; i < llTotalStreamCountListeners.GetListenerCount(); i++) { |
for (int i = 0; i < llTotalStreamCountListeners.GetListenerCount(); i++) { |
421 |
llTotalStreamCountListeners.GetListener(i)->TotalStreamCountChanged(NewCount); |
llTotalStreamCountListeners.GetListener(i)->TotalStreamCountChanged(NewCount); |
422 |
} |
} |
431 |
} |
} |
432 |
|
|
433 |
void Sampler::fireTotalVoiceCountChanged(int NewCount) { |
void Sampler::fireTotalVoiceCountChanged(int NewCount) { |
434 |
|
if (NewCount == uiOldTotalVoiceCount) return; |
435 |
|
uiOldTotalVoiceCount = NewCount; |
436 |
|
|
437 |
for (int i = 0; i < llTotalVoiceCountListeners.GetListenerCount(); i++) { |
for (int i = 0; i < llTotalVoiceCountListeners.GetListenerCount(); i++) { |
438 |
llTotalVoiceCountListeners.GetListener(i)->TotalVoiceCountChanged(NewCount); |
llTotalVoiceCountListeners.GetListener(i)->TotalVoiceCountChanged(NewCount); |
439 |
} |
} |
520 |
for (; iterChan != mSamplerChannels.end(); iterChan++) { |
for (; iterChan != mSamplerChannels.end(); iterChan++) { |
521 |
if (iterChan->second == pSamplerChannel) { |
if (iterChan->second == pSamplerChannel) { |
522 |
fireChannelToBeRemoved(pSamplerChannel); |
fireChannelToBeRemoved(pSamplerChannel); |
523 |
|
mOldVoiceCounts.erase(pSamplerChannel->Index()); |
524 |
|
mOldStreamCounts.erase(pSamplerChannel->Index()); |
525 |
pSamplerChannel->RemoveAllEngineChangeListeners(); |
pSamplerChannel->RemoveAllEngineChangeListeners(); |
526 |
mSamplerChannels.erase(iterChan); |
mSamplerChannels.erase(iterChan); |
527 |
delete pSamplerChannel; |
delete pSamplerChannel; |
537 |
RemoveSamplerChannel(pChannel); |
RemoveSamplerChannel(pChannel); |
538 |
} |
} |
539 |
|
|
540 |
|
void Sampler::RemoveAllSamplerChannels() { |
541 |
|
/* |
542 |
|
* In maps iterator invalidation occurs when the iterator point |
543 |
|
* to the element that is being erased. So we need to copy the map |
544 |
|
* by calling GetSamplerChannels() to prevent that. |
545 |
|
*/ |
546 |
|
SamplerChannelMap chns = GetSamplerChannels(); |
547 |
|
SamplerChannelMap::iterator iter = chns.begin(); |
548 |
|
for(; iter != chns.end(); iter++) { |
549 |
|
RemoveSamplerChannel(iter->second); |
550 |
|
} |
551 |
|
} |
552 |
|
|
553 |
std::vector<String> Sampler::AvailableAudioOutputDrivers() { |
std::vector<String> Sampler::AvailableAudioOutputDrivers() { |
554 |
return AudioOutputDeviceFactory::AvailableDrivers(); |
return AudioOutputDeviceFactory::AvailableDrivers(); |
555 |
} |
} |
566 |
// create new device |
// create new device |
567 |
AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters); |
AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters); |
568 |
|
|
|
// 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; |
|
|
} |
|
|
} |
|
|
|
|
569 |
fireAudioDeviceCountChanged(AudioOutputDevices()); |
fireAudioDeviceCountChanged(AudioOutputDevices()); |
570 |
return pDevice; |
return pDevice; |
571 |
} |
} |
572 |
|
|
573 |
uint Sampler::AudioOutputDevices() { |
uint Sampler::AudioOutputDevices() { |
574 |
return mAudioOutputDevices.size(); |
return AudioOutputDeviceFactory::Devices().size(); |
575 |
} |
} |
576 |
|
|
577 |
uint Sampler::MidiInputDevices() { |
uint Sampler::MidiInputDevices() { |
578 |
return mMidiInputDevices.size(); |
return MidiInputDeviceFactory::Devices().size(); |
579 |
} |
} |
580 |
|
|
581 |
std::map<uint, AudioOutputDevice*> Sampler::GetAudioOutputDevices() { |
std::map<uint, AudioOutputDevice*> Sampler::GetAudioOutputDevices() { |
582 |
return mAudioOutputDevices; |
return AudioOutputDeviceFactory::Devices(); |
583 |
} |
} |
584 |
|
|
585 |
std::map<uint, MidiInputDevice*> Sampler::GetMidiInputDevices() { |
std::map<uint, MidiInputDevice*> Sampler::GetMidiInputDevices() { |
586 |
return mMidiInputDevices; |
return MidiInputDeviceFactory::Devices(); |
587 |
} |
} |
588 |
|
|
589 |
void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception) { |
void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception) { |
590 |
AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin(); |
if (pDevice) { |
591 |
for (; iter != mAudioOutputDevices.end(); iter++) { |
// check if there are still sampler engines connected to this device |
592 |
if (iter->second == pDevice) { |
for (SamplerChannelMap::iterator iterChan = mSamplerChannels.begin(); |
593 |
// check if there are still sampler engines connected to this device |
iterChan != mSamplerChannels.end(); iterChan++ |
594 |
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."); |
595 |
if (GetSamplerChannel(i)->GetAudioOutputDevice() == pDevice) throw Exception("Sampler channel " + ToString(i) + " is still connected to the audio output device."); |
|
596 |
|
//TODO: should we add fireAudioDeviceToBeDestroyed() here ? |
597 |
// disable device |
AudioOutputDeviceFactory::Destroy(pDevice); |
598 |
pDevice->Stop(); |
fireAudioDeviceCountChanged(AudioOutputDevices()); |
599 |
|
} |
600 |
|
} |
601 |
|
|
602 |
// remove device from the device list |
void Sampler::DestroyAllAudioOutputDevices() throw (Exception) { |
603 |
mAudioOutputDevices.erase(iter); |
/* |
604 |
|
* In maps iterator invalidation occurs when the iterator point |
605 |
|
* to the element that is being erased. So we need to copy the map |
606 |
|
* by calling GetAudioOutputDevices() to prevent that. |
607 |
|
*/ |
608 |
|
std::map<uint, AudioOutputDevice*> devs = GetAudioOutputDevices(); |
609 |
|
std::map<uint, AudioOutputDevice*>::iterator iter = devs.begin(); |
610 |
|
for (; iter != devs.end(); iter++) { |
611 |
|
AudioOutputDevice* pDevice = iter->second; |
612 |
|
|
613 |
// destroy and free device from memory |
// skip non-autonomous devices |
614 |
delete pDevice; |
if (!pDevice->isAutonomousDevice()) continue; |
615 |
|
|
616 |
fireAudioDeviceCountChanged(AudioOutputDevices()); |
DestroyAudioOutputDevice(pDevice); |
|
break; |
|
|
} |
|
617 |
} |
} |
618 |
} |
} |
619 |
|
|
620 |
void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception) { |
void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception) { |
621 |
MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin(); |
if (pDevice) { |
622 |
for (; iter != mMidiInputDevices.end(); iter++) { |
// check if there are still sampler engines connected to this device |
623 |
if (iter->second == pDevice) { |
for (SamplerChannelMap::iterator iterChan = mSamplerChannels.begin(); |
624 |
// check if there are still sampler engines connected to this device |
iterChan != mSamplerChannels.end(); iterChan++ |
625 |
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."); |
626 |
if (GetSamplerChannel(i)->GetMidiInputDevice() == pDevice) throw Exception("Sampler channel " + ToString(i) + " is still connected to the midi input device."); |
|
627 |
|
fireMidiDeviceToBeDestroyed(pDevice); |
628 |
fireMidiDeviceToBeDestroyed(pDevice); |
MidiInputDeviceFactory::Destroy(pDevice); |
629 |
|
fireMidiDeviceCountChanged(MidiInputDevices()); |
630 |
// disable device |
} |
631 |
pDevice->StopListen(); |
} |
632 |
|
|
633 |
// remove device from the device list |
void Sampler::DestroyAllMidiInputDevices() throw (Exception) { |
634 |
mMidiInputDevices.erase(iter); |
/* |
635 |
|
* In maps iterator invalidation occurs when the iterator point |
636 |
|
* to the element that is being erased. So we need to copy the map |
637 |
|
* by calling GetMidiInputDevices() to prevent that. |
638 |
|
*/ |
639 |
|
std::map<uint, MidiInputDevice*> devs = GetMidiInputDevices(); |
640 |
|
std::map<uint, MidiInputDevice*>::iterator iter = devs.begin(); |
641 |
|
for (; iter != devs.end(); iter++) { |
642 |
|
MidiInputDevice* pDevice = iter->second; |
643 |
|
|
644 |
// destroy and free device from memory |
// skip non-autonomous devices |
645 |
delete pDevice; |
if (!pDevice->isAutonomousDevice()) continue; |
646 |
|
|
647 |
fireMidiDeviceCountChanged(MidiInputDevices()); |
DestroyMidiInputDevice(pDevice); |
|
break; |
|
|
} |
|
648 |
} |
} |
649 |
} |
} |
650 |
|
|
652 |
// create new device |
// create new device |
653 |
MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this); |
MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this); |
654 |
|
|
|
// add new device to the midi device list |
|
|
for (uint i = 0; ; i++) { // seek for a free place starting from the beginning |
|
|
if (!mMidiInputDevices[i]) { |
|
|
mMidiInputDevices[i] = pDevice; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
655 |
fireMidiDeviceCreated(pDevice); |
fireMidiDeviceCreated(pDevice); |
656 |
fireMidiDeviceCountChanged(MidiInputDevices()); |
fireMidiDeviceCountChanged(MidiInputDevices()); |
657 |
return pDevice; |
return pDevice; |
682 |
void Sampler::Reset() { |
void Sampler::Reset() { |
683 |
// delete sampler channels |
// delete sampler channels |
684 |
try { |
try { |
685 |
while (true) { |
RemoveAllSamplerChannels(); |
|
SamplerChannelMap::iterator iter = mSamplerChannels.begin(); |
|
|
if (iter == mSamplerChannels.end()) break; |
|
|
RemoveSamplerChannel(iter->second); |
|
|
} |
|
686 |
} |
} |
687 |
catch(...) { |
catch(...) { |
688 |
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; |
691 |
|
|
692 |
// delete midi input devices |
// delete midi input devices |
693 |
try { |
try { |
694 |
while (true) { |
DestroyAllMidiInputDevices(); |
|
MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin(); |
|
|
if (iter == mMidiInputDevices.end()) break; |
|
|
DestroyMidiInputDevice(iter->second); |
|
|
} |
|
695 |
} |
} |
696 |
catch(...) { |
catch(...) { |
697 |
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; |
700 |
|
|
701 |
// delete audio output devices |
// delete audio output devices |
702 |
try { |
try { |
703 |
while (true) { |
DestroyAllAudioOutputDevices(); |
|
AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin(); |
|
|
if (iter == mAudioOutputDevices.end()) break; |
|
|
DestroyAudioOutputDevice(iter->second); |
|
|
} |
|
704 |
} |
} |
705 |
catch(...) { |
catch(...) { |
706 |
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; |
725 |
return Features::enableDenormalsAreZeroMode(); |
return Features::enableDenormalsAreZeroMode(); |
726 |
} |
} |
727 |
|
|
728 |
|
void Sampler::fireStatistics() { |
729 |
|
static const LSCPEvent::event_t eventsArr[] = { |
730 |
|
LSCPEvent::event_voice_count, LSCPEvent::event_stream_count, |
731 |
|
LSCPEvent::event_buffer_fill, LSCPEvent::event_total_voice_count |
732 |
|
}; |
733 |
|
static const std::list<LSCPEvent::event_t> events(eventsArr, eventsArr + 4); |
734 |
|
|
735 |
|
if (LSCPServer::EventSubscribers(events)) |
736 |
|
{ |
737 |
|
LSCPServer::LockRTNotify(); |
738 |
|
std::map<uint,SamplerChannel*> channels = GetSamplerChannels(); |
739 |
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
740 |
|
for (; iter != channels.end(); iter++) { |
741 |
|
SamplerChannel* pSamplerChannel = iter->second; |
742 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
743 |
|
if (!pEngineChannel) continue; |
744 |
|
Engine* pEngine = pEngineChannel->GetEngine(); |
745 |
|
if (!pEngine) continue; |
746 |
|
fireVoiceCountChanged(iter->first, pEngineChannel->GetVoiceCount()); |
747 |
|
fireStreamCountChanged(iter->first, pEngineChannel->GetDiskStreamCount()); |
748 |
|
fireBufferFillChanged(iter->first, pEngine->DiskStreamBufferFillPercentage()); |
749 |
|
} |
750 |
|
|
751 |
|
fireTotalStreamCountChanged(GetDiskStreamCount()); |
752 |
|
fireTotalVoiceCountChanged(GetVoiceCount()); |
753 |
|
|
754 |
|
LSCPServer::UnlockRTNotify(); |
755 |
|
} |
756 |
|
} |
757 |
|
|
758 |
|
#if defined(WIN32) |
759 |
|
static HINSTANCE dllInstance = NULL; |
760 |
|
|
761 |
|
String Sampler::GetInstallDir() { |
762 |
|
char buf[MAX_PATH + 1]; |
763 |
|
if (GetModuleFileName(dllInstance, buf, MAX_PATH)) { |
764 |
|
String s(buf); |
765 |
|
size_t n = s.rfind('\\'); |
766 |
|
if (n != String::npos) { |
767 |
|
return s.substr(0, n); |
768 |
|
} |
769 |
|
} |
770 |
|
return ""; |
771 |
|
} |
772 |
|
#endif |
773 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |
774 |
|
|
775 |
|
#if defined(WIN32) |
776 |
|
extern "C" { |
777 |
|
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) |
778 |
|
{ |
779 |
|
switch (reason) { |
780 |
|
case DLL_PROCESS_ATTACH: |
781 |
|
LinuxSampler::dllInstance = instance; |
782 |
|
break; |
783 |
|
} |
784 |
|
return TRUE; |
785 |
|
} |
786 |
|
} |
787 |
|
#endif |