Skip to content

Commit

Permalink
Make MTS-ESP Disconnected State sticky in dawExtraState
Browse files Browse the repository at this point in the history
Add the Disconnected state to the dawExtraState so you can do
a mix of connected and disconnected in a single reaper session

Addreses surge-synthesizer#7040
  • Loading branch information
baconpaul committed Jul 22, 2023
1 parent fc42067 commit 3994b4d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/common/SurgePatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,8 @@ struct DAWExtraStateStorage
int oddsoundRetuneMode = 0;

bool isDirty{false};

bool disconnectFromOddSoundMTS{false};
};

struct PatchTuningStorage
Expand Down
24 changes: 19 additions & 5 deletions src/common/SurgeSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/surge-xt/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3677,6 +3677,7 @@ juce::PopupMenu SurgeGUIEditor::makeTuningMenu(const juce::Point<int> &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;
});
}

Expand All @@ -3687,6 +3688,7 @@ juce::PopupMenu SurgeGUIEditor::makeTuningMenu(const juce::Point<int> &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);
});

Expand Down

0 comments on commit 3994b4d

Please sign in to comment.