25 |
|
|
26 |
#include "Sampler.h" |
#include "Sampler.h" |
27 |
|
|
28 |
|
#include "engines/EngineFactory.h" |
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" |
48 |
|
|
49 |
SamplerChannel::~SamplerChannel() { |
SamplerChannel::~SamplerChannel() { |
50 |
if (pEngineChannel) { |
if (pEngineChannel) { |
51 |
|
Engine* engine = pEngineChannel->GetEngine(); |
52 |
|
if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(engine); |
53 |
|
|
54 |
MidiInputPort* pMidiInputPort = (pEngineChannel) ? pEngineChannel->GetMidiInputPort() : __GetMidiInputDevicePort(GetMidiInputChannel()); |
MidiInputPort* pMidiInputPort = (pEngineChannel) ? pEngineChannel->GetMidiInputPort() : __GetMidiInputDevicePort(GetMidiInputChannel()); |
55 |
if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel); |
if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel); |
56 |
if (pEngineChannel) { |
if (pEngineChannel) { |
57 |
if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice(); |
if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice(); |
58 |
EngineChannelFactory::Destroy(pEngineChannel); |
EngineChannelFactory::Destroy(pEngineChannel); |
59 |
|
|
60 |
|
// reconnect engine if it still exists |
61 |
|
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
62 |
|
if (engines.find(engine) != engines.end()) pAudioOutputDevice->Connect(engine); |
63 |
} |
} |
64 |
} |
} |
65 |
} |
} |
78 |
MidiInputPort* pMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort()); |
MidiInputPort* pMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort()); |
79 |
// disconnect old engine channel |
// disconnect old engine channel |
80 |
if (pEngineChannel) { |
if (pEngineChannel) { |
81 |
|
Engine* engine = pEngineChannel->GetEngine(); |
82 |
|
if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(engine); |
83 |
|
|
84 |
if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel); |
if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel); |
85 |
if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice(); |
if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice(); |
86 |
EngineChannelFactory::Destroy(pEngineChannel); |
EngineChannelFactory::Destroy(pEngineChannel); |
87 |
|
|
88 |
|
// reconnect engine if it still exists |
89 |
|
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
90 |
|
if (engines.find(engine) != engines.end()) pAudioOutputDevice->Connect(engine); |
91 |
} |
} |
92 |
|
|
93 |
// connect new engine channel |
// connect new engine channel |
|
if (pMidiInputPort) pMidiInputPort->Connect(pNewEngineChannel, GetMidiInputChannel()); |
|
94 |
if (pAudioOutputDevice) { |
if (pAudioOutputDevice) { |
95 |
pNewEngineChannel->Connect(pAudioOutputDevice); |
pNewEngineChannel->Connect(pAudioOutputDevice); |
96 |
pAudioOutputDevice->Connect(pNewEngineChannel->GetEngine()); |
pAudioOutputDevice->Connect(pNewEngineChannel->GetEngine()); |
97 |
} |
} |
98 |
|
if (pMidiInputPort) pMidiInputPort->Connect(pNewEngineChannel, GetMidiInputChannel()); |
99 |
pEngineChannel = pNewEngineChannel; |
pEngineChannel = pNewEngineChannel; |
100 |
|
|
101 |
// from now on get MIDI device and port from EngineChannel object |
// from now on get MIDI device and port from EngineChannel object |
102 |
this->pMidiInputDevice = NULL; |
this->pMidiInputDevice = NULL; |
103 |
this->iMidiPort = 0; |
this->iMidiPort = 0; |
104 |
|
|
105 |
|
pEngineChannel->StatusChanged(true); |
106 |
|
|
107 |
dmsg(2,("OK\n")); |
dmsg(2,("OK\n")); |
108 |
} |
} |
109 |
|
|
110 |
void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) { |
void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) { |
111 |
// disconnect old device |
// disconnect old device |
112 |
if (pAudioOutputDevice && pEngineChannel) pEngineChannel->DisconnectAudioOutputDevice(); |
if (pAudioOutputDevice && pEngineChannel) { |
113 |
|
Engine* engine = pEngineChannel->GetEngine(); |
114 |
|
pAudioOutputDevice->Disconnect(engine); |
115 |
|
|
116 |
|
pEngineChannel->DisconnectAudioOutputDevice(); |
117 |
|
|
118 |
|
// reconnect engine if it still exists |
119 |
|
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
120 |
|
if (engines.find(engine) != engines.end()) pAudioOutputDevice->Connect(engine); |
121 |
|
} |
122 |
|
|
123 |
// connect new device |
// connect new device |
124 |
pAudioOutputDevice = pDevice; |
pAudioOutputDevice = pDevice; |
125 |
if (pEngineChannel) { |
if (pEngineChannel) { |
336 |
|
|
337 |
// destroy and free device from memory |
// destroy and free device from memory |
338 |
delete pDevice; |
delete pDevice; |
339 |
|
|
340 |
|
break; |
341 |
} |
} |
342 |
} |
} |
343 |
} |
} |
358 |
|
|
359 |
// destroy and free device from memory |
// destroy and free device from memory |
360 |
delete pDevice; |
delete pDevice; |
361 |
|
|
362 |
|
break; |
363 |
} |
} |
364 |
} |
} |
365 |
} |
} |
379 |
return pDevice; |
return pDevice; |
380 |
} |
} |
381 |
|
|
382 |
|
int Sampler::GetVoiceCount() { |
383 |
|
int count = 0; |
384 |
|
std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin(); |
385 |
|
|
386 |
|
for(; it != EngineFactory::EngineInstances().end(); it++) { |
387 |
|
count += (*it)->VoiceCount(); |
388 |
|
} |
389 |
|
|
390 |
|
return count; |
391 |
|
} |
392 |
|
|
393 |
void Sampler::Reset() { |
void Sampler::Reset() { |
394 |
// delete sampler channels |
// delete sampler channels |
395 |
try { |
try { |