From f26784bceeb68dea81cc1d952307a2fcf7d896a3 Mon Sep 17 00:00:00 2001 From: Stefan Westerfeld Date: Tue, 18 Jun 2024 12:47:30 -0700 Subject: [PATCH 1/2] devices/liquidsfz/liquidsfz.cc: fix for LiquidSFZ race cond by Stefan Westerfeld, #44 https://github.com/tim-janik/anklang/issues/44 swesterfeld commented Jun 18, 2024: > > tim-janik commented Jun 18, 2024: > > all input events must always be processed in render > > I agree. At least the filename changes, midi events can safely be dropped while a file is being loaded. > > Your patch is not good, because it will introduce race conditions of both threads accessing the same data. > Since we cannot use locks due to RT constraints, I guess the real fix will be to use a lock-free queue to send events to the loader thread. > I'll look into it and come up with a real fix and submit a PR. > However, here is a quick fix that just avoids the initial load problem and is still safe as in it doesn't introduce race conditions Signed-off-by: Tim Janik --- devices/liquidsfz/liquidsfz.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devices/liquidsfz/liquidsfz.cc b/devices/liquidsfz/liquidsfz.cc index 00abb7d8..ea97bf9b 100644 --- a/devices/liquidsfz/liquidsfz.cc +++ b/devices/liquidsfz/liquidsfz.cc @@ -73,7 +73,7 @@ class LiquidSFZLoader { if (state_.load() == STATE_IDLE) { - if (want_sfz_ == have_sfz_ && want_sample_rate_ == have_sample_rate_) + if (want_sfz_ == have_sfz_ && (want_sample_rate_ == have_sample_rate_ || want_sfz_ == "")) return true; } state_.store (STATE_LOAD); From b4ecaec53b1d1df72a31c177322dfb7e763f799e Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Tue, 18 Jun 2024 23:23:58 +0200 Subject: [PATCH 2/2] devices/liquidsfz/liquidsfz.cc: add TODO about unconditional event processing See also: https://github.com/tim-janik/anklang/issues/44#issuecomment-2176839260 Signed-off-by: Tim Janik --- devices/liquidsfz/liquidsfz.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/devices/liquidsfz/liquidsfz.cc b/devices/liquidsfz/liquidsfz.cc index ea97bf9b..b43c3996 100644 --- a/devices/liquidsfz/liquidsfz.cc +++ b/devices/liquidsfz/liquidsfz.cc @@ -173,6 +173,8 @@ class LiquidSFZ : public AudioProcessor { void render (uint n_frames) override { + // TODO: rework the logic so midi_event_input(), and in particular MidiMessage::PARAM_VALUE are processed unconditionally + // See also: https://github.com/tim-janik/anklang/issues/44#issuecomment-2176839260 if (loader_.idle()) { if (synth_need_reset_)