Allow mini-TXTP with "commands" to simplify config

This commit is contained in:
bnnm 2019-08-15 15:46:03 +02:00
parent e8989f5300
commit 5a80a29c37
2 changed files with 17 additions and 22 deletions

View File

@ -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

View File

@ -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: