-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcsnd_test.go
232 lines (209 loc) · 4.7 KB
/
csnd_test.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package csnd
import (
"fmt"
"testing"
"unsafe"
)
func TestInstantiation(t *testing.T) {
cs := Create(nil)
if cs.Cs == nil {
t.Errorf("Could not create Csound instance")
}
fmt.Println("\n", cs.Version(), cs.APIVersion())
cs.Destroy()
if cs.Cs != nil {
t.Errorf("Csound was destroyed and opaque pointer is not cleared!")
}
}
type Point struct{ x, y, z int }
func (point Point) String() string {
return fmt.Sprintf("(%d, %d, %d)", point.x, point.y, point.z)
}
type Triangle map[*Point]string
func TestHostData(t *testing.T) {
cs := Create(nil)
ht := cs.HostData()
if ht != nil {
t.Errorf("Hostdata should be nil when instance created with nil arg")
}
i := 1956
cs.SetHostData(unsafe.Pointer(&i))
ht = cs.HostData()
pi := (*int)(ht)
if pi != &i {
t.Errorf("Int hostdata read is different of hostdata written")
} else {
fmt.Println("\n", *pi)
}
s := "Une chaîne de caractères"
cs.SetHostData(unsafe.Pointer(&s))
ht = cs.HostData()
ps := (*string)(ht)
if ps != &s {
t.Errorf("String hostdata read is different of hostdata written")
} else {
fmt.Println("\n", *ps)
}
cs.SetHostData(nil)
ht = cs.HostData()
if ht != nil {
t.Errorf("Hostdata should have been cleared")
}
cs.Destroy()
triangle := make(Triangle, 3)
triangle[&Point{1, 2, 3}] = "α"
triangle[&Point{4, 5, 6}] = "β"
triangle[&Point{7, 8, 9}] = "γ"
s1 := "togodo tsoin tsoin"
cs = Create(unsafe.Pointer(&s1))
ht = cs.HostData()
pt := (*string)(unsafe.Pointer(ht))
if pt != &s1 {
t.Errorf("String hostdata read is different of hostdata written")
} else {
fmt.Println("\n", *pt)
}
cs.SetHostData(nil)
ht = cs.HostData()
if ht != nil {
t.Errorf("Hostdata should have been cleared")
}
cs.Destroy()
}
func TestCsoundParams(t *testing.T) {
cs := Create(nil)
var p CsoundParams
fmt.Println(p)
cs.Params(&p)
fmt.Println(p)
p.RingBell = 1
cs.SetParams(&p)
p.RingBell = 0
fmt.Println(p)
cs.Params(&p)
fmt.Println(p)
cs.SetDebug(true)
cs.Params(&p)
fmt.Println(p)
fmt.Println(cs.Debug())
p.RingBell = 0
p.DebugMode = 0
cs.SetParams(&p)
fmt.Println(cs.Debug())
cs.Destroy()
}
func TestRTAudioIO(t *testing.T) {
cs := Create(nil)
var name, mtype string
err := CSOUND_SUCCESS
n := 0
for err != CSOUND_ERROR {
name, mtype, err = cs.Module(n)
n++
fmt.Printf("Module %d: %s (%s)\n", n, name, mtype)
}
cs.Compile([]string{"dummy", "simple.csd"})
list := cs.AudioDevList(true)
fmt.Println("\nAudioDevList(true)")
for i := range list {
fmt.Printf("%d: %s (%s), %d chan\n",
i, list[i].DeviceId, list[i].DeviceName, list[i].MaxNchnls)
}
list = cs.AudioDevList(false)
fmt.Println("\nAudioDevList(false)")
for i := range list {
fmt.Printf("%d: %s (%s), %d chan\n",
i, list[i].DeviceId, list[i].DeviceName, list[i].MaxNchnls)
}
fmt.Println()
cs.Destroy()
}
func TestMidiIO(t *testing.T) {
cs := Create(nil)
cs.Compile([]string{"dummy", "simple.csd"})
list := cs.MidiDevList(true)
fmt.Println()
for i := range list {
fmt.Println(list[i])
}
list = cs.MidiDevList(false)
fmt.Println()
for i := range list {
fmt.Println(list[i])
}
fmt.Println()
cs.Destroy()
}
func TestChannels(t *testing.T) {
cs := Create(nil)
cs.Compile([]string{"dummy", "simple.csd"})
cs.Start()
cs.ChannelPtr("Zobie", CSOUND_CONTROL_CHANNEL)
lst, err := cs.ListChannels()
if err != nil {
fmt.Println(err)
} else if lst == nil {
fmt.Println("Channel list is empty")
} else {
fmt.Println(len(lst))
}
}
func TestOpcodeList(t *testing.T) {
cs := Create(nil)
if list := cs.OpcodeList(); list != nil {
fmt.Println(list)
fmt.Println(len(list))
}
cs.Destroy()
}
func TestNamedGens(t *testing.T) {
cs := Create(nil)
namedGens := cs.NamedGens()
fmt.Println(namedGens)
cs.Destroy()
}
func TestRunCommand(t *testing.T) {
cs := Create(nil)
cs.RunCommand([]string{"ls", "-a"}, false)
cs.Destroy()
}
func TestUtilities(t *testing.T) {
cs := Create(nil)
if list, err := cs.ListUtilities(); err == nil {
for _, name := range list {
fmt.Printf("%s: %s\n", name, cs.UtilityDescription(name))
}
}
cs.Destroy()
}
func TestRand31(t *testing.T) {
cs := Create(nil)
seed := int32(1956)
for i := 0; i < 1000; i++ {
n := cs.Rand31(&seed)
fmt.Printf("%d ", n)
}
fmt.Println()
cs.Destroy()
}
func TestRandMT(t *testing.T) {
cs := Create(nil)
p := cs.SeedRandMT([]uint32{1956})
for i := 0; i < 1000; i++ {
n := cs.RandMT(p)
fmt.Printf("%d ", n)
}
fmt.Println()
cs.Destroy()
}
func TestMessages(t *testing.T) {
cs := Create(nil)
version := cs.Version()
apiVersion := cs.APIVersion()
sr := cs.Sr()
ksmps := cs.Ksmps()
cs.Message("\n%s, %s, %f, %d\n\n", version, apiVersion, sr, ksmps)
cs.MessageS(CSOUNDMSG_FG_RED|CSOUNDMSG_FG_UNDERLINE, "\n%s, %s, %f, %d\n\n",
version, apiVersion, sr, ksmps)
cs.Destroy()
}