-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
66 lines (59 loc) · 1.78 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// Probably Note
// Created by Attila Enhardt on 2017-04-14
// Copyright codecave STHLM / LogicScripts 2017.
//
PluginParameters = [];
let scriptName = new Parameter(null, "Probably Note by codecave STHLM")
let prob = new Parameter(null, "Transpose probability", "lin", "prop", null, 0, 100, 0, 100, " %");
let semiTones = new Parameter(null, "Transpose semitones", "lin", null, null, -12, 12, 0, 24, " st.");
let noteLookUp = [];
for (let i = 0; i < 128; i++) {
noteLookUp.push(i);
}
function HandleMIDI(e) {
if (e instanceof NoteOn) {
treatNoteOn(e);
}
if (e instanceof NoteOff) {
treatNoteOff(e);
}
e.send();
}
function treatNoteOn(e) {
let p = Math.floor(Math.random() * 101);
if (p <= GetParameter("Transpose probability")) {
let originalPitch = e.pitch;
e.pitch += GetParameter("Transpose semitones");
noteLookUp[originalPitch] = e.pitch;
}
}
function treatNoteOff(e) {
let originalPitch = e.pitch;
e.pitch = noteLookUp[e.pitch];
noteLookUp[originalPitch] = originalPitch;
}
function Parameter(cb, n, t, pc, vs, miv, mav, def, nos, unit) {
let vsl = vs ? vs.length : null;
this.callBack = cb || function(v) {
this.currentValue = v;
};
this.name = n;
this.type = t || "text";
this.pc = pc || null;
this.valueStrings = vs || null;
if (t != "checkbox") {
this.minValue = miv || 0;
this.maxValue = mav || 0;
}
this.defaultValue = def || Math.floor(vsl / 2) || 0;
this.numberOfSteps = nos || vsl || null;
this.unit = unit || null;
this.pc = pc || null;
this.currentValue = 0;
this._index = PluginParameters.length;
this.remove = function() {
PluginParameters.splice(this._index, 1);
};
PluginParameters.push(this);
}