Created
July 6, 2016 22:55
-
-
Save jtackaberry/cc28f6d974e632c6e0e9c6f1635afb7b to your computer and use it in GitHub Desktop.
Use CC11 to smooth out volume transition of low CC1 values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Must be compiled using SublimeKSP: https://github.com/nojanath/SublimeKSP/ | |
on init | |
declare const CC1_MIN_THRESHOLD := 30 | |
declare read last_cc_in[128] := (127) | |
declare read last_cc11_out := 127 | |
declare value | |
end on | |
on midi_in | |
if MIDI_COMMAND = MIDI_COMMAND_CC and (MIDI_BYTE_1 = 1 or MIDI_BYTE_1 = 11) | |
last_cc_in[MIDI_BYTE_1] := MIDI_BYTE_2 | |
// Linear scaling | |
// value := (last_cc_in[1] * last_cc_in[11]) / CC1_MIN_THRESHOLD | |
// Quadratic scaling | |
value := (last_cc_in[1] * last_cc_in[1] * last_cc_in[11]) / (CC1_MIN_THRESHOLD * CC1_MIN_THRESHOLD) | |
if value > last_cc_in[11] | |
// Clamp outgoing CC11 to highest received input CC11 value | |
value := last_cc_in[11] | |
end if | |
if MIDI_BYTE_1 = 11 | |
// Don't pass on received CC11, which we'll scale instead. | |
ignore_midi | |
end if | |
if value # last_cc11_out | |
set_midi(MIDI_CHANNEL, MIDI_COMMAND_CC, 11, value) | |
last_cc11_out := value | |
end if | |
end if | |
end on |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment