Skip to content

Commit 9e73f42

Browse files
authored
Formula: Add host transport to state table (#8488)
* Formula: Add host transport to state table
1 parent c65d4ce commit 9e73f42

9 files changed

Lines changed: 37 additions & 21 deletions

File tree

scripts/misc/Formula-state-variable-test.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function init(state)
1717
print("highest_key", state.highest_key)
1818
print("hold", state.hold)
1919
print("intphase", state.intphase)
20+
print("is_playing", state.is_playing)
2021
print("is_rendering_to_ui", state.is_rendering_to_ui)
2122
print("is_voice", state.is_voice)
2223
print("key", state.key)
@@ -79,6 +80,7 @@ function process(state)
7980
print("highest_key", state.highest_key)
8081
print("hold", state.hold)
8182
print("intphase", state.intphase)
83+
print("is_playing", state.is_playing)
8284
print("is_rendering_to_ui", state.is_rendering_to_ui)
8385
print("is_voice", state.is_voice)
8486
print("key", state.key)

src/common/SurgeStorage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,7 @@ class alignas(16) SurgeStorage
16201620
float temposyncratio, temposyncratio_inv; // 1.f is 120 BPM
16211621
float unstreamedTempo{120.f}; // this one is in actual BPM
16221622
double songpos;
1623+
bool isPlaying{false}; // host transport state
16231624
void init_tables();
16241625
float nyquist_pitch;
16251626
int last_key[2]; // TODO: FIX SCENE ASSUMPTION

src/common/SurgeSynthesizer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4324,6 +4324,7 @@ void SurgeSynthesizer::resetStateFromTimeData()
43244324
if (time_data.timeSigDenominator < 1)
43254325
time_data.timeSigDenominator = 4;
43264326
storage.songpos = time_data.ppqPos;
4327+
storage.isPlaying = time_data.isPlaying;
43274328
if (time_data.tempo > 0)
43284329
{
43294330
storage.temposyncratio = time_data.tempo / 120.f;

src/common/SurgeSynthesizer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct timedata
4242
{
4343
double ppqPos, tempo;
4444
int timeSigNumerator = 4, timeSigDenominator = 4;
45+
bool isPlaying = false;
4546
};
4647

4748
struct parametermeta

src/common/dsp/modulators/FormulaModulationHelper.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ end
276276

277277
addn("tempo", s.tempo);
278278
addn("songpos", s.songpos);
279+
addb("is_playing", s.isPlaying);
279280
addn("pb_range_up", s.pbrange_up);
280281
addn("pb_range_dn", s.pbrange_dn);
281282
addn("mpe_bendrange", s.mpebendrange);
@@ -650,6 +651,7 @@ void valueAt(int phaseIntPart, float phaseFracPart, SurgeStorage *storage,
650651
addn("phase", phaseFracPart);
651652
addn("tempo", s->tempo);
652653
addn("songpos", s->songpos);
654+
addb("is_playing", s->isPlaying);
653655

654656
addn("pb", s->pitchbend);
655657
addn("pb_range_up", s->pbrange_up);
@@ -876,27 +878,27 @@ enum showFilter
876878
bool isUserDefined(std::string str)
877879
{
878880
// clang-format off
879-
static constexpr std::array<std::string_view, 59> keywords = {
880-
"amplitude", "attack", "block_size",
881-
"cc_breath", "cc_expr", "cc_mw",
882-
"cc_sus", "chan_at", "channel",
883-
"clamp_output", "cycle", "decay",
884-
"deform", "delay", "highest_key",
885-
"hold", "intphase", "is_rendering_to_ui",
886-
"is_voice", "key", "labels",
887-
"latest_key", "lfo_id", "lowest_key",
888-
"macros", "mpe_bend", "mpe_bendrange",
889-
"mpe_enabled", "mpe_pressure", "mpe_timbre",
890-
"output", "pb", "pb_range_dn",
891-
"pb_range_up", "phase", "play_mode",
892-
"poly_at", "poly_limit", "rate",
893-
"rel_velocity", "release", "released",
894-
"retrigger_AEG", "retrigger_FEG", "samplerate",
895-
"scene_mode", "songpos", "split_point",
896-
"startphase", "sustain", "tempo",
897-
"tuned_key", "use_amplitude", "use_envelope",
898-
"use_rate", "velocity", "voice_count",
899-
"voice_id", "subscriptions"};
881+
static constexpr std::array<std::string_view, 60> keywords = {
882+
"amplitude", "attack", "block_size",
883+
"cc_breath", "cc_expr", "cc_mw",
884+
"cc_sus", "chan_at", "channel",
885+
"clamp_output", "cycle", "decay",
886+
"deform", "delay", "highest_key",
887+
"hold", "intphase", "is_playing",
888+
"is_rendering_to_ui", "is_voice", "key",
889+
"labels", "latest_key", "lfo_id",
890+
"lowest_key", "macros", "mpe_bend",
891+
"mpe_bendrange", "mpe_enabled", "mpe_pressure",
892+
"mpe_timbre", "output", "pb",
893+
"pb_range_dn", "pb_range_up", "phase",
894+
"play_mode", "poly_at", "poly_limit",
895+
"rate", "rel_velocity", "release",
896+
"released", "retrigger_AEG", "retrigger_FEG",
897+
"samplerate", "scene_mode", "songpos",
898+
"split_point", "startphase", "sustain",
899+
"tempo", "tuned_key", "use_amplitude",
900+
"use_envelope", "use_rate", "velocity",
901+
"voice_count", "voice_id", "subscriptions"};
900902
// clang-format on
901903

902904
auto foundInList = std::find(keywords.begin(), keywords.end(), str) != keywords.end();

src/common/dsp/modulators/FormulaModulationHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ struct EvaluatorState
7171
float rate, amp, phase, deform;
7272
float tempo;
7373
double songpos;
74+
bool isPlaying{false};
7475

7576
bool retrigger_AEG{false}, retrigger_FEG{false};
7677

src/common/dsp/modulators/LFOModulationSource.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ void LFOModulationSource::attackFrom(float start)
483483
formulastate.deform = localcopy[ideform].f;
484484
formulastate.tempo = storage->temposyncratio * 120.0;
485485
formulastate.songpos = storage->songpos;
486+
formulastate.isPlaying = storage->isPlaying;
486487

487488
formulastate.isVoice = isVoice;
488489

@@ -1211,6 +1212,7 @@ void LFOModulationSource::process_block()
12111212
formulastate.deform = localcopy[ideform].f;
12121213
formulastate.tempo = storage->temposyncratio * 120.0;
12131214
formulastate.songpos = storage->songpos;
1215+
formulastate.isPlaying = storage->isPlaying;
12141216

12151217
formulastate.isVoice = isVoice;
12161218

src/surge-xt/SurgeSynthProcessor.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@ void SurgeSynthProcessor::processBlockPlayhead()
791791
juce::AudioPlayHead::CurrentPositionInfo cp;
792792
playhead->getCurrentPosition(cp);
793793
surge->time_data.tempo = cp.bpm;
794+
surge->time_data.isPlaying = cp.isPlaying;
794795

795796
// isRecording should always imply isPlaying but better safe than sorry
796797
if (cp.isPlaying || cp.isRecording)
@@ -819,6 +820,10 @@ void SurgeSynthProcessor::processBlockPlayhead()
819820
surge->time_data.tempo = standaloneTempo;
820821
surge->time_data.timeSigNumerator = 4;
821822
surge->time_data.timeSigDenominator = 4;
823+
824+
// Formula modulator only, in standalone the transport is always set running.
825+
surge->time_data.isPlaying = (wrapperType == wrapperType_Standalone);
826+
822827
surge->resetStateFromTimeData();
823828
}
824829
}

src/surge-xt/gui/overlays/LuaEditors.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,6 +2300,7 @@ struct ExpandingFormulaDebugger : public juce::Component,
23002300
formulastate.deform = localcopy[lfodata->deform.param_id_in_scene].f;
23012301
formulastate.tempo = storage->temposyncratio * 120.0;
23022302
formulastate.songpos = storage->songpos;
2303+
formulastate.isPlaying = storage->isPlaying;
23032304

23042305
Surge::Formula::setupEvaluatorStateFrom(lfoDebugger->formulastate,
23052306
editor->storage->getPatch(), editor->scene);

0 commit comments

Comments
 (0)