-
Notifications
You must be signed in to change notification settings - Fork 0
/
DspUnit.java
51 lines (39 loc) · 1.23 KB
/
DspUnit.java
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
package vibrato.dspunits;
import vibrato.oscillators.Operation;
import vibrato.oscillators.Oscillator;
import java.util.Collection;
import java.util.stream.Stream;
public interface DspUnit {
Operation[] operations();
default void connectTo(Oscillator oscillator) {
for (Operation operation : operations()) {
oscillator.triggers(operation);
}
}
static Operation[] noOps() {
return new Operation[0];
}
static <D extends DspUnit, C extends Collection<D>> Operation[] ops(C dspUnits) {
return dspUnits.stream()
.map(DspUnit::operations)
.flatMap(Stream::of)
.toArray(Operation[]::new);
}
static Operation[] ops(DspUnit... dspUnits) {
return Stream.of(dspUnits)
.map(DspUnit::operations)
.flatMap(Stream::of)
.toArray(Operation[]::new);
}
static Operation[] ops(Operation[]... operations) {
return Stream.of(operations)
.flatMap(Stream::of)
.toArray(Operation[]::new);
}
static Operation[] ops(Operation... operations) {
return operations;
}
static DspUnit create(Operation... operations) {
return () -> operations;
}
}