diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2013-05-03 21:08:42 +0400 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2013-05-03 21:08:42 +0400 |
commit | 1058def8e7827e56ce4a70afb4aeacb5dc44148f (patch) | |
tree | 4495d23e7b54ab5700e3839081e797c1eafe0db9 /lib/libsalsa/seq_input.c | |
download | oss4-upstream/4.2-build2006.tar.gz |
Imported Upstream version 4.2-build2006upstream/4.2-build2006upstream
Diffstat (limited to 'lib/libsalsa/seq_input.c')
-rw-r--r-- | lib/libsalsa/seq_input.c | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/lib/libsalsa/seq_input.c b/lib/libsalsa/seq_input.c new file mode 100644 index 0000000..b61d22a --- /dev/null +++ b/lib/libsalsa/seq_input.c @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2004 by Hannu Savolainen < hannu@opensound.com> + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#include <stdio.h> +#include "local.h" + +static snd_seq_event_t * +alloc_event (snd_seq_t * seq) +{ + snd_seq_event_t *ev; + + if (seq->nevents >= MAX_EVENTS) + { + fprintf (stderr, "libsalsa: Local buffer overflow - event dropped\n"); + return NULL; + } + + ev = &seq->events[seq->nevents++]; + + ev->type = SND_SEQ_EVENT_SENSING; /* NOP message */ + + return ev; +} + +static void +voice_message (snd_seq_t * seq, unsigned char msg, unsigned char ch, + unsigned char *parms, int len) +{ + snd_seq_event_t *ev; + if ((ev = alloc_event (seq)) == NULL) + return; + + dbg_printf3 ("Voice message %02x, ch=%d, %3d, %3d\n", msg, ch, parms[0], + parms[1]); + + switch (msg) + { + case MIDI_NOTEON: + ev->type = SND_SEQ_EVENT_NOTEON; + ev->data.note.channel = ch; + ev->data.note.note = parms[0]; + ev->data.note.velocity = parms[1]; + break; + + case MIDI_NOTEOFF: + ev->type = SND_SEQ_EVENT_NOTEOFF; + ev->data.note.channel = ch; + ev->data.note.note = parms[0]; + ev->data.note.velocity = parms[1]; + break; + } +} + +static void +channel_message (snd_seq_t * seq, unsigned char msg, unsigned char ch, + unsigned char *parms, int len) +{ + snd_seq_event_t *ev; + if ((ev = alloc_event (seq)) == NULL) + return; + + dbg_printf3 ("Channel message %02x, ch=%d, %3d, %3d\n", msg, ch, parms[0], + parms[1]); +} + +static void +realtime_message (snd_seq_t * seq, unsigned char msg, unsigned char *parms, + int len) +{ + snd_seq_event_t *ev; + if ((ev = alloc_event (seq)) == NULL) + return; + + dbg_printf3 ("Realtime message %02x, %2x\n", msg, parms[0]); +} + +static void +sysex_message (snd_seq_t * seq, unsigned char *parms, int len) +{ + int i; + snd_seq_event_t *ev; + if ((ev = alloc_event (seq)) == NULL) + return; + + + if (alib_verbose > 2) + { + printf ("Sysex message: "); + for (i = 0; i < len; i++) + printf ("%02x ", parms[i]); + printf ("\n"); + } +} + +void +midiparser_callback (void *context, int category, unsigned char msg, + unsigned char ch, unsigned char *parms, int len) +{ + + switch (category) + { + case CAT_VOICE: + voice_message ((snd_seq_t *) context, msg, ch, parms, len); + break; + + case CAT_CHN: + channel_message ((snd_seq_t *) context, msg, ch, parms, len); + break; + + case CAT_REALTIME: + realtime_message ((snd_seq_t *) context, msg, parms, len); + break; + + case CAT_SYSEX: + sysex_message ((snd_seq_t *) context, parms, len); + break; + + case CAT_MTC: + default: + dbg_printf ("Unknown MIDI message category %d\n", category); + } +} |