#include #include #include #include snd_seq_t * open_alsa () { snd_seq_t *sequencer; int ret, port; ret = snd_seq_open (&sequencer, "default", SND_SEQ_OPEN_INPUT, 0); if (ret < 0) return NULL; snd_seq_set_client_name (sequencer, "Midi-Dumper"); port = snd_seq_create_simple_port (sequencer, "Midi-Dumper in", SND_SEQ_PORT_CAP_WRITE, SND_SEQ_PORT_TYPE_MIDI_GENERIC); if (port < 0) return NULL; /* Hardcoded Midi Keyboard */ snd_seq_connect_from (sequencer, port, 72, 0); return sequencer; } int main (int argc, char *argv[]) { snd_seq_t *sequencer; snd_seq_event_t *event; sequencer = open_alsa (); if (!sequencer) exit (1); while (1) { if (snd_seq_event_input_pending (sequencer, 1) > 0) { snd_seq_event_input (sequencer, &event); if (event->type == SND_SEQ_EVENT_NOTEON && event->data.note.velocity == 0) event->type = SND_SEQ_EVENT_NOTEOFF; switch (event->type) { case SND_SEQ_EVENT_NOTEON: fprintf (stderr, "Note On: %d (%d)\n", event->data.note.note, event->data.note.velocity); break; case SND_SEQ_EVENT_NOTEOFF: fprintf (stderr, "Note Off: %d\n", event->data.note.note); break; case SND_SEQ_EVENT_CONTROLLER: fprintf (stderr, "Ctrl %d: %d\n", event->data.control.param, event->data.control.value); break; case SND_SEQ_EVENT_PITCHBEND: fprintf (stderr, "Pitchbend: %d\n", event->data.control.value); break; default: break; } } else { usleep (2000); } } return 0; }