mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-19 00:04:04 +01:00
Unity plugin titles and improve TXTP handling
This commit is contained in:
parent
5949e5f83f
commit
01eaab1f01
@ -386,11 +386,16 @@ static void print_tags(cli_config* cfg) {
|
|||||||
|
|
||||||
static void print_title(VGMSTREAM* vgmstream, cli_config* cfg) {
|
static void print_title(VGMSTREAM* vgmstream, cli_config* cfg) {
|
||||||
char title[1024];
|
char title[1024];
|
||||||
|
vgmstream_title_t tcfg = {0};
|
||||||
|
|
||||||
if (!cfg->show_title)
|
if (!cfg->show_title)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
vgmstream_get_title(title, sizeof(title), cfg->infilename, vgmstream, NULL);
|
tcfg.force_title = 0;
|
||||||
|
tcfg.subsong_range = 0;
|
||||||
|
tcfg.remove_extension = 0;
|
||||||
|
|
||||||
|
vgmstream_get_title(title, sizeof(title), cfg->infilename, vgmstream, &tcfg);
|
||||||
|
|
||||||
printf("title: %s\n", title);
|
printf("title: %s\n", title);
|
||||||
}
|
}
|
||||||
|
@ -429,8 +429,7 @@ void input_vgmstream::get_subsong_info(t_uint32 p_subsong, pfc::string_base & ti
|
|||||||
int num_samples = vgmstream_get_samples(infostream);
|
int num_samples = vgmstream_get_samples(infostream);
|
||||||
*length_in_ms = num_samples*1000LL / infostream->sample_rate;
|
*length_in_ms = num_samples*1000LL / infostream->sample_rate;
|
||||||
|
|
||||||
char temp[1024];
|
describe_vgmstream(infostream, temp, sizeof(temp));
|
||||||
describe_vgmstream(infostream, temp, 1024);
|
|
||||||
description = temp;
|
description = temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -438,30 +437,12 @@ void input_vgmstream::get_subsong_info(t_uint32 p_subsong, pfc::string_base & ti
|
|||||||
|
|
||||||
/* infostream gets added with index 0 (other) or 1 (current) */
|
/* infostream gets added with index 0 (other) or 1 (current) */
|
||||||
if (infostream && title) {
|
if (infostream && title) {
|
||||||
const char *p = filename + strlen(filename);
|
vgmstream_title_t tcfg = {0};
|
||||||
while (*p != '\\' && p >= filename) p--;
|
tcfg.remove_extension = 1;
|
||||||
p++;
|
|
||||||
const char *e = filename + strlen(filename);
|
|
||||||
while (*e != '.' && e >= filename) e--;
|
|
||||||
title.set_string(p, e - p); /* name without ext */
|
|
||||||
|
|
||||||
const char* info_name = infostream->stream_name;
|
const char* filename_str = filename;
|
||||||
int info_streams = infostream->num_streams;
|
vgmstream_get_title(temp, sizeof(temp), filename_str, infostream, &tcfg);
|
||||||
int info_subsong = infostream->stream_index;
|
title = temp;
|
||||||
if (info_subsong == 0)
|
|
||||||
info_subsong = 1;
|
|
||||||
|
|
||||||
/* show number if file has more than 1 subsong */
|
|
||||||
if (info_streams > 1) {
|
|
||||||
sprintf(temp,"#%d",info_subsong);
|
|
||||||
title += temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* show name if file has subsongs (implicitly shows also for TXTP) */
|
|
||||||
if (info_name[0] != '\0' && info_streams > 0) {
|
|
||||||
sprintf(temp," (%s)",info_name);
|
|
||||||
title += temp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// and only close if was querying a new subsong
|
// and only close if was querying a new subsong
|
||||||
|
@ -178,6 +178,10 @@ VGMSTREAM* init_vgmstream_txtp(STREAMFILE* sf) {
|
|||||||
/* should result in a final, single vgmstream possibly containing multiple vgmstreams */
|
/* should result in a final, single vgmstream possibly containing multiple vgmstreams */
|
||||||
vgmstream = txtp->vgmstream[0];
|
vgmstream = txtp->vgmstream[0];
|
||||||
|
|
||||||
|
/* flags for title config */
|
||||||
|
vgmstream->config.is_txtp = 1;
|
||||||
|
vgmstream->config.is_mini_txtp = (get_streamfile_size(sf) == 0);
|
||||||
|
|
||||||
clean_txtp(txtp, 0);
|
clean_txtp(txtp, 0);
|
||||||
return vgmstream;
|
return vgmstream;
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ void vgmstream_get_title(char* buf, int buf_len, const char* filename, VGMSTREAM
|
|||||||
char* pos2;
|
char* pos2;
|
||||||
char temp[1024];
|
char temp[1024];
|
||||||
|
|
||||||
|
buf[0] = '\0';
|
||||||
|
|
||||||
/* name without path */
|
/* name without path */
|
||||||
pos = strrchr(filename, '\\');
|
pos = strrchr(filename, '\\');
|
||||||
@ -80,23 +81,31 @@ void vgmstream_get_title(char* buf, int buf_len, const char* filename, VGMSTREAM
|
|||||||
strncpy(buf, pos, buf_len);
|
strncpy(buf, pos, buf_len);
|
||||||
|
|
||||||
/* name without extension */
|
/* name without extension */
|
||||||
pos2 = strrchr(buf, '.');
|
if (cfg->remove_extension) {
|
||||||
if (pos2)
|
pos2 = strrchr(buf, '.');
|
||||||
pos2[0] = '\0';
|
if (pos2 && strlen(pos2) < 15) /* too big extension = file name probably has a dot in the middle */
|
||||||
|
pos2[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const char* stream_name = vgmstream->stream_name;
|
const char* stream_name = vgmstream->stream_name;
|
||||||
int total_subsongs = vgmstream->num_streams;
|
int total_subsongs = vgmstream->num_streams;
|
||||||
int target_subsong = vgmstream->stream_index;
|
int target_subsong = vgmstream->stream_index;
|
||||||
//int is_first = vgmstream->stream_index == 0;
|
//int is_first = vgmstream->stream_index == 0;
|
||||||
//int is_txtp = ; //todo don't show number/name for txtp but show for mini-txtp
|
|
||||||
int show_name;
|
int show_name;
|
||||||
|
|
||||||
|
/* special considerations for TXTP:
|
||||||
|
* - full txtp: don't show subsong number, nor name (assumes one names .txtp as wanted)
|
||||||
|
* - mini txtp: don't show subsong number, but show name (assumes one choses song #n in filename, but wants title)
|
||||||
|
*/
|
||||||
|
int full_txtp = vgmstream->config.is_txtp && !vgmstream->config.is_mini_txtp;
|
||||||
|
int mini_txtp = vgmstream->config.is_mini_txtp;
|
||||||
|
|
||||||
if (target_subsong == 0)
|
if (target_subsong == 0)
|
||||||
target_subsong = 1;
|
target_subsong = 1;
|
||||||
|
|
||||||
/* show number if file has more than 1 subsong */
|
/* show number if file has more than 1 subsong */
|
||||||
if (total_subsongs > 1) {
|
if (total_subsongs > 1 && !(full_txtp || mini_txtp)) {
|
||||||
if (cfg && cfg->subsong_range)
|
if (cfg && cfg->subsong_range)
|
||||||
snprintf(temp, sizeof(temp), "%s#1~%i", buf, total_subsongs);
|
snprintf(temp, sizeof(temp), "%s#1~%i", buf, total_subsongs);
|
||||||
else
|
else
|
||||||
@ -105,13 +114,19 @@ void vgmstream_get_title(char* buf, int buf_len, const char* filename, VGMSTREAM
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* show name for some cases */
|
/* show name for some cases */
|
||||||
show_name = (total_subsongs > 0 && (!cfg || !cfg->subsong_range)) ||
|
show_name = (total_subsongs > 0) && (!cfg || !cfg->subsong_range);
|
||||||
(cfg && cfg->force_title);
|
if (full_txtp)
|
||||||
|
show_name = 0;
|
||||||
|
if (cfg && cfg->force_title)
|
||||||
|
show_name = 1;
|
||||||
|
|
||||||
if (stream_name[0] != '\0' && show_name) {
|
if (stream_name[0] != '\0' && show_name) {
|
||||||
snprintf(temp, sizeof(temp), "%s (%s)", buf, stream_name);
|
snprintf(temp, sizeof(temp), "%s (%s)", buf, stream_name);
|
||||||
strncpy(buf, temp, buf_len);
|
strncpy(buf, temp, buf_len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buf[buf_len - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -174,6 +189,9 @@ static void load_default_config(play_config_t* def, play_config_t* tcfg) {
|
|||||||
copy_time(&def->trim_begin_set, &def->trim_begin, &def->trim_begin_s, &tcfg->trim_begin_set, &tcfg->trim_begin, &tcfg->trim_begin_s);
|
copy_time(&def->trim_begin_set, &def->trim_begin, &def->trim_begin_s, &tcfg->trim_begin_set, &tcfg->trim_begin, &tcfg->trim_begin_s);
|
||||||
copy_time(&def->trim_end_set, &def->trim_end, &def->trim_end_s, &tcfg->trim_end_set, &tcfg->trim_end, &tcfg->trim_end_s);
|
copy_time(&def->trim_end_set, &def->trim_end, &def->trim_end_s, &tcfg->trim_end_set, &tcfg->trim_end, &tcfg->trim_end_s);
|
||||||
copy_time(&def->body_time_set, &def->body_time, &def->body_time_s, &tcfg->body_time_set, &tcfg->body_time, &tcfg->body_time_s);
|
copy_time(&def->body_time_set, &def->body_time, &def->body_time_s, &tcfg->body_time_set, &tcfg->body_time, &tcfg->body_time_s);
|
||||||
|
|
||||||
|
def->is_mini_txtp = tcfg->is_mini_txtp;
|
||||||
|
def->is_txtp = tcfg->is_txtp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void load_player_config(play_config_t* def, vgmstream_cfg_t* vcfg) {
|
static void load_player_config(play_config_t* def, vgmstream_cfg_t* vcfg) {
|
||||||
|
@ -71,6 +71,7 @@ void vgmstream_set_play_forever(VGMSTREAM* vgmstream, int enabled);
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
int force_title;
|
int force_title;
|
||||||
int subsong_range;
|
int subsong_range;
|
||||||
|
int remove_extension;
|
||||||
} vgmstream_title_t;
|
} vgmstream_title_t;
|
||||||
|
|
||||||
/* get a simple title for plugins */
|
/* get a simple title for plugins */
|
||||||
|
@ -821,6 +821,9 @@ typedef struct {
|
|||||||
int fade_time_set;
|
int fade_time_set;
|
||||||
int pad_end_set;
|
int pad_end_set;
|
||||||
|
|
||||||
|
/* for lack of a better place... */
|
||||||
|
int is_txtp;
|
||||||
|
int is_mini_txtp;
|
||||||
|
|
||||||
} play_config_t;
|
} play_config_t;
|
||||||
|
|
||||||
@ -843,6 +846,7 @@ typedef struct {
|
|||||||
|
|
||||||
int32_t play_duration; /* total samples that the stream lasts (after applying all config) */
|
int32_t play_duration; /* total samples that the stream lasts (after applying all config) */
|
||||||
int32_t play_position; /* absolute sample where stream is */
|
int32_t play_position; /* absolute sample where stream is */
|
||||||
|
|
||||||
} play_state_t;
|
} play_state_t;
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,7 +150,8 @@ static void wa_ichar_to_char(char *dst, size_t dstsize, const in_char *wsrc) {
|
|||||||
//int size_needed = WideCharToMultiByte(CP_UTF8,0, src,-1, NULL,0, NULL, NULL);
|
//int size_needed = WideCharToMultiByte(CP_UTF8,0, src,-1, NULL,0, NULL, NULL);
|
||||||
WideCharToMultiByte(CP_UTF8,0, wsrc,-1, dst,dstsize, NULL, NULL);
|
WideCharToMultiByte(CP_UTF8,0, wsrc,-1, dst,dstsize, NULL, NULL);
|
||||||
#else
|
#else
|
||||||
strcpy(dst,wsrc);
|
strncpy(dst, wsrc, dstsize);
|
||||||
|
dst[dstsize - 1] = '\0';
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +161,8 @@ static void wa_char_to_ichar(in_char *wdst, size_t wdstsize, const char *src) {
|
|||||||
//int size_needed = MultiByteToWideChar(CP_UTF8,0, src,-1, NULL,0);
|
//int size_needed = MultiByteToWideChar(CP_UTF8,0, src,-1, NULL,0);
|
||||||
MultiByteToWideChar(CP_UTF8,0, src,-1, wdst,wdstsize);
|
MultiByteToWideChar(CP_UTF8,0, src,-1, wdst,wdstsize);
|
||||||
#else
|
#else
|
||||||
strcpy(wdst,src);
|
strncpy(wdst, src, wdstsize);
|
||||||
|
wdst[wdstsize - 1] = '\0';
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -891,43 +893,27 @@ static void build_extension_list(char *winamp_list, int winamp_list_size) {
|
|||||||
|
|
||||||
/* unicode utils */
|
/* unicode utils */
|
||||||
static void get_title(in_char* dst, int dst_size, const in_char* fn, VGMSTREAM* infostream) {
|
static void get_title(in_char* dst, int dst_size, const in_char* fn, VGMSTREAM* infostream) {
|
||||||
in_char* basename;
|
|
||||||
in_char buffer[PATH_LIMIT];
|
|
||||||
in_char filename[PATH_LIMIT];
|
in_char filename[PATH_LIMIT];
|
||||||
//int stream_index = 0;
|
char buffer[PATH_LIMIT];
|
||||||
|
char filename_utf8[PATH_LIMIT];
|
||||||
|
|
||||||
parse_fn_string(fn, NULL, filename,PATH_LIMIT);
|
parse_fn_string(fn, NULL, filename,PATH_LIMIT);
|
||||||
//parse_fn_int(fn, wa_L("$s"), &stream_index);
|
//parse_fn_int(fn, wa_L("$s"), &stream_index);
|
||||||
|
|
||||||
basename = (in_char*)filename + wa_strlen(filename); /* find end */
|
wa_ichar_to_char(filename_utf8, PATH_LIMIT, filename);
|
||||||
while (*basename != '\\' && basename >= filename) /* and find last "\" */
|
|
||||||
basename--;
|
|
||||||
basename++;
|
|
||||||
wa_strcpy(dst,basename);
|
|
||||||
|
|
||||||
/* infostream gets added at first with index 0, then once played it re-adds proper numbers */
|
/* infostream gets added at first with index 0, then once played it re-adds proper numbers */
|
||||||
if (infostream) {
|
if (infostream) {
|
||||||
const char* info_name = infostream->stream_name;
|
vgmstream_title_t tcfg = {0};
|
||||||
int info_streams = infostream->num_streams;
|
|
||||||
int info_subsong = infostream->stream_index;
|
|
||||||
int is_first = infostream->stream_index == 0;
|
int is_first = infostream->stream_index == 0;
|
||||||
|
|
||||||
/* show number if file has more than 1 subsong */
|
tcfg.force_title = settings.force_title;
|
||||||
if (info_streams > 1) {
|
tcfg.subsong_range = is_first;
|
||||||
if (is_first)
|
tcfg.remove_extension = 1;
|
||||||
wa_snprintf(buffer,PATH_LIMIT, wa_L("#1~%i"), info_streams);
|
|
||||||
else
|
|
||||||
wa_snprintf(buffer,PATH_LIMIT, wa_L("#%i"), info_subsong);
|
|
||||||
wa_strcat(dst,buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* show name if file has subsongs (implicitly shows also for TXTP) */
|
vgmstream_get_title(buffer, sizeof(buffer), filename_utf8, infostream, &tcfg);
|
||||||
if (info_name[0] != '\0' && ((info_streams > 0 && !is_first) || info_streams == 1 || settings.force_title)) {
|
|
||||||
in_char stream_name[PATH_LIMIT];
|
wa_char_to_ichar(dst, dst_size, buffer);
|
||||||
wa_char_to_ichar(stream_name, PATH_LIMIT, info_name);
|
|
||||||
wa_snprintf(buffer,PATH_LIMIT, wa_L(" (%s)"), stream_name);
|
|
||||||
wa_strcat(dst,buffer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user