From 8a8ebbe04d32d2db02e54b857f79bcfc5748b2e4 Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 22 Jul 2023 19:18:17 -0400 Subject: [PATCH] Make MTS-ESP Disconnected State sticky in dawExtraState (#7110) Add the Disconnected state to the dawExtraState so you can do a mix of connected and disconnected in a single reaper session Closes #7040 --- src/common/SurgePatch.cpp | 12 ++++++++++++ src/common/SurgeStorage.h | 2 ++ src/common/SurgeSynthesizer.cpp | 24 +++++++++++++++++++----- src/surge-xt/gui/SurgeGUIEditor.cpp | 24 ++++++++++++++---------- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/common/SurgePatch.cpp b/src/common/SurgePatch.cpp index 76b8d1dc95f..d6db031678b 100644 --- a/src/common/SurgePatch.cpp +++ b/src/common/SurgePatch.cpp @@ -2922,6 +2922,14 @@ void SurgePatch::load_xml(const void *data, int datasize, bool is_preset) dawExtraState.isDirty = ival; } + p = TINYXML_SAFE_TO_ELEMENT(de->FirstChild("disconnectFromOddSoundMTS")); + dawExtraState.disconnectFromOddSoundMTS = false; + + if (p && p->QueryIntAttribute("v", &ival) == TIXML_SUCCESS) + { + dawExtraState.disconnectFromOddSoundMTS = ival; + } + p = TINYXML_SAFE_TO_ELEMENT(de->FirstChild("mpePitchBendRange")); if (p && p->QueryIntAttribute("v", &ival) == TIXML_SUCCESS) @@ -3657,6 +3665,10 @@ unsigned int SurgePatch::save_xml(void **data) // allocates mem, must be freed b isDi.SetAttribute("v", dawExtraState.isDirty ? 1 : 0); dawExtraXML.InsertEndChild(isDi); + TiXmlElement odS("disconnectFromOddSoundMTS"); + odS.SetAttribute("v", dawExtraState.disconnectFromOddSoundMTS ? 1 : 0); + dawExtraXML.InsertEndChild(odS); + TiXmlElement mpm("monoPedalMode"); mpm.SetAttribute("v", dawExtraState.monoPedalMode); dawExtraXML.InsertEndChild(mpm); diff --git a/src/common/SurgeStorage.h b/src/common/SurgeStorage.h index 8c02a9caef7..7c3391a6068 100644 --- a/src/common/SurgeStorage.h +++ b/src/common/SurgeStorage.h @@ -961,6 +961,8 @@ struct DAWExtraStateStorage int oddsoundRetuneMode = 0; bool isDirty{false}; + + bool disconnectFromOddSoundMTS{false}; }; struct PatchTuningStorage diff --git a/src/common/SurgeSynthesizer.cpp b/src/common/SurgeSynthesizer.cpp index 6f25f8b4198..c08f259c4ea 100644 --- a/src/common/SurgeSynthesizer.cpp +++ b/src/common/SurgeSynthesizer.cpp @@ -4197,12 +4197,26 @@ void SurgeSynthesizer::processControl() storage.oddsound_mts_on_check = (storage.oddsound_mts_on_check + 1) & (1024 - 1); if (storage.oddsound_mts_on_check == 0) { - bool prior = storage.oddsound_mts_active_as_client; - storage.setOddsoundMTSActiveTo(MTS_HasMaster(storage.oddsound_mts_client)); - - if (prior != storage.oddsound_mts_active_as_client) + if (storage.getPatch().dawExtraState.disconnectFromOddSoundMTS) { - refresh_editor = true; + if (storage.oddsound_mts_active_as_client) + { + auto q = storage.oddsound_mts_client; + storage.oddsound_mts_active_as_client = false; + storage.oddsound_mts_client = nullptr; + MTS_DeregisterClient(q); + refresh_editor = true; + } + } + else + { + bool prior = storage.oddsound_mts_active_as_client; + storage.setOddsoundMTSActiveTo(MTS_HasMaster(storage.oddsound_mts_client)); + + if (prior != storage.oddsound_mts_active_as_client) + { + refresh_editor = true; + } } } } diff --git a/src/surge-xt/gui/SurgeGUIEditor.cpp b/src/surge-xt/gui/SurgeGUIEditor.cpp index 0a79bc0d6a1..b8a80159963 100644 --- a/src/surge-xt/gui/SurgeGUIEditor.cpp +++ b/src/surge-xt/gui/SurgeGUIEditor.cpp @@ -3674,21 +3674,25 @@ juce::PopupMenu SurgeGUIEditor::makeTuningMenu(const juce::Point &where, bo if (tsMode && !this->synth->storage.oddsound_mts_client && !getStorage()->oddsound_mts_active_as_main) { - tuningSubMenu.addItem(Surge::GUI::toOSCase("Reconnect as Client to MTS-ESP"), [this]() { - this->synth->storage.initialize_oddsound(); - this->synth->refresh_editor = true; - }); + tuningSubMenu.addItem( + Surge::GUI::toOSCase("Reconnect Instance as MTS-ESP Client"), [this]() { + this->synth->storage.initialize_oddsound(); + this->synth->refresh_editor = true; + this->synth->storage.getPatch().dawExtraState.disconnectFromOddSoundMTS = false; + }); } if (this->synth->storage.oddsound_mts_active_as_client && this->synth->storage.oddsound_mts_client) { - tuningSubMenu.addItem(Surge::GUI::toOSCase("Disconnect as Client from MTS-ESP"), [this]() { - auto q = this->synth->storage.oddsound_mts_client; - this->synth->storage.oddsound_mts_active_as_client = false; - this->synth->storage.oddsound_mts_client = nullptr; - MTS_DeregisterClient(q); - }); + tuningSubMenu.addItem( + Surge::GUI::toOSCase("Disconnect Instance as MTS-ESP Client"), [this]() { + auto q = this->synth->storage.oddsound_mts_client; + this->synth->storage.oddsound_mts_active_as_client = false; + this->synth->storage.oddsound_mts_client = nullptr; + this->synth->storage.getPatch().dawExtraState.disconnectFromOddSoundMTS = true; + MTS_DeregisterClient(q); + }); tuningSubMenu.addSeparator();