47 |
pSynthesisEvents[i] = new RTEList<Event>(pEventPool); |
pSynthesisEvents[i] = new RTEList<Event>(pEventPool); |
48 |
} |
} |
49 |
for (uint i = 0; i < 128; i++) { |
for (uint i = 0; i < 128; i++) { |
50 |
pMIDIKeyInfo[i].pActiveVoices = new RTEList<Voice>(pVoicePool); |
pMIDIKeyInfo[i].pActiveVoices = new RTEList<Voice>(pVoicePool); |
51 |
pMIDIKeyInfo[i].KeyPressed = false; |
pMIDIKeyInfo[i].KeyPressed = false; |
52 |
pMIDIKeyInfo[i].Active = false; |
pMIDIKeyInfo[i].Active = false; |
53 |
pMIDIKeyInfo[i].pSelf = NULL; |
pMIDIKeyInfo[i].ReleaseTrigger = false; |
54 |
pMIDIKeyInfo[i].pEvents = new RTEList<Event>(pEventPool); |
pMIDIKeyInfo[i].pSelf = NULL; |
55 |
|
pMIDIKeyInfo[i].pEvents = new RTEList<Event>(pEventPool); |
56 |
} |
} |
57 |
for (Voice* pVoice = pVoicePool->alloc(); pVoice; pVoice = pVoicePool->alloc()) { |
for (Voice* pVoice = pVoicePool->alloc(); pVoice; pVoice = pVoicePool->alloc()) { |
58 |
pVoice->SetEngine(this); |
pVoice->SetEngine(this); |
162 |
for (uint i = 0; i < 128; i++) { |
for (uint i = 0; i < 128; i++) { |
163 |
pMIDIKeyInfo[i].pActiveVoices->clear(); |
pMIDIKeyInfo[i].pActiveVoices->clear(); |
164 |
pMIDIKeyInfo[i].pEvents->clear(); |
pMIDIKeyInfo[i].pEvents->clear(); |
165 |
pMIDIKeyInfo[i].KeyPressed = false; |
pMIDIKeyInfo[i].KeyPressed = false; |
166 |
pMIDIKeyInfo[i].Active = false; |
pMIDIKeyInfo[i].Active = false; |
167 |
pMIDIKeyInfo[i].pSelf = NULL; |
pMIDIKeyInfo[i].ReleaseTrigger = false; |
168 |
|
pMIDIKeyInfo[i].pSelf = NULL; |
169 |
} |
} |
170 |
|
|
171 |
// reset all key groups |
// reset all key groups |
567 |
// release voices on this key if needed |
// release voices on this key if needed |
568 |
if (pKey->Active && !SustainPedal) { |
if (pKey->Active && !SustainPedal) { |
569 |
pNoteOffEvent->Type = Event::type_release; // transform event type |
pNoteOffEvent->Type = Event::type_release; // transform event type |
|
pEvents->move(pNoteOffEvent, pKey->pEvents); // move event to the key's own event list |
|
570 |
} |
} |
571 |
|
|
572 |
|
// spawn release triggered voice(s) if needed |
573 |
|
if (pKey->ReleaseTrigger) { |
574 |
|
LaunchVoice(pNoteOffEvent, 0, true); |
575 |
|
pKey->ReleaseTrigger = false; |
576 |
|
} |
577 |
|
|
578 |
|
// move event to the key's own event list |
579 |
|
pEvents->move(pNoteOffEvent, pKey->pEvents); |
580 |
} |
} |
581 |
|
|
582 |
/** |
/** |
595 |
* called by the ProcessNoteOn() method and by the voices itself |
* called by the ProcessNoteOn() method and by the voices itself |
596 |
* (e.g. to spawn further voices on the same key for layered sounds). |
* (e.g. to spawn further voices on the same key for layered sounds). |
597 |
* |
* |
598 |
* @param pNoteOnEvent - key, velocity and time stamp of the event |
* @param pNoteOnEvent - key, velocity and time stamp of the event |
599 |
* @param iLayer - layer index for the new voice (optional - only |
* @param iLayer - layer index for the new voice (optional - only |
600 |
* in case of layered sounds of course) |
* in case of layered sounds of course) |
601 |
|
* @param ReleaseTriggerVoice - if new voice is a release triggered voice |
602 |
|
* (optional, default = false) |
603 |
*/ |
*/ |
604 |
void Engine::LaunchVoice(Event* pNoteOnEvent, int iLayer) { |
void Engine::LaunchVoice(Event* pNoteOnEvent, int iLayer, bool ReleaseTriggerVoice) { |
605 |
midi_key_info_t* pKey = &pMIDIKeyInfo[pNoteOnEvent->Key]; |
midi_key_info_t* pKey = &pMIDIKeyInfo[pNoteOnEvent->Key]; |
606 |
|
|
607 |
// allocate a new voice for the key |
// allocate a new voice for the key |
608 |
Voice* pNewVoice = pKey->pActiveVoices->alloc(); |
Voice* pNewVoice = pKey->pActiveVoices->alloc(); |
609 |
if (pNewVoice) { |
if (pNewVoice) { |
610 |
// launch the new voice |
// launch the new voice |
611 |
if (pNewVoice->Trigger(pNoteOnEvent, this->Pitch, this->pInstrument, iLayer) < 0) { |
if (pNewVoice->Trigger(pNoteOnEvent, this->Pitch, this->pInstrument, iLayer, ReleaseTriggerVoice) < 0) { |
612 |
dmsg(1,("Triggering new voice failed!\n")); |
dmsg(1,("Triggering new voice failed!\n")); |
613 |
pKey->pActiveVoices->free(pNewVoice); |
pKey->pActiveVoices->free(pNewVoice); |
614 |
} |
} |
620 |
midi_key_info_t* pOtherKey = &pMIDIKeyInfo[**ppKeyGroup]; |
midi_key_info_t* pOtherKey = &pMIDIKeyInfo[**ppKeyGroup]; |
621 |
// kill all voices on the (other) key |
// kill all voices on the (other) key |
622 |
Voice* pVoiceToBeKilled = pOtherKey->pActiveVoices->first(); |
Voice* pVoiceToBeKilled = pOtherKey->pActiveVoices->first(); |
623 |
for (; pVoiceToBeKilled; pVoiceToBeKilled = pOtherKey->pActiveVoices->next()) |
while (pVoiceToBeKilled) { |
624 |
if (pVoiceToBeKilled != pNewVoice) pVoiceToBeKilled->Kill(pNoteOnEvent); |
Voice* pVoiceToBeKilledNext = pOtherKey->pActiveVoices->next(); |
625 |
|
if (pVoiceToBeKilled->Type != Voice::type_release_trigger) pVoiceToBeKilled->Kill(pNoteOnEvent); |
626 |
|
pOtherKey->pActiveVoices->set_current(pVoiceToBeKilled); |
627 |
|
pVoiceToBeKilled = pVoiceToBeKilledNext; |
628 |
|
} |
629 |
} |
} |
630 |
} |
} |
631 |
if (!pKey->Active) { // mark as active key |
if (!pKey->Active) { // mark as active key |
636 |
if (pNewVoice->KeyGroup) { |
if (pNewVoice->KeyGroup) { |
637 |
*ppKeyGroup = pKey->pSelf; // put key as the (new) active key to its key group |
*ppKeyGroup = pKey->pSelf; // put key as the (new) active key to its key group |
638 |
} |
} |
639 |
|
if (pNewVoice->Type == Voice::type_release_trigger_required) pKey->ReleaseTrigger = true; // mark key for the need of release triggered voice(s) |
640 |
} |
} |
641 |
} |
} |
642 |
else std::cerr << "No free voice!" << std::endl << std::flush; |
else std::cerr << "No free voice!" << std::endl << std::flush; |
667 |
pKey->Active = false; |
pKey->Active = false; |
668 |
pActiveKeys->free(pKey->pSelf); // remove key from list of active keys |
pActiveKeys->free(pKey->pSelf); // remove key from list of active keys |
669 |
pKey->pSelf = NULL; |
pKey->pSelf = NULL; |
670 |
|
pKey->ReleaseTrigger = false; |
671 |
dmsg(3,("Key has no more voices now\n")); |
dmsg(3,("Key has no more voices now\n")); |
672 |
} |
} |
673 |
} |
} |
840 |
} |
} |
841 |
|
|
842 |
String Engine::Version() { |
String Engine::Version() { |
843 |
String s = "$Revision: 1.10 $"; |
String s = "$Revision: 1.11 $"; |
844 |
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 |
845 |
} |
} |
846 |
|
|