-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui_bridge_darwin.go
More file actions
234 lines (205 loc) · 5.18 KB
/
ui_bridge_darwin.go
File metadata and controls
234 lines (205 loc) · 5.18 KB
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
//go:build darwin
package main
// #include <stdlib.h>
import "C"
import (
cfgPkg "ambientgo/internal/config"
engPkg "ambientgo/internal/engine"
"math"
"sync/atomic"
)
//export GoSetVolume
func GoSetVolume(v C.double) {
if appState != nil && appState.CtrlCh != nil {
appState.CtrlCh <- engPkg.ControlMsg{Kind: "volume", F1: float64(v)}
}
}
//export GoTogglePlay
func GoTogglePlay() {
if appState != nil && appState.Ctrl != nil {
appState.Ctrl.Paused = !appState.Ctrl.Paused
}
}
//export GoSetPads
func GoSetPads(a, b C.double) {
if appState != nil && appState.CtrlCh != nil {
appState.CtrlCh <- engPkg.ControlMsg{Kind: "pads", F1: float64(a), F2: float64(b)}
}
}
//export GoSetNoise
func GoSetNoise(amp C.double) {
if appState != nil && appState.CtrlCh != nil {
appState.CtrlCh <- engPkg.ControlMsg{Kind: "noise", F1: float64(amp)}
}
}
//export GoSetDelay
func GoSetDelay(mix C.double) {
if appState != nil && appState.CtrlCh != nil {
appState.CtrlCh <- engPkg.ControlMsg{Kind: "delayMix", F1: float64(mix)}
}
}
//export GoSetVibe
func GoSetVibe(v C.double) {
if appState != nil && appState.CtrlCh != nil {
appState.CtrlCh <- engPkg.ControlMsg{Kind: "vibe", F1: float64(v)}
}
}
//export GoSetBPM
func GoSetBPM(b C.double) {
if appState != nil && appState.CtrlCh != nil {
appState.CtrlCh <- engPkg.ControlMsg{Kind: "bpm", F1: float64(b)}
}
}
//export GoSetAmbience
func GoSetAmbience(a C.double) {
if appState != nil && appState.CtrlCh != nil {
appState.CtrlCh <- engPkg.ControlMsg{Kind: "ambience", F1: float64(a)}
}
}
//export GoSetReverb
func GoSetReverb(mix, decay C.double) {
if appState != nil && appState.CtrlCh != nil {
appState.CtrlCh <- engPkg.ControlMsg{Kind: "reverb", F1: float64(mix), F2: float64(decay)}
}
}
//export GoGetVU
func GoGetVU() C.double {
return C.double(math.Float64frombits(atomic.LoadUint64(&vizVUbits)))
}
//export GoGetAmbienceVal
func GoGetAmbienceVal() C.double {
if appState != nil {
return C.double(appState.Amb)
}
return C.double(0)
}
//export GoGetVibeVal
func GoGetVibeVal() C.double {
if appState != nil {
return C.double(appState.Vibe)
}
return C.double(0)
}
//export GoGetBPMVal
func GoGetBPMVal() C.double {
if appState != nil {
return C.double(appState.Bpm)
}
return C.double(80)
}
//export GoGetPadAHz
func GoGetPadAHz() C.double {
if appState != nil && appState.CurAHz > 0 {
return C.double(appState.CurAHz)
}
return C.double(110)
}
//export GoGetPadBHz
func GoGetPadBHz() C.double {
if appState != nil && appState.CurBHz > 0 {
return C.double(appState.CurBHz)
}
return C.double(146.8)
}
//export GoGetNoiseAmp
func GoGetNoiseAmp() C.double {
if appState != nil {
return C.double(appState.NoiseAmp)
}
return C.double(0)
}
//export GoSetBladePad
func GoSetBladePad(x, y C.double) {
if appState != nil && appState.CtrlCh != nil {
appState.CtrlCh <- engPkg.ControlMsg{Kind: "brpad", F1: float64(x), F2: float64(y)}
}
}
//export GoGetSpectrumCount
func GoGetSpectrumCount() C.int {
vizSpecMu.RLock()
n := len(vizSpec)
vizSpecMu.RUnlock()
return C.int(n)
}
//export GoGetSpectrumBin
func GoGetSpectrumBin(i C.int) C.double {
idx := int(i)
vizSpecMu.RLock()
defer vizSpecMu.RUnlock()
if idx >= 0 && idx < len(vizSpec) {
return C.double(vizSpec[idx])
}
return 0
}
//export GoGetSpectrumBinFreq
func GoGetSpectrumBinFreq(i C.int) C.double {
n := vizNFFT
if n <= 0 {
n = 2048
}
// fs comes from audio package constant
fs := float64(sampleRate)
f := (float64(i) * fs) / float64(n)
return C.double(f)
}
//export GoApplyPreset
func GoApplyPreset(kind C.int) {
if appState == nil || appState.CtrlCh == nil {
return
}
s := ""
switch int(kind) {
case 0:
s = "cathedral"
case 1:
s = "noir"
case 2:
s = "starscape"
}
if s != "" {
appState.CtrlCh <- engPkg.ControlMsg{Kind: "preset", S: s}
}
}
//export GoSetAIMood
func GoSetAIMood(m C.double) {
if appState != nil && appState.CtrlCh != nil {
appState.CtrlCh <- engPkg.ControlMsg{Kind: "ai_mood", F1: float64(m)}
}
}
//export GoSetHQReverb
func GoSetHQReverb(on C.int) {
if appState != nil && appState.CtrlCh != nil {
appState.CtrlCh <- engPkg.ControlMsg{Kind: "hq_reverb", I: int(on)}
}
}
//export GoSetTractorLevel
func GoSetTractorLevel(v C.double) {
if appState != nil && appState.CtrlCh != nil {
appState.CtrlCh <- engPkg.ControlMsg{Kind: "tractor_level", F1: float64(v)}
}
}
//export GoSetTractorDrive
func GoSetTractorDrive(v C.double) {
if appState != nil && appState.CtrlCh != nil {
appState.CtrlCh <- engPkg.ControlMsg{Kind: "tractor_drive", F1: float64(v)}
}
}
//export GoSetTractorRate
func GoSetTractorRate(v C.double) {
if appState != nil && appState.CtrlCh != nil {
appState.CtrlCh <- engPkg.ControlMsg{Kind: "tractor_rate", F1: float64(v)}
}
}
//export GoSaveSettings
func GoSaveSettings() {
if appState == nil {
return
}
cfg, _ := cfgPkg.Load()
cfg.Settings.Vibe = appState.Vibe
cfg.Settings.BPM = appState.Bpm
cfg.Settings.Ambience = appState.Amb
cfg.Settings.AIMood = appState.AiMood
cfg.Settings.HQReverb = appState.HqReverb
_ = cfgPkg.Save(cfg)
}