forked from alexgeorg/LogicProX_Midi_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTYPE2BEAT.js
94 lines (88 loc) · 3.26 KB
/
TYPE2BEAT.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
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
//--------------------------------------------------------------------------------------------------------------------------------------
// Type2Beat
//--------------------------------------------------------------------------------------------------------------------------------------
/*
* A PlugIn that creates a beat / a note pattern from an input string (idea is based on TypeDrummer).
* INPUT has to be changed within the editor. Haven't come up with a better solution yet, sorry.
*/
//--------------------------------------------------------------------------------------------------------------------------------------
var INPUT = "Ryan Gosling is a handsome man!"; // Change it up!!!
//--------------------------------------------------------------------------------------------------------------------------------------
var string = INPUT;
var currentStep = 0;
NeedsTimingInfo = true;
var wasPlaying = false;
function ProcessMIDI() {
var info = GetTimingInfo();
if (wasPlaying && !info.playing) {
MIDI.allNotesOff();
currentStep = 0;
}
wasPlaying = info.playing;
if (info.playing) {
var seq = typeToBeat(string);
var div = GetParameter("Beat Division");
var nextBeat = Math.ceil(info.blockStartBeat * div) / div;
var noteLength = 1 / div;
if (info.cycling && info.blockEndBeat >= info.rightCycleBeat) {
if (info.blockEndBeat >= info.rightCycleBeat) {
var cycleBeats = info.rightCycleBeat - info.leftCycleBeat;
var cycleEnd = info.blockEndBeat - cycleBeats;
}
}
while ((nextBeat >= info.blockStartBeat && nextBeat < info.blockEndBeat) ||
(info.cycling && nextBeat < cycleEnd)) {
if (info.cycling && nextBeat >= info.rightCycleBeat) {
nextBeat -= cycleBeats;
}
if (seq[(currentStep % seq.length)] != null) {
var noteOn = new NoteOn();
noteOn.pitch = seq[(currentStep % seq.length)];
noteOn.sendAtBeat(nextBeat);
Trace("Note: " + MIDI.noteName(noteOn.pitch));
var noteOff = new NoteOff(noteOn);
noteOff.sendAtBeat(nextBeat + noteLength);
}
currentStep += 1;
nextBeat += 0.001;
nextBeat = Math.ceil(nextBeat * div) / div;
}
}
}
function typeToBeat(string) {
var startNote = GetParameter("A → ");
var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
var inputArray = Array.from(this.string.toUpperCase());
var outputArray = [];
for (i = 0; i < inputArray.length; i++) {
if (alphabet.includes(inputArray[i])) {
outputArray.push(alphabet.indexOf(inputArray[i]) + startNote);
} else {
outputArray.push(null);
}
}
return outputArray;
}
ResetParameterDefaults = false;
var PluginParameters = [{
name: "🥁 TYPE2BEAT",
type: "text",
},{
name: "Text: " + INPUT,
type: "text",
}, {
name: "A → ",
type: "menu",
valueStrings: MIDI._noteNames,
minValue: 0,
maxValue: 127,
numberOfSteps: 128,
defaultValue: 60
}, {
name: "Beat Division",
type: "linear",
minValue: 1,
maxValue: 8,
numberOfSteps: 7,
defaultValue: 4
}];