Created
February 6, 2021 10:23
-
-
Save avinmathew/eea6eb54e05051becd3d3b6fa02e4766 to your computer and use it in GitHub Desktop.
Monophonic filter that only keeps top note in a chord for Mainstage/Logic Pro
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
/* | |
Only play highest note in a chord | |
*/ | |
var notes = []; | |
function highestPitch() { | |
var highestPitch = -1; | |
notes.forEach(function(note) { | |
if (note.pitch > highestPitch) | |
{ | |
highestPitch = note.pitch; | |
} | |
}); | |
return highestPitch; | |
} | |
function HandleMIDI(event) | |
{ | |
var previousPitch = highestPitch(); | |
if (event instanceof NoteOn) | |
{ | |
notes.push(event); | |
if (event.pitch > previousPitch && previousPitch > -1) { | |
// New note is higher, so switch off previous note | |
var off = new NoteOff(); | |
off.pitch = previousPitch; | |
off.send(); | |
event.send(); | |
} else if (previousPitch == -1) { | |
// No previous note | |
event.send(); | |
} | |
} | |
else if (event instanceof NoteOff) | |
{ | |
// Remove from notes | |
var index = notes.findIndex(function(note) { | |
return note.pitch === event.pitch; | |
}); | |
notes.splice(index, 1); | |
if (event.pitch === previousPitch && GetParameter('Restore Lower Keys') == 100) | |
{ | |
// Highest note has been turned off, so turn on next highest | |
previousPitch = highestPitch(); | |
var on = notes.find(function(note) { | |
return note.pitch === previousPitch; | |
}); | |
if (on) { | |
on.send(); | |
} | |
} | |
event.send(); | |
} | |
} | |
var PluginParameters = [ | |
{ | |
name:'Restore Lower Keys', | |
type:'menu', | |
valueStrings:['off', 'on'], | |
defaultValue:0, | |
numberOfSteps: 100 | |
} | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment