Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devices/liquidsfz/liquidsfz.cc: track instrument changes while loading #65

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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