Hi Rocky,
a possible cause is that notes with velocity of 0 need to able to play at that velocity. (i.e. note off).
The code above should work for that though (is this a slightly different version to the one causing the infinite sustain?), although won’t work as intended for range_low as it appears to just play the original velocity.
If you have another version of the code where the elseif looks like:
elseif ivelocity < range_low then
Note(channel, pitch, range_low)
… this will create the infinite sustain as any soft note - including 0 velocity - will get played at the range_low velocity.
Try this code for the elseif…
elseif ivelocity < range_low and ivelocity > 0 then
Note(channel, pitch, range_low)
… this will ensure all the soft notes get played at the range_low velocity, but 0’s will fall through to the ‘else’ logic that follows along with anything in between low and high.
And, for what it’s worth, I built a similar one a while ago - more a ‘normaliser’ than a compressor or limiter. This has a little gate in it also (which I put in nearly all my routines) so that really soft notes/ghost notes don’t suddenly get blasted out. Feel free to copy or pinch ideas as required
Chris
Gate_Threshold = 0
Norm_Low=80
Norm_High=120
function OnNote(channel, pitch, ivelocity)
if ivelocity == 0 then
-- always play note off events
Note(channel, pitch, ivelocity)
elseif ivelocity > 0 and ivelocity < Gate_Threshold then
-- below gate threshold? don't play anything
else
– work out note velocity as percentage of midi maximum (127)
– ? how will this work with my gating?
PercOfMax = ivelocity / 127
-- recalculate the value into the normalisation target range
TargetRange = Norm_High - Norm_Low
NewVelocity = math.floor(Norm_Low + (TargetRange * PercOfMax))
-- play the note
Note(channel, pitch, NewVelocity)
Print(
" Pitch:",pitch,
" Velocity:", ivelocity,
" New Velocity:", NewVelocity
)
end
end
function OnFrame(notes)
end
function OnStart(info)
– assign a description to be displayed in the header
info.description = “Normalises midi input velocity into a given output window”
info.link = “http://jamorigin.com/midi-machine”
-- create widgets in the user interface
Knob("Gate_Threshold", 1, 1,127,1)
Knob("Norm_Low", 1, 1,127,1)
Knob("Norm_High", 1, 1,127,1)
end