Jam Origin

MIDI Guitar & MIDI Bass user forum

Compressor Midi Machine

Hello,

Is there a compressor midi machine out there? I’m having trouble programming it.

You set a high range and low range knobs. If the velocity played is higher than high range it becomes high range value, if lower than low range it becomes low range value. This is my code below. It seems to produce an infinite sustain type effect for some reason.

range_high = 70
range_low = 50

function OnNote(channel, pitch, ivelocity)
– for any note played, send out the exact same note
if ivelocity > range_high then
Note(channel, pitch, range_high)
elseif ivelocity < range_low then
Note(channel, pitch, ivelocity)
else
Note(channel, pitch, ivelocity)
end
end

function OnFrame(notes)
end

function OnStart(info)
– assign a description to be displayed in the header
info.description = “Fix any note into a solid velocity”
info.link = “http://jamorigin.com/midi-machine

-- create widgets in the user interface
Knob("range_low", 0, 1,127,1)
--List("my_parameter_2", 1, "option 1","option 2","option 3")
Knob("range_high", 0, 1,127,1)
--List("my_parameter_2", 1, "option 1","option 2","option 3")

end

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 :slight_smile:

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