Skip to content

Commit

Permalink
devices/liquidsfz/liquidsfz.cc: track instrument changes while loading
Browse files Browse the repository at this point in the history
See also tim-janik#44.

Signed-off-by: Stefan Westerfeld <[email protected]>
  • Loading branch information
swesterfeld committed Jun 27, 2024
1 parent 5993a34 commit ee92328
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions devices/liquidsfz/liquidsfz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class LiquidSFZ : public AudioProcessor {
OBusId stereo_out_;
Synth synth_;
bool synth_need_reset_ = false;
bool instrument_changed_ = false;
LiquidSFZLoader loader_;

enum Params {
Expand Down Expand Up @@ -150,7 +151,7 @@ class LiquidSFZ : public AudioProcessor {
switch (tag)
{
case INSTRUMENT:
loader_.load (text_param_from_quark (INSTRUMENT, irintf (get_param (tag))));
instrument_changed_ = true;
break;
}
}
Expand All @@ -173,9 +174,14 @@ 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())
bool loader_idle = loader_.idle();
if (instrument_changed_ && loader_idle)
{
loader_.load (text_param_from_quark (INSTRUMENT, irintf (get_param (INSTRUMENT))));
instrument_changed_ = false;
loader_idle = loader_.idle(); /* calling load can change idle state */
}
if (loader_idle)
{
if (synth_need_reset_)
{
Expand Down Expand Up @@ -216,6 +222,16 @@ class LiquidSFZ : public AudioProcessor {
}
else
{
// loader thread is busy, so we can't access synth_ - ignore all events that affect synth_
MidiEventInput evinput = midi_event_input();
for (const auto &ev : evinput)
{
if (ev.message() == MidiMessage::PARAM_VALUE) // still track instrument changes, though
{
apply_event (ev);
adjust_param (ev.param);
}
}
float *left_out = oblock (stereo_out_, 0);
float *right_out = oblock (stereo_out_, 1);

Expand Down

0 comments on commit ee92328

Please sign in to comment.