All of lore.kernel.org
 help / color / mirror / Atom feed
* Help with editing the Raw Midi data with ALSA?
@ 2013-09-06 18:02 Ember Autumn Rose Leona
  2013-09-06 22:08 ` Keith A. Milner
  2013-09-07 10:01 ` Clemens Ladisch
  0 siblings, 2 replies; 6+ messages in thread
From: Ember Autumn Rose Leona @ 2013-09-06 18:02 UTC (permalink / raw)
  To: alsa-devel

Dear ALSA team,

I just joined the mailing list on after being referred to it.

Is it possible for me to edit the Raw Midi data with ALSA... I looked
a RtMidi and that opens a port but doesn't help me Midi Poison or Midi
Message Map.

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. On the fly. Basically I want to take the note on
message byte and use the
note number as an index for an array of remapped keys.

I want to flip the keyboard on a D note for now... then later allow
users to turn this remapping off and on (on the fly.) Also it would be
nice to have certain note ranges  mapped to different programs/patches.

-Ember

PS> I wish I could help test the sound drivers... but I only have an
inexpensive intel integrated sound chip and I am on a dell which needs
to be replaced with something par.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help with editing the Raw Midi data with ALSA?
  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
  1 sibling, 0 replies; 6+ messages in thread
From: Keith A. Milner @ 2013-09-06 22:08 UTC (permalink / raw)
  To: alsa-devel; +Cc: Ember Autumn Rose Leona

On Friday 06 Sep 2013 11:02:19 Ember Autumn Rose Leona wrote:
> Dear ALSA team,
> 
> I just joined the mailing list on after being referred to it.

I actually think this is the wrong place. Alsa-user might be more appropriate 
as you are probably talking about a program which uses the ALSA APIs, rather 
than developments to ALSA itself, which is what this list is for.

https://lists.sourceforge.net/lists/listinfo/alsa-user

Despite being off-topic, I will try to give some guidance.

> 
> Is it possible for me to edit the Raw Midi data with ALSA... I looked
> a RtMidi and that opens a port but doesn't help me Midi Poison or Midi
> Message Map.
> 
> 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. On the fly. Basically I want to take the note on
> message byte and use the
> note number as an index for an array of remapped keys.
> 
> I want to flip the keyboard on a D note for now... then later allow
> users to turn this remapping off and on (on the fly.) Also it would be
> nice to have certain note ranges  mapped to different programs/patches.
> 

It sounds like you want to receive note events from a MIDI IN interface (e.g. 
from a keyboard) and want to transform them before pushing them out of a MIDI 
OUT interface?

If so, I strongly recommend you consider looking at Jack Connection Kit for 
this sort of application.

http://jackaudio.org/

Jack is a layer which sits over ALSA and provides, amongst other things, 
flexible connections and routing for audio and midi data. It will give you a 
lot of flexibility and allow you to connect your application to other 
applications (e.g. virtual midi keyboards like VMPK, and sound generators like 
Qsynth or Pianoteq).

If you aim to produce something that you will publish for other people to use 
in audio production, Jack is really the standard that people will expect.

If you want a starting point, something like KMidimon, which works directly 
with ALSA as well as via Jack, would give lots of useful example code:

http://kmidimon.sourceforge.net/

Cheers,

Keith

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help with editing the Raw Midi data with ALSA?
  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
  2013-09-09  1:24   ` Ember Autumn Rose Leona
  1 sibling, 1 reply; 6+ messages in thread
From: Clemens Ladisch @ 2013-09-07 10:01 UTC (permalink / raw)
  To: Ember Autumn Rose Leona; +Cc: alsa-devel

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));
	}
}

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help with editing the Raw Midi data with ALSA?
  2013-09-07 10:01 ` Clemens Ladisch
@ 2013-09-09  1:24   ` Ember Autumn Rose Leona
  2013-09-09  1:37     ` Ember Autumn Rose Leona
  0 siblings, 1 reply; 6+ messages in thread
From: Ember Autumn Rose Leona @ 2013-09-09  1:24 UTC (permalink / raw)
  To: Clemens Ladisch; +Cc: alsa-devel

Thank you Clemens!

You pretty much wrote it all for me, I made a minor edit so that it
flips the keyboard on D5.
I know that this should work... but I am getting compiler errors with
undefined reference...

here's the error: http://pastebin.com/41WAvjCs

I even looked into the ld in /usr/bin/ which was a link to ld.bfd I
redirected it to ld.gold... I still get errors. I already have the
library libasound2-dev installed  and I even compiled from source
cmake . then make  and put the all the /include/ files in the program
directory....

It must be something I am doing wrong... if you can help that would be nice.
PS>$ pkg-config --libs alsa
-lasound

This is what I changed.

if (snd_seq_ev_is_note_type(ev))
                    if (ev->data.note.note < 125)
ev->data.note.note = (((127 - (ev->data.note.note & 127)) - 3) & 127)

I might end up using an array I think there will be less latency...
The ANDs make sure that it is within the byte range  0-127 before and
after... -3 is the offset for D5 -27 for D4 I am going to put these in
an array. I want to allow the user to choose what note to mirror on.

I have tried -lasound I even put the entire alsa lib in the project
root and changed the .c file to include "asoundlib.h"
include "seqmid.h"  //this is where most those macros and functions are

Well, I really tried b4 bugging you again...

Thanks for you help thus far,
Ember


On 9/7/13, Clemens Ladisch <clemens@ladisch.de> wrote:
> 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));
> 	}
> }
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help with editing the Raw Midi data with ALSA?
  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
  0 siblings, 1 reply; 6+ messages in thread
From: Ember Autumn Rose Leona @ 2013-09-09  1:37 UTC (permalink / raw)
  To: Clemens Ladisch; +Cc: alsa-devel

Dear Clemens,

I just figured it out... Thank you... I had to use sudo
$sudo gcc -o keyflipd5 KeyFlip.c

Now I see it in aconnect. ^-^
You are kick awesome!! thank you!!!!
-Ember

On 9/8/13, Ember Autumn Rose Leona <emberleona@gmail.com> wrote:
> Thank you Clemens!
>
> You pretty much wrote it all for me, I made a minor edit so that it
> flips the keyboard on D5.
> I know that this should work... but I am getting compiler errors with
> undefined reference...
>
> here's the error: http://pastebin.com/41WAvjCs
>
> I even looked into the ld in /usr/bin/ which was a link to ld.bfd I
> redirected it to ld.gold... I still get errors. I already have the
> library libasound2-dev installed  and I even compiled from source
> cmake . then make  and put the all the /include/ files in the program
> directory....
>
> It must be something I am doing wrong... if you can help that would be
> nice.
> PS>$ pkg-config --libs alsa
> -lasound
>
> This is what I changed.
>
> if (snd_seq_ev_is_note_type(ev))
>                     if (ev->data.note.note < 125)
> ev->data.note.note = (((127 - (ev->data.note.note & 127)) - 3) & 127)
>
> I might end up using an array I think there will be less latency...
> The ANDs make sure that it is within the byte range  0-127 before and
> after... -3 is the offset for D5 -27 for D4 I am going to put these in
> an array. I want to allow the user to choose what note to mirror on.
>
> I have tried -lasound I even put the entire alsa lib in the project
> root and changed the .c file to include "asoundlib.h"
> include "seqmid.h"  //this is where most those macros and functions are
>
> Well, I really tried b4 bugging you again...
>
> Thanks for you help thus far,
> Ember
>
>
> On 9/7/13, Clemens Ladisch <clemens@ladisch.de> wrote:
>> 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));
>> 	}
>> }
>>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help with editing the Raw Midi data with ALSA?
  2013-09-09  1:37     ` Ember Autumn Rose Leona
@ 2013-09-09  8:21       ` Clemens Ladisch
  0 siblings, 0 replies; 6+ messages in thread
From: Clemens Ladisch @ 2013-09-09  8:21 UTC (permalink / raw)
  To: Ember Autumn Rose Leona; +Cc: alsa-devel

Ember Autumn Rose Leona wrote:
> $ gcc -o keyflipd5 KeyFlip.c

You forgot "-lasound".


Regards,
Clemens

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-09-09  8:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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.