joystick

Description

Syntax

kres joystick kdevice ktab

Performance

Note

Please note that this opcode is currently only supported on
Linux.

kdevice -- the index of the joystick device, either /dev/jsN or
/dev/input/jsN.

ktab -- A table to hold input results,
should be at least enough elements to store one value for each
stick axis and one for each button + 2. The first two elements
of the table are initialized with the number of axes and the
number of buttons, respectively, when a joystick is opened. If a
joystick is unplugged during performance, the opcode will
repeatedly attempt to reopen the device with a delay between
attempts.

Examples

Here is an example of the joystick opcode. It uses the file joystick.csd.

<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform
-odac ;;;realtime audio out;-iadc ;;;uncomment -iadc if realtime audio input is needed too; For Non-realtime ouput leave only the line below:; -o joystick.wav -W ;;; for file output any platform</CsOptions><CsInstruments>sr=44100ksmps=32nchnls=2;0dbfs = 1instr1; gives information about your joystick in real time
kmaskjoystick0,1
kidx=2
kaxestab0,1; number of axes has been stored in position 0
kbuttonstab1,1; number of buttons has been stored in position 1printf"this joystick has %d axes, %d buttons\n", kidx, kaxes, kbuttons
kuniqinit0reportaxis:; first we see if we have any x/y input
kcheck= kmask&(1<<kidx)if kcheck==0kgotonexta
krestab kidx,1
kuniq= kuniq+1; to be sure to make the printf printprintf"axis %d, value %6d\n", kuniq, kidx-2, kresnexta:
kidx= kidx+1if kidx<(kaxes+2)kgotoreportaxisreportbutton:; now we check for any buttons pressed
kcheck= kmask&1<<kidxif kcheck==0kgotonextb
krestab kidx,1; a button has been pressed, get from tableprintf"button %d, pushed\n", kidx*kres,(kidx-(kaxes+2))printf"button %d, released\n", kidx*(1-kres),(kidx-(kaxes+2))nextb:
kidx= kidx+1if kidx<(kaxes+kbuttons+2)kgotoreportbuttonendin</CsInstruments><CsScore>f10327070; will hold the joystick datai1060000e</CsScore></CsoundSynthesizer>

Here is another example of the joystick opcode. It uses the file joystick-2.csd.