Skip to contentSkip to conversation

arecordmidi and aplaymidi

DISCUSSION Alexandre B 2 participants 4 messages Nov 16, 2004 – Nov 17, 2004

lore
Share & tools
lore
#0 lore raw

I have a couple of suggestions for arecordmidi and aplaymidi, maybe to the last one who sent some patches (Pedro Lopez-Cabanillas) for these programs.

I'd like to use arecordmidi and aplaymidi to pipe MIDI events to a Perl script, which in turn would control light spots for a play.

For now, arecordmidi has a --dump option, which suits my needs perfectly, but it seems it *has* to save a file. It would be even more fun if the saving of the .mid file would be optionnal when --dump is passed. Even though I can just delete the file afterwards.

Also.. it would be even better if aplaymidi could just pipe events in text form (perhaps another --dump ?) to standard output, just like the "arecordmidi --dump" output.. that way.. it would be possible to *save* lighting effects into a .midi file.. and recall them back using a single Perl script or so, since both outputs (arecordmidi and aplaymidi) would be the same.

I'd be very pleased to see those features introduced in the next release!

Thanks to all for your excellent work!

Alexandre Bourget

-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE FREE OODBMS DOWNLOAD - A multidimensional database that combines robust object and relational technologies, making it a perfect match for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8

#1 lore raw
Quoted 2 lines · Alexandre B

I'd like to use arecordmidi and aplaymidi to pipe MIDI events to a Perl script, which in turn would control light spots for a play.

Well, this is not quite what these programs were designed for.

Quoted 2 lines

For now, arecordmidi has a --dump option, which suits my needs perfectly, but it seems it *has* to save a file.

/dev/null?

Quoted 4 lines

Also.. it would be even better if aplaymidi could just pipe events in text form (perhaps another --dump ?) to standard output, just like the "arecordmidi --dump" output.. that way.. it would be possible to *save* lighting effects into a .midi file..

Do you want to convert _from_ or _to_ text form?

There is an example sequencer client in the alsa-lib source package (alsa-lib/test/seq.c) that just outputs events it receives as text. It should be easy to modify it to fit your needs.

Having separate tool for playing and converting to text is the unixy way. :-)

Best regards,
Clemens

-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE FREE OODBMS DOWNLOAD - A multidimensional database that combines robust object and relational technologies, making it a perfect match for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8

#2 lore raw

Le Mardi 16 Novembre 2004 03:10, vous avez écrit :

Quoted 5 lines
Quoted 2 lines · Alexandre B

I'd like to use arecordmidi and aplaymidi to pipe MIDI events to a Perl script, which in turn would control light spots for a play.

Well, this is not quite what these programs were designed for.

aplaymidi already reads the .mid file.. it would just need to dump the events with the correct delays but not to the midi device, to the stdout. It does all the job already..

Quoted 4 lines
Quoted 2 lines

For now, arecordmidi has a --dump option, which suits my needs perfectly, but it seems it *has* to save a file.

/dev/null?

true..

Quoted 6 lines
Quoted 4 lines

Also.. it would be even better if aplaymidi could just pipe events in text form (perhaps another --dump ?) to standard output, just like the "arecordmidi --dump" output.. that way.. it would be possible to *save* lighting effects into a .midi file..

Do you want to convert _from_ or _to_ text form?

I want it to convert a .midi *to* text form.. so that a perl script can read it. It's to be able to save a sequence of timed events to preset some lighting effects for a play.

Quoted 4 lines

There is an example sequencer client in the alsa-lib source package (alsa-lib/test/seq.c) that just outputs events it receives as text. It should be easy to modify it to fit your needs.

but how would I playback a saved .midi file ?

Quoted 2 lines

Having separate tool for playing and converting to text is the unixy way. :-)

yeah.. but these two tools are so close to do the job :)

thanks

Alexandre Bourget

-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE FREE OODBMS DOWNLOAD - A multidimensional database that combines robust object and relational technologies, making it a perfect match for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8

#3 lore raw
Quoted 9 lines · Alexandre B

Le Mardi 16 Novembre 2004 03:10, vous avez écrit :

Quoted 5 lines
Quoted 2 lines · Alexandre B

I'd like to use arecordmidi and aplaymidi to pipe MIDI events to a Perl script, which in turn would control light spots for a play.

Well, this is not quite what these programs were designed for.

aplaymidi already reads the .mid file.. it would just need to dump the events with the correct delays but not to the midi device, to the stdout.

Playing MIDI files (sending events at specified times) and converting events to text are two completely different tasks, so there should be two independent programs for each one.

Attached is tool that simply prints all MIDI events it receives. (compile with "gcc -o dumpevents dumpevents.c -lasound")

Quoted 1 line

but how would I playback a saved .midi file ?

Run dumpevents (piping to your Perl script as desired), then tell aplaymidi to play to its port.

If you want to play to two ports at the same time (e.g. dumpevents and a synthesizer), load snd-seq-dummy and connect from a "through" port to both destination ports.

HTH
Clemens

/*
* dumpevents.c - print ALSA sequencer events as text
*
* ... blah blah ... freeware ... blah blah ... no warranty ... blah blah ... */

#include <stdio.h>
#include <stdlib.h>
#include <alsa/asoundlib.h>

void check(int err, const char* operation)

{
	if (err < 0) {
		fprintf(stderr, "cannot %s: %s\n",
			operation, snd_strerror(err));
		exit(1);
	}
}

int main()

{
	snd_seq_t *seq;
	int err;

	err = snd_seq_open(&seq, "default", SND_SEQ_OPEN_INPUT, 0);
	check(err, "open sequencer");
	err = snd_seq_set_client_name(seq, "dumpevents");
	check(err, "set client name");
	err = snd_seq_create_simple_port(seq, "dump port", 
					 SND_SEQ_PORT_CAP_WRITE |
					 SND_SEQ_PORT_CAP_SUBS_WRITE,
					 SND_SEQ_PORT_TYPE_MIDI_GENERIC |
					 SND_SEQ_PORT_TYPE_APPLICATION);
	check(err, "create port");

	for (;;) {
		static const struct {
			int type;
			const char *name;
		} names[] = {
			{SND_SEQ_EVENT_NOTEON, "note_on"},
			{SND_SEQ_EVENT_NOTEOFF, "note_off"},
			{SND_SEQ_EVENT_KEYPRESS, "poly_aftertouch"},
			{SND_SEQ_EVENT_CONTROLLER, "control_change"},
			{SND_SEQ_EVENT_PGMCHANGE, "program_change"},
			{SND_SEQ_EVENT_CHANPRESS, "channel_aftertouch"},
			{SND_SEQ_EVENT_PITCHBEND, "pitch_bend"},
			{SND_SEQ_EVENT_CONTROL14, "control_change_14"},
			{SND_SEQ_EVENT_NONREGPARAM, "nrpn"},
			{SND_SEQ_EVENT_REGPARAM, "rpn"},
			{SND_SEQ_EVENT_SYSEX, "sysex"},
		};
		snd_seq_event_t *ev;
		const char *name = NULL;
		int i;

		if (snd_seq_event_input(seq, &ev) < 0)
			continue;
		for (i = 0; i < sizeof(names) / sizeof(names[0]); i++)
			if (names[i].type == ev->type) {
				name = names[i].name;
				break;
			}
		if (!name)
			continue;
		switch (ev->type) {
		case SND_SEQ_EVENT_NOTEON:
		case SND_SEQ_EVENT_NOTEOFF:
		case SND_SEQ_EVENT_KEYPRESS:
			printf("%s %d %d %d\n", name,
			       ev->data.note.channel, ev->data.note.note, ev->data.note.velocity);
			break;
		case SND_SEQ_EVENT_CONTROLLER:
		case SND_SEQ_EVENT_CONTROL14:	/* most clients simply ... */
		case SND_SEQ_EVENT_NONREGPARAM:	/* ... send multiple controller... */
		case SND_SEQ_EVENT_REGPARAM:	/* ... events instead of these three */
			printf("%s %d %d %d\n", name,
			       ev->data.control.channel, ev->data.control.param, ev->data.control.value);
			break;
		case SND_SEQ_EVENT_PGMCHANGE:
		case SND_SEQ_EVENT_CHANPRESS:
		case SND_SEQ_EVENT_PITCHBEND:
			printf("%s %d %d\n", name,
			       ev->data.control.channel, ev->data.control.value);
			break;
		case SND_SEQ_EVENT_SYSEX:
			printf("%s", name);
			for (i = 0; i < ev->data.ext.len; i++)
				printf(" %02x", i[(unsigned char*)ev->data.ext.ptr]);
			printf("\n");
			break;
		}
	}
}