665 |
pKey->KeyPressed = false; // the MIDI key was now released |
pKey->KeyPressed = false; // the MIDI key was now released |
666 |
|
|
667 |
// release voices on this key if needed |
// release voices on this key if needed |
668 |
if (pKey->Active && !pEngineChannel->SustainPedal) { |
if (pKey->Active && ShouldReleaseVoice(pEngineChannel, itNoteOffEvent->Param.Note.Key)) { |
669 |
itNoteOffEvent->Type = Event::type_release; // transform event type |
itNoteOffEvent->Type = Event::type_release; // transform event type |
670 |
|
|
671 |
// move event to the key's own event list |
// move event to the key's own event list |
1156 |
} |
} |
1157 |
case 64: { // sustain |
case 64: { // sustain |
1158 |
if (itControlChangeEvent->Param.CC.Value >= 64 && !pEngineChannel->SustainPedal) { |
if (itControlChangeEvent->Param.CC.Value >= 64 && !pEngineChannel->SustainPedal) { |
1159 |
dmsg(4,("PEDAL DOWN\n")); |
dmsg(4,("DAMPER (RIGHT) PEDAL DOWN\n")); |
1160 |
pEngineChannel->SustainPedal = true; |
pEngineChannel->SustainPedal = true; |
1161 |
|
|
1162 |
#if !CONFIG_PROCESS_MUTED_CHANNELS |
#if !CONFIG_PROCESS_MUTED_CHANNELS |
1178 |
} |
} |
1179 |
} |
} |
1180 |
if (itControlChangeEvent->Param.CC.Value < 64 && pEngineChannel->SustainPedal) { |
if (itControlChangeEvent->Param.CC.Value < 64 && pEngineChannel->SustainPedal) { |
1181 |
dmsg(4,("PEDAL UP\n")); |
dmsg(4,("DAMPER (RIGHT) PEDAL UP\n")); |
1182 |
pEngineChannel->SustainPedal = false; |
pEngineChannel->SustainPedal = false; |
1183 |
|
|
1184 |
#if !CONFIG_PROCESS_MUTED_CHANNELS |
#if !CONFIG_PROCESS_MUTED_CHANNELS |
1189 |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
1190 |
for (; iuiKey; ++iuiKey) { |
for (; iuiKey; ++iuiKey) { |
1191 |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey]; |
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey]; |
1192 |
if (!pKey->KeyPressed) { |
if (!pKey->KeyPressed && ShouldReleaseVoice(pEngineChannel, *iuiKey)) { |
1193 |
|
RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend(); |
1194 |
|
if (itNewEvent) { |
1195 |
|
*itNewEvent = *itControlChangeEvent; // copy event to the key's own event list |
1196 |
|
itNewEvent->Type = Event::type_release; // transform event type |
1197 |
|
} |
1198 |
|
else dmsg(1,("Event pool emtpy!\n")); |
1199 |
|
} |
1200 |
|
} |
1201 |
|
} |
1202 |
|
break; |
1203 |
|
} |
1204 |
|
case 66: { // sostenuto |
1205 |
|
if (itControlChangeEvent->Param.CC.Value >= 64 && !pEngineChannel->SostenutoPedal) { |
1206 |
|
dmsg(4,("SOSTENUTO (CENTER) PEDAL DOWN\n")); |
1207 |
|
pEngineChannel->SostenutoPedal = true; |
1208 |
|
|
1209 |
|
#if !CONFIG_PROCESS_MUTED_CHANNELS |
1210 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
1211 |
|
#endif |
1212 |
|
|
1213 |
|
SostenutoKeyCount = 0; |
1214 |
|
// Remeber the pressed keys |
1215 |
|
RTList<uint>::Iterator iuiKey = pEngineChannel->pActiveKeys->first(); |
1216 |
|
for (; iuiKey; ++iuiKey) { |
1217 |
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[*iuiKey]; |
1218 |
|
if (pKey->KeyPressed && SostenutoKeyCount < 128) SostenutoKeys[SostenutoKeyCount++] = *iuiKey; |
1219 |
|
} |
1220 |
|
} |
1221 |
|
if (itControlChangeEvent->Param.CC.Value < 64 && pEngineChannel->SostenutoPedal) { |
1222 |
|
dmsg(4,("SOSTENUTO (CENTER) PEDAL UP\n")); |
1223 |
|
pEngineChannel->SostenutoPedal = false; |
1224 |
|
|
1225 |
|
#if !CONFIG_PROCESS_MUTED_CHANNELS |
1226 |
|
if (pEngineChannel->GetMute()) return; // skip if sampler channel is muted |
1227 |
|
#endif |
1228 |
|
|
1229 |
|
// release voices if the damper pedal is up and their respective key is not pressed |
1230 |
|
for (int i = 0; i < SostenutoKeyCount; i++) { |
1231 |
|
midi_key_info_t* pKey = &pEngineChannel->pMIDIKeyInfo[SostenutoKeys[i]]; |
1232 |
|
if (!pKey->KeyPressed && !pEngineChannel->SustainPedal) { |
1233 |
RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend(); |
RTList<Event>::Iterator itNewEvent = pKey->pEvents->allocAppend(); |
1234 |
if (itNewEvent) { |
if (itNewEvent) { |
1235 |
*itNewEvent = *itControlChangeEvent; // copy event to the key's own event list |
*itNewEvent = *itControlChangeEvent; // copy event to the key's own event list |
1397 |
} |
} |
1398 |
} |
} |
1399 |
|
|
1400 |
|
/** |
1401 |
|
* Determines whether the specified voice should be released. |
1402 |
|
* |
1403 |
|
* @param pEngineChannel - The engine channel on which the voice should be checked |
1404 |
|
* @param Key - The key number |
1405 |
|
* @returns true if the specified should be released, false otherwise. |
1406 |
|
*/ |
1407 |
|
bool Engine::ShouldReleaseVoice(EngineChannel* pEngineChannel, int Key) { |
1408 |
|
if (pEngineChannel->SustainPedal) return false; |
1409 |
|
|
1410 |
|
if (pEngineChannel->SostenutoPedal) { |
1411 |
|
for (int i = 0; i < SostenutoKeyCount; i++) |
1412 |
|
if (Key == SostenutoKeys[i]) return false; |
1413 |
|
} |
1414 |
|
|
1415 |
|
return true; |
1416 |
|
} |
1417 |
|
|
1418 |
uint Engine::VoiceCount() { |
uint Engine::VoiceCount() { |
1419 |
return ActiveVoiceCount; |
return ActiveVoiceCount; |
1420 |
} |
} |
1452 |
} |
} |
1453 |
|
|
1454 |
String Engine::Version() { |
String Engine::Version() { |
1455 |
String s = "$Revision: 1.54 $"; |
String s = "$Revision: 1.55 $"; |
1456 |
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 |
1457 |
} |
} |
1458 |
|
|