/* * Copyright (C) 2005 Pedro Lopez-Cabanillas * * 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 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; }