Skip to content

Instantly share code, notes, and snippets.

@AinTunez
Created April 25, 2018 12:25
Show Gist options
  • Select an option

  • Save AinTunez/002d3572a5e4ba6f589126f8c27b6505 to your computer and use it in GitHub Desktop.

Select an option

Save AinTunez/002d3572a5e4ba6f589126f8c27b6505 to your computer and use it in GitHub Desktop.
Logic Pro X script to non-destructively add swing
PluginParameters = [
{name: 'Swing %', minValue: 0, maxValue: 30, numberOfSteps: 60, defaultValue: 20},
{name: 'Note Length Adjust %', minValue: 0, maxValue: 100, numberOfSteps: 200, defaultValue: 50},
{name: 'Ignore Channel', minValue: 0, maxValue: 16, numberOfSteps: 16, defaultValue: 0}
];
var beat = 0;
NeedsTimingInfo = true;
var activeSwing = [];
function HandleMIDI (e) {
var ignore = GetParameter('Ignore Channel'), delay = GetParameter('Swing %')/100;
if (e instanceof NoteOn) {
var isSwing = beat.toString().slice(-2) == '.5';
if (isSwing && e.channel !== ignore && delay > 0) {
activeSwing.push(e);
e.sendAfterBeats(delay);
} else {
e.send();
}
} else if (e instanceof NoteOff) {
var comp = delay - delay * GetParameter('Note Length Adjust %')/100;
if (comp > 0) {
var ind = swingIndex(e);
if (swingIndex(e) > -1) {
activeSwing.splice(ind,1);
e.sendAfterBeats(comp);
} else {
e.send();
}
} else {
e.send();
}
}
}
function swingIndex(off) {
for (var n = 0; n < activeSwing.length; n++) {
var on = activeSwing[n];
if (on.channel == off.channel && on.pitch == off.pitch) return n;
}
return -1;
}
function ProcessMIDI () {
var info = GetTimingInfo();
var curr = Math.ceil(info.blockStartBeat * 24) / 24;
if (info.playing && beat !== curr) beat = curr;
}
@CrushedPixel
Copy link

Works great 6 years later - thanks a ton!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment