-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathenvgen.go
53 lines (50 loc) · 1.35 KB
/
envgen.go
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
package sc
// EnvGen plays back breakpoint envelopes.
// The envelopes must implement the Envelope interface.
// The envelope and the arguments for LevelScale, LevelBias,
// and TimeScale are polled when the EnvGen is triggered and
// remain constant for the duration of the envelope.
type EnvGen struct {
// Env determines the shape of the envelope
Env Envelope
// Gate triggers the envelope and holds it open while > 0
Gate Input
// LevelScale scales the levels of the breakpoints
LevelScale Input
// LevelBias offsets the levels of the breakpoints
LevelBias Input
// TimeScale scales the durations of the segments
TimeScale Input
// Done is the ugen done action
Done int
}
func (envgen *EnvGen) defaults() {
if envgen.Gate == nil {
envgen.Gate = C(1)
}
if envgen.LevelScale == nil {
envgen.LevelScale = C(1)
}
if envgen.LevelBias == nil {
envgen.LevelBias = C(0)
}
if envgen.TimeScale == nil {
envgen.TimeScale = C(1)
}
}
// Rate creates a new ugen at a specific rate.
// If rate is an unsupported value this method will cause
// a runtime panic.
func (envgen EnvGen) Rate(rate int8) Input {
CheckRate(rate)
(&envgen).defaults()
ins := []Input{
envgen.Gate,
envgen.LevelScale,
envgen.LevelBias,
envgen.TimeScale,
C(float32(envgen.Done)),
}
ins = append(ins, envgen.Env.Inputs()...)
return NewInput("EnvGen", rate, 0, 1, ins...)
}