From 3994b4d96b115b3d43b5178f3e224cecf6818076 Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Sat, 22 Jul 2023 18:40:23 -0400 Subject: [PATCH] Make MTS-ESP Disconnected State sticky in dawExtraState Add the Disconnected state to the dawExtraState so you can do a mix of connected and disconnected in a single reaper session Addreses #7040 --- src/common/SurgePatch.cpp | 12 ++++++++++++ src/common/SurgeStorage.h | 2 ++ src/common/SurgeSynthesizer.cpp | 24 +++++++++++++++++++----- src/surge-xt/gui/SurgeGUIEditor.cpp | 2 ++ 4 files changed, 35 insertions(+), 5 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..d9ab8f7f18b 100644 --- a/src/surge-xt/gui/SurgeGUIEditor.cpp +++ b/src/surge-xt/gui/SurgeGUIEditor.cpp @@ -3677,6 +3677,7 @@ juce::PopupMenu SurgeGUIEditor::makeTuningMenu(const juce::Point &where, bo tuningSubMenu.addItem(Surge::GUI::toOSCase("Reconnect as Client to MTS-ESP"), [this]() { this->synth->storage.initialize_oddsound(); this->synth->refresh_editor = true; + this->synth->storage.getPatch().dawExtraState.disconnectFromOddSoundMTS = false; }); } @@ -3687,6 +3688,7 @@ juce::PopupMenu SurgeGUIEditor::makeTuningMenu(const juce::Point &where, bo 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); });