From 7a551f95ca1df5cef2338ffdbe9986480e18945a Mon Sep 17 00:00:00 2001 From: brummer10 Date: Fri, 23 Dec 2022 06:31:31 +0100 Subject: [PATCH] Fix issue #18 Fluida loses GUI state on hide/show window --- Fluida/fluida.cpp | 23 +++++++++++++++++++++-- Fluida/fluida_ui.c | 1 + Fluida/lv2_plugin.cc | 7 ++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Fluida/fluida.cpp b/Fluida/fluida.cpp index af9e794..c903c88 100644 --- a/Fluida/fluida.cpp +++ b/Fluida/fluida.cpp @@ -200,6 +200,7 @@ class Fluida_ { inline void retrieve_ctrl_values(const LV2_Atom_Object* obj); inline void send_filebrowser_state(); inline void send_controller_state(); + inline void send_all_controller_state(); inline void send_instrument_state(); inline void send_next_instrument_state(); inline void do_non_rt_work_f(); @@ -274,7 +275,7 @@ Fluida_::Fluida_() : // destructor Fluida_::~Fluida_() { - xsynth.unload_synth(); + //xsynth.unload_synth(); flworker.stop(); }; @@ -524,6 +525,23 @@ void Fluida_::send_controller_state() { } } +void Fluida_::send_all_controller_state() { + FluidaLV2URIs* uris = &this->uris; + write_float_value(uris->fluida_rev_lev,(float)xsynth.reverb_level); + write_float_value(uris->fluida_rev_width, (float)xsynth.reverb_width); + write_float_value(uris->fluida_rev_damp, (float)xsynth.reverb_damp); + write_float_value(uris->fluida_rev_size, (float)xsynth.reverb_roomsize); + write_bool_value(uris->fluida_rev_on, (float)xsynth.reverb_on); + + write_int_value(uris->fluida_chorus_type, (float)xsynth.chorus_type); + write_float_value(uris->fluida_chorus_depth, (float)xsynth.chorus_depth); + write_float_value(uris->fluida_chorus_speed, (float)xsynth.chorus_speed); + write_float_value(uris->fluida_chorus_lev, (float)xsynth.chorus_level); + write_int_value(uris->fluida_chorus_voices, (float)xsynth.chorus_voices); + write_bool_value(uris->fluida_chorus_on, (float)xsynth.chorus_on); + write_int_value(uris->fluida_channel_pressure, (float)xsynth.channel_pressure); +} + void Fluida_::retrieve_ctrl_values(const LV2_Atom_Object* obj) { FluidaLV2URIs* uris = &this->uris; const LV2_Atom* value = NULL; @@ -638,9 +656,10 @@ void Fluida_::run_dsp_(uint32_t n_samples) { const LV2_Atom* value = read_set_gui(uris, obj); if (value) { //flags = ~(-1 << 15); + flags |= SEND_SOUNDFONT | SEND_INSTRUMENTS; send_filebrowser_state(); send_instrument_state(); - send_controller_state(); + send_all_controller_state(); } } else if (obj->body.otype == uris->fluida_sflist_next) { send_next_instrument_state(); diff --git a/Fluida/fluida_ui.c b/Fluida/fluida_ui.c index c71829d..38ef537 100644 --- a/Fluida/fluida_ui.c +++ b/Fluida/fluida_ui.c @@ -465,6 +465,7 @@ void plugin_cleanup(X11_UI *ui) { } free(ps->instruments); free(ps); + ps = NULL; ui->private_ptr = NULL; } diff --git a/Fluida/lv2_plugin.cc b/Fluida/lv2_plugin.cc index 4d2f122..6ce8d0b 100644 --- a/Fluida/lv2_plugin.cc +++ b/Fluida/lv2_plugin.cc @@ -149,7 +149,6 @@ static LV2UI_Handle instantiate(const LV2UI_Descriptor * descriptor, ui->controller = controller; // store pointer to the host write function ui->write_function = write_function; - return (LV2UI_Handle)ui; } @@ -181,8 +180,10 @@ static int ui_idle(LV2UI_Handle handle) { X11_UI* ui = (X11_UI*)handle; // Xputty event loop setup to run one cycle when called run_embedded(&ui->main); - if (!ui->first_loop) first_loop(ui); - ui->first_loop = 1; + if (!ui->first_loop) { + first_loop(ui); + ui->first_loop = 1; + } return 0; }