--- Makefile | 10 +++++++--- alsa.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ alsa.h | 10 ++++++++++ 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 alsa.c create mode 100644 alsa.h diff --git a/Makefile b/Makefile index a4a15fd..b8fe4c7 100644 --- a/Makefile +++ b/Makefile _AT_@ -2,8 +2,8 @@ # VERSION = 0 # SOURCE -SOURCE = main.c sndio.c -OBJ = main.o sndio.o +SOURCE = main.c sndio.c alsa.c +OBJ = main.o HDR = midi.h config.h PREFIX = /usr/local _AT_@ -15,10 +15,14 @@ XFLAGS = `pkg-config --cflags x11` SOUNDLIBS = -lsndio SOUNDFLAGS = -DSNDIO +SOUNDOBJ = sndio.o # TODO: implement # #uncomment for ALSA -#SOUNDLIBS = -lalsa +#SOUNDLIBS = -lasound #SOUNDFLAGS = -DALSA +#SOUNDOBJ = alsa.o + +OBJ += $(SOUNDOBJ) LIBS = ${XLIBS} ${SOUNDLIBS} CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${XFLAGS} ${SOUNDFLAGS} diff --git a/alsa.c b/alsa.c new file mode 100644 index 0000000..48ecc3d --- /dev/null +++ b/alsa.c _AT_@ -0,0 +1,45 @@ +#include <alsa/asoundlib.h> + +snd_seq_t *hdl; +static snd_midi_event_t *mbuf; +static int midiport; + +/* open */ +int +midiopen(void) +{ + snd_midi_event_new(32, &mbuf); + if (snd_seq_open(&hdl, "default", SND_SEQ_OPEN_OUTPUT, 0) != 0) { + return 1; + } else { + snd_seq_set_client_name(hdl, "svmidi"); + if ((midiport = snd_seq_create_simple_port(hdl, "svmidi", + SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ, + SND_SEQ_PORT_TYPE_APPLICATION)) < 0) { + return 1; + } + return 0; + } +} + +/* send message */ +void +_midisend(unsigned char message[], size_t count) +{ + snd_seq_event_t ev; + + snd_midi_event_encode(mbuf, message, count, &ev); + + snd_seq_ev_set_subs(&ev); + snd_seq_ev_set_direct(&ev); + snd_seq_ev_set_source(&ev, midiport); + snd_seq_event_output_direct(hdl, &ev); +} + +/* close */ +void +midiclose(void) +{ + snd_midi_event_free(mbuf); + snd_seq_close(hdl); +} diff --git a/alsa.h b/alsa.h new file mode 100644 index 0000000..c870308 --- /dev/null +++ b/alsa.h _AT_@ -0,0 +1,10 @@ +#include <alsa/asoundlib.h> + +/* device */ +extern snd_seq_t *hdl; + +/* functions */ +void _midisend(unsigned char [], size_t); +#define midisend(msg) _midisend(msg, sizeof(msg)) +int midiopen(void); +void midiclose(void); -- 2.4.6 --vGgW1X5XWziG23Ko--Received on Mon Sep 17 2001 - 00:00:00 CEST
This archive was generated by hypermail 2.3.0 : Wed Apr 06 2016 - 22:48:12 CEST