Skip to content

Instantly share code, notes, and snippets.

@xuanvu
Forked from acarabott/chordNoteShifter.js
Created May 3, 2014 23:52
Show Gist options
  • Save xuanvu/4672e014db42804cca8a to your computer and use it in GitHub Desktop.
Save xuanvu/4672e014db42804cca8a to your computer and use it in GitHub Desktop.
NeedsTimingInfo = true;
var start = Date.now(),
triggered = false,
prev;
var PluginParameters = [
{
name: "Window Length",
defaultValue: 80,
minValue: 0,
maxValue: 500,
numberOfSteps: 500,
unit: "ms",
type: "lin"
},
{
name: "Added Velocity",
defaultValue: 30,
minValue: 0,
maxValue: 127,
numberOfSteps: 128,
type: "lin"
},
{
name: "Transpose",
defaultValue: 12,
minValue: -24,
maxValue: 24,
numberOfSteps: 4,
type: "lin"
},
{
name: "Note Choice",
type: "menu",
defaultValue: 1,
valueStrings: ["Bottom", "Top"]
}
];
function HandleMIDI(event) {
event.send();
if (event instanceof NoteOn) {
if (prev === undefined) {
prev = event;
} else {
if (GetParameter("Note Choice") === 1) {
if (event.pitch > prev.pitch) {
prev = event;
}
} else {
if (event.pitch < prev.pitch) {
prev = event;
}
}
}
if (!triggered) {
triggered = true;
start = Date.now();
}
}
}
function ProcessMIDI () {
var info = GetTimingInfo(),
now = Date.now(),
dur = GetParameter("Window Length"),
pitch = GetParameter("Transpose"),
vel = GetParameter("Added Velocity");
if (triggered && (start + dur) <= now) {
prev.pitch += pitch;
prev.velocity += vel;
prev.send();
triggered = false;
prev = undefined;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment