49 |
if (pEngineChannel) { |
if (pEngineChannel) { |
50 |
MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort); |
MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort); |
51 |
if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel); |
if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel); |
52 |
if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(pEngineChannel); |
if (pEngineChannel) { |
53 |
delete pEngineChannel; |
if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice(); |
54 |
|
delete pEngineChannel; |
55 |
|
} |
56 |
} |
} |
57 |
} |
} |
58 |
|
|
68 |
// disconnect old engine |
// disconnect old engine |
69 |
if (pEngineChannel) { |
if (pEngineChannel) { |
70 |
if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel); |
if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel); |
71 |
if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(pEngineChannel); |
if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice(); |
72 |
delete pEngineChannel; |
delete pEngineChannel; |
73 |
} |
} |
74 |
|
|
75 |
// connect new engine channel |
// connect new engine channel |
76 |
pEngineChannel = pNewEngineChannel; |
pEngineChannel = pNewEngineChannel; |
77 |
if (pMidiInputPort) pMidiInputPort->Connect(pNewEngineChannel, this->midiChannel); |
if (pMidiInputPort) pMidiInputPort->Connect(pNewEngineChannel, this->midiChannel); |
78 |
if (pAudioOutputDevice) pAudioOutputDevice->Connect(pNewEngineChannel); |
if (pAudioOutputDevice) { |
79 |
|
pNewEngineChannel->Connect(pAudioOutputDevice); |
80 |
|
pAudioOutputDevice->Connect(pNewEngineChannel->GetEngine()); |
81 |
|
} |
82 |
dmsg(2,("OK\n")); |
dmsg(2,("OK\n")); |
83 |
} |
} |
84 |
|
|
85 |
void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) { |
void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) { |
86 |
// disconnect old device |
// disconnect old device |
87 |
if (pAudioOutputDevice && pEngineChannel) pAudioOutputDevice->Disconnect(pEngineChannel); |
if (pAudioOutputDevice && pEngineChannel) pEngineChannel->DisconnectAudioOutputDevice(); |
88 |
// connect new device |
// connect new device |
89 |
pAudioOutputDevice = pDevice; |
pAudioOutputDevice = pDevice; |
90 |
if (pEngineChannel) pAudioOutputDevice->Connect(pEngineChannel); |
if (pEngineChannel) { |
91 |
|
pEngineChannel->Connect(pAudioOutputDevice); |
92 |
|
pAudioOutputDevice->Connect(pEngineChannel->GetEngine()); |
93 |
|
} |
94 |
} |
} |
95 |
|
|
96 |
void SamplerChannel::SetMidiInputDevice(MidiInputDevice* pDevice) { |
void SamplerChannel::SetMidiInputDevice(MidiInputDevice* pDevice) { |
185 |
if (!mSamplerChannels.size()) { |
if (!mSamplerChannels.size()) { |
186 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
187 |
mSamplerChannels[0] = pChannel; |
mSamplerChannels[0] = pChannel; |
188 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, 1)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, 1)); |
189 |
return pChannel; |
return pChannel; |
190 |
} |
} |
191 |
|
|
200 |
// we found an unused index, so insert the new channel there |
// we found an unused index, so insert the new channel there |
201 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
202 |
mSamplerChannels[i] = pChannel; |
mSamplerChannels[i] = pChannel; |
203 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, i)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i)); |
204 |
return pChannel; |
return pChannel; |
205 |
} |
} |
206 |
throw LinuxSamplerException("Internal error: could not find unoccupied sampler channel index."); |
throw LinuxSamplerException("Internal error: could not find unoccupied sampler channel index."); |
209 |
// 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 |
210 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
211 |
mSamplerChannels[lastIndex + 1] = pChannel; |
mSamplerChannels[lastIndex + 1] = pChannel; |
212 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, lastIndex + 1)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, lastIndex + 1)); |
213 |
return pChannel; |
return pChannel; |
214 |
} |
} |
215 |
|
|
227 |
if (iterChan->second == pSamplerChannel) { |
if (iterChan->second == pSamplerChannel) { |
228 |
mSamplerChannels.erase(iterChan); |
mSamplerChannels.erase(iterChan); |
229 |
delete pSamplerChannel; |
delete pSamplerChannel; |
230 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, mSamplerChannels.size())); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, mSamplerChannels.size())); |
231 |
return; |
return; |
232 |
} |
} |
233 |
} |
} |
316 |
|
|
317 |
MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) { |
MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) { |
318 |
// create new device |
// create new device |
319 |
MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters); |
MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this); |
320 |
|
|
321 |
// add new device to the midi device list |
// add new device to the midi device list |
322 |
for (uint i = 0; ; i++) { // seek for a free place starting from the beginning |
for (uint i = 0; ; i++) { // seek for a free place starting from the beginning |