From 5a80a29c371bb6b801269dd14dea5d3fccefe517 Mon Sep 17 00:00:00 2001 From: bnnm Date: Thu, 15 Aug 2019 15:46:03 +0200 Subject: [PATCH] Allow mini-TXTP with "commands" to simplify config --- doc/TXTP.md | 6 ++++-- src/meta/txtp.c | 33 +++++++++++++-------------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/doc/TXTP.md b/doc/TXTP.md index 1e744e45..d57137ac 100644 --- a/doc/TXTP.md +++ b/doc/TXTP.md @@ -520,9 +520,11 @@ The parser is fairly simplistic and lax, and may be erratic with edge cases or b ## MINI-TXTP -To simplify TXTP creation, if the .txtp is empty (0 bytes) its filename is used directly as a command. Note that extension is also included (since vgmstream needs a full filename). +To simplify TXTP creation, if the .txtp doesn't set a name inside its filename is used directly including config. Note that extension must be included (since vgmstream needs a full filename). You can set `commands` inside the .txtp too: - *bgm.sxd2#12.txtp*: plays subsong 12 -- *Ryoshima Coast 1 & 2.aix#c1,2.txtp*: channel mask +- *bgm.sxd2#12.txtp*, , inside has `commands = #@volume 0.5`: plays subsong 12 at half volume +- *bgm.sxd2.txtp*, , inside has `commands = #12 #@volume 0.5`: plays subsong 12 at half volume +- *Ryoshima Coast 1 & 2.aix#C1,2.txtp*: channel downmix - *boss2_3ningumi_ver6.adx#l2#F.txtp*: loop twice then play song end file normally - etc diff --git a/src/meta/txtp.c b/src/meta/txtp.c index 58423926..3c13ca00 100644 --- a/src/meta/txtp.c +++ b/src/meta/txtp.c @@ -1317,29 +1317,12 @@ static txtp_header* parse_txtp(STREAMFILE* streamFile) { txtp->is_segmented = 1; - /* empty file: use filename with config (ex. "song.ext#3.txtp") */ - if (get_streamfile_size(streamFile) == 0) { - char filename[PATH_LIMIT] = {0}; - char* ext; - get_streamfile_filename(streamFile, filename,PATH_LIMIT); - - /* remove ".txtp" */ - ext = strrchr(filename,'.'); - if (!ext) goto fail; /* ??? */ - ext[0] = '\0'; - - if (!add_entry(txtp, filename, 0)) - goto fail; - - return txtp; - } - - /* skip BOM if needed */ - if ((uint16_t)read_16bitLE(0x00, streamFile) == 0xFFFE || (uint16_t)read_16bitLE(0x00, streamFile) == 0xFEFF) + if (file_size > 0 && + ((uint16_t)read_16bitLE(0x00, streamFile) == 0xFFFE || (uint16_t)read_16bitLE(0x00, streamFile) == 0xFEFF)) txt_offset = 0x02; - /* normal file: read and parse lines */ + /* read and parse lines */ while (txt_offset < file_size) { char line[TXTP_LINE_MAX] = {0}; char key[TXTP_LINE_MAX] = {0}, val[TXTP_LINE_MAX] = {0}; /* at least as big as a line to avoid overflows (I hope) */ @@ -1371,6 +1354,16 @@ static txtp_header* parse_txtp(STREAMFILE* streamFile) { goto fail; } + /* mini-txth: if no entries are set try with filename, ex. from "song.ext#3.txtp" use "song.ext#3" + * (it's possible to have default "commands" inside the .txtp plus filename+config) */ + if (txtp->entry_count == 0) { + char filename[PATH_LIMIT] = {0}; + + get_streamfile_basename(streamFile, filename, sizeof(filename)); + + add_entry(txtp, filename, 0); + } + return txtp; fail: