Blame test/seq.c

Packit 4a16fb
#include <stdio.h>
Packit 4a16fb
#include <stdlib.h>
Packit 4a16fb
#include <string.h>
Packit 4a16fb
#include <errno.h>
Packit 4a16fb
#include <ctype.h>
Packit 4a16fb
#include <getopt.h>
Packit 4a16fb
#include "../include/asoundlib.h"
Packit 4a16fb
Packit 4a16fb
#include "seq-decoder.c"
Packit 4a16fb
#include "seq-sender.c"
Packit 4a16fb
Packit 4a16fb
#define SEQ_VERSION "0.0.1"
Packit 4a16fb
Packit 4a16fb
#define HELPID_HELP             1000
Packit 4a16fb
#define HELPID_DEBUG            1001
Packit 4a16fb
#define HELPID_VERBOSE		1002
Packit 4a16fb
#define HELPID_VERSION          1003
Packit 4a16fb
Packit 4a16fb
int max_clients;
Packit 4a16fb
int max_ports;
Packit 4a16fb
int max_queues;
Packit 4a16fb
int debug = 0;
Packit 4a16fb
int verbose = 0;
Packit 4a16fb
Packit 4a16fb
void set_name(snd_seq_t *handle)
Packit 4a16fb
{
Packit 4a16fb
	int err;
Packit 4a16fb
	char name[64];
Packit 4a16fb
	
Packit 4a16fb
	sprintf(name, "SeqUtil - %i", getpid());
Packit 4a16fb
	if ((err = snd_seq_set_client_name(handle, name)) < 0) {
Packit 4a16fb
		fprintf(stderr, "Set client info error: %s\n", snd_strerror(err));
Packit 4a16fb
		exit(0);
Packit 4a16fb
	}
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
void system_info(snd_seq_t *handle)
Packit 4a16fb
{
Packit 4a16fb
	int err;
Packit 4a16fb
	snd_seq_system_info_t *sysinfo;
Packit 4a16fb
	
Packit 4a16fb
	snd_seq_system_info_alloca(&sysinfo);
Packit 4a16fb
	if ((err = snd_seq_system_info(handle, sysinfo))<0) {
Packit 4a16fb
		fprintf(stderr, "System info error: %s\n", snd_strerror(err));
Packit 4a16fb
		exit(0);
Packit 4a16fb
	}
Packit 4a16fb
	max_clients = snd_seq_system_info_get_clients(sysinfo);
Packit 4a16fb
	max_ports = snd_seq_system_info_get_ports(sysinfo);
Packit 4a16fb
	max_queues = snd_seq_system_info_get_ports(sysinfo);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
void show_system_info(snd_seq_t *handle ATTRIBUTE_UNUSED)
Packit 4a16fb
{
Packit 4a16fb
	printf("System info\n");
Packit 4a16fb
	printf("  Max queues    : %i\n", max_queues);
Packit 4a16fb
	printf("  Max clients   : %i\n", max_clients);
Packit 4a16fb
	printf("  Max ports     : %i\n", max_ports);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
void show_queue_status(snd_seq_t *handle, int queue)
Packit 4a16fb
{
Packit 4a16fb
	int err, idx, min, max;
Packit 4a16fb
	snd_seq_queue_status_t *status;
Packit 4a16fb
Packit 4a16fb
	snd_seq_queue_status_alloca(&status);
Packit 4a16fb
	min = queue < 0 ? 0 : queue;
Packit 4a16fb
	max = queue < 0 ? max_queues : queue + 1;
Packit 4a16fb
	for (idx = min; idx < max; idx++) {
Packit 4a16fb
		if ((err = snd_seq_get_queue_status(handle, idx, status))<0) {
Packit 4a16fb
			if (err == -ENOENT)
Packit 4a16fb
				continue;
Packit 4a16fb
			fprintf(stderr, "Client %i info error: %s\n", idx, snd_strerror(err));
Packit 4a16fb
			exit(0);
Packit 4a16fb
		}
Packit 4a16fb
		printf("Queue %i info\n", snd_seq_queue_status_get_queue(status));
Packit 4a16fb
		printf("  Tick          : %u\n", snd_seq_queue_status_get_tick_time(status)); 
Packit 4a16fb
		printf("  Realtime      : %i.%i\n",
Packit 4a16fb
		       snd_seq_queue_status_get_real_time(status)->tv_sec,
Packit 4a16fb
		       snd_seq_queue_status_get_real_time(status)->tv_nsec);
Packit 4a16fb
		printf("  Flags         : 0x%x\n", snd_seq_queue_status_get_status(status));
Packit 4a16fb
	}
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
void show_port_info(snd_seq_t *handle, int client, int port)
Packit 4a16fb
{
Packit 4a16fb
	int err, idx, min, max;
Packit 4a16fb
	snd_seq_port_info_t *info;
Packit 4a16fb
Packit 4a16fb
	snd_seq_port_info_alloca(&info;;
Packit 4a16fb
	min = port < 0 ? 0 : port;
Packit 4a16fb
	max = port < 0 ? max_ports : port + 1;
Packit 4a16fb
	for (idx = min; idx < max; idx++) {
Packit 4a16fb
		if ((err = snd_seq_get_any_port_info(handle, client, idx, info))<0) {
Packit 4a16fb
			if (err == -ENOENT)
Packit 4a16fb
				continue;
Packit 4a16fb
			fprintf(stderr, "Port %i/%i info error: %s\n", client, idx, snd_strerror(err));
Packit 4a16fb
			exit(0);
Packit 4a16fb
		}
Packit 4a16fb
		printf("  Port %i info\n", idx);
Packit 4a16fb
		printf("    Client        : %i\n", snd_seq_port_info_get_client(info));
Packit 4a16fb
		printf("    Port          : %i\n", snd_seq_port_info_get_port(info));
Packit 4a16fb
		printf("    Name          : %s\n", snd_seq_port_info_get_name(info));
Packit 4a16fb
		printf("    Capability    : 0x%x\n", snd_seq_port_info_get_capability(info));
Packit 4a16fb
		printf("    Type          : 0x%x\n", snd_seq_port_info_get_type(info));
Packit 4a16fb
		//printf("    Midi channels : %i\n", info.midi_channels);
Packit 4a16fb
		//printf("    Synth voices  : %i\n", info.synth_voices);
Packit 4a16fb
		printf("    Output subs   : %i\n", snd_seq_port_info_get_write_use(info));
Packit 4a16fb
		printf("    Input subs    : %i\n", snd_seq_port_info_get_read_use(info));
Packit 4a16fb
	}
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
void show_client_info(snd_seq_t *handle, int client)
Packit 4a16fb
{
Packit 4a16fb
	int err, idx, min, max;
Packit 4a16fb
	snd_seq_client_info_t *info;
Packit 4a16fb
Packit 4a16fb
	snd_seq_client_info_alloca(&info;;
Packit 4a16fb
	min = client < 0 ? 0 : client;
Packit 4a16fb
	max = client < 0 ? max_clients : client + 1;
Packit 4a16fb
	for (idx = min; idx < max; idx++) {
Packit 4a16fb
		if ((err = snd_seq_get_any_client_info(handle, idx, info))<0) {
Packit 4a16fb
			if (err == -ENOENT)
Packit 4a16fb
				continue;
Packit 4a16fb
			fprintf(stderr, "Client %i info error: %s\n", idx, snd_strerror(err));
Packit 4a16fb
			exit(0);
Packit 4a16fb
		}
Packit 4a16fb
		printf("Client %i info\n", idx);
Packit 4a16fb
		if (verbose)
Packit 4a16fb
			printf("  Client        : %i\n", snd_seq_client_info_get_client(info));
Packit 4a16fb
		printf("  Type          : %s\n", snd_seq_client_info_get_type(info) == SND_SEQ_KERNEL_CLIENT ? "kernel" : "user");
Packit 4a16fb
		printf("  Name          : %s\n", snd_seq_client_info_get_name(info));
Packit 4a16fb
	}
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static void help(void)
Packit 4a16fb
{
Packit 4a16fb
	printf("Usage: seq <options> command\n");
Packit 4a16fb
	printf("\nAvailable options:\n");
Packit 4a16fb
	printf("  -h,--help       this help\n");
Packit 4a16fb
	printf("  -d,--debug      debug mode\n");
Packit 4a16fb
	printf("  -v,--verbose    verbose mode\n");
Packit 4a16fb
	printf("  -V,--version    print version of this program\n");
Packit 4a16fb
	printf("\nAvailable commands:\n");
Packit 4a16fb
	printf("  system          show basic sequencer info\n");
Packit 4a16fb
	printf("  queue [#]       show all queues or specified queue\n");
Packit 4a16fb
	printf("  client [#]      show all clients or specified client\n");
Packit 4a16fb
	printf("  port <client> [#]  show all ports or specified port for specified client\n");
Packit 4a16fb
	printf("  decoder         event decoder\n");
Packit 4a16fb
	printf("  sender <client.port> [<client.port>] ...   event sender\n");
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int main(int argc, char *argv[])
Packit 4a16fb
{
Packit 4a16fb
	int morehelp, err, arg, arg1;
Packit 4a16fb
	snd_seq_t *handle;
Packit 4a16fb
	static struct option long_option[] =
Packit 4a16fb
	{
Packit 4a16fb
		{"help", 0, NULL, HELPID_HELP},
Packit 4a16fb
		{"debug", 0, NULL, HELPID_DEBUG},
Packit 4a16fb
		{"verbose", 0, NULL, HELPID_VERBOSE},
Packit 4a16fb
		{"version", 0, NULL, HELPID_VERSION},
Packit 4a16fb
		{NULL, 0, NULL, 0},
Packit 4a16fb
        };
Packit 4a16fb
        
Packit 4a16fb
        morehelp = 0;
Packit 4a16fb
	
Packit 4a16fb
	while (1) {
Packit 4a16fb
		int c;
Packit 4a16fb
Packit 4a16fb
		if ((c = getopt_long(argc, argv, "hdvV", long_option, NULL)) < 0)
Packit 4a16fb
			break;
Packit 4a16fb
		switch (c) {
Packit 4a16fb
		case 'h':
Packit 4a16fb
		case HELPID_HELP:
Packit 4a16fb
			morehelp++;
Packit 4a16fb
			break;
Packit 4a16fb
		case 'd':
Packit 4a16fb
		case HELPID_DEBUG:
Packit 4a16fb
			debug = 1;
Packit 4a16fb
			break;
Packit 4a16fb
		case 'v':
Packit 4a16fb
		case HELPID_VERBOSE:
Packit 4a16fb
			verbose = 1;
Packit 4a16fb
			break;
Packit 4a16fb
		case 'V':
Packit 4a16fb
		case HELPID_VERSION:
Packit 4a16fb
			printf("alsactl version " SEQ_VERSION "\n");
Packit 4a16fb
			return 1;
Packit 4a16fb
		default:
Packit 4a16fb
			fprintf(stderr, "\07Invalid switch or option needs an argument.\n");
Packit 4a16fb
			morehelp++;
Packit 4a16fb
		}
Packit 4a16fb
	}
Packit 4a16fb
        if (morehelp) {
Packit 4a16fb
                help();
Packit 4a16fb
                return 1;
Packit 4a16fb
        }
Packit 4a16fb
	if (argc - optind <= 0) {
Packit 4a16fb
		fprintf(stderr, "seq: Specify command...\n");
Packit 4a16fb
		return 0;
Packit 4a16fb
	}
Packit 4a16fb
	if ((err = snd_seq_open(&handle, "hw", SND_SEQ_OPEN_DUPLEX, 0))<0) {
Packit 4a16fb
		fprintf(stderr, "Open error: %s\n", snd_strerror(err));
Packit 4a16fb
		exit(0);
Packit 4a16fb
	}
Packit 4a16fb
	set_name(handle);
Packit 4a16fb
	system_info(handle);
Packit 4a16fb
Packit 4a16fb
        if (!strcmp(argv[optind], "system")) {
Packit 4a16fb
		show_system_info(handle);
Packit 4a16fb
	} else if (!strcmp(argv[optind], "queue")) {
Packit 4a16fb
		arg = argc - optind > 1 ? atoi(argv[optind + 1]) : -1;
Packit 4a16fb
		show_queue_status(handle, arg);
Packit 4a16fb
	} else if (!strcmp(argv[optind], "client")) {
Packit 4a16fb
		arg = argc - optind > 1 ? atoi(argv[optind + 1]) : -1;
Packit 4a16fb
		show_client_info(handle, arg);
Packit 4a16fb
	} else if (!strcmp(argv[optind], "port")) {
Packit 4a16fb
		arg = argc - optind > 1 ? atoi(argv[optind + 1]) : -1;
Packit 4a16fb
		if (arg < 0) {
Packit 4a16fb
			fprintf(stderr, "Specify port...\n");
Packit 4a16fb
			exit(0);
Packit 4a16fb
		}
Packit 4a16fb
		arg1 = argc - optind > 2 ? atoi(argv[optind + 2]) : -1;
Packit 4a16fb
		show_port_info(handle, arg, arg1);
Packit 4a16fb
	} else if (!strcmp(argv[optind], "decoder")) {
Packit 4a16fb
		event_decoder(handle, argc - optind - 1, argv + optind + 1);
Packit 4a16fb
	} else if (!strcmp(argv[optind], "sender")) {
Packit 4a16fb
		event_sender(handle, argc - optind - 1, argv + optind + 1);
Packit 4a16fb
	} else {
Packit 4a16fb
		help();
Packit 4a16fb
	}
Packit 4a16fb
	exit(1);
Packit 4a16fb
}