Created
April 25, 2020 22:00
-
-
Save jkap/d911ae4678e79412ce08d64f0c7ef901 to your computer and use it in GitHub Desktop.
Logic Pro X Scripter script for assigning MIDI NoteOn events to random channels
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
// assigns incoming MIDI NoteOn events to a "random" channel in a given range | |
// channel assignment is deterministic based on position in song and specified seed | |
// for Logic Pro X Scripter plugin | |
// written by jae kaplan, 2020 | |
// twitter.com/jkap | |
// github.com/jkap | |
// MIT licensed | |
var NeedsTimingInfo = true; | |
function randomSeeded(seed) { | |
const x = Math.sin(seed) * 10000; | |
return x - Math.floor(x); | |
} | |
var PluginParameters = [ | |
{ | |
name: "Min Channel", | |
defaultValue: 1, | |
minValue: 1, | |
maxValue: 15, | |
numberOfSteps: 14, | |
}, | |
{ | |
name: "Max Channel", | |
defaultValue: 7, | |
minValue: 2, | |
maxValue: 16, | |
numberOfSteps: 14, | |
}, | |
{ | |
name: "Fixed Seed", | |
defaultValue: 69, | |
minValue: 1, | |
maxValue: 100, | |
numberOfSteps: 99, | |
}, | |
]; | |
const noteMap = new Map(); | |
function HandleMIDI(event) { | |
const minChannel = GetParameter("Min Channel"); | |
const maxChannel = GetParameter("Max Channel"); | |
const fixedSeed = GetParameter("Fixed Seed"); | |
let channel = | |
Math.floor( | |
randomSeeded(event.beatPos + fixedSeed) * (maxChannel + 1 - minChannel) | |
) + minChannel; | |
if (event instanceof NoteOn) { | |
noteMap.set(event.pitch, channel); | |
} else if (event instanceof NoteOff) { | |
channel = noteMap.get(event.pitch) || 1; | |
} | |
event.channel = channel; | |
event.trace(); | |
event.send(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment