-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScripter.js
More file actions
106 lines (93 loc) · 1.69 KB
/
Scripter.js
File metadata and controls
106 lines (93 loc) · 1.69 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
function Songs(noteName) {
switch (noteName) {
case "C4":
return [
[
new Note("E3", Length.Double),
new Note("A3", Length.Whole),
],
new Note("G#3", Length.Whole),
];
case "B3":
return [
[
new Note("D3", Length.Whole),
new Note("A2", Length.Whole),
new Note("D2", Length.Whole)
],
[
new Note("C#3", Length.Whole),
new Note("G#2", Length.Whole),
new Note("C#2", Length.Whole)
],
];
default:
return [];
}
};
function HandleMIDI(event)
{
var notes = Songs(MIDI.noteName(event.pitch));
if (notes.length > 0) {
new Sequencer(notes).play(event.beatPos);
return
}
event.send();
}
class Note
{
constructor(pitch, length)
{
this.pitch = pitch;
this.length = length;
}
play(beat)
{
var noteOn = new NoteOn;
noteOn.pitch = MIDI.noteNumber(this.pitch);
noteOn.sendAtBeat(beat);
var noteOff = new NoteOff(noteOn);
noteOff.sendAtBeat(beat + this.beatDuration() - GetParameter("Release"));
}
beatDuration()
{
return this.length * GetTimingInfo().meterNumerator;
}
}
class Sequencer
{
constructor(notes)
{
this.notes = notes;
}
play(beatPosition)
{
var currentBeat = beatPosition;
for (var note of this.notes)
{
var chord = Array.isArray(note) ? note : [note];
chord.forEach(n => n.play(currentBeat));
var minDuration = Math.min(...chord.map(n => n.beatDuration()));
currentBeat += minDuration;
}
}
}
var Length = {
Double: 2,
Whole: 1,
Half: 1 / 2,
Quarter: 1 / 4,
Eighth: 1 / 8,
Sixteenth: 1 / 16,
};
var NeedsTimingInfo = true
var PluginParameters = [
{
name: "Release",
defaultValue: 0.5,
minValue: 0,
maxValue: 1,
numberOfSteps: 10,
type: "lin"
}
];