| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
; Select audio/midi flags here according to platform |
| 4 |
-odac ;;;realtime audio out |
| 5 |
;-iadc ;;;uncomment -iadc if realtime audio input is needed too |
| 6 |
; For Non-realtime ouput leave only the line below: |
| 7 |
; -o joystick.wav -W ;;; for file output any platform |
| 8 |
</CsOptions> |
| 9 |
<CsInstruments> |
| 10 |
|
| 11 |
sr = 44100 |
| 12 |
ksmps = 32 |
| 13 |
nchnls = 2 |
| 14 |
;0dbfs = 1 |
| 15 |
|
| 16 |
instr 1 ; gives information about your joystick in real time |
| 17 |
|
| 18 |
kmask joystick 0, 1 |
| 19 |
kidx = 2 |
| 20 |
kaxes tab 0, 1 ; number of axes has been stored in position 0 |
| 21 |
kbuttons tab 1, 1 ; number of buttons has been stored in position 1 |
| 22 |
printf "this joystick has %d axes, %d buttons\n", kidx, kaxes, kbuttons |
| 23 |
kuniq init 0 |
| 24 |
|
| 25 |
reportaxis: ; first we see if we have any x/y input |
| 26 |
kcheck = kmask & (1<<kidx) |
| 27 |
if kcheck == 0 kgoto nexta |
| 28 |
kres tab kidx, 1 |
| 29 |
kuniq = kuniq + 1 ; to be sure to make the printf print |
| 30 |
printf "axis %d, value %6d\n", kuniq, kidx-2, kres |
| 31 |
nexta: |
| 32 |
kidx = kidx+1 |
| 33 |
if kidx < (kaxes+2) kgoto reportaxis |
| 34 |
|
| 35 |
reportbutton: ; now we check for any buttons pressed |
| 36 |
kcheck = kmask & 1<<kidx |
| 37 |
if kcheck == 0 kgoto nextb |
| 38 |
kres tab kidx, 1 ; a button has been pressed, get from table |
| 39 |
printf "button %d, pushed\n", kidx*kres, (kidx-(kaxes+2)) |
| 40 |
printf "button %d, released\n", kidx*(1-kres), (kidx-(kaxes+2)) |
| 41 |
|
| 42 |
nextb: |
| 43 |
kidx = kidx+1 |
| 44 |
if kidx < (kaxes+kbuttons+2) kgoto reportbutton |
| 45 |
|
| 46 |
endin |
| 47 |
</CsInstruments> |
| 48 |
<CsScore> |
| 49 |
|
| 50 |
f1 0 32 7 0 7 0 ; will hold the joystick data |
| 51 |
|
| 52 |
i1 0 60000 |
| 53 |
|
| 54 |
e |
| 55 |
</CsScore> |
| 56 |
</CsoundSynthesizer> |