Edrwin Nahwlnin Posted March 7, 2017 Share Posted March 7, 2017 Hi guys! I´ve been searching for a script that lets me transform polyphonic midi input into monophonic performance with LOW note priority. My primary goal is to layer a polyphonic pad with a monophonic bass so that the bass always plays the lowest note in the chord. I´ve already found one M4l device (http://www.maxforlive.com/library/device/437/midi-mono-ddg-mono) that works perfectly but i would like to do this in MainStage as well. Here is a script that i found (forgot where unfortunately) that ALMOST closes the deal. Just won't work with upward legato playing. I´m a complete illiterate when it comes to scripting so any help would be very appreciated. Cheers! /Edvin var NoteIsOn = 0; function SwitchNote(NoteNumber, Velo, state) { if(Velo == 0) return state; if(state == 0) { var on = new NoteOn; on.pitch = NoteNumber; on.velocity = Velo; on.send(); } else { var off = new NoteOff; off.pitch = NoteNumber; off.velocity = Velo; off.send(); } state = 1 - state; return state; } function Reset() { if(NoteIsOn == 1) NoteIsOn = SwitchNote(BassNoteNumber, 1, NoteIsOn); BassNoteNumber = 1000; } function HandleMIDI(event) { if(event instanceof NoteOn) { var Pitch = event.pitch; if(Pitch < BassNoteNumber) { if(NoteIsOn == 1) NoteIsOn = SwitchNote(BassNoteNumber, 1, NoteIsOn); // switch old note off BassNoteNumber = Pitch; NoteIsOn = SwitchNote(BassNoteNumber, event.velocity, NoteIsOn); // switch new Note on } } else if(event instanceof NoteOff) { var Pitch = event.pitch; if(Pitch == BassNoteNumber) { if(NoteIsOn == 1) NoteIsOn = SwitchNote(BassNoteNumber, 1, NoteIsOn); // switch old note off BassNoteNumber = 1000; } } else event.send(); } Quote Link to comment Share on other sites More sharing options...
Unheardofski Posted March 14, 2017 Share Posted March 14, 2017 What is the desired result when playing upward legato? I've made a quick attempt at this but I realise I am not sure what you want it to do. Right now it triggers next lowest already playing note if you legato from the low note upwards. It isn't bullet proof though - it can't handle immediate legato back down etc. Here it is anyway for what it's worth. var actBassNote; var actTotNotes = []; function HandleMIDI(e) { switch (true) { case (e instanceof Note): handleNotes(e); return; break; default: e.send(); } } function handleNotes(e) { if (actBassNote && e.pitch > actBassNote.pitch) { if (e instanceof NoteOn) { actTotNotes.push(e); } else { for (var i = actTotNotes.length - 1; i >= 0; i--) { if (actTotNotes[i].pitch == e.pitch) { actTotNotes.splice(i, 1); } } } return; } if ((actBassNote && e instanceof NoteOn && e.pitch < actBassNote.pitch) || !actBassNote && e instanceof NoteOn) { if (actBassNote) { var off = new NoteOff(actBassNote); off.pitch < 128 ? off.send() : false; }; actBassNote = e; e.send(); return; } if (actBassNote && e.pitch == actBassNote.pitch && e instanceof NoteOff) { e.send(); actBassNote = { pitch: 128 }; if (actTotNotes.length) { actTotNotes.forEach(function(c, i) { if (c.pitch < actBassNote.pitch) { actBassNote = c; actBassNote.i = i; } }); actBassNote.send(); actTotNotes.splice(actBassNote.i, 1); } } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.