Skip to content

Commit

Permalink
Make MTS-ESP Disconnected State sticky in dawExtraState (#7110)
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

Closes #7040
  • Loading branch information
baconpaul authored Jul 22, 2023
1 parent fc42067 commit 8a8ebbe
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 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
24 changes: 14 additions & 10 deletions src/surge-xt/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3674,21 +3674,25 @@ juce::PopupMenu SurgeGUIEditor::makeTuningMenu(const juce::Point<int> &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();

Expand Down

0 comments on commit 8a8ebbe

Please sign in to comment.