--- linuxsampler/trunk/src/Sampler.cpp 2007/08/10 15:06:11 1283 +++ linuxsampler/trunk/src/Sampler.cpp 2008/02/14 14:58:50 1686 @@ -3,7 +3,7 @@ * LinuxSampler - modular, streaming capable sampler * * * * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * - * Copyright (C) 2005 - 2007 Christian Schoenebeck * + * Copyright (C) 2005 - 2008 Christian Schoenebeck * * * * This library is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -25,9 +25,10 @@ #include "Sampler.h" +#include "common/global_private.h" #include "engines/EngineFactory.h" #include "engines/EngineChannelFactory.h" -#include "engines/InstrumentEditorFactory.h" +#include "plugins/InstrumentEditorFactory.h" #include "drivers/audio/AudioOutputDeviceFactory.h" #include "drivers/midi/MidiInputDeviceFactory.h" #include "drivers/midi/MidiInstrumentMapper.h" @@ -75,6 +76,8 @@ } } + fireEngineToBeChanged(); + // create new engine channel EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType); if (!pNewEngineChannel) throw Exception("Unknown engine type"); @@ -224,6 +227,12 @@ llEngineChangeListeners.RemoveAllListeners(); } + void SamplerChannel::fireEngineToBeChanged() { + for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) { + llEngineChangeListeners.GetListener(i)->EngineToBeChanged(Index()); + } + } + void SamplerChannel::fireEngineChanged() { for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) { llEngineChangeListeners.GetListener(i)->EngineChanged(Index()); @@ -269,6 +278,18 @@ } } + void Sampler::fireChannelAdded(SamplerChannel* pChannel) { + for (int i = 0; i < llChannelCountListeners.GetListenerCount(); i++) { + llChannelCountListeners.GetListener(i)->ChannelAdded(pChannel); + } + } + + void Sampler::fireChannelToBeRemoved(SamplerChannel* pChannel) { + for (int i = 0; i < llChannelCountListeners.GetListenerCount(); i++) { + llChannelCountListeners.GetListener(i)->ChannelToBeRemoved(pChannel); + } + } + void Sampler::AddAudioDeviceCountListener(AudioDeviceCountListener* l) { llAudioDeviceCountListeners.AddListener(l); } @@ -339,6 +360,20 @@ } } + void Sampler::AddTotalStreamCountListener(TotalStreamCountListener* l) { + llTotalStreamCountListeners.AddListener(l); + } + + void Sampler::RemoveTotalStreamCountListener(TotalStreamCountListener* l) { + llTotalStreamCountListeners.RemoveListener(l); + } + + void Sampler::fireTotalStreamCountChanged(int NewCount) { + for (int i = 0; i < llTotalStreamCountListeners.GetListenerCount(); i++) { + llTotalStreamCountListeners.GetListener(i)->TotalStreamCountChanged(NewCount); + } + } + void Sampler::AddTotalVoiceCountListener(TotalVoiceCountListener* l) { llTotalVoiceCountListeners.AddListener(l); } @@ -367,6 +402,10 @@ } } + void Sampler::EventHandler::EngineToBeChanged(int ChannelId) { + // nothing to do here + } + void Sampler::EventHandler::EngineChanged(int ChannelId) { EngineChannel* engineChannel = pSampler->GetSamplerChannel(ChannelId)->GetEngineChannel(); if(engineChannel == NULL) return; @@ -383,6 +422,7 @@ if (!mSamplerChannels.size()) { SamplerChannel* pChannel = new SamplerChannel(this); mSamplerChannels[0] = pChannel; + fireChannelAdded(pChannel); fireChannelCountChanged(1); pChannel->AddEngineChangeListener(&eventHandler); return pChannel; @@ -399,6 +439,7 @@ // we found an unused index, so insert the new channel there SamplerChannel* pChannel = new SamplerChannel(this); mSamplerChannels[i] = pChannel; + fireChannelAdded(pChannel); fireChannelCountChanged(SamplerChannels()); pChannel->AddEngineChangeListener(&eventHandler); return pChannel; @@ -409,6 +450,7 @@ // we have not reached the index limit so we just add the channel past the highest index SamplerChannel* pChannel = new SamplerChannel(this); mSamplerChannels[lastIndex + 1] = pChannel; + fireChannelAdded(pChannel); fireChannelCountChanged(SamplerChannels()); pChannel->AddEngineChangeListener(&eventHandler); return pChannel; @@ -426,6 +468,7 @@ SamplerChannelMap::iterator iterChan = mSamplerChannels.begin(); for (; iterChan != mSamplerChannels.end(); iterChan++) { if (iterChan->second == pSamplerChannel) { + fireChannelToBeRemoved(pSamplerChannel); pSamplerChannel->RemoveAllEngineChangeListeners(); mSamplerChannels.erase(iterChan); delete pSamplerChannel; @@ -547,6 +590,17 @@ return pDevice; } + int Sampler::GetDiskStreamCount() { + int count = 0; + std::set::iterator it = EngineFactory::EngineInstances().begin(); + + for(; it != EngineFactory::EngineInstances().end(); it++) { + count += (*it)->DiskStreamCount(); + } + + return count; + } + int Sampler::GetVoiceCount() { int count = 0; std::set::iterator it = EngineFactory::EngineInstances().begin();