Commit b69ea6ad authored by yids's avatar yids
Browse files

start on midicontroller thing

parent 28c76cda
......@@ -46,3 +46,6 @@ bigscreen: bigscreen.c
tcp2rtsp: tcp2rtsp.c
gcc -g tcp2rtsp.c -o tcp2rtsp `pkg-config --cflags --libs gstreamer-1.0 gstreamer-pbutils-1.0 gstreamer-video-1.0 gstreamer-rtsp-server-1.0` $(CFLAGS)
midicontrol: midicontrol.c
gcc -g midicontrol.c -o midicontrol `pkg-config --cflags --libs alsa` $(CFLAGS)
#include <alsa/asoundlib.h>
static snd_seq_t *seq_handle;
static int in_port;
#define CHK(stmt, msg) if((stmt) < 0) {puts("ERROR: "#msg); exit(1);}
void midi_open(void)
{
CHK(snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_INPUT, 0),
"Could not open sequencer");
CHK(snd_seq_set_client_name(seq_handle, "Midi Listener"),
"Could not set client name");
CHK(in_port = snd_seq_create_simple_port(seq_handle, "listen:in",
SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE,
SND_SEQ_PORT_TYPE_APPLICATION),
"Could not open port");
}
snd_seq_event_t *midi_read(void)
{
snd_seq_event_t *ev = NULL;
snd_seq_event_input(seq_handle, &ev);
return ev;
}
void midi_process(const snd_seq_event_t *ev)
{
if((ev->type == SND_SEQ_EVENT_NOTEON)
||(ev->type == SND_SEQ_EVENT_NOTEOFF)) {
const char *type = (ev->type==SND_SEQ_EVENT_NOTEON) ? "on " : "off";
printf("[%d] Note %s: %2x vel(%2x)\n", ev->time.tick, type,
ev->data.note.note,
ev->data.note.velocity);
}
else if(ev->type == SND_SEQ_EVENT_CONTROLLER)
printf("[%d] Control: %2x val(%2x)\n", ev->time.tick,
ev->data.control.param,
ev->data.control.value);
else
printf("[%d] Unknown: Unhandled Event Received\n", ev->time.tick);
}
int main()
{
midi_open();
while(1)
midi_process(midi_read());
return -1;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment