Skip to content

Instantly share code, notes, and snippets.

@karlsander
Created February 17, 2017 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlsander/6b5f0f836709a7a8d9f34999775b097c to your computer and use it in GitHub Desktop.
Save karlsander/6b5f0f836709a7a8d9f34999775b097c to your computer and use it in GitHub Desktop.
MIDI FX Trill Script
//-----------------------------------------------------------------------------
// Trill script adapted from Simple Arpeggiator
//-----------------------------------------------------------------------------
var NeedsTimingInfo = true;
var activeNotes = [];
function HandleMIDI(event) {
if (event instanceof NoteOn) {
// add note to array
activeNotes.push(event);
}
else if (event instanceof NoteOff) {
// remove note from array
for (i=0; i < activeNotes.length; i++) {
if (activeNotes[i].pitch == event.pitch) {
activeNotes.splice(i, 1);
break;
}
}
}
// pass non-note events through
else event.send();
}
//-----------------------------------------------------------------------------
function ProcessMIDI() {
// Get timing information from the host application
var musicInfo = GetTimingInfo();
if (activeNotes.length != 0) {
// get parameters
var division = GetParameter("Beat Division");
var noteLength = (GetParameter("Note Length") / 100) * (1 / division);
var interval = GetParameter("Interval");
// calculate beat to schedule
var lookAheadEnd = musicInfo.blockEndBeat;
var nextBeat = Math.ceil(musicInfo.blockStartBeat * division) / division;
// loop through the beats that fall within this buffer
while (nextBeat >= musicInfo.blockStartBeat && nextBeat < lookAheadEnd) {
// calculate step
var lastNotePitch = activeNotes[activeNotes.length - 1].pitch;
// send events
var noteLowOn = new NoteOn();
noteLowOn.pitch = lastNotePitch;
noteLowOn.sendAtBeat(nextBeat);
var noteLowOff = new NoteOff(noteLowOn);
noteLowOff.sendAtBeat(nextBeat + noteLength/2)
var noteHighOn = new NoteOn();
noteHighOn.pitch = lastNotePitch + interval;
noteHighOn.sendAtBeat(nextBeat + 0.5 / division);
var noteHighOff = new NoteOff(noteHighOn);
noteHighOff.sendAtBeat(nextBeat + 0.5 / division + noteLength/2)
// advance to next beat
nextBeat += 0.001;
nextBeat = Math.ceil(nextBeat * division) / division;
}
}
}
//-----------------------------------------------------------------------------
var PluginParameters =
[
{name:"Beat Division", type:"linear",
minValue:1, maxValue:8, numberOfSteps:70, defaultValue:4},
{name:"Note Length", unit:"%", type:"linear",
minValue:1, maxValue:200, defaultValue:50.0, numberOfSteps:199},
{name:"Interval", unit:" semi", type:"linear",
minValue:1, maxValue:12, defaultValue:3, numberOfSteps:11},
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment