Skip to content

Commit

Permalink
Handle Tuning Mode error when Togglign MTS (surge-synthesizer#5397)
Browse files Browse the repository at this point in the history
When toggling MTS from a non-RETUNE_MIDI patch the synth
ended up in a mixed state of half-MTS half-native tuning.
So

1. Set the state to RETUNE MIDI if MTS is active
2. Keep the 'patch' state around so we can keep it saved for
   non mts applications

Addresses surge-synthesizer#5386 but there's more to do there - can I make the
filter tuning work with MTS is the open question left.
  • Loading branch information
baconpaul authored Nov 14, 2021
1 parent 5b1e0c7 commit fc8e653
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/common/SurgePatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2481,7 +2481,14 @@ unsigned int SurgePatch::save_xml(void **data) // allocates mem, must be freed b

// Revision 16 adds the TAM
TiXmlElement tam("tuningApplicationMode");
tam.SetAttribute("v", (int)(storage->tuningApplicationMode));
if (storage->oddsound_mts_active)
{
tam.SetAttribute("v", (int)(storage->patchStoredTuningApplicationMode));
}
else
{
tam.SetAttribute("v", (int)(storage->tuningApplicationMode));
}
nonparamconfig.InsertEndChild(tam);

patch.InsertEndChild(nonparamconfig);
Expand Down
25 changes: 23 additions & 2 deletions src/common/SurgeStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2093,7 +2093,12 @@ bool SurgeStorage::resetToCurrentScaleAndMapping()
void SurgeStorage::setTuningApplicationMode(const TuningApplicationMode m)
{
tuningApplicationMode = m;
patchStoredTuningApplicationMode = m;
resetToCurrentScaleAndMapping();
if (oddsound_mts_active)
{
tuningApplicationMode = RETUNE_MIDI_ONLY;
}
}

bool SurgeStorage::skipLoadWtAndPatch = false;
Expand Down Expand Up @@ -2250,7 +2255,7 @@ void SurgeStorage::initialize_oddsound()
oddsound_mts_client = MTS_RegisterClient();
if (oddsound_mts_client)
{
oddsound_mts_active = MTS_HasMaster(oddsound_mts_client);
setOddsoundMTSActiveTo(MTS_HasMaster(oddsound_mts_client));
}
}

Expand All @@ -2261,7 +2266,23 @@ void SurgeStorage::deinitialize_oddsound()
MTS_DeregisterClient(oddsound_mts_client);
}
oddsound_mts_client = nullptr;
oddsound_mts_active = false;
setOddsoundMTSActiveTo(false);
}

void SurgeStorage::setOddsoundMTSActiveTo(bool b)
{
bool poa = oddsound_mts_active;
oddsound_mts_active = b;
if (b && b != poa)
{
// Oddsound right now is MIDI_ONLY so force that to avoid
// lingering problems
tuningApplicationMode = RETUNE_MIDI_ONLY;
}
if (!b && b != poa)
{
tuningApplicationMode = patchStoredTuningApplicationMode;
}
}

void SurgeStorage::toggleTuningToCache()
Expand Down
5 changes: 4 additions & 1 deletion src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,9 @@ class alignas(16) SurgeStorage
{
RETUNE_ALL = 0, // These values are streamed so don't change them if you add
RETUNE_MIDI_ONLY = 1
} tuningApplicationMode = RETUNE_MIDI_ONLY; // This is the default as of 1.9/sv16
} tuningApplicationMode = RETUNE_MIDI_ONLY,
patchStoredTuningApplicationMode =
tuningApplicationMode; // This is the default as of 1.9/sv16

float tuningPitch = 32.0f, tuningPitchInv = 0.03125f;

Expand Down Expand Up @@ -1241,6 +1243,7 @@ class alignas(16) SurgeStorage
void deinitialize_oddsound();
MTSClient *oddsound_mts_client = nullptr;
std::atomic<bool> oddsound_mts_active;
void setOddsoundMTSActiveTo(bool b);
uint32_t oddsound_mts_on_check = 0;
enum OddsoundRetuneMode
{
Expand Down
3 changes: 2 additions & 1 deletion src/common/SurgeSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3611,7 +3611,8 @@ void SurgeSynthesizer::processControl()
if (storage.oddsound_mts_on_check == 0)
{
bool prior = storage.oddsound_mts_active;
storage.oddsound_mts_active = MTS_HasMaster(storage.oddsound_mts_client);
storage.setOddsoundMTSActiveTo(MTS_HasMaster(storage.oddsound_mts_client));

if (prior != storage.oddsound_mts_active)
{
refresh_editor = true;
Expand Down

0 comments on commit fc8e653

Please sign in to comment.