30 |
#include "drivers/audio/AudioOutputDeviceFactory.h" |
#include "drivers/audio/AudioOutputDeviceFactory.h" |
31 |
#include "drivers/midi/MidiInputDeviceFactory.h" |
#include "drivers/midi/MidiInputDeviceFactory.h" |
32 |
#include "drivers/midi/MidiInstrumentMapper.h" |
#include "drivers/midi/MidiInstrumentMapper.h" |
|
#include "network/lscpserver.h" |
|
33 |
|
|
34 |
namespace LinuxSampler { |
namespace LinuxSampler { |
35 |
|
|
103 |
this->iMidiPort = 0; |
this->iMidiPort = 0; |
104 |
|
|
105 |
pEngineChannel->StatusChanged(true); |
pEngineChannel->StatusChanged(true); |
106 |
|
fireEngineChanged(); |
107 |
dmsg(2,("OK\n")); |
dmsg(2,("OK\n")); |
108 |
} |
} |
109 |
|
|
204 |
throw Exception("Internal error: SamplerChannel index not found"); |
throw Exception("Internal error: SamplerChannel index not found"); |
205 |
} |
} |
206 |
|
|
207 |
|
void SamplerChannel::AddEngineChangeListener(EngineChangeListener* l) { |
208 |
|
llEngineChangeListeners.AddListener(l); |
209 |
|
} |
210 |
|
|
211 |
|
void SamplerChannel::RemoveEngineChangeListener(EngineChangeListener* l) { |
212 |
|
llEngineChangeListeners.RemoveListener(l); |
213 |
|
} |
214 |
|
|
215 |
|
void SamplerChannel::RemoveAllEngineChangeListeners() { |
216 |
|
llEngineChangeListeners.RemoveAllListeners(); |
217 |
|
} |
218 |
|
|
219 |
|
void SamplerChannel::fireEngineChanged() { |
220 |
|
for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) { |
221 |
|
llEngineChangeListeners.GetListener(i)->EngineChanged(Index()); |
222 |
|
} |
223 |
|
} |
224 |
|
|
225 |
MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) { |
MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) { |
226 |
MidiInputPort* pMidiInputPort = NULL; |
MidiInputPort* pMidiInputPort = NULL; |
227 |
MidiInputDevice* pMidiInputDevice = GetMidiInputDevice(); |
MidiInputDevice* pMidiInputDevice = GetMidiInputDevice(); |
236 |
// * Sampler |
// * Sampler |
237 |
|
|
238 |
Sampler::Sampler() { |
Sampler::Sampler() { |
239 |
|
eventHandler.SetSampler(this); |
240 |
} |
} |
241 |
|
|
242 |
Sampler::~Sampler() { |
Sampler::~Sampler() { |
247 |
return mSamplerChannels.size(); |
return mSamplerChannels.size(); |
248 |
} |
} |
249 |
|
|
250 |
|
void Sampler::AddChannelCountListener(ChannelCountListener* l) { |
251 |
|
llChannelCountListeners.AddListener(l); |
252 |
|
} |
253 |
|
|
254 |
|
void Sampler::RemoveChannelCountListener(ChannelCountListener* l) { |
255 |
|
llChannelCountListeners.RemoveListener(l); |
256 |
|
} |
257 |
|
|
258 |
|
void Sampler::fireChannelCountChanged(int NewCount) { |
259 |
|
for (int i = 0; i < llChannelCountListeners.GetListenerCount(); i++) { |
260 |
|
llChannelCountListeners.GetListener(i)->ChannelCountChanged(NewCount); |
261 |
|
} |
262 |
|
} |
263 |
|
|
264 |
|
void Sampler::AddAudioDeviceCountListener(AudioDeviceCountListener* l) { |
265 |
|
llAudioDeviceCountListeners.AddListener(l); |
266 |
|
} |
267 |
|
|
268 |
|
void Sampler::RemoveAudioDeviceCountListener(AudioDeviceCountListener* l) { |
269 |
|
llAudioDeviceCountListeners.RemoveListener(l); |
270 |
|
} |
271 |
|
|
272 |
|
void Sampler::fireAudioDeviceCountChanged(int NewCount) { |
273 |
|
for (int i = 0; i < llAudioDeviceCountListeners.GetListenerCount(); i++) { |
274 |
|
llAudioDeviceCountListeners.GetListener(i)->AudioDeviceCountChanged(NewCount); |
275 |
|
} |
276 |
|
} |
277 |
|
|
278 |
|
void Sampler::AddMidiDeviceCountListener(MidiDeviceCountListener* l) { |
279 |
|
llMidiDeviceCountListeners.AddListener(l); |
280 |
|
} |
281 |
|
|
282 |
|
void Sampler::RemoveMidiDeviceCountListener(MidiDeviceCountListener* l) { |
283 |
|
llMidiDeviceCountListeners.RemoveListener(l); |
284 |
|
} |
285 |
|
|
286 |
|
void Sampler::fireMidiDeviceCountChanged(int NewCount) { |
287 |
|
for (int i = 0; i < llMidiDeviceCountListeners.GetListenerCount(); i++) { |
288 |
|
llMidiDeviceCountListeners.GetListener(i)->MidiDeviceCountChanged(NewCount); |
289 |
|
} |
290 |
|
} |
291 |
|
|
292 |
|
void Sampler::AddVoiceCountListener(VoiceCountListener* l) { |
293 |
|
llVoiceCountListeners.AddListener(l); |
294 |
|
} |
295 |
|
|
296 |
|
void Sampler::RemoveVoiceCountListener(VoiceCountListener* l) { |
297 |
|
llVoiceCountListeners.RemoveListener(l); |
298 |
|
} |
299 |
|
|
300 |
|
void Sampler::fireVoiceCountChanged(int ChannelId, int NewCount) { |
301 |
|
for (int i = 0; i < llVoiceCountListeners.GetListenerCount(); i++) { |
302 |
|
llVoiceCountListeners.GetListener(i)->VoiceCountChanged(ChannelId, NewCount); |
303 |
|
} |
304 |
|
} |
305 |
|
|
306 |
|
void Sampler::AddStreamCountListener(StreamCountListener* l) { |
307 |
|
llStreamCountListeners.AddListener(l); |
308 |
|
} |
309 |
|
|
310 |
|
void Sampler::RemoveStreamCountListener(StreamCountListener* l) { |
311 |
|
llStreamCountListeners.RemoveListener(l); |
312 |
|
} |
313 |
|
|
314 |
|
void Sampler::fireStreamCountChanged(int ChannelId, int NewCount) { |
315 |
|
for (int i = 0; i < llStreamCountListeners.GetListenerCount(); i++) { |
316 |
|
llStreamCountListeners.GetListener(i)->StreamCountChanged(ChannelId, NewCount); |
317 |
|
} |
318 |
|
} |
319 |
|
|
320 |
|
void Sampler::AddBufferFillListener(BufferFillListener* l) { |
321 |
|
llBufferFillListeners.AddListener(l); |
322 |
|
} |
323 |
|
|
324 |
|
void Sampler::RemoveBufferFillListener(BufferFillListener* l) { |
325 |
|
llBufferFillListeners.RemoveListener(l); |
326 |
|
} |
327 |
|
|
328 |
|
void Sampler::fireBufferFillChanged(int ChannelId, String FillData) { |
329 |
|
for (int i = 0; i < llBufferFillListeners.GetListenerCount(); i++) { |
330 |
|
llBufferFillListeners.GetListener(i)->BufferFillChanged(ChannelId, FillData); |
331 |
|
} |
332 |
|
} |
333 |
|
|
334 |
|
void Sampler::AddTotalVoiceCountListener(TotalVoiceCountListener* l) { |
335 |
|
llTotalVoiceCountListeners.AddListener(l); |
336 |
|
} |
337 |
|
|
338 |
|
void Sampler::RemoveTotalVoiceCountListener(TotalVoiceCountListener* l) { |
339 |
|
llTotalVoiceCountListeners.RemoveListener(l); |
340 |
|
} |
341 |
|
|
342 |
|
void Sampler::fireTotalVoiceCountChanged(int NewCount) { |
343 |
|
for (int i = 0; i < llTotalVoiceCountListeners.GetListenerCount(); i++) { |
344 |
|
llTotalVoiceCountListeners.GetListener(i)->TotalVoiceCountChanged(NewCount); |
345 |
|
} |
346 |
|
} |
347 |
|
|
348 |
|
void Sampler::AddFxSendCountListener(FxSendCountListener* l) { |
349 |
|
llFxSendCountListeners.AddListener(l); |
350 |
|
} |
351 |
|
|
352 |
|
void Sampler::RemoveFxSendCountListener(FxSendCountListener* l) { |
353 |
|
llFxSendCountListeners.RemoveListener(l); |
354 |
|
} |
355 |
|
|
356 |
|
void Sampler::fireFxSendCountChanged(int ChannelId, int NewCount) { |
357 |
|
for (int i = 0; i < llFxSendCountListeners.GetListenerCount(); i++) { |
358 |
|
llFxSendCountListeners.GetListener(i)->FxSendCountChanged(ChannelId, NewCount); |
359 |
|
} |
360 |
|
} |
361 |
|
|
362 |
|
void Sampler::EventHandler::EngineChanged(int ChannelId) { |
363 |
|
EngineChannel* engineChannel = pSampler->GetSamplerChannel(ChannelId)->GetEngineChannel(); |
364 |
|
if(engineChannel == NULL) return; |
365 |
|
engineChannel->AddFxSendCountListener(this); |
366 |
|
} |
367 |
|
|
368 |
|
void Sampler::EventHandler::FxSendCountChanged(int ChannelId, int NewCount) { |
369 |
|
pSampler->fireFxSendCountChanged(ChannelId, NewCount); |
370 |
|
} |
371 |
|
|
372 |
|
|
373 |
SamplerChannel* Sampler::AddSamplerChannel() { |
SamplerChannel* Sampler::AddSamplerChannel() { |
374 |
// if there's no sampler channel yet |
// if there's no sampler channel yet |
375 |
if (!mSamplerChannels.size()) { |
if (!mSamplerChannels.size()) { |
376 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
377 |
mSamplerChannels[0] = pChannel; |
mSamplerChannels[0] = pChannel; |
378 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, 1)); |
fireChannelCountChanged(1); |
379 |
|
pChannel->AddEngineChangeListener(&eventHandler); |
380 |
return pChannel; |
return pChannel; |
381 |
} |
} |
382 |
|
|
391 |
// we found an unused index, so insert the new channel there |
// we found an unused index, so insert the new channel there |
392 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
393 |
mSamplerChannels[i] = pChannel; |
mSamplerChannels[i] = pChannel; |
394 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i)); |
fireChannelCountChanged(SamplerChannels()); |
395 |
|
pChannel->AddEngineChangeListener(&eventHandler); |
396 |
return pChannel; |
return pChannel; |
397 |
} |
} |
398 |
throw Exception("Internal error: could not find unoccupied sampler channel index."); |
throw Exception("Internal error: could not find unoccupied sampler channel index."); |
401 |
// 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 |
402 |
SamplerChannel* pChannel = new SamplerChannel(this); |
SamplerChannel* pChannel = new SamplerChannel(this); |
403 |
mSamplerChannels[lastIndex + 1] = pChannel; |
mSamplerChannels[lastIndex + 1] = pChannel; |
404 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, lastIndex + 1)); |
fireChannelCountChanged(SamplerChannels()); |
405 |
|
pChannel->AddEngineChangeListener(&eventHandler); |
406 |
return pChannel; |
return pChannel; |
407 |
} |
} |
408 |
|
|
418 |
SamplerChannelMap::iterator iterChan = mSamplerChannels.begin(); |
SamplerChannelMap::iterator iterChan = mSamplerChannels.begin(); |
419 |
for (; iterChan != mSamplerChannels.end(); iterChan++) { |
for (; iterChan != mSamplerChannels.end(); iterChan++) { |
420 |
if (iterChan->second == pSamplerChannel) { |
if (iterChan->second == pSamplerChannel) { |
421 |
|
pSamplerChannel->RemoveAllEngineChangeListeners(); |
422 |
mSamplerChannels.erase(iterChan); |
mSamplerChannels.erase(iterChan); |
423 |
delete pSamplerChannel; |
delete pSamplerChannel; |
424 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, mSamplerChannels.size())); |
fireChannelCountChanged(SamplerChannels()); |
425 |
return; |
return; |
426 |
} |
} |
427 |
} |
} |
457 |
} |
} |
458 |
} |
} |
459 |
|
|
460 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, AudioOutputDevices())); |
fireAudioDeviceCountChanged(AudioOutputDevices()); |
461 |
return pDevice; |
return pDevice; |
462 |
} |
} |
463 |
|
|
494 |
// destroy and free device from memory |
// destroy and free device from memory |
495 |
delete pDevice; |
delete pDevice; |
496 |
|
|
497 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, AudioOutputDevices())); |
fireAudioDeviceCountChanged(AudioOutputDevices()); |
498 |
break; |
break; |
499 |
} |
} |
500 |
} |
} |
517 |
// destroy and free device from memory |
// destroy and free device from memory |
518 |
delete pDevice; |
delete pDevice; |
519 |
|
|
520 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, MidiInputDevices())); |
fireMidiDeviceCountChanged(MidiInputDevices()); |
521 |
break; |
break; |
522 |
} |
} |
523 |
} |
} |
535 |
} |
} |
536 |
} |
} |
537 |
|
|
538 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, MidiInputDevices())); |
fireMidiDeviceCountChanged(MidiInputDevices()); |
539 |
return pDevice; |
return pDevice; |
540 |
} |
} |
541 |
|
|