27 |
this->pDiskThread = new DiskThread(((pAudioIO->MaxSamplesPerCycle() << MAX_PITCH) << 1) + 6); //FIXME: assuming stereo |
this->pDiskThread = new DiskThread(((pAudioIO->MaxSamplesPerCycle() << MAX_PITCH) << 1) + 6); //FIXME: assuming stereo |
28 |
this->pInstrument = NULL; |
this->pInstrument = NULL; |
29 |
this->Pitch = 0; |
this->Pitch = 0; |
30 |
|
this->SustainPedal = 0; |
31 |
Voice::pDiskThread = this->pDiskThread; |
Voice::pDiskThread = this->pDiskThread; |
32 |
Voice::pEngine = this; |
Voice::pEngine = this; |
33 |
pEventQueue = new RingBuffer<ModulationSystem::Event>(MAX_EVENTS_PER_FRAGMENT); |
pEventQueue = new RingBuffer<ModulationSystem::Event>(MAX_EVENTS_PER_FRAGMENT); |
35 |
pVoicePool = new RTELMemoryPool<Voice>(MAX_AUDIO_VOICES); |
pVoicePool = new RTELMemoryPool<Voice>(MAX_AUDIO_VOICES); |
36 |
pActiveKeys = new RTELMemoryPool<uint>(128); |
pActiveKeys = new RTELMemoryPool<uint>(128); |
37 |
pEvents = new RTEList<ModulationSystem::Event>(pEventPool); |
pEvents = new RTEList<ModulationSystem::Event>(pEventPool); |
38 |
|
pCCEvents = new RTEList<ModulationSystem::Event>(pEventPool); |
39 |
for (uint i = 0; i < ModulationSystem::destination_count; i++) { |
for (uint i = 0; i < ModulationSystem::destination_count; i++) { |
40 |
pCCEvents[i] = new RTEList<ModulationSystem::Event>(pEventPool); |
pSynthesisEvents[i] = new RTEList<ModulationSystem::Event>(pEventPool); |
41 |
} |
} |
42 |
for (uint i = 0; i < 128; i++) { |
for (uint i = 0; i < 128; i++) { |
43 |
pMIDIKeyInfo[i].pActiveVoices = new RTEList<Voice>(pVoicePool); |
pMIDIKeyInfo[i].pActiveVoices = new RTEList<Voice>(pVoicePool); |
64 |
|
|
65 |
// initialize modulation system |
// initialize modulation system |
66 |
ModulationSystem::Initialize(pAudioIO->SampleRate(), pAudioIO->MaxSamplesPerCycle()); |
ModulationSystem::Initialize(pAudioIO->SampleRate(), pAudioIO->MaxSamplesPerCycle()); |
67 |
|
|
68 |
// sustain pedal value |
// set all MIDI controller values to zero |
69 |
PrevHoldCCValue = 0; |
memset(ControllerTable, 0x00, 128); |
|
SustainPedal = 0; |
|
70 |
|
|
71 |
SuspensionRequested = false; |
SuspensionRequested = false; |
72 |
pthread_mutex_init(&__render_state_mutex, NULL); |
pthread_mutex_init(&__render_state_mutex, NULL); |
90 |
if (pMIDIKeyInfo[i].pEvents) delete pMIDIKeyInfo[i].pEvents; |
if (pMIDIKeyInfo[i].pEvents) delete pMIDIKeyInfo[i].pEvents; |
91 |
} |
} |
92 |
for (uint i = 0; i < ModulationSystem::destination_count; i++) { |
for (uint i = 0; i < ModulationSystem::destination_count; i++) { |
93 |
if (pCCEvents[i]) delete pCCEvents[i]; |
if (pSynthesisEvents[i]) delete pSynthesisEvents[i]; |
94 |
} |
} |
95 |
delete[] pCCEvents; |
delete[] pSynthesisEvents; |
96 |
if (pEvents) delete pEvents; |
if (pEvents) delete pEvents; |
97 |
|
if (pCCEvents) delete pCCEvents; |
98 |
if (pEventQueue) delete pEventQueue; |
if (pEventQueue) delete pEventQueue; |
99 |
if (pEventPool) delete pEventPool; |
if (pEventPool) delete pEventPool; |
100 |
if (pVoicePool) delete pVoicePool; |
if (pVoicePool) delete pVoicePool; |
129 |
|
|
130 |
// empty the event lists for the new fragment |
// empty the event lists for the new fragment |
131 |
pEvents->clear(); |
pEvents->clear(); |
132 |
|
pCCEvents->clear(); |
133 |
for (uint i = 0; i < ModulationSystem::destination_count; i++) { |
for (uint i = 0; i < ModulationSystem::destination_count; i++) { |
134 |
pCCEvents[i]->clear(); |
pSynthesisEvents[i]->clear(); |
135 |
} |
} |
136 |
|
|
137 |
// read and copy events from input queue |
// read and copy events from input queue |
333 |
int currentPitch = pPitchbendEvent->Pitch; |
int currentPitch = pPitchbendEvent->Pitch; |
334 |
pPitchbendEvent->Pitch -= this->Pitch; // convert to delta |
pPitchbendEvent->Pitch -= this->Pitch; // convert to delta |
335 |
this->Pitch = currentPitch; // store current absolute pitch value |
this->Pitch = currentPitch; // store current absolute pitch value |
336 |
pEvents->move(pPitchbendEvent, pCCEvents[ModulationSystem::destination_vco]); |
pEvents->move(pPitchbendEvent, pSynthesisEvents[ModulationSystem::destination_vco]); |
337 |
} |
} |
338 |
|
|
339 |
/** |
/** |
374 |
|
|
375 |
switch (pControlChangeEvent->Controller) { |
switch (pControlChangeEvent->Controller) { |
376 |
case 64: { |
case 64: { |
377 |
if (pControlChangeEvent->Value >= 64 && PrevHoldCCValue < 64) { |
if (pControlChangeEvent->Value >= 64 && !SustainPedal) { |
378 |
dmsg(4,("PEDAL DOWN\n")); |
dmsg(4,("PEDAL DOWN\n")); |
379 |
SustainPedal = true; |
SustainPedal = true; |
380 |
|
|
392 |
else dmsg(1,("Event pool emtpy!\n")); |
else dmsg(1,("Event pool emtpy!\n")); |
393 |
} |
} |
394 |
} |
} |
|
pEvents->free(pControlChangeEvent); // free the original event |
|
395 |
} |
} |
396 |
} |
} |
397 |
if (pControlChangeEvent->Value < 64 && PrevHoldCCValue >= 64) { |
if (pControlChangeEvent->Value < 64 && SustainPedal) { |
398 |
dmsg(4,("PEDAL UP\n")); |
dmsg(4,("PEDAL UP\n")); |
399 |
SustainPedal = false; |
SustainPedal = false; |
400 |
|
|
412 |
else dmsg(1,("Event pool emtpy!\n")); |
else dmsg(1,("Event pool emtpy!\n")); |
413 |
} |
} |
414 |
} |
} |
|
pEvents->free(pControlChangeEvent); // free the original event |
|
415 |
} |
} |
|
|
|
416 |
} |
} |
|
PrevHoldCCValue = pControlChangeEvent->Value; |
|
417 |
break; |
break; |
418 |
} |
} |
419 |
} |
} |
420 |
|
|
421 |
|
// update controller value in the engine's controller table |
422 |
|
ControllerTable[pControlChangeEvent->Controller] = pControlChangeEvent->Value; |
423 |
|
|
424 |
|
// move event from the unsorted event list to the control change event list |
425 |
|
pEvents->move(pControlChangeEvent, pCCEvents); |
426 |
} |
} |
427 |
|
|
428 |
/** |
/** |
561 |
*/ |
*/ |
562 |
void AudioThread::ResetInternal() { |
void AudioThread::ResetInternal() { |
563 |
this->Pitch = 0; |
this->Pitch = 0; |
|
PrevHoldCCValue = 0; // sustain pedal value |
|
564 |
SustainPedal = 0; |
SustainPedal = 0; |
565 |
ActiveVoiceCount = 0; |
ActiveVoiceCount = 0; |
566 |
ActiveVoiceCountMax = 0; |
ActiveVoiceCountMax = 0; |