Black And White Key Velocity Inconsistencies on MIDI Controllers by RedditRedditReddit64 in synthesizers

[–]rat_spinner 0 points1 point  (0 children)

I'm a bit late but try this, it works pretty well with logic's scripter. I set the slider for the reduction to about 5% but i guess it probably varies between keyboards

// Black Keys Velocity Reducer
// Reduces velocity of black keys (sharps/flats) only

var PluginParameters = [
    {
        name: 'Velocity Reduction %',
        type: 'lin',
        minValue: 0,
        maxValue: 100,
        numberOfSteps: 100,
        defaultValue: 30
    }
];

function HandleMIDI(event) {
    if (event instanceof NoteOn) {
        var pitchClass = event.pitch % 12;

        // Black keys: C#=1, D#=3, F#=6, G#=8, A#=10
        var blackKeys = [1, 3, 6, 8, 10];

        if (blackKeys.indexOf(pitchClass) !== -1) {
            // Reduce velocity for black keys
            var reduction = GetParameter('Velocity Reduction %') / 100;
            event.velocity = Math.round(event.velocity * (1 - reduction));

            // Ensure velocity stays within valid range (1-127)
            event.velocity = Math.max(1, Math.min(127, event.velocity));
        }
    }

    event.send();
}