From: Clemens Ladisch <clemens@ladisch.de>
To: Ember Autumn Rose Leona <emberleona@gmail.com>
Cc: alsa-devel@alsa-project.org
Subject: Re: Help with editing the Raw Midi data with ALSA?
Date: Sat, 07 Sep 2013 12:01:34 +0200 [thread overview]
Message-ID: <522AF97E.6080105@ladisch.de> (raw)
In-Reply-To: <CAAVa-AFWJwBAYK2ix643bEVVraG0FkaEO-ovhfrYPZSSU53vdQ@mail.gmail.com>
Ember Autumn Rose Leona wrote:
> I just joined the mailing list on after being referred to it.
Please note that, regardless of what others might say, this is the list
where you are most likely to get an answer.
> Is it possible for me to edit the Raw Midi data with ALSA...
It would be possible to write your own tool that does the editing.
> What I want to do is edit the Midi Messages, re-mapping the notes. I simply
> want to flip the progression of the keys on a midi piano from high
> notes to low notes.
See the example program below. It modifies MIDI messages received at
its input ports and re-sends them from its output port. Insert it into
your routing like this:
Keyboard --> KeyFlip --> Synth
(Use aconnect to make the connections.)
Regards,
Clemens
--8<---------------------------------------------------------------->8--
#include <stdio.h>
#include <stdlib.h>
#include <alsa/asoundlib.h>
#define CHECK(fn) check((fn), #fn)
static void check(int err, const char *fn)
{
if (err < 0) {
fprintf(stderr, "%s failed: %s\n", fn, snd_strerror(err));
exit(EXIT_FAILURE);
}
}
int main(void)
{
snd_seq_t *seq;
/* create I/O ports */
CHECK(snd_seq_open(&seq, "default", SND_SEQ_OPEN_DUPLEX, 0));
CHECK(snd_seq_set_client_name(seq, "Keyboard Flipper"));
CHECK(snd_seq_create_simple_port(seq, "KeyFlip",
SND_SEQ_PORT_CAP_READ |
SND_SEQ_PORT_CAP_WRITE |
SND_SEQ_PORT_CAP_DUPLEX |
SND_SEQ_PORT_CAP_SUBS_READ |
SND_SEQ_PORT_CAP_SUBS_WRITE,
SND_SEQ_PORT_TYPE_MIDI_GENERIC |
SND_SEQ_PORT_TYPE_SOFTWARE |
SND_SEQ_PORT_TYPE_APPLICATION));
for (;;) {
snd_seq_event_t *ev;
int err;
/* read one event from the input port */
err = snd_seq_event_input(seq, &ev);
if (err == -ENOSPC)
continue;
CHECK(err);
/* modify the note value */
if (snd_seq_ev_is_note_type(ev))
ev->data.note.note = 127 - (ev->data.note.note & 127);
/* send the event from the output port */
snd_seq_ev_set_subs(ev);
snd_seq_ev_set_source(ev, 0);
snd_seq_ev_set_direct(ev);
CHECK(snd_seq_event_output_direct(seq, ev));
}
}
next prev parent reply other threads:[~2013-09-07 10:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-06 18:02 Help with editing the Raw Midi data with ALSA? Ember Autumn Rose Leona
2013-09-06 22:08 ` Keith A. Milner
2013-09-07 10:01 ` Clemens Ladisch [this message]
2013-09-09 1:24 ` Ember Autumn Rose Leona
2013-09-09 1:37 ` Ember Autumn Rose Leona
2013-09-09 8:21 ` Clemens Ladisch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=522AF97E.6080105@ladisch.de \
--to=clemens@ladisch.de \
--cc=alsa-devel@alsa-project.org \
--cc=emberleona@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.