| 1 |
// 47.ck : midi write (fail-correct) |
| 2 |
|
| 3 |
sinosc s => dac; |
| 4 |
|
| 5 |
MidiIn min; |
| 6 |
MidiMsg msg; |
| 7 |
MidiMsgOut mrw; // use MidiMsgOut |
| 8 |
|
| 9 |
// open MIDI device |
| 10 |
if( !min.open( 0 ) ) |
| 11 |
me.exit(); |
| 12 |
|
| 13 |
// open for write |
| 14 |
mrw.open( "z.txt" ); |
| 15 |
|
| 16 |
int count; |
| 17 |
|
| 18 |
// infinite time loop |
| 19 |
while( true ) |
| 20 |
{ |
| 21 |
// wait on event |
| 22 |
min => now; |
| 23 |
|
| 24 |
// loop through msg |
| 25 |
while( min.recv( msg ) ) |
| 26 |
{ |
| 27 |
if( msg.data1 == 144 ) // note on |
| 28 |
{ |
| 29 |
<<< "now:", now, msg.data1, msg.data2, msg.data3 >>>; |
| 30 |
std.mtof(msg.data2) => s.freq; |
| 31 |
msg.data3 / 128.0 => s.gain; |
| 32 |
mrw.write( msg, now ); |
| 33 |
//<<<count + 1 => count>>>; |
| 34 |
} |
| 35 |
} |
| 36 |
} |
| 37 |
|