-
Notifications
You must be signed in to change notification settings - Fork 4
/
SuperDirtUGens.sc
81 lines (56 loc) · 1.76 KB
/
SuperDirtUGens.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
/*
A few UGen classes that build subgraphs for SuperDirt Synths
*/
/*
convenience methods for panning and releasing
*/
DirtPan {
*ar { |signal, numChannels, pan = 0.0, mul = 1.0, mix = false|
var output, mono;
mono = signal.size <= 1;
if(numChannels == 2) {
output = Pan2.ar(signal, (pan * 2) - 1, mul)
} {
output = PanAz.ar(numChannels, signal, pan, mul)
};
if(mono.not) {
if(mix.not) {
// if multichannel, take only the diagonal
output = numChannels.collect(output[_]);
};
output = output.sum;
};
^output
}
}
/*
In order to avoid bookkeeping on the language side, we implement cutgroups as follows:
The language initialises the synth with its sample id (some number that correlates with the sample name) and the cutgroup.
Before we start the new synth, we send a /set message to all synths, and those that match the specifics will be released.
*/
DirtGateCutGroup {
*ar { |sustain = 1, releaseTime = 0.02, doneAction = 2|
// this is necessary because the message "==" tests for objects, not for signals
var same = { |a, b| BinaryOpUGen('==', a, b) };
var sameCutGroup = same.(\cutGroup.ir(0), abs(\gateCutGroup.kr(0)));
var sameSample = same.(\sample.ir(0), \gateSample.kr(0));
var which = \gateCutGroup.kr(0).sign; // -1, 0, 1
var free = Select.kr(which + 1, // 0, 1, 2
[
sameSample,
0.0, // default cut group 0 doesn't ever cut
1.0
]
) * sameCutGroup; // same cut group is mandatory
^EnvGen.ar(Env([1, 1, 0], [sustain, releaseTime]), doneAction:doneAction)
*
EnvGen.kr(Env.cutoff(releaseTime), (1 - free), doneAction:doneAction);
}
}
//
// DirtReleaseAfter {
//
// *ar { |sustain, releaseTime = 0.02, doneAction = 2|
// ^DirtGateCutGroup.ar(sustain, releaseTime, doneAction)
// }
// }