5 #include <jack/midiport.h>
7 static jack_port_t
* port
;
10 describe (jack_midi_event_t
* event
, char* buffer
, size_t buflen
)
16 if (event
->size
== 0) {
20 int type
= event
->buffer
[0] & 0xf0;
21 int channel
= event
->buffer
[0] & 0xf;
25 assert (event
->size
== 3);
26 snprintf (buffer
, buflen
, "note on (channel %d): pitch %d, velocity %d", channel
, event
->buffer
[1], event
->buffer
[2]);
29 assert (event
->size
== 3);
30 snprintf (buffer
, buflen
, "note off (channel %d): pitch %d, velocity %d", channel
, event
->buffer
[1], event
->buffer
[2]);
33 assert (event
->size
== 3);
34 snprintf (buffer
, buflen
, "control change (channel %d): controller %d, value %d", channel
, event
->buffer
[1], event
->buffer
[2]);
42 process (jack_nframes_t frames
, void* arg
)
47 char description
[256];
49 buffer
= jack_port_get_buffer (port
, frames
);
52 N
= jack_midi_get_event_count (buffer
);
53 for (i
= 0; i
< N
; ++i
) {
54 jack_midi_event_t event
;
57 r
= jack_midi_event_get (&event
, buffer
, i
);
61 printf ("%d:", event
.time
);
62 for (j
= 0; j
< event
.size
; ++j
) {
63 printf (" %x", event
.buffer
[j
]);
66 describe (&event
, description
, sizeof (description
));
67 printf (" %s", description
);
78 main (int argc
, char* argv
[])
80 jack_client_t
* client
;
81 char const default_name
[] = "midi-monitor";
82 char const * client_name
;
86 client_name
= argv
[1];
88 client_name
= default_name
;
91 client
= jack_client_open (client_name
, JackNullOption
, NULL
);
93 fprintf (stderr
, "Could not create JACK client.\n");
97 jack_set_process_callback (client
, process
, 0);
99 port
= jack_port_register (client
, "input", JACK_DEFAULT_MIDI_TYPE
, JackPortIsInput
, 0);
101 fprintf (stderr
, "Could not register port.\n");
105 r
= jack_activate (client
);
107 fprintf (stderr
, "Could not activate client.\n");
111 /* run until interrupted */