forked from lexesv/gobass.dll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannel.go
169 lines (154 loc) · 4.7 KB
/
channel.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
package bass
/*
#include "bass.h"
#include "stdlib.h"
*/
import "C"
import (
"unsafe"
"runtime/cgo"
)
type Channel struct {
handle C.DWORD
}
func (self Channel) cint() C.DWORD {
return self.handle
}
func (self Channel) GetHandle() uint32 {
return uint32(self.handle)
}
func (self Channel) toStream() Stream {
return Stream{Channel: self}
}
// internal function, do not use
func (self Channel) ToError() (Channel, error) {
if self.handle == 0 {
return Channel{}, GetLastError()
} else {
return self, nil
}
}
// somewhat unsafe function that creates a channel from a raw BASS handle.
func ChannelFromHandle(handle uint32) Channel {
return Channel{handle: C.DWORD(handle)}
}
func (self Channel) SetSync(syncType int, flags Flags, param int, callback cgo.Handle) (Sync, error) {
sync := Sync(C.BASS_ChannelSetSync(self.cint(), cuint(syncType)|cuint(flags), culong(param), goSyncprocCallback, unsafe.Pointer(callback)))
if sync == 0 {
return 0, errMsg()
} else {
return sync, nil
}
}
func (self Channel) SetSyncCCallback(syncType int, flags Flags, param int, callback *C.SYNCPROC, userdata unsafe.Pointer) (Sync, error) {
sync := Sync(C.BASS_ChannelSetSync(self.cint(), cuint(syncType)|cuint(flags), culong(param), callback, userdata))
if sync == 0 {
return 0, errMsg()
} else {
return sync, nil
}
}
// ChannelPlay
// BOOL BASSDEF(BASS_ChannelPlay)(DWORD handle, BOOL restart);
func (self Channel) Play(restart bool) error {
return boolToError(C.BASS_ChannelPlay(self.cint(), boolToInt(restart)))
}
// ChannelPause
// BOOL BASSDEF(BASS_ChannelPause)(DWORD handle);
func (self Channel) Pause() error {
return boolToError(C.BASS_ChannelPause(self.cint()))
}
// ChannelStop
// BOOL BASSDEF(BASS_ChannelStop)(DWORD handle);
func (self Channel) Stop() error {
return boolToError(C.BASS_ChannelStop(self.cint()))
}
func (self Channel) IsActive() (int, error) {
active := int(C.BASS_ChannelIsActive(self.cint()))
if active==ACTIVE_STOPPED {
return active, errMsg()
} else {
return active, nil
}
}
// ChannelGetAttribute
// BOOL BASSDEF(BASS_ChannelGetAttribute)(DWORD handle, DWORD attrib, float *value);
func (self Channel) GetAttribute(attrib int) (float64, error) {
var cvalue C.float
result:=C.BASS_ChannelGetAttribute(self.cint(), C.DWORD(attrib), &cvalue)
return float64(cvalue), boolToError(result)
}
// ChannelSetAttribute
// BOOL BASSDEF(BASS_ChannelSetAttribute)(DWORD handle, DWORD attrib, float value);
func (self Channel) SetAttribute(attrib int, value float64) error {
return boolToError(C.BASS_ChannelSetAttribute(self.cint(), C.DWORD(attrib), C.float(value)))
}
//ChannelGetLevel
//DWORD BASSDEF(BASS_ChannelGetLevel)(DWORD handle);
func (self Channel) GetLevel() (c int, e error) {
c = int(C.BASS_ChannelGetLevel(self.cint()))
if c == -1 {
return 0, errMsg()
}
return c, nil
}
// ChannelGetTags
// const char *BASSDEF(BASS_ChannelGetTags)(DWORD handle, DWORD tags);
func (self Channel) GetTags(tag int) string {
return C.GoString(C.BASS_ChannelGetTags(self.cint(), C.DWORD(tag)))
}
func (self Channel) SlideAttribute(attrib uint64, value float64, time uint64) error {
return boolToError(C.BASS_ChannelSlideAttribute(self.cint(), cuint(attrib), C.float(value), cuint(time)))
}
func (self Channel) SetPosition(pos, mode int) error {
return boolToError(C.BASS_ChannelSetPosition(self.cint(), culong(pos), cuint(mode)))
}
func (self Channel) GetPosition(mode uint64) (int, error) {
value := C.BASS_ChannelGetPosition(self.cint(), C.DWORD(mode))
if value+1 == 0 {
return 0, errMsg()
} else {
return int(value), nil
}
}
func (self Channel) GetLength(mode uint64) (int, error) {
result := C.BASS_ChannelGetLength(self.cint(), C.DWORD(mode))
if result +1 == 0 {
return 0, errMsg()
} else {
return int(result), nil
}
}
func (self Channel) Bytes2Seconds(bytes int) (float64, error) {
value:=float64(C.BASS_ChannelBytes2Seconds(self.cint(), C.QWORD(bytes)))
if value<0 {
return value, errMsg()
} else {
return value, nil
}
}
func (self Channel) Seconds2Bytes(seconds float64) (int, error) {
res := int(C.BASS_ChannelSeconds2Bytes(self.cint(), C.double(seconds)))
if res == -1 {
return 0, GetLastError()
}
return res, nil
}
func (self Channel) Flags(flags, mask Flags) (Flags, error) {
return Flags(C.BASS_ChannelFlags(self.cint(), cuint(flags), cuint(mask))), errMsg()
}
func (self Channel) GetData(data []byte, flags Flags) (int, error) {
var ptr unsafe.Pointer
if len(data)>0 {
ptr = unsafe.Pointer(&data[0])
}
val := C.BASS_ChannelGetData(self.cint(), ptr, C.DWORD(len(data)|int(flags)))
if val +1 == 0 { // -1 indicates an error, but this is an unsigned integer
return 0, errMsg()
} else {
return int(val), nil
}
}
func (self Channel) Free() error {
return boolToError(C.BASS_ChannelFree(self.cint()))
}