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 - 2008 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 "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" |
68 |
|
|
69 |
void SamplerChannel::SetEngineType(String EngineType) throw (Exception) { |
void SamplerChannel::SetEngineType(String EngineType) throw (Exception) { |
70 |
dmsg(2,("SamplerChannel: Assigning engine type...")); |
dmsg(2,("SamplerChannel: Assigning engine type...")); |
71 |
|
|
72 |
|
if (pEngineChannel) { |
73 |
|
if (!strcasecmp(pEngineChannel->EngineName().c_str(), EngineType.c_str())) { |
74 |
|
dmsg(2,("OK\n")); |
75 |
|
return; |
76 |
|
} |
77 |
|
} |
78 |
|
|
79 |
|
fireEngineToBeChanged(); |
80 |
|
|
81 |
// create new engine channel |
// create new engine channel |
82 |
EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType); |
EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType); |
227 |
llEngineChangeListeners.RemoveAllListeners(); |
llEngineChangeListeners.RemoveAllListeners(); |
228 |
} |
} |
229 |
|
|
230 |
|
void SamplerChannel::fireEngineToBeChanged() { |
231 |
|
for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) { |
232 |
|
llEngineChangeListeners.GetListener(i)->EngineToBeChanged(Index()); |
233 |
|
} |
234 |
|
} |
235 |
|
|
236 |
void SamplerChannel::fireEngineChanged() { |
void SamplerChannel::fireEngineChanged() { |
237 |
for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) { |
for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) { |
238 |
llEngineChangeListeners.GetListener(i)->EngineChanged(Index()); |
llEngineChangeListeners.GetListener(i)->EngineChanged(Index()); |
278 |
} |
} |
279 |
} |
} |
280 |
|
|
281 |
|
void Sampler::fireChannelAdded(SamplerChannel* pChannel) { |
282 |
|
for (int i = 0; i < llChannelCountListeners.GetListenerCount(); i++) { |
283 |
|
llChannelCountListeners.GetListener(i)->ChannelAdded(pChannel); |
284 |
|
} |
285 |
|
} |
286 |
|
|
287 |
|
void Sampler::fireChannelToBeRemoved(SamplerChannel* pChannel) { |
288 |
|
for (int i = 0; i < llChannelCountListeners.GetListenerCount(); i++) { |
289 |
|
llChannelCountListeners.GetListener(i)->ChannelToBeRemoved(pChannel); |
290 |
|
} |
291 |
|
} |
292 |
|
|
293 |
void Sampler::AddAudioDeviceCountListener(AudioDeviceCountListener* l) { |
void Sampler::AddAudioDeviceCountListener(AudioDeviceCountListener* l) { |
294 |
llAudioDeviceCountListeners.AddListener(l); |
llAudioDeviceCountListeners.AddListener(l); |
295 |
} |
} |
318 |
} |
} |
319 |
} |
} |
320 |
|
|
321 |
|
void Sampler::fireMidiDeviceToBeDestroyed(MidiInputDevice* pDevice) { |
322 |
|
for (int i = 0; i < llMidiDeviceCountListeners.GetListenerCount(); i++) { |
323 |
|
llMidiDeviceCountListeners.GetListener(i)->MidiDeviceToBeDestroyed(pDevice); |
324 |
|
} |
325 |
|
} |
326 |
|
|
327 |
|
void Sampler::fireMidiDeviceCreated(MidiInputDevice* pDevice) { |
328 |
|
for (int i = 0; i < llMidiDeviceCountListeners.GetListenerCount(); i++) { |
329 |
|
llMidiDeviceCountListeners.GetListener(i)->MidiDeviceCreated(pDevice); |
330 |
|
} |
331 |
|
} |
332 |
|
|
333 |
void Sampler::AddVoiceCountListener(VoiceCountListener* l) { |
void Sampler::AddVoiceCountListener(VoiceCountListener* l) { |
334 |
llVoiceCountListeners.AddListener(l); |
llVoiceCountListeners.AddListener(l); |
335 |
} |
} |
372 |
} |
} |
373 |
} |
} |
374 |
|
|
375 |
|
void Sampler::AddTotalStreamCountListener(TotalStreamCountListener* l) { |
376 |
|
llTotalStreamCountListeners.AddListener(l); |
377 |
|
} |
378 |
|
|
379 |
|
void Sampler::RemoveTotalStreamCountListener(TotalStreamCountListener* l) { |
380 |
|
llTotalStreamCountListeners.RemoveListener(l); |
381 |
|
} |
382 |
|
|
383 |
|
void Sampler::fireTotalStreamCountChanged(int NewCount) { |
384 |
|
for (int i = 0; i < llTotalStreamCountListeners.GetListenerCount(); i++) { |
385 |
|
llTotalStreamCountListeners.GetListener(i)->TotalStreamCountChanged(NewCount); |
386 |
|
} |
387 |
|
} |
388 |
|
|
389 |
void Sampler::AddTotalVoiceCountListener(TotalVoiceCountListener* l) { |
void Sampler::AddTotalVoiceCountListener(TotalVoiceCountListener* l) { |
390 |
llTotalVoiceCountListeners.AddListener(l); |
llTotalVoiceCountListeners.AddListener(l); |
391 |
} |
} |
414 |
} |
} |
415 |
} |
} |
416 |
|
|
417 |
|
void Sampler::EventHandler::EngineToBeChanged(int ChannelId) { |
418 |
|
// nothing to do here |
419 |
|
} |
420 |
|
|
421 |
void Sampler::EventHandler::EngineChanged(int ChannelId) { |
void Sampler::EventHandler::EngineChanged(int ChannelId) { |
422 |
EngineChannel* engineChannel = pSampler->GetSamplerChannel(ChannelId)->GetEngineChannel(); |
EngineChannel* engineChannel = pSampler->GetSamplerChannel(ChannelId)->GetEngineChannel(); |
423 |
if(engineChannel == NULL) return; |
if(engineChannel == NULL) return; |
434 |
if (!mSamplerChannels.size()) { |
if (!mSamplerChannels.size()) { |
435 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
436 |
mSamplerChannels[0] = pChannel; |
mSamplerChannels[0] = pChannel; |
437 |
|
fireChannelAdded(pChannel); |
438 |
fireChannelCountChanged(1); |
fireChannelCountChanged(1); |
439 |
pChannel->AddEngineChangeListener(&eventHandler); |
pChannel->AddEngineChangeListener(&eventHandler); |
440 |
return pChannel; |
return pChannel; |
451 |
// we found an unused index, so insert the new channel there |
// we found an unused index, so insert the new channel there |
452 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
453 |
mSamplerChannels[i] = pChannel; |
mSamplerChannels[i] = pChannel; |
454 |
|
fireChannelAdded(pChannel); |
455 |
fireChannelCountChanged(SamplerChannels()); |
fireChannelCountChanged(SamplerChannels()); |
456 |
pChannel->AddEngineChangeListener(&eventHandler); |
pChannel->AddEngineChangeListener(&eventHandler); |
457 |
return pChannel; |
return pChannel; |
462 |
// 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 |
463 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
464 |
mSamplerChannels[lastIndex + 1] = pChannel; |
mSamplerChannels[lastIndex + 1] = pChannel; |
465 |
|
fireChannelAdded(pChannel); |
466 |
fireChannelCountChanged(SamplerChannels()); |
fireChannelCountChanged(SamplerChannels()); |
467 |
pChannel->AddEngineChangeListener(&eventHandler); |
pChannel->AddEngineChangeListener(&eventHandler); |
468 |
return pChannel; |
return pChannel; |
480 |
SamplerChannelMap::iterator iterChan = mSamplerChannels.begin(); |
SamplerChannelMap::iterator iterChan = mSamplerChannels.begin(); |
481 |
for (; iterChan != mSamplerChannels.end(); iterChan++) { |
for (; iterChan != mSamplerChannels.end(); iterChan++) { |
482 |
if (iterChan->second == pSamplerChannel) { |
if (iterChan->second == pSamplerChannel) { |
483 |
|
fireChannelToBeRemoved(pSamplerChannel); |
484 |
pSamplerChannel->RemoveAllEngineChangeListeners(); |
pSamplerChannel->RemoveAllEngineChangeListeners(); |
485 |
mSamplerChannels.erase(iterChan); |
mSamplerChannels.erase(iterChan); |
486 |
delete pSamplerChannel; |
delete pSamplerChannel; |
571 |
for (uint i = 0; i < SamplerChannels(); i++) |
for (uint i = 0; i < SamplerChannels(); i++) |
572 |
if (GetSamplerChannel(i)->GetMidiInputDevice() == pDevice) throw Exception("Sampler channel " + ToString(i) + " is still connected to the midi input device."); |
if (GetSamplerChannel(i)->GetMidiInputDevice() == pDevice) throw Exception("Sampler channel " + ToString(i) + " is still connected to the midi input device."); |
573 |
|
|
574 |
|
fireMidiDeviceToBeDestroyed(pDevice); |
575 |
|
|
576 |
// disable device |
// disable device |
577 |
pDevice->StopListen(); |
pDevice->StopListen(); |
578 |
|
|
600 |
} |
} |
601 |
} |
} |
602 |
|
|
603 |
|
fireMidiDeviceCreated(pDevice); |
604 |
fireMidiDeviceCountChanged(MidiInputDevices()); |
fireMidiDeviceCountChanged(MidiInputDevices()); |
605 |
return pDevice; |
return pDevice; |
606 |
} |
} |
607 |
|
|
608 |
|
int Sampler::GetDiskStreamCount() { |
609 |
|
int count = 0; |
610 |
|
std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin(); |
611 |
|
|
612 |
|
for(; it != EngineFactory::EngineInstances().end(); it++) { |
613 |
|
count += (*it)->DiskStreamCount(); |
614 |
|
} |
615 |
|
|
616 |
|
return count; |
617 |
|
} |
618 |
|
|
619 |
int Sampler::GetVoiceCount() { |
int Sampler::GetVoiceCount() { |
620 |
int count = 0; |
int count = 0; |
621 |
std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin(); |
std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin(); |
675 |
std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI instrument maps, exiting.\n" << std::flush; |
std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI instrument maps, exiting.\n" << std::flush; |
676 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
677 |
} |
} |
678 |
|
|
679 |
|
// unload all instrument editor DLLs |
680 |
|
InstrumentEditorFactory::ClosePlugins(); |
681 |
} |
} |
682 |
|
|
683 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |