-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFMChord.sc
95 lines (66 loc) · 1.48 KB
/
FMChord.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
/*
'Frequency Modulation' Chord
Arguments: carrier, modulator, index
Use:
a = FMChord.new(7, -5, 9)
a
a.index
a.car
a.car = 4
a.mod
a.addChord.plot
a.diffChord.plot
a.fmChord.plot
a.fmChord.asPitchSeq.plot
a.fmChord.asPitchSeq.playMidi;
*/
FMChord {
var <>car, <>mod, <>index;
var <>thisRound = 0.5;
*new {|car, mod, index|
^super.new.init(car, mod, index);
}
init {arg thiCar = 7, thiMod = -4, thisIndex = 9;
car = thiCar;
mod = thiMod;
index = thisIndex;
}
addFreqs {
var carFreq, modFreq, out;
carFreq = (car+60).midicps;
modFreq = (mod+60).midicps;
out = [carFreq, modFreq];
index.do {|i|
out = out ++ ((car+60).midicps + (i * (mod+60).midicps));
};
^out
}
addMidi {
^this.addFreqs.cpsmidi.round(thisRound)
}
addChord {
^LilyChord(this.addMidi.wrap(35,100) - 60);
}
diffFreqs {
var carFreq, modFreq, out;
carFreq = (car+60).midicps;
modFreq = (mod+60).midicps;
out = [carFreq, modFreq];
index.do {|i|
out = out ++ ((car+60).midicps - (i * (mod+60).midicps));
};
^out
}
diffMidi {
^this.diffFreqs.cpsmidi.round(thisRound)
}
diffChord {
^LilyChord(this.diffMidi.wrap0(35,100) - 60);
}
/* Chord equivalent to all frequencies */
fmChord {
^LilyChord.new(
(this.diffChord.notenumber) ++ (this.addChord.notenumber)
);
}
}