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
|
#ifndef UDO_WIIMOTE
#define UDO_WIIMOTE ##
/*
Wiimote FLTK debugging/substitution interface
This file is part of the SONICS UDO collection by Richard Knight 2023
License: GPL-2.0-or-later
http://1bpm.net
*/
#include "interop.udo"
FLpanel "WiiBug", 600, 500, 100, 100, 0, 1, 1
gkwii_pitch, gkwii_roll, gij1x, gij1y FLjoy "Main pitch and roll", 0, 1, 0, 1, 0, 0, -1, -1, 200, 200, 0, 0
#ifdef USE_WIIMOTE_NUNCHUCK
gkwii_ncpitch, gkwii_ncroll, gij2x, gij2y FLjoy "Nunchuck pitch and roll", 0, 1, 0, 1, 0, 0, -1, -1, 200, 200, 200, 0
gkj3x, gkj3y, gij3x, gij3y FLjoy "Nunchuck angle and mag", 0, 1, 0, 1, 0, 0, -1, -1, 200, 200, 400, 0
#end
gkb1, gib1 FLbutton "1", 1, 0, 2, 50, 50, 0, 250, -1
gkb2, gib2 FLbutton "2", 1, 0, 2, 50, 50, 50, 250, -1
gkbA, gibA FLbutton "A", 1, 0, 2, 50, 50, 100, 250, -1
gkbB, gibB FLbutton "B", 1, 0, 2, 50, 50, 150, 250, -1
gkbHome, gibHome FLbutton "Home", 1, 0, 2, 50, 50, 200, 250, -1
gkbMinus, gibMinus FLbutton "Minus", 1, 0, 2, 50, 50, 250, 250, -1
gkbPlus, gibPlus FLbutton "Plus", 1, 0, 2, 50, 50, 300, 250, -1
gkbLeft, gibLeft FLbutton "Left", 1, 0, 2, 50, 50, 0, 300, -1
gkbRight, gibRight FLbutton "Right", 1, 0, 2, 50, 50, 50, 300, -1
gkbUp, gibUp FLbutton "Up", 1, 0, 2, 50, 50, 100, 300, -1
gkbDown, gibDown FLbutton "Down", 1, 0, 2, 50, 50, 150, 300, -1
#ifdef USE_WIIMOTE_NUNCHUCK
gkbZ, gibC FLbutton "Z", 1, 0, 2, 50, 50, 200, 300, -1
gkbC, gibZ FLbutton "C", 1, 0, 2, 50, 50, 250, 300, -1
#end
gkwii_accelX, gis1 FLslider "Accel X", 0, 1, 0, 1, -1, 400, 35, 0, 350
gkwii_accelY, gis2 FLslider "Accel Y", 0, 1, 0, 1, -1, 400, 35, 0, 400
gkwii_accelZ, gis3 FLslider "Accel Z", 0, 1, 0, 1, -1, 400, 35, 0, 450
FLpanelEnd
FLrun
; button bit masks
#define WII_1 #2#
#define WII_2 #1#
#define WII_A #8#
#define WII_B #4#
#define WII_HOME #128#
#define WII_MINUS #16#
#define WII_PLUS #4096#
#define WII_LEFT #256#
#define WII_RIGHT #512#
#define WII_UP #2048#
#define WII_DOWN #1024#
#ifdef USE_WIIMOTE_NUNCHUCK
#define WII_Z #-33#
#define WII_C #-34#
gkwii_ncang init 0
gkwii_ncmag init 0
#end
/*
Get the state of a wiimote button
kstate wii_button ibutton
kstate 1 if pressed/held or 0 if not
ibutton the bit mask of the button; use the macros defined
*/
opcode wii_button, k, i
ibutton xin
if (ibutton == $WII_1) then
kvalue = gkb1
elseif (ibutton == $WII_2) then
kvalue = gkb2
elseif (ibutton == $WII_A) then
kvalue = gkbA
elseif (ibutton == $WII_B) then
kvalue = gkbB
elseif (ibutton == $WII_HOME) then
kvalue = gkbHome
elseif (ibutton == $WII_MINUS) then
kvalue = gkbMinus
elseif (ibutton == $WII_PLUS) then
kvalue = gkbPlus
elseif (ibutton == $WII_LEFT) then
kvalue = gkbLeft
elseif (ibutton == $WII_RIGHT) then
kvalue = gkbRight
elseif (ibutton == $WII_UP) then
kvalue = gkbUp
elseif (ibutton == $WII_DOWN) then
kvalue = gkbDown
#ifdef USE_WIIMOTE_NUNCHUCK
elseif (ibutton == $WII_Z) then
kvalue = gkbZ
elseif (ibutton == $WII_C) then
kvalue = gkbC
#end
else
kvalue init 0
endif
xout kvalue
endop
/*
Keep an instrument on for as long as a wiimote button is held
wii_buttonhold ibutton, Sinstrument
ibutton the bit mask of the button; use the macros defined
Sinstrument instrument name to start/stop accordingly
*/
opcode wii_buttonhold, 0, iS
ibutton, Sinstrument xin
kbut = wii_button(ibutton)
if (changed:k(kbut) == 1) then
if (kbut == 1) then
schedulek(Sinstrument, 0, -1)
else
turnoff2(Sinstrument, 0, 1)
endif
endif
endop
opcode wii_buttonhold, 0, iSi
ibutton, Sinstrument, ip4 xin
kbut = wii_button(ibutton)
if (changed:k(kbut) == 1) then
if (kbut == 1) then
schedulek(Sinstrument, 0, -1, ip4)
else
turnoff2(Sinstrument, 0, 1)
endif
endif
endop
/*
Use the wiimote minus and plus buttons to scroll through item indexes
kitem wii_pager imaxitems [, iteminitial=0, ksetindex=-1]
kitem the selected item/page
imaxindex maximum number of items
initialindex initial value
ksetindex set the item index directly with this
*/
opcode wii_pager, k, ioJ
imaxindex, initialindex, ksetindex xin
kcurrentitem init initialindex
kplus = wii_button($WII_PLUS)
kminus = wii_button($WII_MINUS)
if (kminus == 1 && changed:k(kminus) == 1) then
if (kcurrentitem == 0) then
kcurrentitem = imaxindex
else
kcurrentitem -= 1
endif
elseif (kplus == 1 && changed:k(kplus) == 1) then
if (kcurrentitem == imaxindex) then
kcurrentitem = 0
else
kcurrentitem += 1
endif
elseif (changed:k(ksetindex) == 1) then
if (ksetindex >= 0 && ksetindex <= imaxindex) then
kcurrentitem = ksetindex
endif
endif
xout kcurrentitem
endop
instr wii_handler
icbid = p4
SonComplete = strget(p5)
SonFailWatchdog = strget(p6)
iconnecttimeout = (p7 == 0) ? 1 : p7
if (icbid > 0) then
io_sendstring("callback", sprintf("{\"cbid\": %d, \"success\": true}", icbid))
endif
if (strcmp(SonComplete, "") != 0) then
schedule(SonComplete, 0, -1)
endif
endin
#end
|