Last active
July 10, 2024 20:34
-
-
Save kbola/eb296fa8f169f864ede8c46f126a2abc to your computer and use it in GitHub Desktop.
Portamento / Glide MIDI Scripter Plugin for Logic Pro X
This file contains 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
/* | |
Portamento / Glide MIDI Scripter Plugin for Logic Pro X | |
https://www.reddit.com/r/Logic_Studio/comments/8901vy/request_midi_script_for_faking_glideportamento/ | |
Bolasol, Inc. 2018 | |
*/ | |
var PluginParameters = [ | |
{ | |
name:"Glide time (ms)", | |
type:"lin", | |
defaultValue:50, | |
minValue:0, | |
maxValue:500, | |
numberOfSteps:500 | |
}, | |
{ | |
name:"Glide resolution (ms)", | |
type:"lin", | |
defaultValue:1, | |
minValue:1, | |
maxValue:50, | |
numberOfSteps:49 | |
}, | |
{ | |
name:"Inst. Bend Range", | |
type:"lin", | |
defaultValue:12, | |
minValue:1, | |
maxValue:24, | |
numberOfSteps:23 | |
}]; | |
//Stores the last note played so we know where we are gliding from. | |
var lastPitch = 0; | |
function HandleMIDI(event) { | |
var glideTime = GetParameter("Glide time (ms)"); | |
var glideResolution = GetParameter("Glide resolution (ms)"); | |
var pitchBendRange = GetParameter("Inst. Bend Range"); | |
if (event instanceof NoteOn) { | |
if(lastPitch > 0 && pitchBendRange > 0) { | |
//Determine distance incoming note and last note played | |
var interval = event.pitch - lastPitch; | |
//Translate that interval to the pitch bend value (-8192 - 8191) | |
var startingPitchBendValue = -8192 * (interval / pitchBendRange); | |
//clamp to real pitch bend values | |
startingPitchBendValue = clamp(startingPitchBendValue, -8192, 8191); | |
var numberOfSteps = (glideTime / glideResolution); | |
//Scheduling pitch bend messages for 'glide' | |
for(var i = 0; i <= numberOfSteps; i++) { | |
var pb = new PitchBend(); | |
pb.value = (startingPitchBendValue / numberOfSteps) * (numberOfSteps - i); | |
pb.sendAfterMilliseconds(i * glideResolution); | |
} | |
} | |
//store the pitch of this message so we can compare | |
//the next message to it. | |
lastPitch = event.pitch; | |
} | |
event.send(); | |
} | |
function clamp(num, min, max) { | |
return num <= min ? min : num >= max ? max : num; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment