From 6f64fa070d53ae0461ed1adadcc0feb9cac3700d Mon Sep 17 00:00:00 2001
From: GrimReaperFloof <GrimReaperFloof@users.noreply.github.com>
Date: Wed, 26 May 2021 23:16:05 +0200
Subject: [PATCH] Add repeat count setting to openmpt decoder

---
 doc/plugins.rst                              | 2 ++
 src/decoder/plugins/OpenmptDecoderPlugin.cxx | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/doc/plugins.rst b/doc/plugins.rst
index 69a1f8361..24acdf619 100644
--- a/doc/plugins.rst
+++ b/doc/plugins.rst
@@ -505,6 +505,8 @@ Module player based on `libopenmpt <https://lib.openmpt.org>`_.
 
    * - Setting
      - Description
+   * - **repeat_count**
+     - Set how many times the module repeats. -1: repeat forever. 0: play once, repeat zero times (the default). n>0: play once and repeat n times after that.
    * - **stereo_separation**
      - Sets the stereo separation. The supported value range is [0,200]. Defaults to 100.
    * - **interpolation_filter 0|1|2|4|8**
diff --git a/src/decoder/plugins/OpenmptDecoderPlugin.cxx b/src/decoder/plugins/OpenmptDecoderPlugin.cxx
index 327fd532a..b6722a62f 100644
--- a/src/decoder/plugins/OpenmptDecoderPlugin.cxx
+++ b/src/decoder/plugins/OpenmptDecoderPlugin.cxx
@@ -38,6 +38,7 @@ static constexpr Domain openmpt_domain("openmpt");
 static constexpr size_t OPENMPT_FRAME_SIZE = 4096;
 static constexpr int32_t OPENMPT_SAMPLE_RATE = 48000;
 
+static int openmpt_repeat_count;
 static int openmpt_stereo_separation;
 static int openmpt_interpolation_filter;
 static bool openmpt_override_mptm_interp_filter;
@@ -51,6 +52,7 @@ static std::string_view openmpt_emulate_amiga_type;
 static bool
 openmpt_decoder_init(const ConfigBlock &block)
 {
+	openmpt_repeat_count = block.GetBlockValue("repeat_count", 0);
 	openmpt_stereo_separation = block.GetBlockValue("stereo_separation", 100);
 	openmpt_interpolation_filter = block.GetBlockValue("interpolation_filter", 0);
 	openmpt_override_mptm_interp_filter = block.GetBlockValue("override_mptm_interp_filter", false);
@@ -79,6 +81,7 @@ mod_decode(DecoderClient &client, InputStream &is)
 	openmpt::module mod(buffer.data(), buffer.size());
 
 	/* alter settings */
+	mod.set_repeat_count(openmpt_repeat_count);
 	mod.set_render_param(mod.RENDER_STEREOSEPARATION_PERCENT, openmpt_stereo_separation);
 	mod.set_render_param(mod.RENDER_INTERPOLATIONFILTER_LENGTH, openmpt_interpolation_filter);
 	if (!openmpt_override_mptm_interp_filter && mod.get_metadata("type") == "mptm") {