-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLilyPitch.sc
executable file
·143 lines (95 loc) · 3.24 KB
/
LilyPitch.sc
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
LilyPitch : LilyShowableObj {
var <notenumber, <>duration;
var <pitch, <octave, <artic, <>afterNote, <>beforeNote;
var <>template = "just-pitches";
*new { arg notenumber;
^super.new.init(notenumber);
}
init { arg thisnotenumber;
this.notenumber_(thisnotenumber);
this.afterNote = [];
this.beforeNote = [];
}
qt {
^(notenumber.frac.round(0.5) == (0.5))
}
notenumber_ { arg newnotenumber;
var index, octIndex, notenumberFloor, noteNumberFloor;
notenumber = newnotenumber;
notenumberFloor = notenumber.floor;
pitch = pitchList.at(notenumberFloor % 12);
((notenumber - notenumberFloor).round(0.5) == (0.5)).if({
pitch = pitch ++ "ih"
});
octIndex = ((notenumber+60)/12).floor;
octave = octaveList.at(octIndex);
}
string {
var thisOut = pitch ++ octave;
if(thisOut.isNil) {
^""
}{
^thisOut;
};
}
putAfterNote { arg newArticulation;
if (afterNote.includes(newArticulation) == false,
{afterNote = afterNote.add(newArticulation)},
{"This Array already contains this string".warn}
)
}
putBeforeNote { arg newArticulation;
// some articulations needs to be placed *before* the pitch, right?
if(
// again: let's check if it's already there
beforeNote.includes(newArticulation) == false,
{beforeNote = beforeNote.add(newArticulation)},
{"This Array already contains this string".warn}
)
}
t { arg value;
// transpose the note with a number (interval)
// is there a need to make a Interval class?
this.notenumber = this.notenumber + value;
}
lily_ { arg newLilyString;
/* Change the pitch with a new string in Lilypond Format
Have to separate pitchclass and octave data
as always: c' = 0 */
var newPitchString, newOctString;
newPitchString = "";
newOctString = "";
newLilyString.do({|i|
var string = i.asString;
case
{ (string != "'").and(string != ",") }
{ newPitchString = newPitchString ++ string }
{(string == "'").or(string == ",") }
{newOctString = newOctString ++ string};
});
this.notenumber = pitchDict[newPitchString] + (octDict[newOctString] * 12);
}
cps_ { arg newCps;
// set the Pitch with its frequency in Hz
this.notenumber = (newCps.cpsmidi - 60).round(0.5)
}
== { arg otherPitch;
if(
otherPitch.isKindOf(LilyPitch),
{^this.notenumber == otherPitch.notenumber},
{"This is not a LilyPitch Object".error}
);
}
makeHarmonicSeries { arg lo=0, high=15, roundNotes=0.5;
var outputArray, thisCps, numberOfNotes;
thisCps = (this.notenumber + 60).midicps;
numberOfNotes = high-lo;
outputArray = Array.new;
(lo..high).do({|i|
outputArray = outputArray.add(
thisCps + (thisCps * i))
});
// returns a PitchSequence:
^LilyChord(outputArray.cpsmidi.round(roundNotes) - 60)
}
}