[prev in list] [next in list] [prev in thread] [next in thread]
List: linux-audio-dev
Subject: Re: [linux-audio-dev] HOw to create an ALSA out port
From: Pedro Lopez-Cabanillas <pedro.lopez.cabanillas () gmail ! com>
Date: 2005-07-25 16:55:38
Message-ID: 200507251855.38252.pedro.lopez.cabanillas () gmail ! com
[Download RAW message or body]
On Monday 25 July 2005, Jens M Andreasen wrote:
> On Mon, 2005-07-25 at 00:50 +0200, Christoph Eckert wrote:
> > I only need to write sysex data which are kept in a character
> > array. Is there a possibility to easily
> > * connect to a certain port of a device (the Midisport control
> > port)
> > * send the contents of the array to this port
[...]
> Let's see if not someone will post the alsa version ... soon.
I hope the attached program to be simple enough to be useful in your context.
Compile it with:
$ gcc -o amsgsysex -l asound amsgsysex.c
Use it with;
$ amsgsysex 64:1
Regards,
Pedro
["amsgsysex.c" (text/x-csrc)]
/*
* Copyright (C) 2005 Pedro Lopez-Cabanillas <plcl@users.sf.net>
*
* This program sends a sysex MIDI message to an ALSA sequencer port
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 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 General Public License for more details.
*/
#include <alsa/asoundlib.h>
unsigned char msg_gmreset[] =
{ 0xf0, 0x7e, 0x7f, 0x09, 0x01, 0xf7 };
char *port_address = NULL;
int port_out_id;
snd_seq_t *seq_handle;
void send_event(snd_seq_event_t *ev)
{
int err;
snd_seq_ev_set_source(ev, port_out_id);
snd_seq_ev_set_subs(ev);
snd_seq_ev_set_direct(ev);
if ((err = snd_seq_event_output_direct(seq_handle, ev)) < 0) {
fprintf(stderr, "error %i at send_event (%s)\n", err, snd_strerror(err));
exit(EXIT_FAILURE);
}
snd_seq_drain_output(seq_handle);
}
void send_syx_event(unsigned char *data, int len)
{
snd_seq_event_t ev;
snd_seq_ev_clear(&ev);
snd_seq_ev_set_sysex(&ev, len, data);
send_event(&ev);
}
int main(int argc, char *argv[])
{
snd_seq_addr_t dest;
if (argc > 1) {
port_address = argv[1];
} else {
fprintf(stderr, "Usage: amsgsysex SEQUENCER_PORT\n");
return EXIT_FAILURE;
}
if (snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_OUTPUT, 0) < 0) {
fprintf(stderr, "Error opening ALSA sequencer.\n");
exit(EXIT_FAILURE);
}
snd_seq_set_client_name(seq_handle, "client name");
if ((port_out_id = snd_seq_create_simple_port(seq_handle, "output port name",
SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ,
SND_SEQ_PORT_TYPE_APPLICATION)) < 0) {
fprintf(stderr, "Error creating sequencer port.\n");
exit(EXIT_FAILURE);
}
if (snd_seq_parse_address(seq_handle, &dest, port_address) < 0) {
fprintf(stderr, "invalid destination address %s\n", port_address);
return EXIT_FAILURE;
}
if (snd_seq_connect_to(seq_handle, port_out_id, dest.client, dest.port) < 0) {
fprintf(stderr, "invalid connection to %d:%d (%s)\n", dest.client, dest.port, port_address);
return EXIT_FAILURE;
}
send_syx_event(&msg_gmreset[0], sizeof(msg_gmreset));
snd_seq_close(seq_handle);
return EXIT_SUCCESS;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic