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