Skip to content

Commit

Permalink
Move and conslolidate voice count to a Storage atomic
Browse files Browse the repository at this point in the history
Make the vcoice=0->1 swap for display only in formula modulator
Add a comment to why we did this micro-cheat

Closes #7742
  • Loading branch information
baconpaul committed Nov 28, 2024
1 parent 88f6939 commit 1949672
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1364,9 +1364,11 @@ class alignas(16) SurgeStorage
bool oscReceiving{false};
bool oscSending{false};

int voiceCount; // TODO: use SurgeSynthesizer class to fetch synth->polydisplay directly from
// valueAt() in FormulaModulationHelper.cpp where it's needed and remove
// this and its assignment in SurgeSynthesizer.cpp
/*
* A bit of a cheat - this isn't really the storage, but is updated by the synth at render time.
* We put it here so LFOS can get it, which formula needs
*/
std::atomic<int> activeVoiceCount{0};

bool getOverrideDataHome(std::string &value);
void createUserDirectory();
Expand Down
5 changes: 2 additions & 3 deletions src/common/SurgeSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ SurgeSynthesizer::SurgeSynthesizer(PluginLayer *parent, const std::string &suppl
send[i][1].set_blocksize(BLOCK_SIZE);
}

polydisplay = 0;
storage.activeVoiceCount = 0;
refresh_editor = false;
patch_loaded = false;
storage.getPatch().category = "Init";
Expand Down Expand Up @@ -4822,8 +4822,7 @@ void SurgeSynthesizer::process()
}

storage.modRoutingMutex.unlock();
polydisplay = vcount;
storage.voiceCount = vcount;
storage.activeVoiceCount = vcount;

// TODO: FIX SCENE ASSUMPTION
if (play_scene[0])
Expand Down
1 change: 0 additions & 1 deletion src/common/SurgeSynthesizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ class alignas(16) SurgeSynthesizer
std::atomic<int> patchid_queue;

// updated in audio thread, read from UI, so have assignments be atomic
std::atomic<int> polydisplay;
std::atomic<int> hasUpdatedMidiCC;
std::atomic<int> modwheelCC, pitchbendMIDIVal, sustainpedalCC;
std::atomic<bool> midiSoftTakeover;
Expand Down
4 changes: 2 additions & 2 deletions src/common/dsp/modulators/FormulaModulationHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,8 @@ void valueAt(int phaseIntPart, float phaseFracPart, SurgeStorage *storage,
addi("cycle", phaseIntPart); // Alias cycle for intphase

// Fake a voice count of one for display calls
int voiceCount = storage->voiceCount;
if (voiceCount == 0)
int voiceCount = storage->activeVoiceCount;
if (voiceCount == 0 && s->is_display)
voiceCount = 1;
addi("voice_count", voiceCount);

Expand Down
4 changes: 2 additions & 2 deletions src/surge-xt/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,9 @@ void SurgeGUIEditor::idle()
{
int prior = polydisp->getPlayingVoiceCount();

if (prior != synth->polydisplay)
if (prior != synth->storage.activeVoiceCount)
{
polydisp->setPlayingVoiceCount(synth->polydisplay);
polydisp->setPlayingVoiceCount(synth->storage.activeVoiceCount);
polydisp->repaint();
}
}
Expand Down

0 comments on commit 1949672

Please sign in to comment.