2 // desc: uses first 3 axes of a joystick to control mf, cf, and index for FM
3 // author: Spencer Salazar
7 // get from command line
8 if( me.args() ) me.arg(0) => Std.atoi => device;
10 // modulator to carrier
11 SinOsc m => SinOsc c => Envelope e => dac;
15 // modulator frequency
17 // index of modulation
20 // phase modulation is FM synthesis (sync is 2)
34 set( base, a0, a1, a2 );
41 if( !hi.openJoystick( device ) ) me.exit();
42 <<< "joystick '" + hi.name() + "' ready...", "" >>>;
50 while( hi.recv( msg ) )
52 if( msg.isAxisMotion() )
54 if( msg.which == 0 ) msg.axisPosition => a0;
55 else if( msg.which == 1 ) msg.axisPosition => a1;
56 else if( msg.which == 2 ) msg.axisPosition => a2;
57 set( base, a0, a1, a2 );
60 else if( msg.isButtonDown() )
64 if( count == 1 ) e.keyOn();
65 set( base, a0, a1, a2 );
68 else if( msg.isButtonUp() )
72 if( !count ) e.keyOff();
78 fun void set( int base, float v0, float v1, float v2 )
80 // modulator frequency
81 ( 500 + 5*base + ( 500 * v0) ) => m.freq;
83 ( 220 + (220 * v2) ) => c.freq;
84 // index of modulation
85 ( 1000 * (v1+1) ) => m.gain;
86 <<< "carrier:", c.freq(), "modulator:", m.freq(), "index:", m.gain() >>>;