mirror of
https://github.com/gmcn42/mt32-pi-control.git
synced 2026-09-22 18:37:58 +00:00
Merge pull request #8 from M-HT/linux-alsa-client-name
Allow using ALSA client name to select output in Linux/ALSA version
This commit is contained in:
1 file changed
+21
-19
+21
-19
@@ -28,17 +28,27 @@ typedef enum {
|
|||||||
|
|
||||||
static snd_seq_t *seq = NULL;
|
static snd_seq_t *seq = NULL;
|
||||||
static int src_port = -1, dst_port = -1, dst_client = -1;
|
static int src_port = -1, dst_port = -1, dst_client = -1;
|
||||||
|
static char *alsa_client = NULL;
|
||||||
|
|
||||||
static char *dev_optstr = "p:";
|
static char *dev_optstr = "p:";
|
||||||
|
|
||||||
int mididev_init(void) {
|
int mididev_init(void) {
|
||||||
if(dst_port == -1 || dst_client == -1) {
|
if(snd_seq_open(&seq, "default", SND_SEQ_OPEN_OUTPUT, 0) < 0) {
|
||||||
fprintf(stderr, "ERROR: You must specify ALSA client and port using -p [CLIENT]:[PORT]\n");
|
fprintf(stderr, "ERROR: Could not open ALSA sequencer.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(snd_seq_open(&seq, "default", SND_SEQ_OPEN_OUTPUT, 0) < 0) {
|
if(alsa_client != NULL && *alsa_client != 0) {
|
||||||
fprintf(stderr, "ERROR: Could not open ALSA sequencer.\n");
|
snd_seq_addr_t addr;
|
||||||
|
if(snd_seq_parse_address(seq, &addr, alsa_client) >= 0) {
|
||||||
|
dst_client = addr.client;
|
||||||
|
dst_port = addr.port;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(dst_port == -1 || dst_client == -1) {
|
||||||
|
fprintf(stderr, "ERROR: You must specify ALSA client and port using -p [CLIENT]:[PORT]\n");
|
||||||
|
snd_seq_close(seq);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,25 +160,17 @@ int mididev_parse_arg(int c, const char *optarg) {
|
|||||||
fprintf(stderr, "ERROR: Unknown option \'%c\'.\n", c);
|
fprintf(stderr, "ERROR: Unknown option \'%c\'.\n", c);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if(alsa_client != NULL) {
|
||||||
|
free(alsa_client);
|
||||||
|
alsa_client = NULL;
|
||||||
|
}
|
||||||
size_t len = strlen(optarg);
|
size_t len = strlen(optarg);
|
||||||
char *temparg = (char*) malloc(len+1);
|
alsa_client = (char*) malloc(len+1);
|
||||||
if(temparg == NULL) {
|
if(alsa_client == NULL) {
|
||||||
fprintf(stderr, "Error allocating memory.\n");
|
fprintf(stderr, "Error allocating memory.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy(temparg, optarg, len+1);
|
memcpy(alsa_client, optarg, len+1);
|
||||||
|
|
||||||
char *firstarg = strtok(temparg, ":");
|
|
||||||
if(firstarg == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
char *secondarg = firstarg + strlen(firstarg) + 1;
|
|
||||||
if(secondarg - temparg >= len) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
dst_client = (int) strtol(firstarg, NULL, 10);
|
|
||||||
dst_port = (int) strtol(secondarg, NULL, 10);
|
|
||||||
free(temparg);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user