diff options
author | Richard <q@1bpm.net> | 2025-04-13 18:48:02 +0100 |
---|---|---|
committer | Richard <q@1bpm.net> | 2025-04-13 18:48:02 +0100 |
commit | 9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22 (patch) | |
tree | 291bd79ce340e67affa755a8a6b4f6a83cce93ea /site/udo/wiimote_fltk.udo | |
download | apps.csound.1bpm.net-9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22.tar.gz apps.csound.1bpm.net-9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22.tar.bz2 apps.csound.1bpm.net-9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22.zip |
initial
Diffstat (limited to 'site/udo/wiimote_fltk.udo')
-rwxr-xr-x | site/udo/wiimote_fltk.udo | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/site/udo/wiimote_fltk.udo b/site/udo/wiimote_fltk.udo new file mode 100755 index 0000000..38bb91d --- /dev/null +++ b/site/udo/wiimote_fltk.udo @@ -0,0 +1,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
|