Adding my code as well for anyone looking to do hihats from GM layout, but support e-kit that uses CC4 to open/close note 46 for tip and note 26 for edge:
onInit function and declarations:
// Create a midilist with 128 elements
const var midiData = Engine.createMidiList();
// This count will manage our position in the midilist
var count = 0;
const TipTranslations = [70, 69, 68, 67, 66];
const ShoulderTranslations = [64, 63, 62, 61, 60];
function getTranslatedNote(input, cc4Value) {
var translatedNote = input;
var translation = (input == 46) ? TipTranslations : (input == 26) ? ShoulderTranslations : null;
if (translation != null) {
for (i = 0; i < cc4Ranges.length; i++) {
if (cc4Value >= cc4Ranges[i][0] && cc4Value <= cc4Ranges[i][1]) {
translatedNote = translation[i];
break;
}
}
}
return translatedNote;
}
function onNoteOn()
{
var input = Message.getNoteNumber();
var id = Message.getEventId();
var weight;
// Get the translated note number
var newMsg = getTranslatedNote(input, cc4Value);
// Send the modified note
Message.setNoteNumber(newMsg);
// Check if the note number is within the specified range or matches specific values
if ((newMsg >= 60 && newMsg <= 70) || newMsg == 44 || newMsg == 73 || newMsg == 42)
{
// Assign weights based on note number
switch(newMsg) {
case 70:
case 64:
weight = 5;
break;
case 69:
case 63:
weight = 4;
break;
case 68:
case 62:
weight = 3;
break;
case 67:
case 61:
weight = 2;
break;
case 60:
case 66:
weight = 1;
break;
case 44:
case 73:
weight = 1;
break;
default:
weight = 1;
}
// Calculate the indices for the midilist
var index1 = count * 2;
var index2 = index1 + 1;
// Store event ID and weight in the midilist
midiData.setValue(index1, id);
midiData.setValue(index2, weight);
// Increment and reset count as necessary
count = (count + 1) % 64;
// Loop through midilist weights
for (var i = 1; i < 128; i += 2)
{
var storedWeight = midiData.getValue(i);
if (storedWeight > weight) // Checking weights at odd indices
{
var storedId = midiData.getValue(i - 1); // Retrieve the event ID from the previous index
Synth.addVolumeFade(storedId, 150, -60); // 150 ms fade to -60 dB
//Console.print("Killed notes: " + storedId);
// Set weight to 0 to mark as "killed" and skip in future checks
midiData.setValue(i, 0);
}
}
}
}
function onController()
{
var number = Message.getControllerNumber();
var value = Message.getControllerValue();
if (number == 4)
{
cc4Value = value;
}
}
This could be improved to change the fade time/amount depending on the weight difference (which I probably will to control open > less open vs open to full closed, and to generate new transition sounds (hihat rattling) when closing the pedal after a recent open hit.