From ba0345ceb61c6aa4faccdb5c27cd0d1ea8bb09b6 Mon Sep 17 00:00:00 2001 From: bnnm Date: Fri, 15 Feb 2019 23:46:21 +0100 Subject: [PATCH] Show loop info even when disabling loops in plugin's config --- fb2k/foo_vgmstream.cpp | 16 ++++++++-------- fb2k/foo_vgmstream.h | 2 +- src/vgmstream.c | 21 ++++++++++++++------- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/fb2k/foo_vgmstream.cpp b/fb2k/foo_vgmstream.cpp index 609c8486..624d48e0 100644 --- a/fb2k/foo_vgmstream.cpp +++ b/fb2k/foo_vgmstream.cpp @@ -131,11 +131,11 @@ void input_vgmstream::get_info(t_uint32 p_subsong, file_info & p_info, abort_cal int length_in_ms=0, channels = 0, samplerate = 0; int total_samples = -1; int bitrate = 0; - int loop_start = -1, loop_end = -1; + int loop_flag = -1, loop_start = -1, loop_end = -1; pfc::string8 description; pfc::string8_fast temp; - get_subsong_info(p_subsong, temp, &length_in_ms, &total_samples, &loop_start, &loop_end, &samplerate, &channels, &bitrate, description, p_abort); + get_subsong_info(p_subsong, temp, &length_in_ms, &total_samples, &loop_flag, &loop_start, &loop_end, &samplerate, &channels, &bitrate, description, p_abort); /* set tag info (metadata tab in file properties) */ @@ -193,7 +193,8 @@ void input_vgmstream::get_info(t_uint32 p_subsong, file_info & p_info, abort_cal p_info.info_set_bitrate(bitrate / 1000); if (total_samples > 0) p_info.info_set_int("stream_total_samples", total_samples); - if (loop_start >= 0 && loop_end >= loop_start) { + if (loop_start >= 0 && loop_end > loop_start) { + p_info.info_set("looping", loop_flag > 0 ? "enabled" : "disabled"); p_info.info_set_int("loop_start", loop_start); p_info.info_set_int("loop_end", loop_end); } @@ -440,7 +441,7 @@ void input_vgmstream::setup_vgmstream(abort_callback & p_abort) { fade_samples = (int)(config.song_fade_time * vgmstream->sample_rate); } -void input_vgmstream::get_subsong_info(t_uint32 p_subsong, pfc::string_base & title, int *length_in_ms, int *total_samples, int *loop_start, int *loop_end, int *sample_rate, int *channels, int *bitrate, pfc::string_base & description, abort_callback & p_abort) { +void input_vgmstream::get_subsong_info(t_uint32 p_subsong, pfc::string_base & title, int *length_in_ms, int *total_samples, int *loop_flag, int *loop_start, int *loop_end, int *sample_rate, int *channels, int *bitrate, pfc::string_base & description, abort_callback & p_abort) { VGMSTREAM * infostream = NULL; bool is_infostream = false; foobar_song_config infoconfig; @@ -473,10 +474,9 @@ void input_vgmstream::get_subsong_info(t_uint32 p_subsong, pfc::string_base & ti *channels = infostream->channels; *total_samples = infostream->num_samples; *bitrate = get_vgmstream_average_bitrate(infostream); - if (infostream->loop_flag) { - *loop_start = infostream->loop_start_sample; - *loop_end = infostream->loop_end_sample; - } + *loop_flag = infostream->loop_flag; + *loop_start = infostream->loop_start_sample; + *loop_end = infostream->loop_end_sample; char temp[1024]; describe_vgmstream(infostream, temp, 1024); diff --git a/fb2k/foo_vgmstream.h b/fb2k/foo_vgmstream.h index 52933247..a72dbf11 100644 --- a/fb2k/foo_vgmstream.h +++ b/fb2k/foo_vgmstream.h @@ -85,7 +85,7 @@ class input_vgmstream : public input_stubs { VGMSTREAM * init_vgmstream_foo(t_uint32 p_subsong, const char * const filename, abort_callback & p_abort); void setup_vgmstream(abort_callback & p_abort); void load_settings(); - void get_subsong_info(t_uint32 p_subsong, pfc::string_base & title, int *length_in_ms, int *total_samples, int *loop_start, int *loop_end, int *sample_rate, int *channels, int *bitrate, pfc::string_base & description, abort_callback & p_abort); + void get_subsong_info(t_uint32 p_subsong, pfc::string_base & title, int *length_in_ms, int *total_samples, int *loop_flag, int *loop_start, int *loop_end, int *sample_rate, int *channels, int *bitrate, pfc::string_base & description, abort_callback & p_abort); bool get_description_tag(pfc::string_base & temp, pfc::string_base const& description, const char *tag, char delimiter = '\n'); void set_config_defaults(foobar_song_config *current); void apply_config(VGMSTREAM * vgmstream, foobar_song_config *current); diff --git a/src/vgmstream.c b/src/vgmstream.c index 63622f89..d24f5f43 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -506,15 +506,17 @@ static VGMSTREAM * init_vgmstream_internal(STREAMFILE *streamFile) { close_vgmstream(vgmstream); continue; } - - /* Sanify loops! */ + + /* sanify loops and remove bad metadata */ if (vgmstream->loop_flag) { if (vgmstream->loop_end_sample <= vgmstream->loop_start_sample || vgmstream->loop_end_sample > vgmstream->num_samples || vgmstream->loop_start_sample < 0) { - vgmstream->loop_flag = 0; VGM_LOG("VGMSTREAM: wrong loops ignored (lss=%i, lse=%i, ns=%i)\n", vgmstream->loop_start_sample, vgmstream->loop_end_sample, vgmstream->num_samples); + vgmstream->loop_flag = 0; + vgmstream->loop_start_sample = 0; + vgmstream->loop_end_sample = 0; } } @@ -542,8 +544,9 @@ static VGMSTREAM * init_vgmstream_internal(STREAMFILE *streamFile) { /* save info */ /* stream_index 0 may be used by plugins to signal "vgmstream default" (IOW don't force to 1) */ - if (vgmstream->stream_index == 0) + if (vgmstream->stream_index == 0) { vgmstream->stream_index = streamFile->stream_index; + } setup_vgmstream(vgmstream); /* final setup */ @@ -958,11 +961,13 @@ void vgmstream_force_loop(VGMSTREAM* vgmstream, int loop_flag, int loop_start_sa if (loop_flag) { vgmstream->loop_start_sample = loop_start_sample; vgmstream->loop_end_sample = loop_end_sample; - } else { + } +#if 0 /* keep metadata as it's may be shown (with 'loop disabled' info) */ + else { vgmstream->loop_start_sample = 0; vgmstream->loop_end_sample = 0; } - +#endif /* propagate changes to layouts that need them */ if (vgmstream->layout_type == layout_layered) { @@ -2275,10 +2280,12 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) { vgmstream->channels); concatn(length,desc,temp); - if (vgmstream->loop_flag) { + if (vgmstream->loop_start_sample >= 0 && vgmstream->loop_end_sample > vgmstream->loop_start_sample) { snprintf(temp,TEMPSIZE, + "looping: %s\n" "loop start: %d samples (%.4f seconds)\n" "loop end: %d samples (%.4f seconds)\n", + vgmstream->loop_flag ? "enabled" : "disabled", vgmstream->loop_start_sample, (double)vgmstream->loop_start_sample/vgmstream->sample_rate, vgmstream->loop_end_sample,