2 |
* * |
* * |
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, 2006 Christian Schoenebeck * |
* Copyright (C) 2005-2007 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program 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 * |
51 |
if (engines.count(pDevice)) { |
if (engines.count(pDevice)) { |
52 |
dmsg(4,("Using existing gig::Engine.\n")); |
dmsg(4,("Using existing gig::Engine.\n")); |
53 |
pEngine = engines[pDevice]; |
pEngine = engines[pDevice]; |
54 |
|
|
55 |
|
// Disable the engine while the new engine channel is |
56 |
|
// added and initialized. The engine will be enabled again |
57 |
|
// in EngineChannel::Connect. |
58 |
|
pEngine->DisableAndLock(); |
59 |
} else { // create a new engine (and disk thread) instance for the given audio output device |
} else { // create a new engine (and disk thread) instance for the given audio output device |
60 |
dmsg(4,("Creating new gig::Engine.\n")); |
dmsg(4,("Creating new gig::Engine.\n")); |
61 |
pEngine = (Engine*) EngineFactory::Create("gig"); |
pEngine = (Engine*) EngineFactory::Create("gig"); |
102 |
pAudioOutputDevice = NULL; |
pAudioOutputDevice = NULL; |
103 |
pDiskThread = NULL; |
pDiskThread = NULL; |
104 |
pEventGenerator = NULL; |
pEventGenerator = NULL; |
105 |
pSysexBuffer = new RingBuffer<uint8_t>(CONFIG_SYSEX_BUFFER_SIZE, 0); |
pSysexBuffer = new RingBuffer<uint8_t,false>(CONFIG_SYSEX_BUFFER_SIZE, 0); |
106 |
pEventQueue = new RingBuffer<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0); |
pEventQueue = new RingBuffer<Event,false>(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0); |
107 |
pEventPool = new Pool<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT); |
pEventPool = new Pool<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT); |
108 |
pVoicePool = new Pool<Voice>(CONFIG_MAX_VOICES); |
pVoicePool = new Pool<Voice>(CONFIG_MAX_VOICES); |
109 |
|
pDimRegionsInUse = new ::gig::DimensionRegion*[CONFIG_MAX_VOICES + 1]; |
110 |
pVoiceStealingQueue = new RTList<Event>(pEventPool); |
pVoiceStealingQueue = new RTList<Event>(pEventPool); |
111 |
pGlobalEvents = new RTList<Event>(pEventPool); |
pGlobalEvents = new RTList<Event>(pEventPool); |
112 |
|
InstrumentChangeQueue = new RingBuffer<instrument_change_command_t,false>(1, 0); |
113 |
|
InstrumentChangeReplyQueue = new RingBuffer<instrument_change_reply_t,false>(1, 0); |
114 |
|
|
115 |
for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) { |
for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) { |
116 |
iterVoice->SetEngine(this); |
iterVoice->SetEngine(this); |
117 |
} |
} |
141 |
if (pEventGenerator) delete pEventGenerator; |
if (pEventGenerator) delete pEventGenerator; |
142 |
if (pVoiceStealingQueue) delete pVoiceStealingQueue; |
if (pVoiceStealingQueue) delete pVoiceStealingQueue; |
143 |
if (pSysexBuffer) delete pSysexBuffer; |
if (pSysexBuffer) delete pSysexBuffer; |
144 |
EngineFactory::Destroy(this); |
if (pGlobalEvents) delete pGlobalEvents; |
145 |
|
if (InstrumentChangeQueue) delete InstrumentChangeQueue; |
146 |
|
if (InstrumentChangeReplyQueue) delete InstrumentChangeReplyQueue; |
147 |
|
if (pDimRegionsInUse) delete[] pDimRegionsInUse; |
148 |
|
Unregister(); |
149 |
} |
} |
150 |
|
|
151 |
void Engine::Enable() { |
void Engine::Enable() { |
270 |
delete this->pDiskThread; |
delete this->pDiskThread; |
271 |
dmsg(1,("OK\n")); |
dmsg(1,("OK\n")); |
272 |
} |
} |
273 |
this->pDiskThread = new DiskThread(((pAudioOut->MaxSamplesPerCycle() << CONFIG_MAX_PITCH) << 1) + 6); //FIXME: assuming stereo |
this->pDiskThread = new DiskThread(((pAudioOut->MaxSamplesPerCycle() << CONFIG_MAX_PITCH) << 1) + 6, //FIXME: assuming stereo |
274 |
|
&instruments); |
275 |
if (!pDiskThread) { |
if (!pDiskThread) { |
276 |
dmsg(0,("gig::Engine new diskthread = NULL\n")); |
dmsg(0,("gig::Engine new diskthread = NULL\n")); |
277 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
320 |
* current audio cycle |
* current audio cycle |
321 |
*/ |
*/ |
322 |
void Engine::ImportEvents(uint Samples) { |
void Engine::ImportEvents(uint Samples) { |
323 |
RingBuffer<Event>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader(); |
RingBuffer<Event,false>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader(); |
324 |
Event* pEvent; |
Event* pEvent; |
325 |
while (true) { |
while (true) { |
326 |
// get next event from input event queue |
// get next event from input event queue |
354 |
* @returns 0 on success |
* @returns 0 on success |
355 |
*/ |
*/ |
356 |
int Engine::RenderAudio(uint Samples) { |
int Engine::RenderAudio(uint Samples) { |
357 |
dmsg(5,("RenderAudio(Samples=%d)\n", Samples)); |
dmsg(7,("RenderAudio(Samples=%d)\n", Samples)); |
358 |
|
|
359 |
// return if engine disabled |
// return if engine disabled |
360 |
if (EngineDisabled.Pop()) { |
if (EngineDisabled.Pop()) { |
391 |
// reset internal voice counter (just for statistic of active voices) |
// reset internal voice counter (just for statistic of active voices) |
392 |
ActiveVoiceCountTemp = 0; |
ActiveVoiceCountTemp = 0; |
393 |
|
|
394 |
|
// handle instrument change commands |
395 |
|
instrument_change_command_t command; |
396 |
|
if (InstrumentChangeQueue->pop(&command) > 0) { |
397 |
|
EngineChannel* pEngineChannel = command.pEngineChannel; |
398 |
|
pEngineChannel->pInstrument = command.pInstrument; |
399 |
|
|
400 |
|
// iterate through all active voices and mark their |
401 |
|
// dimension regions as "in use". The instrument resource |
402 |
|
// manager may delete all of the instrument except the |
403 |
|
// dimension regions and samples that are in use. |
404 |
|
int i = 0; |
405 |
|
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
406 |
|
RTList<uint>::Iterator end = pEngineChannel->pActiveKeys->end(); |
407 |
|
while (iuiKey != end) { // iterate through all active keys |
408 |
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey]; |
409 |
|
++iuiKey; |
410 |
|
|
411 |
|
RTList<Voice>::Iterator itVoice = pKey->pActiveVoices->first(); |
412 |
|
RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end(); |
413 |
|
for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key |
414 |
|
if (!itVoice->Orphan) { |
415 |
|
itVoice->Orphan = true; |
416 |
|
pDimRegionsInUse[i++] = itVoice->pDimRgn; |
417 |
|
} |
418 |
|
} |
419 |
|
} |
420 |
|
pDimRegionsInUse[i] = 0; // end of list |
421 |
|
|
422 |
|
// send a reply to the calling thread, which is waiting |
423 |
|
instrument_change_reply_t reply; |
424 |
|
InstrumentChangeReplyQueue->push(&reply); |
425 |
|
} |
426 |
|
|
427 |
// handle events on all engine channels |
// handle events on all engine channels |
428 |
for (int i = 0; i < engineChannels.size(); i++) { |
for (int i = 0; i < engineChannels.size(); i++) { |
|
if (!engineChannels[i]->pInstrument) continue; // ignore if no instrument loaded |
|
429 |
ProcessEvents(engineChannels[i], Samples); |
ProcessEvents(engineChannels[i], Samples); |
430 |
} |
} |
431 |
|
|
432 |
// render all 'normal', active voices on all engine channels |
// render all 'normal', active voices on all engine channels |
433 |
for (int i = 0; i < engineChannels.size(); i++) { |
for (int i = 0; i < engineChannels.size(); i++) { |
|
if (!engineChannels[i]->pInstrument) continue; // ignore if no instrument loaded |
|
434 |
RenderActiveVoices(engineChannels[i], Samples); |
RenderActiveVoices(engineChannels[i], Samples); |
435 |
} |
} |
436 |
|
|
437 |
// now that all ordinary voices on ALL engine channels are rendered, render new stolen voices |
// now that all ordinary voices on ALL engine channels are rendered, render new stolen voices |
438 |
RenderStolenVoices(Samples); |
RenderStolenVoices(Samples); |
439 |
|
|
440 |
|
// handle audio routing for engine channels with FX sends |
441 |
|
for (int i = 0; i < engineChannels.size(); i++) { |
442 |
|
if (engineChannels[i]->fxSends.empty()) continue; // ignore if no FX sends |
443 |
|
RouteAudio(engineChannels[i], Samples); |
444 |
|
} |
445 |
|
|
446 |
// handle cleanup on all engine channels for the next audio fragment |
// handle cleanup on all engine channels for the next audio fragment |
447 |
for (int i = 0; i < engineChannels.size(); i++) { |
for (int i = 0; i < engineChannels.size(); i++) { |
|
if (!engineChannels[i]->pInstrument) continue; // ignore if no instrument loaded |
|
448 |
PostProcess(engineChannels[i]); |
PostProcess(engineChannels[i]); |
449 |
} |
} |
450 |
|
|
526 |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
527 |
#endif |
#endif |
528 |
|
|
529 |
|
uint voiceCount = 0; |
530 |
|
uint streamCount = 0; |
531 |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
532 |
RTList<uint>::Iterator end = pEngineChannel->pActiveKeys->end(); |
RTList<uint>::Iterator end = pEngineChannel->pActiveKeys->end(); |
533 |
while (iuiKey != end) { // iterate through all active keys |
while (iuiKey != end) { // iterate through all active keys |
539 |
for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key |
for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key |
540 |
// now render current voice |
// now render current voice |
541 |
itVoice->Render(Samples); |
itVoice->Render(Samples); |
542 |
if (itVoice->IsActive()) ActiveVoiceCountTemp++; // still active |
if (itVoice->IsActive()) { // still active |
543 |
else { // voice reached end, is now inactive |
ActiveVoiceCountTemp++; |
544 |
|
voiceCount++; |
545 |
|
|
546 |
|
if (itVoice->PlaybackState == Voice::playback_state_disk) { |
547 |
|
if ((itVoice->DiskStreamRef).State == Stream::state_active) streamCount++; |
548 |
|
} |
549 |
|
} else { // voice reached end, is now inactive |
550 |
FreeVoice(pEngineChannel, itVoice); // remove voice from the list of active voices |
FreeVoice(pEngineChannel, itVoice); // remove voice from the list of active voices |
551 |
} |
} |
552 |
} |
} |
553 |
} |
} |
554 |
|
|
555 |
|
pEngineChannel->SetVoiceCount(voiceCount); |
556 |
|
pEngineChannel->SetDiskStreamCount(streamCount); |
557 |
} |
} |
558 |
|
|
559 |
/** |
/** |
574 |
RTList<Event>::Iterator end = pVoiceStealingQueue->end(); |
RTList<Event>::Iterator end = pVoiceStealingQueue->end(); |
575 |
for (; itVoiceStealEvent != end; ++itVoiceStealEvent) { |
for (; itVoiceStealEvent != end; ++itVoiceStealEvent) { |
576 |
EngineChannel* pEngineChannel = (EngineChannel*) itVoiceStealEvent->pEngineChannel; |
EngineChannel* pEngineChannel = (EngineChannel*) itVoiceStealEvent->pEngineChannel; |
577 |
|
if (!pEngineChannel->pInstrument) continue; // ignore if no instrument loaded |
578 |
Pool<Voice>::Iterator itNewVoice = |
Pool<Voice>::Iterator itNewVoice = |
579 |
LaunchVoice(pEngineChannel, itVoiceStealEvent, itVoiceStealEvent->Param.Note.Layer, itVoiceStealEvent->Param.Note.ReleaseTrigger, false, false); |
LaunchVoice(pEngineChannel, itVoiceStealEvent, itVoiceStealEvent->Param.Note.Layer, itVoiceStealEvent->Param.Note.ReleaseTrigger, false, false); |
580 |
if (itNewVoice) { |
if (itNewVoice) { |
581 |
itNewVoice->Render(Samples); |
itNewVoice->Render(Samples); |
582 |
if (itNewVoice->IsActive()) ActiveVoiceCountTemp++; // still active |
if (itNewVoice->IsActive()) { // still active |
583 |
else { // voice reached end, is now inactive |
ActiveVoiceCountTemp++; |
584 |
|
pEngineChannel->SetVoiceCount(pEngineChannel->GetVoiceCount() + 1); |
585 |
|
|
586 |
|
if (itNewVoice->PlaybackState == Voice::playback_state_disk) { |
587 |
|
if (itNewVoice->DiskStreamRef.State == Stream::state_active) { |
588 |
|
pEngineChannel->SetDiskStreamCount(pEngineChannel->GetDiskStreamCount() + 1); |
589 |
|
} |
590 |
|
} |
591 |
|
} else { // voice reached end, is now inactive |
592 |
FreeVoice(pEngineChannel, itNewVoice); // remove voice from the list of active voices |
FreeVoice(pEngineChannel, itNewVoice); // remove voice from the list of active voices |
593 |
} |
} |
594 |
} |
} |
602 |
} |
} |
603 |
|
|
604 |
/** |
/** |
605 |
|
* Will be called in case the respective engine channel sports FX send |
606 |
|
* channels. In this particular case, engine channel local buffers are |
607 |
|
* used to render and mix all voices to. This method is responsible for |
608 |
|
* copying the audio data from those local buffers to the master audio |
609 |
|
* output channels as well as to the FX send audio output channels with |
610 |
|
* their respective FX send levels. |
611 |
|
* |
612 |
|
* @param pEngineChannel - engine channel from which audio should be |
613 |
|
* routed |
614 |
|
* @param Samples - amount of sample points to be routed in |
615 |
|
* this audio fragment cycle |
616 |
|
*/ |
617 |
|
void Engine::RouteAudio(EngineChannel* pEngineChannel, uint Samples) { |
618 |
|
// route master signal |
619 |
|
{ |
620 |
|
AudioChannel* pDstL = pAudioOutputDevice->Channel(pEngineChannel->AudioDeviceChannelLeft); |
621 |
|
AudioChannel* pDstR = pAudioOutputDevice->Channel(pEngineChannel->AudioDeviceChannelRight); |
622 |
|
pEngineChannel->pChannelLeft->MixTo(pDstL, Samples); |
623 |
|
pEngineChannel->pChannelRight->MixTo(pDstR, Samples); |
624 |
|
} |
625 |
|
// route FX send signal |
626 |
|
{ |
627 |
|
for (int iFxSend = 0; iFxSend < pEngineChannel->GetFxSendCount(); iFxSend++) { |
628 |
|
FxSend* pFxSend = pEngineChannel->GetFxSend(iFxSend); |
629 |
|
// left channel |
630 |
|
const int iDstL = pFxSend->DestinationChannel(0); |
631 |
|
if (iDstL < 0) { |
632 |
|
dmsg(1,("Engine::RouteAudio() Error: invalid FX send (L) destination channel")); |
633 |
|
} else { |
634 |
|
AudioChannel* pDstL = pAudioOutputDevice->Channel(iDstL); |
635 |
|
if (!pDstL) { |
636 |
|
dmsg(1,("Engine::RouteAudio() Error: invalid FX send (L) destination channel")); |
637 |
|
} else pEngineChannel->pChannelLeft->MixTo(pDstL, Samples, pFxSend->Level()); |
638 |
|
} |
639 |
|
// right channel |
640 |
|
const int iDstR = pFxSend->DestinationChannel(1); |
641 |
|
if (iDstR < 0) { |
642 |
|
dmsg(1,("Engine::RouteAudio() Error: invalid FX send (R) destination channel")); |
643 |
|
} else { |
644 |
|
AudioChannel* pDstR = pAudioOutputDevice->Channel(iDstR); |
645 |
|
if (!pDstR) { |
646 |
|
dmsg(1,("Engine::RouteAudio() Error: invalid FX send (R) destination channel")); |
647 |
|
} else pEngineChannel->pChannelRight->MixTo(pDstR, Samples, pFxSend->Level()); |
648 |
|
} |
649 |
|
} |
650 |
|
} |
651 |
|
// reset buffers with silence (zero out) for the next audio cycle |
652 |
|
pEngineChannel->pChannelLeft->Clear(); |
653 |
|
pEngineChannel->pChannelRight->Clear(); |
654 |
|
} |
655 |
|
|
656 |
|
/** |
657 |
* Free all keys which have turned inactive in this audio fragment, from |
* Free all keys which have turned inactive in this audio fragment, from |
658 |
* the list of active keys and clear all event lists on that engine |
* the list of active keys and clear all event lists on that engine |
659 |
* channel. |
* channel. |
730 |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
731 |
#endif |
#endif |
732 |
|
|
733 |
|
if (!pEngineChannel->pInstrument) return; // ignore if no instrument loaded |
734 |
|
|
735 |
|
//HACK: we should better add the transpose value only to the most mandatory places (like for retrieving the region and calculating the tuning), because otherwise voices will unintendedly survive when changing transpose while playing |
736 |
|
itNoteOnEvent->Param.Note.Key += pEngineChannel->GlobalTranspose; |
737 |
|
|
738 |
const int key = itNoteOnEvent->Param.Note.Key; |
const int key = itNoteOnEvent->Param.Note.Key; |
739 |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[key]; |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[key]; |
740 |
|
|
822 |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
823 |
#endif |
#endif |
824 |
|
|
825 |
|
//HACK: we should better add the transpose value only to the most mandatory places (like for retrieving the region and calculating the tuning), because otherwise voices will unintendedly survive when changing transpose while playing |
826 |
|
itNoteOffEvent->Param.Note.Key += pEngineChannel->GlobalTranspose; |
827 |
|
|
828 |
const int iKey = itNoteOffEvent->Param.Note.Key; |
const int iKey = itNoteOffEvent->Param.Note.Key; |
829 |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[iKey]; |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[iKey]; |
830 |
pKey->KeyPressed = false; // the MIDI key was now released |
pKey->KeyPressed = false; // the MIDI key was now released |
835 |
bool bShouldRelease = pKey->Active && ShouldReleaseVoice(pEngineChannel, itNoteOffEventOnKeyList->Param.Note.Key); |
bool bShouldRelease = pKey->Active && ShouldReleaseVoice(pEngineChannel, itNoteOffEventOnKeyList->Param.Note.Key); |
836 |
|
|
837 |
// in case Solo Mode is enabled, kill all voices on this key and respawn a voice on the highest pressed key (if any) |
// in case Solo Mode is enabled, kill all voices on this key and respawn a voice on the highest pressed key (if any) |
838 |
if (pEngineChannel->SoloMode) { //TODO: this feels like too much code just for handling solo mode :P |
if (pEngineChannel->SoloMode && pEngineChannel->pInstrument) { //TODO: this feels like too much code just for handling solo mode :P |
839 |
bool bOtherKeysPressed = false; |
bool bOtherKeysPressed = false; |
840 |
if (iKey == pEngineChannel->SoloKey) { |
if (iKey == pEngineChannel->SoloKey) { |
841 |
pEngineChannel->SoloKey = -1; |
pEngineChannel->SoloKey = -1; |
898 |
itNoteOffEventOnKeyList->Type = Event::type_release; // transform event type |
itNoteOffEventOnKeyList->Type = Event::type_release; // transform event type |
899 |
|
|
900 |
// spawn release triggered voice(s) if needed |
// spawn release triggered voice(s) if needed |
901 |
if (pKey->ReleaseTrigger) { |
if (pKey->ReleaseTrigger && pEngineChannel->pInstrument) { |
902 |
// first, get total amount of required voices (dependant on amount of layers) |
// first, get total amount of required voices (dependant on amount of layers) |
903 |
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(itNoteOffEventOnKeyList->Param.Note.Key); |
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(itNoteOffEventOnKeyList->Param.Note.Key); |
904 |
if (pRegion) { |
if (pRegion) { |
1093 |
std::cerr << "gig::Engine::LaunchVoice() Error: Unknown dimension\n" << std::flush; |
std::cerr << "gig::Engine::LaunchVoice() Error: Unknown dimension\n" << std::flush; |
1094 |
} |
} |
1095 |
} |
} |
1096 |
|
|
1097 |
|
// return if this is a release triggered voice and there is no |
1098 |
|
// releasetrigger dimension (could happen if an instrument |
1099 |
|
// change has occured between note on and off) |
1100 |
|
if (ReleaseTriggerVoice && VoiceType != Voice::type_release_trigger) return Pool<Voice>::Iterator(); |
1101 |
|
|
1102 |
::gig::DimensionRegion* pDimRgn = pRegion->GetDimensionRegionByValue(DimValues); |
::gig::DimensionRegion* pDimRgn = pRegion->GetDimensionRegionByValue(DimValues); |
1103 |
|
|
1104 |
// no need to continue if sample is silent |
// no need to continue if sample is silent |
1328 |
|
|
1329 |
uint keygroup = itVoice->KeyGroup; |
uint keygroup = itVoice->KeyGroup; |
1330 |
|
|
1331 |
|
// if the sample and dimension region belong to an |
1332 |
|
// instrument that is unloaded, tell the disk thread to |
1333 |
|
// release them |
1334 |
|
if (itVoice->Orphan) { |
1335 |
|
pDiskThread->OrderDeletionOfDimreg(itVoice->pDimRgn); |
1336 |
|
} |
1337 |
|
|
1338 |
// free the voice object |
// free the voice object |
1339 |
pVoicePool->free(itVoice); |
pVoicePool->free(itVoice); |
1340 |
|
|
1379 |
// update controller value in the engine channel's controller table |
// update controller value in the engine channel's controller table |
1380 |
pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value; |
pEngineChannel->ControllerTable[itControlChangeEvent->Param.CC.Controller] = itControlChangeEvent->Param.CC.Value; |
1381 |
|
|
1382 |
|
// handle hard coded MIDI controllers |
1383 |
switch (itControlChangeEvent->Param.CC.Controller) { |
switch (itControlChangeEvent->Param.CC.Controller) { |
1384 |
case 5: { // portamento time |
case 5: { // portamento time |
1385 |
pEngineChannel->PortamentoTime = (float) itControlChangeEvent->Param.CC.Value / 127.0f * (float) CONFIG_PORTAMENTO_TIME_MAX + (float) CONFIG_PORTAMENTO_TIME_MIN; |
pEngineChannel->PortamentoTime = (float) itControlChangeEvent->Param.CC.Value / 127.0f * (float) CONFIG_PORTAMENTO_TIME_MAX + (float) CONFIG_PORTAMENTO_TIME_MIN; |
1386 |
break; |
break; |
1387 |
} |
} |
1388 |
|
case 6: { // data entry (currently only used for RPN controllers) |
1389 |
|
if (pEngineChannel->GetMidiRpnController() == 2) { // coarse tuning in half tones |
1390 |
|
int transpose = (int) itControlChangeEvent->Param.CC.Value - 64; |
1391 |
|
// limit to +- two octaves for now |
1392 |
|
transpose = RTMath::Min(transpose, 24); |
1393 |
|
transpose = RTMath::Max(transpose, -24); |
1394 |
|
pEngineChannel->GlobalTranspose = transpose; |
1395 |
|
// workaround, so we won't have hanging notes |
1396 |
|
ReleaseAllVoices(pEngineChannel, itControlChangeEvent); |
1397 |
|
} |
1398 |
|
// to avoid other MIDI CC #6 messages to be misenterpreted as RPN controller data |
1399 |
|
pEngineChannel->ResetMidiRpnController(); |
1400 |
|
break; |
1401 |
|
} |
1402 |
case 7: { // volume |
case 7: { // volume |
1403 |
//TODO: not sample accurate yet |
//TODO: not sample accurate yet |
1404 |
pEngineChannel->GlobalVolume = VolumeCurve[itControlChangeEvent->Param.CC.Value] * CONFIG_GLOBAL_ATTENUATION; |
pEngineChannel->MidiVolume = VolumeCurve[itControlChangeEvent->Param.CC.Value]; |
1405 |
pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag |
pEngineChannel->bStatusChanged = true; // engine channel status has changed, so set notify flag |
1406 |
break; |
break; |
1407 |
} |
} |
1503 |
} |
} |
1504 |
break; |
break; |
1505 |
} |
} |
1506 |
|
case 100: { // RPN controller LSB |
1507 |
|
pEngineChannel->SetMidiRpnControllerLsb(itControlChangeEvent->Param.CC.Value); |
1508 |
|
break; |
1509 |
|
} |
1510 |
|
case 101: { // RPN controller MSB |
1511 |
|
pEngineChannel->SetMidiRpnControllerMsb(itControlChangeEvent->Param.CC.Value); |
1512 |
|
break; |
1513 |
|
} |
1514 |
|
|
1515 |
|
|
1516 |
// Channel Mode Messages |
// Channel Mode Messages |
1540 |
break; |
break; |
1541 |
} |
} |
1542 |
} |
} |
1543 |
|
|
1544 |
|
// handle FX send controllers |
1545 |
|
if (!pEngineChannel->fxSends.empty()) { |
1546 |
|
for (int iFxSend = 0; iFxSend < pEngineChannel->GetFxSendCount(); iFxSend++) { |
1547 |
|
FxSend* pFxSend = pEngineChannel->GetFxSend(iFxSend); |
1548 |
|
if (pFxSend->MidiController() == itControlChangeEvent->Param.CC.Controller) |
1549 |
|
pFxSend->SetLevel(itControlChangeEvent->Param.CC.Value); |
1550 |
|
pFxSend->SetInfoChanged(true); |
1551 |
|
} |
1552 |
|
} |
1553 |
} |
} |
1554 |
|
|
1555 |
/** |
/** |
1558 |
* @param itSysexEvent - sysex data size and time stamp of the sysex event |
* @param itSysexEvent - sysex data size and time stamp of the sysex event |
1559 |
*/ |
*/ |
1560 |
void Engine::ProcessSysex(Pool<Event>::Iterator& itSysexEvent) { |
void Engine::ProcessSysex(Pool<Event>::Iterator& itSysexEvent) { |
1561 |
RingBuffer<uint8_t>::NonVolatileReader reader = pSysexBuffer->get_non_volatile_reader(); |
RingBuffer<uint8_t,false>::NonVolatileReader reader = pSysexBuffer->get_non_volatile_reader(); |
1562 |
|
|
1563 |
uint8_t exclusive_status, id; |
uint8_t exclusive_status, id; |
1564 |
if (!reader.pop(&exclusive_status)) goto free_sysex_data; |
if (!reader.pop(&exclusive_status)) goto free_sysex_data; |
1577 |
|
|
1578 |
// command address |
// command address |
1579 |
uint8_t addr[3]; // 2 byte addr MSB, followed by 1 byte addr LSB) |
uint8_t addr[3]; // 2 byte addr MSB, followed by 1 byte addr LSB) |
1580 |
const RingBuffer<uint8_t>::NonVolatileReader checksum_reader = reader; // so we can calculate the check sum later |
const RingBuffer<uint8_t,false>::NonVolatileReader checksum_reader = reader; // so we can calculate the check sum later |
1581 |
if (reader.read(&addr[0], 3) != 3) goto free_sysex_data; |
if (reader.read(&addr[0], 3) != 3) goto free_sysex_data; |
1582 |
if (addr[0] == 0x40 && addr[1] == 0x00) { // System Parameters |
if (addr[0] == 0x40 && addr[1] == 0x00) { // System Parameters |
1583 |
dmsg(3,("\tSystem Parameter\n")); |
dmsg(3,("\tSystem Parameter\n")); |
1624 |
* question |
* question |
1625 |
* @param DataSize - size of the GS message data (in bytes) |
* @param DataSize - size of the GS message data (in bytes) |
1626 |
*/ |
*/ |
1627 |
uint8_t Engine::GSCheckSum(const RingBuffer<uint8_t>::NonVolatileReader AddrReader, uint DataSize) { |
uint8_t Engine::GSCheckSum(const RingBuffer<uint8_t,false>::NonVolatileReader AddrReader, uint DataSize) { |
1628 |
RingBuffer<uint8_t>::NonVolatileReader reader = AddrReader; |
RingBuffer<uint8_t,false>::NonVolatileReader reader = AddrReader; |
1629 |
uint bytes = 3 /*addr*/ + DataSize; |
uint bytes = 3 /*addr*/ + DataSize; |
1630 |
uint8_t addr_and_data[bytes]; |
uint8_t addr_and_data[bytes]; |
1631 |
reader.read(&addr_and_data[0], bytes); |
reader.read(&addr_and_data[0], bytes); |
1744 |
} |
} |
1745 |
|
|
1746 |
String Engine::Version() { |
String Engine::Version() { |
1747 |
String s = "$Revision: 1.65 $"; |
String s = "$Revision: 1.79 $"; |
1748 |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
1749 |
} |
} |
1750 |
|
|
1751 |
|
InstrumentManager* Engine::GetInstrumentManager() { |
1752 |
|
return &instruments; |
1753 |
|
} |
1754 |
|
|
1755 |
// static constant initializers |
// static constant initializers |
1756 |
const float* Engine::VolumeCurve(InitVolumeCurve()); |
const float* Engine::VolumeCurve(InitVolumeCurve()); |
1757 |
const float* Engine::PanCurve(InitPanCurve()); |
const float* Engine::PanCurve(InitPanCurve()); |
1794 |
return y; |
return y; |
1795 |
} |
} |
1796 |
|
|
1797 |
|
/** |
1798 |
|
* Changes the instrument for an engine channel. |
1799 |
|
* |
1800 |
|
* @param pEngineChannel - engine channel on which the instrument |
1801 |
|
* should be changed |
1802 |
|
* @param pInstrument - new instrument |
1803 |
|
* @returns a list of dimension regions from the old instrument |
1804 |
|
* that are still in use |
1805 |
|
*/ |
1806 |
|
::gig::DimensionRegion** Engine::ChangeInstrument(EngineChannel* pEngineChannel, ::gig::Instrument* pInstrument) { |
1807 |
|
instrument_change_command_t command; |
1808 |
|
command.pEngineChannel = pEngineChannel; |
1809 |
|
command.pInstrument = pInstrument; |
1810 |
|
InstrumentChangeQueue->push(&command); |
1811 |
|
|
1812 |
|
// wait for the audio thread to confirm that the instrument |
1813 |
|
// change has been done |
1814 |
|
instrument_change_reply_t reply; |
1815 |
|
while (InstrumentChangeReplyQueue->pop(&reply) == 0) { |
1816 |
|
usleep(10000); |
1817 |
|
} |
1818 |
|
return pDimRegionsInUse; |
1819 |
|
} |
1820 |
|
|
1821 |
}} // namespace LinuxSampler::gig |
}} // namespace LinuxSampler::gig |