51 |
if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel); |
if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel); |
52 |
if (pEngineChannel) { |
if (pEngineChannel) { |
53 |
if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice(); |
if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice(); |
54 |
delete pEngineChannel; |
EngineChannelFactory::Destroy(pEngineChannel); |
55 |
} |
} |
56 |
} |
} |
57 |
} |
} |
63 |
EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType); |
EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType); |
64 |
if (!pNewEngineChannel) throw LinuxSamplerException("Unknown engine type"); |
if (!pNewEngineChannel) throw LinuxSamplerException("Unknown engine type"); |
65 |
|
|
66 |
|
//FIXME: hack to allow fast retrieval of engine channel's sampler channel index |
67 |
|
pNewEngineChannel->iSamplerChannelIndex = Index(); |
68 |
|
|
69 |
// dereference midi input port. |
// dereference midi input port. |
70 |
MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort); |
MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort); |
71 |
// disconnect old engine |
// disconnect old engine |
72 |
if (pEngineChannel) { |
if (pEngineChannel) { |
73 |
if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel); |
if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel); |
74 |
if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice(); |
if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice(); |
75 |
delete pEngineChannel; |
EngineChannelFactory::Destroy(pEngineChannel); |
76 |
} |
} |
77 |
|
|
78 |
// connect new engine channel |
// connect new engine channel |
188 |
if (!mSamplerChannels.size()) { |
if (!mSamplerChannels.size()) { |
189 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
190 |
mSamplerChannels[0] = pChannel; |
mSamplerChannels[0] = pChannel; |
191 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, 1)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, 1)); |
192 |
return pChannel; |
return pChannel; |
193 |
} |
} |
194 |
|
|
203 |
// we found an unused index, so insert the new channel there |
// we found an unused index, so insert the new channel there |
204 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
205 |
mSamplerChannels[i] = pChannel; |
mSamplerChannels[i] = pChannel; |
206 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, i)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i)); |
207 |
return pChannel; |
return pChannel; |
208 |
} |
} |
209 |
throw LinuxSamplerException("Internal error: could not find unoccupied sampler channel index."); |
throw LinuxSamplerException("Internal error: could not find unoccupied sampler channel index."); |
212 |
// 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 |
213 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
214 |
mSamplerChannels[lastIndex + 1] = pChannel; |
mSamplerChannels[lastIndex + 1] = pChannel; |
215 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, lastIndex + 1)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, lastIndex + 1)); |
216 |
return pChannel; |
return pChannel; |
217 |
} |
} |
218 |
|
|
230 |
if (iterChan->second == pSamplerChannel) { |
if (iterChan->second == pSamplerChannel) { |
231 |
mSamplerChannels.erase(iterChan); |
mSamplerChannels.erase(iterChan); |
232 |
delete pSamplerChannel; |
delete pSamplerChannel; |
233 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, mSamplerChannels.size())); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, mSamplerChannels.size())); |
234 |
return; |
return; |
235 |
} |
} |
236 |
} |
} |
319 |
|
|
320 |
MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) { |
MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) { |
321 |
// create new device |
// create new device |
322 |
MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters); |
MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this); |
323 |
|
|
324 |
// add new device to the midi device list |
// add new device to the midi device list |
325 |
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 |