-
Notifications
You must be signed in to change notification settings - Fork 2
/
instrument.go
63 lines (51 loc) · 1.25 KB
/
instrument.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
54
55
56
57
58
59
60
61
62
63
package supergollider
import "io/ioutil"
type generator interface {
newNodeId() int
newBusId() int
newGroupId() int
newSampleBuffer() int
}
type instrument interface {
Name() string
}
type sCInstrument struct {
name string // name of the instrument must not have characters other than [a-zA-Z0-9_]
Path string // path of the instrument
// Offset float64 // offset applied to every instance of the instrument
used bool
}
// the outer invoker may use the first voices instrument to query loadcode etc
func newSCInstrument(g generator, name, path string, numVoices int) []*Voice {
i := &sCInstrument{
name: name,
Path: path,
}
return _voices(numVoices, g, i, -1)
}
func (i *sCInstrument) Name() string {
return i.name
}
func (i *sCInstrument) IsUsed() bool {
return i.used
}
func (i *sCInstrument) Use() {
i.used = true
}
func (i *sCInstrument) LoadCode() []byte {
data, err := ioutil.ReadFile(i.Path)
if err != nil {
panic("can't read instrument " + i.Path)
}
return data
}
func _voices(num int, g generator, instr instrument, groupid int) []*Voice {
voices_ := make([]*Voice, num)
for i := 0; i < num; i++ {
voices_[i] = &Voice{generator: g, instrument: instr}
if groupid > -1 {
voices_[i].Group = groupid
}
}
return voices_
}