From 48a32e663197a3d06865c33f73395b99a6675a43 Mon Sep 17 00:00:00 2001 From: bnnm Date: Sun, 1 Nov 2020 16:49:43 +0100 Subject: [PATCH] Add TXTP special value "all" in random groups --- doc/TXTP.md | 2 +- src/meta/txtp.c | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/doc/TXTP.md b/doc/TXTP.md index c794c32c..1d1cb6d2 100644 --- a/doc/TXTP.md +++ b/doc/TXTP.md @@ -190,7 +190,7 @@ group = -S2 #segment prev 2 (will start from pos.1 = bgm1+2, makes group of bgm # may mix groups of auto and manual positions too, but results are harder to predict ``` -Group `R` is meant to help with games that randomly select a file in a group. You can set with `>N` which file will be selected. This way you can quickly edit the TXTP and change the file (you could/should just comment files too, this is just for convenience in complex cases and testing). Files do need to exist and are parsed before being selected, and it can select groups too. +Group `R` is meant to help with games that randomly select a file in a group. You can set with `>N` which file will be selected. This way you can quickly edit the TXTP and change the file (you could just comment files too, this is just for convenience in complex cases and testing). You can also set `>-`, meaning "play all", basically turning `R` into `S`. Files do need to exist and are parsed before being selected, and it can select groups too. ``` bgm1.adx bgm2.adx diff --git a/src/meta/txtp.c b/src/meta/txtp.c index 2cc73329..bb7d2af7 100644 --- a/src/meta/txtp.c +++ b/src/meta/txtp.c @@ -10,6 +10,7 @@ #define TXTP_GROUP_MODE_SEGMENTED 'S' #define TXTP_GROUP_MODE_LAYERED 'L' #define TXTP_GROUP_MODE_RANDOM 'R' +#define TXTP_GROUP_RANDOM_ALL '-' #define TXTP_GROUP_REPEAT 'R' #define TXTP_POSITION_LOOPS 'L' @@ -479,9 +480,13 @@ static int make_group_random(txtp_header* txtp, int is_group, int position, int return 1; } + /* special case meaning "play all", basically for quick testing */ + if (selected == count) { + return make_group_segment(txtp, is_group, position, count); + } /* 0=actually random for fun and testing, but undocumented since random music is kinda weird, may change anytime - * (plus foobar caches song duration so it can get strange if randoms are too different) */ + * (plus foobar caches song duration unless .txtp is modifies, so it can get strange if randoms are too different) */ if (selected < 0) { static int random_seed = 0; srand((unsigned)txtp + random_seed++); /* whatevs */ @@ -1518,11 +1523,18 @@ static int add_group(txtp_header* txtp, char* line) { line += n; } - m = sscanf(line, " >%d%n", &cfg.selected, &n); - if (m == 1) { - cfg.selected--; /* externally 1=first but internally 0=first */ + m = sscanf(line, " >%c%n", &c, &n); + if (m == 1 && c == TXTP_GROUP_RANDOM_ALL) { + cfg.selected = cfg.count; /* special meaning */ line += n; } + else { + m = sscanf(line, " >%d%n", &cfg.selected, &n); + if (m == 1) { + cfg.selected--; /* externally 1=first but internally 0=first */ + line += n; + } + } parse_params(&cfg.group_settings, line);