From 8d7fb5b7cb2f1deb6600f8cebfff27dba70193b1 Mon Sep 17 00:00:00 2001 From: cbdev Date: Wed, 24 Jul 2019 21:38:45 +0200 Subject: Allow n:1 multi-channel mapping --- README.md | 3 ++- config.c | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bce7b71..3704f5f 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,8 @@ delimiting a range of channels. Multiple such expressions may be used in one ch specification, with the rightmost expression being incremented (or decremented) first for evaluation. -Both sides of a multi-channel assignment need to have the same number of channels. +Both sides of a multi-channel assignment need to have the same number of channels, or one +side must have exactly one channel. Example multi-channel mapping: diff --git a/config.c b/config.c index 24f1223..6d5fd16 100644 --- a/config.c +++ b/config.c @@ -220,7 +220,7 @@ static int config_map(char* to_raw, char* from_raw){ goto done; } - if(spec_to.channels != spec_from.channels + if((spec_to.channels != spec_from.channels && spec_from.channels != 1 && spec_to.channels != 1) || spec_to.channels == 0 || spec_from.channels == 0){ fprintf(stderr, "Multi-channel specification size mismatch: %s.%s (%lu channels) - %s.%s (%lu channels)\n", @@ -235,9 +235,9 @@ static int config_map(char* to_raw, char* from_raw){ //iterate, resolve globs and map rv = 0; - for(n = 0; !rv && n < spec_from.channels; n++){ - channel_from = config_glob_resolve(instance_from, &spec_from, n); - channel_to = config_glob_resolve(instance_to, &spec_to, n); + for(n = 0; !rv && n < max(spec_from.channels, spec_to.channels); n++){ + channel_from = config_glob_resolve(instance_from, &spec_from, min(n, spec_from.channels)); + channel_to = config_glob_resolve(instance_to, &spec_to, min(n, spec_to.channels)); if(!channel_from || !channel_to){ rv = 1; -- cgit v1.2.3