diff --git a/src/common/LuaSupport.cpp b/src/common/LuaSupport.cpp index c6c1fdaf62e..134391f2dbb 100644 --- a/src/common/LuaSupport.cpp +++ b/src/common/LuaSupport.cpp @@ -194,7 +194,7 @@ bool Surge::LuaSupport::setSurgeFunctionEnvironment(lua_State *L) return true; } -bool Surge::LuaSupport::loadSurgePrelude(lua_State *s) +bool Surge::LuaSupport::loadSurgePrelude(lua_State *s, const char *surgeTableName) { #if HAS_LUA auto guard = SGLD("loadPrologue", s); @@ -203,7 +203,7 @@ bool Surge::LuaSupport::loadSurgePrelude(lua_State *s) auto lua_size = lua_script.size(); auto load_stat = luaL_loadbuffer(s, lua_script.c_str(), lua_size, lua_script.c_str()); auto pcall = lua_pcall(s, 0, 1, 0); - lua_setglobal(s, "surge"); + lua_setglobal(s, surgeTableName); #endif return true; } diff --git a/src/common/LuaSupport.h b/src/common/LuaSupport.h index ac4f045fbfd..b14b09b6b9c 100644 --- a/src/common/LuaSupport.h +++ b/src/common/LuaSupport.h @@ -85,10 +85,10 @@ int parseStringDefiningMultipleFunctions(lua_State *s, const std::string &defini bool setSurgeFunctionEnvironment(lua_State *s); /* - * Call this function with a LUA state and it will introduce the global + * Call this function with a LUA state and a tablename and it will introduce the global * 'surge' which is the surge prelude */ -bool loadSurgePrelude(lua_State *s); +bool loadSurgePrelude(lua_State *s, const char *surgeTableName); /* * Call this function to get a string representation of the prelude diff --git a/src/common/dsp/SurgeVoice.cpp b/src/common/dsp/SurgeVoice.cpp index 64f6db0f970..0769268368c 100644 --- a/src/common/dsp/SurgeVoice.cpp +++ b/src/common/dsp/SurgeVoice.cpp @@ -193,7 +193,7 @@ SurgeVoice::SurgeVoice(SurgeStorage *storage, SurgeSceneStorage *oscene, pdata * state.channel = channel; state.voiceOrderAtCreate = voiceOrder; - state.voiceMax = storage->getPatch().polylimit.val.i; + state.polylimit = storage->getPatch().polylimit.val.i; state.velocity = velocity; state.fvel = velocity / 127.f; diff --git a/src/common/dsp/SurgeVoiceState.h b/src/common/dsp/SurgeVoiceState.h index 85fa432f628..21e33b70ee0 100644 --- a/src/common/dsp/SurgeVoiceState.h +++ b/src/common/dsp/SurgeVoiceState.h @@ -33,7 +33,7 @@ struct SurgeVoiceState MidiKeyState *keyState; MidiChannelState *mainChannelState; MidiChannelState *voiceChannelState; - int key, velocity, channel, scene_id, releasevelocity, voiceMax; + int key, velocity, channel, scene_id, releasevelocity, polylimit; float portasrc_key, portaphase; bool porta_doretrigger; diff --git a/src/common/dsp/modulators/FormulaModulationHelper.cpp b/src/common/dsp/modulators/FormulaModulationHelper.cpp index 0a4dc184bd6..dcbf9297aa8 100644 --- a/src/common/dsp/modulators/FormulaModulationHelper.cpp +++ b/src/common/dsp/modulators/FormulaModulationHelper.cpp @@ -81,12 +81,12 @@ bool prepareForEvaluation(SurgeStorage *storage, FormulaModulatorStorage *fs, Ev if (firstTimeThrough) { - // setup global table + // setup shared table lua_newtable(s.L); - lua_setglobal(s.L, "shared"); + lua_setglobal(s.L, sharedTableName); // setup prelude - Surge::LuaSupport::loadSurgePrelude(s.L); + Surge::LuaSupport::loadSurgePrelude(s.L, surgeTableName); auto reserved0 = std::string(R"FN( function surge_reserved_formula_error_stub(m) return 0; @@ -485,10 +485,10 @@ void valueAt(int phaseIntPart, float phaseFracPart, SurgeStorage *storage, lua_setfield(s->L, -2, "cycle"); // fake voice count for display calls - int vcount = 1; + int voiceCount = 1; if (storage->voiceCount != 0) - vcount = storage->voiceCount; - lua_pushinteger(s->L, vcount); + voiceCount = storage->voiceCount; + lua_pushinteger(s->L, voiceCount); lua_setfield(s->L, -2, "voice_count"); auto addn = [s](const char *q, float f) { @@ -532,8 +532,8 @@ void valueAt(int phaseIntPart, float phaseFracPart, SurgeStorage *storage, addn("channel", s->channel); addb("released", s->released); - addn("voice_id", s->voiceid); - addn("voice_max", s->voicemax); + addn("voice_id", s->voiceOrderAtCreate); + addn("voice_polylimit", s->polylimit); addn("poly_at", s->polyat); addn("mpe_bend", s->mpebend); @@ -820,7 +820,7 @@ std::vector createDebugDataOfModState(const EvaluatorState &es) } }; - std::vector tablesList = {es.stateName, "shared"}; + std::vector tablesList = {es.stateName, sharedTableName}; for (const auto &t : tablesList) { lua_getglobal(es.L, t.c_str()); @@ -828,7 +828,7 @@ std::vector createDebugDataOfModState(const EvaluatorState &es) { lua_pop(es.L, -1); rows.emplace_back(0, "Error", "Not a Table"); - return rows; + continue; } rec(0, false); lua_pop(es.L, -1); @@ -916,8 +916,8 @@ void setupEvaluatorStateFrom(EvaluatorState &s, const SurgeVoice *v) s.velocity = v->state.velocity; s.releasevelocity = v->state.releasevelocity; - s.voiceid = v->state.voiceOrderAtCreate; - s.voicemax = v->state.voiceMax; + s.voiceOrderAtCreate = v->state.voiceOrderAtCreate; + s.polylimit = v->state.polylimit; s.polyat = v->storage diff --git a/src/common/dsp/modulators/FormulaModulationHelper.h b/src/common/dsp/modulators/FormulaModulationHelper.h index 60dbbe176cb..a47df3f5a21 100644 --- a/src/common/dsp/modulators/FormulaModulationHelper.h +++ b/src/common/dsp/modulators/FormulaModulationHelper.h @@ -44,6 +44,8 @@ struct GlobalData }; static constexpr int max_formula_outputs{max_lfo_indices}; +static constexpr const char *surgeTableName{"surge"}; +static constexpr const char *sharedTableName{"shared"}; struct EvaluatorState { @@ -68,8 +70,8 @@ struct EvaluatorState // voice features bool isVoice; - int key{60}, channel{0}, velocity{0}, releasevelocity{0}, voicemax{1}, mpebendrange{24}; - int64_t voiceid{1L}; + int key{60}, channel{0}, velocity{0}, releasevelocity{0}, polylimit{1}, mpebendrange{24}; + int64_t voiceOrderAtCreate{1L}; float polyat{0}, mpebend{0}, mpetimbre{0}, mpepressure{0}; // scene features diff --git a/src/surge-testrunner/UnitTestsLUA.cpp b/src/surge-testrunner/UnitTestsLUA.cpp index cf022186639..79d3b8e96e3 100644 --- a/src/surge-testrunner/UnitTestsLUA.cpp +++ b/src/surge-testrunner/UnitTestsLUA.cpp @@ -159,7 +159,8 @@ TEST_CASE("Surge Prelude", "[lua]") REQUIRE(L); luaL_openlibs(L); - REQUIRE(Surge::LuaSupport::loadSurgePrelude(L)); + static constexpr const char *surgeTableName{"surge"}; + REQUIRE(Surge::LuaSupport::loadSurgePrelude(L, surgeTableName)); std::string emsg; REQUIRE(Surge::LuaSupport::parseStringDefiningFunction(