From 6345c3e6ea55cdb11c3e5227c833b51f759ee63c Mon Sep 17 00:00:00 2001 From: bnnm Date: Wed, 5 Aug 2020 21:17:34 +0200 Subject: [PATCH] Fix foobar not disabling loop forever when needed --- fb2k/foo_vgmstream.cpp | 9 +++++++-- fb2k/foo_vgmstream.h | 1 - src/plugins.c | 4 +++- src/plugins.h | 1 + src/render.c | 7 +++++++ 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/fb2k/foo_vgmstream.cpp b/fb2k/foo_vgmstream.cpp index ba2bccc8..fcb4ef56 100644 --- a/fb2k/foo_vgmstream.cpp +++ b/fb2k/foo_vgmstream.cpp @@ -248,7 +248,6 @@ t_filestats input_vgmstream::get_file_stats(abort_callback & p_abort) { // called right before actually playing (decoding) a song/subsong void input_vgmstream::decode_initialize(t_uint32 p_subsong, unsigned p_flags, abort_callback & p_abort) { - force_ignore_loop = !!(p_flags & input_flag_no_looping); // if subsong changes recreate vgmstream if (subsong != p_subsong && !direct_subsong) { @@ -256,7 +255,13 @@ void input_vgmstream::decode_initialize(t_uint32 p_subsong, unsigned p_flags, ab setup_vgmstream(p_abort); } - decode_seek( 0, p_abort ); + // "don't loop forever" flag (set when converting to file, scanning for replaygain, etc) + // flag is set *after* loading vgmstream + applying config so manually disable + bool force_ignore_loop = !!(p_flags & input_flag_no_looping); + if (force_ignore_loop) // could always set but vgmstream is re-created on play start + vgmstream_set_play_forever(vgmstream, 0); + + decode_seek(0, p_abort); }; // called when audio buffer needs to be filled diff --git a/fb2k/foo_vgmstream.h b/fb2k/foo_vgmstream.h index aa4c44ce..4f53bc17 100644 --- a/fb2k/foo_vgmstream.h +++ b/fb2k/foo_vgmstream.h @@ -58,7 +58,6 @@ class input_vgmstream : public input_stubs { double fade_delay_seconds; double loop_count; bool loop_forever; - bool force_ignore_loop; int ignore_loop; bool disable_subsongs; diff --git a/src/plugins.c b/src/plugins.c index 7bec001f..77c7ef5e 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -80,9 +80,9 @@ static void load_default_config(play_config_t* def, play_config_t* tcfg) { def->ignore_loop = 0; } if (tcfg->loop_count_set) { - def->ignore_loop = 0; def->loop_count = tcfg->loop_count; def->loop_count_set = 1; + def->ignore_loop = 0; if (!tcfg->play_forever) def->play_forever = 0; } @@ -93,9 +93,11 @@ static void load_default_config(play_config_t* def, play_config_t* tcfg) { } if (tcfg->fade_delay_set) { def->fade_delay = tcfg->fade_delay; + def->fade_delay_set = 1; } if (tcfg->fade_time_set) { def->fade_time = tcfg->fade_time; + def->fade_time_set = 1; } /* loop priority: #i > #e > #E */ diff --git a/src/plugins.h b/src/plugins.h index 8b26cdf3..a539c520 100644 --- a/src/plugins.h +++ b/src/plugins.h @@ -65,6 +65,7 @@ typedef struct { void vgmstream_apply_config(VGMSTREAM* vgmstream, vgmstream_cfg_t* pcfg); int32_t vgmstream_get_samples(VGMSTREAM* vgmstream); int vgmstream_get_play_forever(VGMSTREAM* vgmstream); +void vgmstream_set_play_forever(VGMSTREAM* vgmstream, int enabled); diff --git a/src/render.c b/src/render.c index 72e16a8d..a6ae9ff2 100644 --- a/src/render.c +++ b/src/render.c @@ -52,6 +52,13 @@ int vgmstream_get_play_forever(VGMSTREAM* vgmstream) { return vgmstream->config.play_forever; } +void vgmstream_set_play_forever(VGMSTREAM* vgmstream, int enabled) { + /* sometimes we need to enable/disable right before playback + * (play config is left untouched, should mix ok as this flag is only used during + * render, while config is always prepared as if play forever wasn't enabled) */ + vgmstream->config.play_forever = enabled; +} + int32_t vgmstream_get_samples(VGMSTREAM* vgmstream) { if (!vgmstream->config_enabled || !vgmstream->config.config_set) return vgmstream->num_samples;