| 1 |
// opens MIDI input devices one by one, starting from 0, |
| 2 |
// until it reaches one it can't open. then waits for |
| 3 |
// midi events on all open devices and prints out the |
| 4 |
// device, and contents of the MIDI message |
| 5 |
|
| 6 |
// devices to open (try: chuck --probe) |
| 7 |
MidiIn min[16]; |
| 8 |
|
| 9 |
// number of devices |
| 10 |
int devices; |
| 11 |
|
| 12 |
// loop |
| 13 |
for( int i; i < min.size(); i++ ) |
| 14 |
{ |
| 15 |
// no print err |
| 16 |
min[i].printerr( 0 ); |
| 17 |
|
| 18 |
// open the device |
| 19 |
if( min[i].open( i ) ) |
| 20 |
{ |
| 21 |
<<< "device", i, "->", min[i].name(), "->", "open: SUCCESS" >>>; |
| 22 |
spork ~ go( min[i], i ); |
| 23 |
devices++; |
| 24 |
} |
| 25 |
else break; |
| 26 |
} |
| 27 |
|
| 28 |
// check |
| 29 |
if( devices == 0 ) |
| 30 |
{ |
| 31 |
<<< "um, couldn't open a single MIDI device, bailing out..." >>>; |
| 32 |
me.exit(); |
| 33 |
} |
| 34 |
|
| 35 |
// infinite time loop |
| 36 |
while( true ) 1::second => now; |
| 37 |
|
| 38 |
|
| 39 |
// handler for one midi event |
| 40 |
fun void go( MidiIn min, int id ) |
| 41 |
{ |
| 42 |
// the message |
| 43 |
MidiMsg msg; |
| 44 |
|
| 45 |
// infinite event loop |
| 46 |
while( true ) |
| 47 |
{ |
| 48 |
// wait on event |
| 49 |
min => now; |
| 50 |
|
| 51 |
// print message |
| 52 |
while( min.recv( msg ) ) |
| 53 |
{ |
| 54 |
// print out midi message with id |
| 55 |
<<< "device", id, ":", msg.data1, msg.data2, msg.data3 >>>; |
| 56 |
} |
| 57 |
} |
| 58 |
} |