[Scriptlet] Velocity Adjuster - set 4 zones for velocity correction

Hi guys,
today i wrote a Scriptlet to help you with a special kind of problem:
What if your keyboard or maybe a special plugin won’t react to velocity as you expect it to do?
Maybe it’s because of uneven sampling softwarewise or poor build quality hardwarewise… there may be several reasons.
With my Scriptlet you are able to set 4 zones around specified “center notes” with a flexible range width of up to +/- 12 halftones (up & down the center note), and for each zone you can set a velocity correction value of +/- 60 which will go back to “normal” percentually the closer you come to the limits of a zone.
Just place the Scriptlet between your Midi in block and the plugin you want to control and then maybe use some some widgets to adjust the parameters.

I hope you like it and it will be helpful…
Cheers!
Erik

This is an example for how to set it up (just a "serving suggestion, if you so want :wink: )

Here is a gig file where you can try how it works:
velocity adjuster.gig (354.7 KB)

And this is the source code of it (just for completeness):

// Declare various kinds of parameters
var
    centerNote1("Center Note #1") : Parameter AsNoteNames C-2..G8 = "C-2" // center note for range #1
    noteRange1("Effect Range #1") : Subrange Parameter 0..12  = 0 // adjust correction range in halftone steps (12 means 12 halftones up AND down from center note = 2 octaves)
    velCorrection1("Velocity Correction #1") : Subrange Parameter -60..60 = 0 // velocity correction for center note (will diminish to the range limits)
    
    centerNote2("Center Note #2") : Parameter AsNoteNames C-2..G8 = "C-2" // center note for range #2
    noteRange2("Effect Range #2") : Subrange Parameter 0..12  = 0 // adjust correction range in halftone steps (12 means 12 halftones up AND down from center note = 2 octaves)
    velCorrection2("Velocity Correction #2") : Subrange Parameter -60..60 = 0
    
    centerNote3("Center Note #3") : Parameter AsNoteNames C-2..G8 = "C-2" // center note for range #3
    noteRange3("Effect Range #3") : Subrange Parameter 0..12  = 0 // adjust correction range in halftone steps (12 means 12 halftones up AND down from center note = 2 octaves)
    velCorrection3("Velocity Correction #3") : Subrange Parameter -60..60 = 0
    
    centerNote4("Center Note #4") : Parameter AsNoteNames C-2..G8 = "C-2" // center note for range #4
    noteRange4("Effect Range #4") : Subrange Parameter 0..12  = 0 // adjust correction range in halftone steps (12 means 12 halftones up AND down from center note = 2 octaves)
    velCorrection4("Velocity Correction #4") : Subrange Parameter -60..60 = 0

Initialization
SetInfoMessage("This Scriptlet lets you create up to four zones around specified center notes where you can define a correction value for the keyboard's velocity")
SetDisplayMessage("Velocity Adjuster - @Schamass")
End

// user defined function to do all the velocity calculation stuff
Function CorrectVelocity(actNoteVar : Integer, actVelVar : Integer, centerNoteVar : double, noteRangeVar : double, velCorrectionVar : double) Returns Integer
var
noteDistVar : Integer
velStepVar : Integer = Round(IntToFloat(velCorrectionVar) / noteRangeVar)
newVelVar : Integer
velPercentVar : Double

    noteDistVar = Round(Abs(actNoteVar - Round(centerNoteVar))) // calculate distance in halftones
    velPercentVar = 1.0 / noteRangeVar // calculate the percentual step for velocity correction decrease per distance step
    newVelVar = actVelVar+ Round(velCorrectionVar - noteDistVar * velCorrectionVar * velPercentVar) // calculate new velocity value
    
    If newVelVar > 127 then newVelVar = 127 End
    If newVelVar < 0 then newVelVar = 0 End

    result = newVelVar //set the content of the variable newVelVar as the result of the function

End

//Called when a NoteOn message is received
On NoteOnEvent(m : NoteMessage) 
var
actVel : Integer = GetVelocity(m)
actNote : Integer = GetNoteNumber(m)

    Select
        // if actual played note is within range 1
        actNote >= (NoteNameToNoteNumber(centerNote1) - Round(noteRange1)) and actNote <= (NoteNameToNoteNumber(centerNote1) + Round(noteRange1)) do
            SendNow(MakeNoteMessage(actNote, CorrectVelocity (actNote, actVel, NoteNameToNoteNumber(centerNote1), noteRange1, velCorrection1))) //send note with corrected velocity
            
        // if actual played note is within range 2
        actNote >= (NoteNameToNoteNumber(centerNote2) - Round(noteRange2)) and actNote <= (NoteNameToNoteNumber(centerNote2) + Round(noteRange2)) do
            SendNow(MakeNoteMessage(actNote, CorrectVelocity (actNote, actVel, NoteNameToNoteNumber(centerNote2), noteRange2, velCorrection2))) //send note with corrected velocity
            
        // if actual played note is within range 3
        actNote >= (NoteNameToNoteNumber(centerNote3) - Round(noteRange3)) and actNote <= (NoteNameToNoteNumber(centerNote3) + Round(noteRange3)) do
            SendNow(MakeNoteMessage(actNote, CorrectVelocity (actNote, actVel, NoteNameToNoteNumber(centerNote3), noteRange3, velCorrection3))) //send note with corrected velocity            
            Print ("Zone 3")
            
        // if actual played note is within range 4
        actNote >= (NoteNameToNoteNumber(centerNote4) - Round(noteRange4)) and actNote <= (NoteNameToNoteNumber(centerNote4) + Round(noteRange4)) do
            SendNow(MakeNoteMessage(actNote, CorrectVelocity (actNote, actVel, NoteNameToNoteNumber(centerNote4), noteRange4, velCorrection4))) //send note with corrected velocity
        
        //Optionally include this for when none of the above matched
        True do
            SendNow(MakeNoteMessage(actNote, actVel)) // send note with original velocity
    End
End




6 Likes

(Off-topic)

This almost forces a guitarist to become a keyboard-player. So many issues, but man, sooo many solutions… :upside_down_face:

2 Likes