Compare commits

..

1 commit

Author SHA1 Message Date
Ranjani Sridharan
a77d607f78
Merge ffc63f76de into 176c94591c 2024-07-19 09:13:18 -07:00
6 changed files with 104 additions and 80 deletions

View file

@ -21,7 +21,7 @@ AC_PROG_SED
AC_DISABLE_STATIC
AM_PROG_LIBTOOL
PKG_PROG_PKG_CONFIG
AM_PATH_ALSA(1.2.12)
AM_PATH_ALSA(1.2.5)
if test "x$enable_alsatest" = "xyes"; then
AC_CHECK_FUNC([snd_ctl_elem_add_enumerated],
, [AC_ERROR([No user enum control support in alsa-lib])])
@ -47,6 +47,17 @@ AC_CHECK_HEADERS([samplerate.h], [have_samplerate="yes"], [have_samplerate="no"]
[#include <samplerate.h>])
AC_CHECK_LIB([asound], [snd_seq_client_info_get_card], [HAVE_SEQ_CLIENT_INFO_GET_CARD="yes"])
if test "$HAVE_SEQ_CLIENT_INFO_GET_CARD" = "yes" ; then
AC_DEFINE([HAVE_SEQ_CLIENT_INFO_GET_CARD], 1, [alsa-lib supports snd_seq_client_info_get_card])
fi
AC_CHECK_LIB([asound], [snd_seq_client_info_get_pid], [HAVE_SEQ_CLIENT_INFO_GET_PID="yes"])
if test "$HAVE_SEQ_CLIENT_INFO_GET_PID" = "yes" ; then
AC_DEFINE([HAVE_SEQ_CLIENT_INFO_GET_PID], 1, [alsa-lib supports snd_seq_client_info_get_pid])
fi
AC_CHECK_LIB([asound], [snd_seq_client_info_get_midi_version], [HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION="yes"])
if test "$HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION" = "yes" -a "$have_rawmidi" = "yes"; then
AC_DEFINE([HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION], 1, [alsa-lib supports snd_seq_client_info_get_midi_version])
fi
AC_CHECK_LIB([atopology], [snd_tplg_save], [have_topology="yes"], [have_topology="no"])
#

View file

@ -29,7 +29,12 @@
#include <alsa/asoundlib.h>
#include "gettext.h"
#ifdef SND_SEQ_PORT_CAP_INACTIVE
#define HANDLE_SHOW_ALL
static int show_all;
#else
#define show_all 0
#endif
static void error_handler(const char *file, int line, const char *function, int err, const char *fmt, ...)
{
@ -62,7 +67,9 @@ static void usage(void)
printf(_(" aconnect -i|-o [-options]\n"));
printf(_(" -i,--input list input (readable) ports\n"));
printf(_(" -o,--output list output (writable) ports\n"));
#ifdef HANDLE_SHOW_ALL
printf(_(" -a,--all show inactive ports, too\n"));
#endif
printf(_(" -l,--list list current connections of each port\n"));
printf(_(" * Remove all exported connections\n"));
printf(_(" -x, --removeall\n"));
@ -77,11 +84,15 @@ static void usage(void)
#define perm_ok(cap,bits) (((cap) & (bits)) == (bits))
#ifdef SND_SEQ_PORT_DIR_INPUT
static int check_direction(snd_seq_port_info_t *pinfo, int bit)
{
int dir = snd_seq_port_info_get_direction(pinfo);
return !dir || (dir & bit);
}
#else
#define check_direction(x, y) 1
#endif
static int check_permission(snd_seq_port_info_t *pinfo, int perm)
{
@ -163,16 +174,20 @@ static void do_search_port(snd_seq_t *seq, int perm, action_func_t do_action)
/* reset query info */
snd_seq_port_info_set_client(pinfo, snd_seq_client_info_get_client(cinfo));
snd_seq_port_info_set_port(pinfo, -1);
#ifdef HANDLE_SHOW_ALL
if (show_all)
snd_seq_port_info_set_capability(pinfo, SND_SEQ_PORT_CAP_INACTIVE);
#endif
count = 0;
while (snd_seq_query_next_port(seq, pinfo) >= 0) {
if (check_permission(pinfo, perm)) {
do_action(seq, cinfo, pinfo, count);
count++;
}
#ifdef HANDLE_SHOW_ALL
if (show_all)
snd_seq_port_info_set_capability(pinfo, SND_SEQ_PORT_CAP_INACTIVE);
#endif
}
}
}
@ -190,6 +205,7 @@ static void print_port(snd_seq_t *seq ATTRIBUTE_UNUSED,
snd_seq_client_info_get_name(cinfo),
(snd_seq_client_info_get_type(cinfo) == SND_SEQ_USER_CLIENT ?
_("user") : _("kernel")));
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
switch (snd_seq_client_info_get_midi_version(cinfo)) {
case SND_SEQ_CLIENT_UMP_MIDI_1_0:
printf(",UMP-MIDI1");
@ -198,11 +214,16 @@ static void print_port(snd_seq_t *seq ATTRIBUTE_UNUSED,
printf(",UMP-MIDI2");
break;
}
#endif
#ifdef HAVE_SEQ_CLIENT_INFO_GET_CARD
card = snd_seq_client_info_get_card(cinfo);
#endif
if (card != -1)
printf(",card=%d", card);
#ifdef HAVE_SEQ_CLIENT_INFO_GET_PID
pid = snd_seq_client_info_get_pid(cinfo);
#endif
if (pid != -1)
printf(",pid=%d", pid);
printf("]\n");
@ -210,8 +231,10 @@ static void print_port(snd_seq_t *seq ATTRIBUTE_UNUSED,
printf(" %3d '%-16s'",
snd_seq_port_info_get_port(pinfo),
snd_seq_port_info_get_name(pinfo));
#ifdef HANDLE_SHOW_ALL
if (snd_seq_port_info_get_capability(pinfo) & SND_SEQ_PORT_CAP_INACTIVE)
printf(" [INACTIVE]");
#endif
printf("\n");
}
@ -276,7 +299,11 @@ enum {
SUBSCRIBE, UNSUBSCRIBE, LIST, REMOVE_ALL
};
#ifdef HANDLE_SHOW_ALL
#define ACONNECT_OPTS "dior:t:elxa"
#else
#define ACONNECT_OPTS "dior:t:elx"
#endif
static const struct option long_option[] = {
{"disconnect", 0, NULL, 'd'},
@ -287,7 +314,9 @@ static const struct option long_option[] = {
{"exclusive", 0, NULL, 'e'},
{"list", 0, NULL, 'l'},
{"removeall", 0, NULL, 'x'},
#ifdef HANDLE_SHOW_ALL
{"all", 0, NULL, 'a'},
#endif
{NULL, 0, NULL, 0},
};
@ -341,10 +370,12 @@ int main(int argc, char **argv)
case 'x':
command = REMOVE_ALL;
break;
#ifdef HANDLE_SHOW_ALL
case 'a':
command = LIST;
show_all = 1;
break;
#endif
default:
usage();
exit(1);

View file

@ -30,7 +30,9 @@
#include <unistd.h>
#include <alsa/asoundlib.h>
#include "version.h"
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
#include <alsa/ump_msg.h>
#endif
/*
* 31.25 kbaud, one start bit, eight data bits, two stop bits.
@ -76,7 +78,9 @@ static int file_offset; /* current offset in input file */
static int num_tracks;
static struct track *tracks;
static int smpte_timing;
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
static int ump_mode;
#endif
/* prints an error message to stderr */
static void errormsg(const char *msg, ...)
@ -681,6 +685,7 @@ static int fill_legacy_event(struct event* event, snd_seq_event_t *ev)
return 0;
}
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
static unsigned char to_ump_status(unsigned char ev_type)
{
switch (ev_type) {
@ -757,10 +762,13 @@ static int fill_ump_event(struct event* event, snd_seq_ump_event_t *ump_ev,
snd_seq_ev_set_ump_data(ump_ev, &ump, sizeof(ump));
return 0;
}
#endif /* HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION */
static void play_midi(void)
{
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
snd_seq_ump_event_t ump_ev;
#endif
snd_seq_event_t ev;
int i, max_tick, err;
@ -822,7 +830,7 @@ static void play_midi(void)
if (err < 0)
continue;
}
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
if (ump_mode) {
err = fill_ump_event(event, &ump_ev, &ev);
if (err < 0)
@ -831,6 +839,7 @@ static void play_midi(void)
check_snd("output event", err);
continue;
}
#endif
/* this blocks when the output pool has been filled */
err = snd_seq_event_output(seq, &ev);
@ -948,7 +957,9 @@ static void usage(const char *argv0)
"-V, --version print current version\n"
"-l, --list list all possible output ports\n"
"-p, --port=client:port,... set port(s) to play to\n"
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
"-u, --ump=version UMP output (only version=1 is supported)\n"
#endif
"-d, --delay=seconds delay after song ends\n",
argv0);
}
@ -958,7 +969,12 @@ static void version(void)
puts("aplaymidi version " SND_UTIL_VERSION_STR);
}
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
#define OPTIONS "hVlp:d:u:"
#else
#define OPTIONS "hVlp:d:"
#endif
int main(int argc, char *argv[])
{
@ -968,7 +984,9 @@ int main(int argc, char *argv[])
{"version", 0, NULL, 'V'},
{"list", 0, NULL, 'l'},
{"port", 1, NULL, 'p'},
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
{"ump", 1, NULL, 'u'},
#endif
{"delay", 1, NULL, 'd'},
{0}
};
@ -995,11 +1013,15 @@ int main(int argc, char *argv[])
case 'd':
end_delay = atoi(optarg);
break;
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
case 'u':
ump_mode = atoi(optarg);
if (ump_mode < 0 || ump_mode > 1)
fatal("Only MIDI 1.0 is supported");
if (strcmp(optarg, "1")) {
errormsg("Only MIDI 1.0 is supported");
return 1;
}
ump_mode = 1;
break;
#endif
default:
usage(argv[0]);
return 1;
@ -1007,11 +1029,13 @@ int main(int argc, char *argv[])
}
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
if (ump_mode) {
int err;
err = snd_seq_set_client_midi_version(seq, SND_SEQ_CLIENT_UMP_MIDI_1_0);
check_snd("set midi version", err);
}
#endif
if (do_list) {
list_ports();

View file

@ -29,7 +29,9 @@
#include <poll.h>
#include <alsa/asoundlib.h>
#include "version.h"
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
#include <alsa/ump_msg.h>
#endif
enum {
VIEW_RAW, VIEW_NORMALIZED, VIEW_PERCENT
@ -39,7 +41,11 @@ static snd_seq_t *seq;
static int port_count;
static snd_seq_addr_t *ports;
static volatile sig_atomic_t stop = 0;
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
static int ump_version;
#else
#define ump_version 0
#endif
static int view_mode = VIEW_RAW;
/* prints an error message to stderr, and dies */
@ -362,6 +368,7 @@ static void dump_event(const snd_seq_event_t *ev)
}
}
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
static int group_number(unsigned char c)
{
if (view_mode != VIEW_RAW)
@ -435,7 +442,7 @@ static const char *midi2_velocity(unsigned int v)
snprintf(tmp, sizeof(tmp), "%.2f",
((double)v * 64.0) / 0x8000);
else
snprintf(tmp, sizeof(tmp), "%.2f",
snprintf(tmp, sizeof(tmp), ".2%f",
((double)(v - 0x8000) * 63.0) / 0x7fff + 64.0);
return tmp;
} else if (view_mode == VIEW_PERCENT) {
@ -673,7 +680,6 @@ static void dump_ump_sysex_event(const unsigned int *ump)
int i, length;
printf("Group %2d, ", group_number(snd_ump_msg_group(ump)));
printf("SysEx ");
switch (snd_ump_sysex_msg_status(ump)) {
case SND_UMP_SYSEX_STATUS_SINGLE:
printf("Single ");
@ -980,6 +986,7 @@ static void dump_ump_event(const snd_seq_ump_event_t *ev)
break;
}
}
#endif /* HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION */
static void list_ports(void)
{
@ -1022,8 +1029,10 @@ static void help(const char *argv0)
" -N,--normalized-view show normalized values\n"
" -P,--percent-view show percent values\n"
" -R,--raw-view show raw values (default)\n"
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
" -u,--ump=version set client MIDI version (0=legacy, 1= UMP MIDI 1.0, 2=UMP MIDI2.0)\n"
" -r,--raw do not convert UMP and legacy events\n"
#endif
" -p,--port=client:port,... source port(s)\n",
argv0);
}
@ -1040,7 +1049,11 @@ static void sighandler(int sig ATTRIBUTE_UNUSED)
int main(int argc, char *argv[])
{
static const char short_options[] = "hVlp:NPRu:r";
static const char short_options[] = "hVlp:NPR"
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
"u:r"
#endif
;
static const struct option long_options[] = {
{"help", 0, NULL, 'h'},
{"version", 0, NULL, 'V'},
@ -1049,8 +1062,10 @@ int main(int argc, char *argv[])
{"normalized-view", 0, NULL, 'N'},
{"percent-view", 0, NULL, 'P'},
{"raw-view", 0, NULL, 'R'},
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
{"ump", 1, NULL, 'u'},
{"raw", 0, NULL, 'r'},
#endif
{0}
};
@ -1085,15 +1100,15 @@ int main(int argc, char *argv[])
case 'N':
view_mode = VIEW_NORMALIZED;
break;
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
case 'u':
ump_version = atoi(optarg);
if (ump_version < 0 || ump_version > 2)
fatal("Invalid UMP version %d", ump_version);
snd_seq_set_client_midi_version(seq, ump_version);
break;
case 'r':
snd_seq_set_client_ump_conversion(seq, 0);
break;
#endif
default:
help(argv[0]);
return 1;
@ -1135,6 +1150,7 @@ int main(int argc, char *argv[])
break;
for (;;) {
snd_seq_event_t *event;
#ifdef HAVE_SEQ_CLIENT_INFO_GET_MIDI_VERSION
snd_seq_ump_event_t *ump_ev;
if (ump_version > 0) {
err = snd_seq_ump_event_input(seq, &ump_ev);
@ -1144,6 +1160,7 @@ int main(int argc, char *argv[])
dump_ump_event(ump_ev);
continue;
}
#endif
err = snd_seq_event_input(seq, &event);
if (err < 0)

View file

@ -14,47 +14,40 @@ It can also send any other MIDI commands.
Messages to be send can be given in the last argument as hex encoded byte string or can be read from raw binary file.
When sending several SysEx messages at once there is a delay of 1ms after each message as deafult and can be set to different value with option \-i.
A client can be specified by its number, its name, or a prefix of its
name. A port is specified by its number; for port 0 of a client, the
":0" part of the port specification can be omitted.
.SH OPTIONS
.TP
\-h, \-\-help
\-h
Prints a list of options.
.TP
\-V, \-\-version
\-V
Prints the current version.
.TP
\-l, \-\-list
\-l
Prints a list of possible output ports.
.TP
\-v, \-\-verbose
\-v
Prints number of bytes actually sent
.TP
\-p, -\-port=client:port
\-p
Target port by number or name
.TP
\-s, \-\-file=filename
\-s
Send raw binary data from given file name
.TP
\-i, \-\-interval=msec
\-i
Interval between SysEx messages in miliseconds
.TP
\-u, \-\-ump=version
Specify the MIDI version. 0 for the legacy MIDI 1.0 (default),
1 for UMP MIDI 1.0 protocol and 2 for UMP MIDI 2.0 protocol.
When UMP MIDI 1.0 or MIDI 2.0 protocol is specified, \fBaseqsend\fP
reads the input as raw UMP packets, 4 each byte in big endian.
A client can be specified by its number, its name, or a prefix of its
name. A port is specified by its number; for port 0 of a client, the
":0" part of the port specification can be omitted.
.SH EXAMPLES

View file

@ -33,7 +33,6 @@
#include <signal.h>
#include <unistd.h>
#include <alsa/asoundlib.h>
#include <alsa/ump_msg.h>
typedef unsigned char mbyte_t;
@ -44,7 +43,6 @@ static char *send_hex;
static mbyte_t *send_data;
static snd_seq_addr_t addr;
static int send_data_length;
static int ump_version;
static void error(const char *format, ...)
{
@ -322,32 +320,6 @@ static void send_midi_msg(snd_seq_event_type_t type, mbyte_t *data, int len)
snd_seq_drain_output(seq);
}
static int send_ump(const unsigned char *data)
{
static int ump_len = 0, offset = 0;
unsigned int ump[4];
snd_seq_ump_event_t ev;
ump[offset] = (data[0] << 24) | (data[1] << 16) |
(data[2] << 8) | data[3];
if (!offset)
ump_len = snd_ump_packet_length(snd_ump_msg_type(ump));
offset++;
if (offset < ump_len)
return 0;
snd_seq_ump_ev_clear(&ev);
snd_seq_ev_set_source(&ev, 0);
snd_seq_ev_set_dest(&ev, addr.client, addr.port);
snd_seq_ev_set_direct(&ev);
snd_seq_ev_set_ump_data(&ev, ump, ump_len * 4);
snd_seq_ump_event_output(seq, &ev);
snd_seq_drain_output(seq);
offset = 0;
return ump_len * 4;
}
static int msg_byte_in_range(mbyte_t *data, mbyte_t len)
{
for (int i = 0; i < len; i++) {
@ -362,17 +334,6 @@ static int msg_byte_in_range(mbyte_t *data, mbyte_t len)
int main(int argc, char *argv[])
{
static const struct option long_options[] = {
{"help", 0, NULL, 'h'},
{"version", 0, NULL, 'V'},
{"verbose", 0, NULL, 'v'},
{"list", 0, NULL, 'l'},
{"port", 1, NULL, 'p'},
{"file", 1, NULL, 's'},
{"interval", 1, NULL, 'i'},
{"ump", 1, NULL, 'u'},
{0}
};
char c = 0;
char do_send_file = 0;
char do_port_list = 0;
@ -381,7 +342,7 @@ int main(int argc, char *argv[])
int sent_data_c;
int k;
while ((c = getopt_long(argc, argv, "hi:Vvlp:s:u:", long_options, NULL)) != -1) {
while ((c = getopt(argc, argv, "hi:Vvlp:s:")) != -1) {
switch (c) {
case 'h':
usage();
@ -405,9 +366,6 @@ int main(int argc, char *argv[])
case 'i':
sysex_interval = atoi(optarg) * 1000; //ms--->us
break;
case 'u':
ump_version = atoi(optarg);
break;
default:
error("Try 'aseqsend -h' for more information.");
exit(EXIT_FAILURE);
@ -443,11 +401,7 @@ int main(int argc, char *argv[])
if (!send_data)
exit(EXIT_SUCCESS);
if (ump_version && (send_data_length % 4) != 0)
fatal("UMP data must be aligned to 4 bytes");
init_seq();
snd_seq_set_client_midi_version(seq, ump_version);
create_port();
if (snd_seq_parse_address(seq, &addr, port_name) < 0) {
@ -460,12 +414,6 @@ int main(int argc, char *argv[])
while (k < send_data_length) {
if (ump_version) {
sent_data_c += send_ump(send_data + k);
k += 4;
continue;
}
if (send_data[k] == 0xF0) {
int c1 = k;