-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcallback.go
700 lines (582 loc) · 20.9 KB
/
callback.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
package csnd
/*
#include <csound/csound.h>
#include <csound/csound_standard_types.h>
void csoundSetFileOpenCB(CSOUND *csound);
void csoundSetPlayOpenCB(CSOUND *csound);
void csoundSetRtPlayCB(CSOUND *csound);
void csoundSetRecOpenCB(CSOUND *csound);
void csoundSetRtRecordCB(CSOUND *csound);
void csoundSetRtCloseCB(CSOUND *csound);
void csoundSetAudioDeviceListCB(CSOUND *csound);
void csoundSetExternalMidiInOpenCB(CSOUND *csound);
void csoundSetExternalMidiReadCB(CSOUND *csound);
void csoundSetExternalMidiInCloseCB(CSOUND *csound);
void csoundSetExternalMidiOutOpenCB(CSOUND *csound);
void csoundSetExternalMidiWriteCB(CSOUND *csound);
void csoundSetExternalMidiOutCloseCB(CSOUND *csound);
void csoundSetExternalMidiErrorStringCB(CSOUND *csound);
void csoundSetMidiDeviceListCB(CSOUND *csound);
void csoundSetCscoreCB(CSOUND *csound);
void csoundSetInputChannelCB(CSOUND *csound);
void csoundSetOutputChannelCB(CSOUND *csound);
int csoundRegisterSenseEventCB(CSOUND *csound, void *userData, int);
void csoundSetMakeGraphCB(CSOUND *csound);
void csoundSetDrawGraphCB(CSOUND *csound);
void csoundSetKillGraphCB(CSOUND *csound);
void csoundSetExitGraphCB(CSOUND *csound);
void csoundSetYieldCB(CSOUND *csound);
*/
import "C"
import (
"fmt"
"reflect"
"sync"
"unsafe"
)
type CsRtAudioParams struct {
devName string // device name (NULL/empty: default)
devNum int32 // device number (0-1023), 1024: default
bufSamp_SW uint32 // buffer fragment size (-b) in sample frames
bufSamp_HW int32 // total buffer size (-B) in sample frames
nChannels int32 // number of channels
sampleFormat int32 // sample format (AE_SHORT etc.)
sampleRate float32 // sample rate in Hz
}
////////////////////////////////////////////////////////////////
type FileOpenHandler func(csound CSOUND, pathName string, fileType int, write, temp bool)
var fileOpenH FileOpenHandler
//export goFileOpenCB
func goFileOpenCB(csound unsafe.Pointer, pathName *C.char, fileType, write, temp C.int) {
if fileOpenH == nil {
return
}
cs := CSOUND{(*C.CSOUND)(csound)}
fileOpenH(cs, C.GoString(pathName), int(fileType), write != 0, temp != 0)
}
// Set an external callback for receiving notices whenever Csound opens
// a file. The callback is made after the file is successfully opened.
// The following information is passed to the callback:
// string pathname of the file; either full or relative to current dir
// int a file type code from the enumeration CSOUND_FILETYPES
// bool true if Csound is writing the file, false if reading
// bool true if a temporary file that Csound will delete; false if not
//
// Pass nil to disable the callback.
// This callback is retained after a Reset() call.
func (csound CSOUND) SetFileOpenCallback(f FileOpenHandler) {
fileOpenH = f
if f == nil {
C.csoundSetFileOpenCallback(csound.Cs, nil)
return
}
C.csoundSetFileOpenCB(csound.Cs)
}
////////////////////////////////////////////////////////////////
type PlayOpenHandler func(csound CSOUND, parm *CsRtAudioParams) int32
var playOpenH PlayOpenHandler
//export goPlayOpenCB
func goPlayOpenCB(csound unsafe.Pointer, parm *C.csRtAudioParams) int32 {
if playOpenH == nil {
return -1
}
cs := CSOUND{(*C.CSOUND)(csound)}
goParm := &CsRtAudioParams{
devName: C.GoString(parm.devName),
devNum: int32(parm.devNum),
bufSamp_SW: uint32(parm.bufSamp_SW),
bufSamp_HW: int32(parm.bufSamp_HW),
nChannels: int32(parm.nChannels),
sampleFormat: int32(parm.sampleFormat),
sampleRate: float32(parm.sampleRate),
}
return playOpenH(cs, goParm)
}
// Set a function to be called by Csound for opening real-time
// audio playback.
func (csound CSOUND) SetPlayOpenCallback(f PlayOpenHandler) {
playOpenH = f
C.csoundSetPlayOpenCB(csound.Cs)
}
////////////////////////////////////////////////////////////////
type RtPlayHandler func(csound CSOUND, outBuf []MYFLT)
var rtPlayH RtPlayHandler
//export goRtPlayCB
func goRtPlayCB(csound unsafe.Pointer, outBuf *C.MYFLT, length int32) {
if rtPlayH == nil {
return
}
cs := CSOUND{(*C.CSOUND)(csound)}
var slice []MYFLT
sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&slice))
sliceHeader.Cap = int(length)
sliceHeader.Len = int(length)
sliceHeader.Data = uintptr(unsafe.Pointer(outBuf))
rtPlayH(cs, slice)
}
// Set a function to be called by Csound for performing real-time
// audio playback.
func (csound CSOUND) SetRtPlayCallback(f RtPlayHandler) {
rtPlayH = f
C.csoundSetRtPlayCB(csound.Cs)
}
////////////////////////////////////////////////////////////////
type RecOpenHandler func(csound CSOUND, parm *CsRtAudioParams) int32
var recOpenH RecOpenHandler
//export goRecOpenCB
func goRecOpenCB(csound unsafe.Pointer, parm *C.csRtAudioParams) int32 {
if recOpenH == nil {
return -1
}
cs := CSOUND{(*C.CSOUND)(csound)}
goParm := &CsRtAudioParams{
devName: C.GoString(parm.devName),
devNum: int32(parm.devNum),
bufSamp_SW: uint32(parm.bufSamp_SW),
bufSamp_HW: int32(parm.bufSamp_HW),
nChannels: int32(parm.nChannels),
sampleFormat: int32(parm.sampleFormat),
sampleRate: float32(parm.sampleRate),
}
return recOpenH(cs, goParm)
}
// Set a function to be called by Csound for opening real-time
// audio recording.
func (csound CSOUND) SetRecOpenCallback(f RecOpenHandler) {
recOpenH = f
C.csoundSetRecOpenCB(csound.Cs)
}
////////////////////////////////////////////////////////////////
type RtRecordHandler func(csound CSOUND, inBuf []MYFLT) int32
var rtRecordH RtRecordHandler
//export goRtRecordCB
func goRtRecordCB(csound unsafe.Pointer, inBuf *C.MYFLT, length int32) int32 {
if rtRecordH == nil {
return -1
}
cs := CSOUND{(*C.CSOUND)(csound)}
var slice []MYFLT
sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&slice))
sliceHeader.Cap = int(length)
sliceHeader.Len = int(length)
sliceHeader.Data = uintptr(unsafe.Pointer(inBuf))
return rtRecordH(cs, slice)
}
// Set a function to be called by Csound for performing real-time
// audio recording.
func (csound CSOUND) SetRtRecordCallback(f RtRecordHandler) {
rtRecordH = f
C.csoundSetRtRecordCB(csound.Cs)
}
////////////////////////////////////////////////////////////////
type RtCloseHandler func(csound CSOUND)
var rtCloseH RtCloseHandler
//export goRtCloseCB
func goRtCloseCB(csound unsafe.Pointer) {
if rtCloseH == nil {
return
}
cs := CSOUND{(*C.CSOUND)(csound)}
rtCloseH(cs)
}
// Set a function to be called by Csound for closing real-time
// audio playback and recording.
func (csound CSOUND) SetRtCloseCallback(f RtCloseHandler) {
rtCloseH = f
C.csoundSetRtCloseCB(csound.Cs)
}
////////////////////////////////////////////////////////////////
type AudioDeviceListHandler func(csound CSOUND, list *CsoundAudioDevice, isOutput bool) int
var audioDevListH AudioDeviceListHandler
//export goAudioDeviceListCB
func goAudioDeviceListCB(csound unsafe.Pointer, list unsafe.Pointer, isOutput int32) int32 {
if audioDevListH == nil {
return -1
}
cs := CSOUND{(*C.CSOUND)(csound)}
return int32(audioDevListH(cs, (*CsoundAudioDevice)(list), isOutput != 0))
}
// Set a function that is called to obtain a list of audio devices.
// This should be set by rtaudio modules and should not be set by hosts.
// (See AudioDevList())
func (csound CSOUND) SetAudioDeviceListCallback(f AudioDeviceListHandler) {
audioDevListH = f
C.csoundSetAudioDeviceListCB(csound.Cs)
}
////////////////////////////////////////////////////////////////
type ExternalMidiInOpenHandler func(csound CSOUND, userData unsafe.Pointer, devName string) int32
var externalMidiInOpenH ExternalMidiInOpenHandler
//export goExternalMidiInOpenCB
func goExternalMidiInOpenCB(csound unsafe.Pointer, userData unsafe.Pointer, devName *C.char) int32 {
if externalMidiInOpenH == nil {
return -1
}
cs := CSOUND{(*C.CSOUND)(csound)}
return externalMidiInOpenH(cs, userData, C.GoString(devName))
}
// Set callback for opening real time MIDI input.
func (csound CSOUND) SetExternalMidiInOpenCallback(f ExternalMidiInOpenHandler) {
externalMidiInOpenH = f
C.csoundSetExternalMidiInOpenCB(csound.Cs)
}
////////////////////////////////////////////////////////////////
type ExternalMidiReadHandler func(csound CSOUND, userData unsafe.Pointer, buf []uint8) int32
var externalMidiReadH ExternalMidiReadHandler
//export goExternalMidiReadCB
func goExternalMidiReadCB(csound unsafe.Pointer, userData unsafe.Pointer, buf *C.uchar, nBytes int32) int32 {
if externalMidiReadH == nil {
return -1
}
cs := CSOUND{(*C.CSOUND)(csound)}
var slice []uint8
sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&slice))
sliceHeader.Cap = int(nBytes)
sliceHeader.Len = int(nBytes)
sliceHeader.Data = uintptr(unsafe.Pointer(buf))
return externalMidiReadH(cs, userData, slice)
}
// Set callback for reading from real time MIDI input.
func (csound CSOUND) SetExternalMidiReadCallback(f ExternalMidiReadHandler) {
externalMidiReadH = f
C.csoundSetExternalMidiReadCB(csound.Cs)
}
////////////////////////////////////////////////////////////////
type ExternalMidiInCloseHandler func(csound CSOUND, userData unsafe.Pointer) int32
var externalMidiInCloseH ExternalMidiInCloseHandler
//export goExternalMidiInCloseCB
func goExternalMidiInCloseCB(csound unsafe.Pointer, userData unsafe.Pointer) int32 {
if externalMidiInCloseH == nil {
return -1
}
cs := CSOUND{(*C.CSOUND)(csound)}
return externalMidiInCloseH(cs, userData)
}
// Set callback for closing real time MIDI input.
func (csound CSOUND) SetExternalMidiInCloseCallback(f ExternalMidiInCloseHandler) {
externalMidiInCloseH = f
C.csoundSetExternalMidiInCloseCB(csound.Cs)
}
////////////////////////////////////////////////////////////////
type ExternalMidiOutOpenHandler func(csound CSOUND, userData unsafe.Pointer, devName string) int32
var externalMidiOutOpenH ExternalMidiOutOpenHandler
//export goExternalMidiOutOpenCB
func goExternalMidiOutOpenCB(csound unsafe.Pointer, userData unsafe.Pointer, devName *C.char) int32 {
if externalMidiOutOpenH == nil {
return -1
}
cs := CSOUND{(*C.CSOUND)(csound)}
return externalMidiOutOpenH(cs, userData, C.GoString(devName))
}
// Set callback for opening real time MIDI output.
func (csound CSOUND) SetExternalMidiOutOpenCallback(f ExternalMidiOutOpenHandler) {
externalMidiOutOpenH = f
C.csoundSetExternalMidiOutOpenCB(csound.Cs)
}
////////////////////////////////////////////////////////////////
type ExternalMidiWriteHandler func(csound CSOUND, userData unsafe.Pointer, buf []uint8) int32
var externalMidiWriteH ExternalMidiWriteHandler
//export goExternalMidiWriteCB
func goExternalMidiWriteCB(csound unsafe.Pointer, userData unsafe.Pointer, buf *C.uchar, nBytes int32) int32 {
if externalMidiWriteH == nil {
return -1
}
cs := CSOUND{(*C.CSOUND)(csound)}
var slice []uint8
sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&slice))
sliceHeader.Cap = int(nBytes)
sliceHeader.Len = int(nBytes)
sliceHeader.Data = uintptr(unsafe.Pointer(buf))
return externalMidiWriteH(cs, userData, slice)
}
// Set callback for writing to real time MIDI output.
func (csound CSOUND) SetExternalMidiWriteCallback(f ExternalMidiWriteHandler) {
externalMidiWriteH = f
C.csoundSetExternalMidiWriteCB(csound.Cs)
}
////////////////////////////////////////////////////////////////
type ExternalMidiOutCloseHandler func(csound CSOUND, userData unsafe.Pointer) int32
var externalMidiOutCloseH ExternalMidiOutCloseHandler
//export goExternalMidiOutCloseCB
func goExternalMidiOutCloseCB(csound unsafe.Pointer, userData unsafe.Pointer) int32 {
if externalMidiOutCloseH == nil {
return -1
}
cs := CSOUND{(*C.CSOUND)(csound)}
return externalMidiOutCloseH(cs, userData)
}
// Set callback for closing real time MIDI output.
func (csound CSOUND) SetExternalMidiOutCloseCallback(f ExternalMidiOutCloseHandler) {
externalMidiOutCloseH = f
C.csoundSetExternalMidiOutCloseCB(csound.Cs)
}
////////////////////////////////////////////////////////////////
type ExternalMidiErrorStringHandler func(err int) string
var externalMidiErrorStringH ExternalMidiErrorStringHandler
//export goExternalMidiErrorStringCB
func goExternalMidiErrorStringCB(err int32) *C.char {
if externalMidiErrorStringH == nil {
return nil
}
s := externalMidiErrorStringH(int(err))
return C.CString(s)
}
// Set callback for converting MIDI error codes to strings.
func (csound CSOUND) SetExternalMidiErrorStringCallback(f ExternalMidiErrorStringHandler) {
externalMidiErrorStringH = f
C.csoundSetExternalMidiErrorStringCB(csound.Cs)
}
////////////////////////////////////////////////////////////////
type MidiDeviceListHandler func(csound CSOUND, list *CsoundMidiDevice, isOutput bool) int
var midiDevListH MidiDeviceListHandler
//export goMidiDeviceListCB
func goMidiDeviceListCB(csound unsafe.Pointer, list unsafe.Pointer, isOutput int32) int32 {
if midiDevListH == nil {
return -1
}
cs := CSOUND{(*C.CSOUND)(csound)}
return int32(midiDevListH(cs, (*CsoundMidiDevice)(list), isOutput != 0))
}
// Set a function that is called to obtain a list of MIDI devices.
// This should be set by IO plugins, and should not be set by hosts.
// (See MidiDevList())
func (csound CSOUND) SetMidiDeviceListCallback(f MidiDeviceListHandler) {
midiDevListH = f
C.csoundSetMidiDeviceListCB(csound.Cs)
}
////////////////////////////////////////////////////////////////
type CscoreHandler func(csound CSOUND)
var cscoreH CscoreHandler
//export goCscoreCB
func goCscoreCB(csound unsafe.Pointer) {
if cscoreH == nil {
return
}
cs := CSOUND{(*C.CSOUND)(csound)}
cscoreH(cs)
}
// Set an external callback for Cscore processing.
// Pass nil to reset to the internal cscore() function
// (which does nothing).
// This callback is retained after a Reset() call.
func (csound CSOUND) SetCscoreCallback(f CscoreHandler) {
cscoreH = f
if f == nil {
C.csoundSetCscoreCallback(csound.Cs, nil)
return
}
C.csoundSetCscoreCB(csound.Cs)
}
////////////////////////////////////////////////////////////////
// TODO:
// setDefaultMessageCallback
// setMesssageCallback
////////////////////////////////////////////////////////////////
type ChannelHandler func(csound CSOUND, channelName string,
channelValue []MYFLT, channelType int)
var inputChannelH ChannelHandler
//export goInputChannelCB
func goInputChannelCB(csound unsafe.Pointer, channelName *C.char,
channelValuePtr unsafe.Pointer, channelType unsafe.Pointer) {
if inputChannelH == nil {
return
}
cs := CSOUND{(*C.CSOUND)(csound)}
var length, chnType int
if channelType == unsafe.Pointer(&C.CS_VAR_TYPE_K) {
length = 1
chnType = CSOUND_CONTROL_CHANNEL
} else if channelType == unsafe.Pointer(&C.CS_VAR_TYPE_A) {
length = int(C.csoundGetKsmps(cs.Cs))
chnType = CSOUND_AUDIO_CHANNEL
} else if channelType == unsafe.Pointer(&C.CS_VAR_TYPE_S) {
length = int(C.csoundGetChannelDatasize(cs.Cs, channelName))
chnType = CSOUND_STRING_CHANNEL
} else {
return
}
var slice []MYFLT
sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&slice))
sliceHeader.Cap = length
sliceHeader.Len = length
sliceHeader.Data = uintptr(channelValuePtr)
inputChannelH(cs, C.GoString(channelName), slice, chnType)
}
// Set the function which will be called whenever the invalue opcode is used.
func (csound CSOUND) SetInputChannelCallback(f ChannelHandler) {
inputChannelH = f
C.csoundSetInputChannelCB(csound.Cs)
}
var outputChannelH ChannelHandler
//export goOutputChannelCB
func goOutputChannelCB(csound unsafe.Pointer, channelName *C.char,
channelValuePtr unsafe.Pointer, channelType unsafe.Pointer) {
if outputChannelH == nil {
return
}
cs := CSOUND{(*C.CSOUND)(csound)}
var length, chnType int
if channelType == unsafe.Pointer(&C.CS_VAR_TYPE_K) {
length = 1
chnType = CSOUND_CONTROL_CHANNEL
} else if channelType == unsafe.Pointer(&C.CS_VAR_TYPE_A) {
length = int(C.csoundGetKsmps(cs.Cs))
chnType = CSOUND_AUDIO_CHANNEL
} else if channelType == unsafe.Pointer(&C.CS_VAR_TYPE_S) {
length = int(C.csoundGetChannelDatasize(cs.Cs, channelName))
chnType = CSOUND_STRING_CHANNEL
} else {
return
}
var slice []MYFLT
sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&slice))
sliceHeader.Cap = length
sliceHeader.Len = length
sliceHeader.Data = uintptr(channelValuePtr)
outputChannelH(cs, C.GoString(channelName), slice, chnType)
}
// Set the function which will be called whenever the outvalue opcode is used.
func (csound CSOUND) SetOutputChannelCallback(f ChannelHandler) {
outputChannelH = f
C.csoundSetOutputChannelCB(csound.Cs)
}
////////////////////////////////////////////////////////////////
type SenseEventHandler func(csound CSOUND, userData unsafe.Pointer)
const maxNumSenseEvent = 10
var senseEventH []SenseEventHandler = make([]SenseEventHandler, maxNumSenseEvent)
var numSenseEvent int
// Workaround to avoid the 'cgo argument has Go pointer to Go pointer'
// runtime error (since go1.6)
var registry = make(map[int]unsafe.Pointer)
var indexes int
var mutex = sync.Mutex{}
//export goSenseEventCB
func goSenseEventCB(csound, userData unsafe.Pointer, numFun int32) {
if senseEventH[numFun] == nil {
return
}
cs := CSOUND{(*C.CSOUND)(csound)}
mutex.Lock()
userDataP := registry[*(*int)(userData)]
mutex.Unlock()
senseEventH[numFun](cs, userDataP)
}
// Register a function to be called once in every control period
// by sensevents(). Any number of functions may be registered,
// and will be called in the order of registration.
// The callback function takes two arguments: the Csound instance
// pointer, and the userData pointer as passed to this function.
// This facility can be used to ensure a function is called synchronously
// before every csound control buffer processing. It is important
// to make sure no blocking operations are performed in the callback.
// The callbacks are cleared on Cleanup().
// Returns zero on success.
func (csound CSOUND) RegisterSenseEventCallback(f SenseEventHandler,
userData unsafe.Pointer) (ret int, err error) {
if numSenseEvent < maxNumSenseEvent {
mutex.Lock()
index := indexes
registry[index] = userData
mutex.Unlock()
ret = int(C.csoundRegisterSenseEventCB(csound.Cs, unsafe.Pointer(&index), C.int(numSenseEvent)))
if ret != 0 {
err = fmt.Errorf("Csound could not register SenseEvent callback %d", numSenseEvent)
} else {
senseEventH[numSenseEvent] = f
numSenseEvent++
indexes++
}
return
}
ret = -1
err = fmt.Errorf("%d SenseEvent callbacks already registered! Max value reached", numSenseEvent)
return
}
////////////////////////////////////////////////////////////////
// TODO:
// RegisterKeyboardCallback
// RemoveKeyboardCallback
////////////////////////////////////////////////////////////////
type MakeGraphHandler func(csound CSOUND, windat unsafe.Pointer, name string)
type GraphHandler func(csound CSOUND, windat unsafe.Pointer)
type ExitGraphHandler func(csound CSOUND) int32
var makeGraphH MakeGraphHandler
var drawGraphH, killGraphH GraphHandler
var exitGraphH ExitGraphHandler
//export goMakeGraphCB
func goMakeGraphCB(csound, windat unsafe.Pointer, name *C.char) {
if makeGraphH == nil {
return
}
cs := CSOUND{(*C.CSOUND)(csound)}
makeGraphH(cs, windat, C.GoString(name))
}
//export goDrawGraphCB
func goDrawGraphCB(csound, windat unsafe.Pointer) {
if drawGraphH == nil {
return
}
cs := CSOUND{(*C.CSOUND)(csound)}
drawGraphH(cs, windat)
}
//export goKillGraphCB
func goKillGraphCB(csound, windat unsafe.Pointer) {
if killGraphH == nil {
return
}
cs := CSOUND{(*C.CSOUND)(csound)}
killGraphH(cs, windat)
}
//export goExitGraphCB
func goExitGraphCB(csound unsafe.Pointer) int32 {
if exitGraphH == nil {
return -1
}
cs := CSOUND{(*C.CSOUND)(csound)}
return exitGraphH(cs)
}
// Called by external software to set Csound's MakeGraph function.
func (csound CSOUND) SetMakeGraphCallback(f MakeGraphHandler) {
makeGraphH = f
C.csoundSetMakeGraphCB(csound.Cs)
}
// Called by external software to set Csound's DrawGraph function.
func (csound CSOUND) SetDrawGraphCallback(f GraphHandler) {
drawGraphH = f
C.csoundSetDrawGraphCB(csound.Cs)
}
// Called by external software to set Csound's KillGraph function.
func (csound CSOUND) SetKillGraphCallback(f GraphHandler) {
killGraphH = f
C.csoundSetKillGraphCB(csound.Cs)
}
// Called by external software to set Csound's ExitGraph function.
func (csound CSOUND) SetExitGraphCallback(f ExitGraphHandler) {
exitGraphH = f
C.csoundSetExitGraphCB(csound.Cs)
}
////////////////////////////////////////////////////////////////
type YieldHandler func(csound CSOUND) bool
var yieldH YieldHandler
//export goYieldCB
func goYieldCB(csound unsafe.Pointer) int32 {
if yieldH == nil {
return 0
}
cs := CSOUND{(*C.CSOUND)(csound)}
if yieldH(cs) {
return 1
} else {
return 0
}
}
// Called by external software to set a function for checking system
// events, yielding cpu time for coopertative multitasking, etc.
// This function is optional. It is often used as a way to 'turn off'
// Csound, allowing it to exit gracefully. In addition, some operations
// like utility analysis routines are not reentrant and you should use
// this function to do any kind of updating during the operation.
// Returns an 'OK to continue' boolean.
func (csound CSOUND) SetYieldCallback(f YieldHandler) {
yieldH = f
C.csoundSetYieldCB(csound.Cs)
}