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
|
ZZZES3 : ZZZ{
var out,
clocks,
vcos;
*new{
arg channels;
^super.newCopyArgs(channels).init;
}
init{
out = Dictionary();
clocks = Dictionary();
vcos = Dictionary();
"Interfacing ZZZ ES-3, using the following channels:".postln;
(1..8).do({
arg item, i;
out.add(item -> super.channels[i]);
postln(item.asString ++ " -> " ++ super.channels[i].asString);
});
}
/**
* Returns the number of the hardware output on the system for a provided
* ES-3 output number
* @return system hardware output number
*/
out{
arg output;
if((output > 0) && (output <= 8), {
^out.at(output);
},{
^nil;
});
}
addClock{
arg output, freq;
if(vcos.at(output).isNil, {
if(clocks.at(output).isNil, {
clocks.add(output -> Synth(\ZZZClock, [\out, this.out(output), \freq, freq]));
},{
("Cannot add clock on output "++ output ++". There is a clock playing.").error;
});
},{
("Cannot add clock on output "++ output ++". There is a VCO playing.").error;
});
}
removeClock{
arg output;
if(clocks.at(output).notNil, {
clocks.at(output).free;
clocks.removeAt(output);
});
}
setClock{
arg output, freq, delta;
var currentFreq, diff, env;
if(clocks.at(output).notNil, {
if(delta.notNil, {
clocks.at(output).get(\freq, {
arg value;
currentFreq = value;
diff = (currentFreq-freq).abs;
if(currentFreq > freq, {
diff = diff*(-1);
});
env = Env.sine((delta*2), diff).asStream;
{
(delta*10).do({
clocks.at(output).set(\freq, (currentFreq+env.next));
0.1.wait;
});
clocks.at(output).set(\freq, freq);
}.fork;
});
},{
clocks.at(output).set(\freq, freq);
});
});
}
clock{
arg output;
^clocks.at(output);
}
addVCO{
arg output, mul;
if(clocks.at(output).isNil, {
if(vcos.at(output).isNil, {
vcos.add(output -> Synth(\ZZZConstant, [\out, this.out(output), \mul, mul]));
},{
("Cannot add VCO on output "++ output ++". There is a VCO playing.").error;
});
},{
("Cannot add VCO on output "++ output ++". There is a clock playing.").error;
});
}
setVCO{
arg output, mul;
if(vcos.at(output).notNil, {
vcos.at(output).set(\mul, mul);
});
}
removeVCO{
arg output;
vcos.removeAt(output);
}
vco{
arg output;
^vcos.at(output);
}
}
|