Skip to content

Commit

Permalink
squash
Browse files Browse the repository at this point in the history
Clang Format

add "global" table to Lua state plus redo voice data for formula editor

Default sandbox functions

Add back "global" table clear in setSurgeFunctionEnvironment()

Add stack test

squash

Fix segfault in testrunner

clang format

Move Nimbus from libsamplerate to our Lanczos downsampler (surge-synthesizer#7726)

1. Makes it ready to move to sst-effects
2. Makes it so we can almost remove libsamplerate (but some
   twist smidgeof work to do that)
3. Uses less CPU

Addresses surge-synthesizer#7359

Remove libsamplerate dependency (surge-synthesizer#7728)

After porting Nimbus ot lanczos in 4b3ffe6 we can now remove the
libsamplerate dependency altogether as long as we fix up the twist
fm (which we did with a simple application of another lanczos ds)
and remove src code from the unit tests (where it was explicitly
tested)

Move Nimbus to sst-effects (surge-synthesizer#7729)

* Move Nimbus to sst-effects

Addresses surge-synthesizer#7359

With an almost-complete port (param name dynamism is in surge
but not in the submodule yet)

* f

Update LFO and Step Seq presets to have the LFO EG enabled (surge-synthesizer#7732)

Code Checks github action, as part one of move to actions

Move to actions here will be a bit trickier, but we will
get there. Step one is have any action at all, so add a code
check action.

Pull Request moves to Github Actions (surge-synthesizer#7733)

The PullRequest support of our azure pipeline is now on GitHub actions, building in various configurations and running the tests. The azure pipeline still exists to trigger the release stage, which is what I'll port tomorrow, or maybe thursday, and then be done with the azure->actions project.

- Adds voice_id, voice_max, voice_count, is_display parameters to formula modulator
- Fakes voice_count of "1" and sets defaults for other params on display calls
- Adds "shared" table to formula modulator
- Sets entries of "shared" table to nil on new Lua function env
- Makes formula debugger also use "shared" table
- Adds lua_isfunction to formula debugger
- Some cleanup
  • Loading branch information
nuoun authored and baconpaul committed Aug 6, 2024
1 parent ee42a17 commit e38cb4c
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 74 deletions.
23 changes: 22 additions & 1 deletion src/common/LuaSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ bool Surge::LuaSupport::setSurgeFunctionEnvironment(lua_State *L)
// stack is now func > table

// List of whitelisted functions and modules
std::vector<std::string> sandboxWhitelist = {"ipairs", "error", "math", "surge"};
std::vector<std::string> sandboxWhitelist = {"ipairs", "error", "math", "surge", "global"};
/*
std::vector<std::string> sandboxWhitelist = {"pairs", "ipairs", "next", "print",
"error", "math", "string", "table",
"bit", "setmetatable", "surge", "shared"};
*/

for (const auto &f : sandboxWhitelist)
{
Expand Down Expand Up @@ -164,6 +169,22 @@ bool Surge::LuaSupport::setSurgeFunctionEnvironment(lua_State *L)
// stack is now f>t>(m). Pop m
lua_pop(L, 1);

// retrieve "shared" table and set entries to nil
lua_getglobal(L, "shared");
if (lua_istable(L, -1))
{
lua_pushnil(L);
while (lua_next(L, -2))
{
lua_pop(L, 1); // pop value
lua_pushvalue(L, -1); // duplicate the key
lua_pushnil(L);
lua_settable(L, -4); // clear the key
}
}
// pop the retrieved value (either table or nil) from the stack
lua_pop(L, 1);

// and now we are back to f>t so we can setfenv it
lua_setfenv(L, -2);

Expand Down
1 change: 1 addition & 0 deletions src/common/LuaSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ struct SGLD
lua_State *L;
int top;
};

} // namespace LuaSupport
} // namespace Surge

Expand Down
2 changes: 2 additions & 0 deletions src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,8 @@ class alignas(16) SurgeStorage
bool oscReceiving{false};
bool oscSending{false};

int voiceCount;

bool getOverrideDataHome(std::string &value);
void createUserDirectory();

Expand Down
24 changes: 11 additions & 13 deletions src/common/SurgeSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,12 +833,12 @@ void SurgeSynthesizer::playVoice(int scene, char channel, char key, char velocit
int mpeMainChannel = getMpeMainChannel(channel, key);

voices[scene].push_back(nvoice);
new (nvoice) SurgeVoice(
&storage, &storage.getPatch().scene[scene], storage.getPatch().scenedata[scene],
key, velocity, channel, scene, detune, &channelState[channel].keyState[key],
&channelState[mpeMainChannel], &channelState[channel], mpeEnabled,
voiceCounter++, voiceN, storage.getPatch().polylimit.val.i, host_noteid,
host_originating_key, host_originating_channel, 0.f, 0.f);
new (nvoice) SurgeVoice(&storage, &storage.getPatch().scene[scene],
storage.getPatch().scenedata[scene], key, velocity, channel,
scene, detune, &channelState[channel].keyState[key],
&channelState[mpeMainChannel], &channelState[channel],
mpeEnabled, voiceCounter++, host_noteid,
host_originating_key, host_originating_channel, 0.f, 0.f);
}
}
break;
Expand Down Expand Up @@ -981,9 +981,8 @@ void SurgeSynthesizer::playVoice(int scene, char channel, char key, char velocit
&storage, &storage.getPatch().scene[scene],
storage.getPatch().scenedata[scene], key, velocity, channel, scene, detune,
&channelState[channel].keyState[key], &channelState[mpeMainChannel],
&channelState[channel], mpeEnabled, voiceCounter++, voiceN,
storage.getPatch().polylimit.val.i, host_noteid, host_originating_key,
host_originating_channel, aegReuse, fegReuse);
&channelState[channel], mpeEnabled, voiceCounter++, host_noteid,
host_originating_key, host_originating_channel, aegReuse, fegReuse);

if (wasGated && pkeyToReuse > 0)
{
Expand Down Expand Up @@ -1126,9 +1125,8 @@ void SurgeSynthesizer::playVoice(int scene, char channel, char key, char velocit
&storage, &storage.getPatch().scene[scene],
storage.getPatch().scenedata[scene], key, velocity, channel, scene, detune,
&channelState[channel].keyState[key], &channelState[mpeMainChannel],
&channelState[channel], mpeEnabled, voiceCounter++, voiceN,
storage.getPatch().polylimit.val.i, host_noteid, host_originating_key,
host_originating_channel, aegStart, fegStart);
&channelState[channel], mpeEnabled, voiceCounter++, host_noteid,
host_originating_key, host_originating_channel, aegStart, fegStart);
}
}
else
Expand Down Expand Up @@ -4711,7 +4709,6 @@ void SurgeSynthesizer::process()
}

storage.modRoutingMutex.unlock();
voiceN = vcount;

using sst::filters::FilterType, sst::filters::FilterSubType;
fbq_global g;
Expand Down Expand Up @@ -4795,6 +4792,7 @@ void SurgeSynthesizer::process()

storage.modRoutingMutex.unlock();
polydisplay = vcount;
storage.voiceCount = 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 @@ -176,7 +176,6 @@ class alignas(16) SurgeSynthesizer
unsigned int voices_usedby[2][MAX_VOICES]; // 0 indicates no user, 1 is scene A, 2 is scene B

int64_t voiceCounter = 1L;
int voiceN = 0;

std::atomic<unsigned int> processRunning{0};

Expand Down
9 changes: 4 additions & 5 deletions src/common/dsp/SurgeVoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ SurgeVoice::SurgeVoice(SurgeStorage *storage, SurgeSceneStorage *oscene, pdata *
int velocity, int channel, int scene_id, float detune,
MidiKeyState *keyState, MidiChannelState *mainChannelState,
MidiChannelState *voiceChannelState, bool mpeEnabled, int64_t voiceOrder,
int voiceN, int polyLimit, int32_t host_nid, int16_t host_key,
int16_t host_chan, float aegStart, float fegStart)
int32_t host_nid, int16_t host_key, int16_t host_chan, float aegStart,
float fegStart)
//: fb(storage,oscene)
{
#ifdef VOICE_LIFETIME_DEBUG
Expand Down Expand Up @@ -191,10 +191,9 @@ SurgeVoice::SurgeVoice(SurgeStorage *storage, SurgeSceneStorage *oscene, pdata *
state.key = key;
state.keyRetuningForKey = -1000;
state.channel = channel;

state.voiceOrderAtCreate = voiceOrder;
state.polyLimit = polyLimit;
// state.polyLimit = storage->getPatch().polylimit.val.i;
state.voiceN = voiceN;
state.voiceMax = storage->getPatch().polylimit.val.i;

state.velocity = velocity;
state.fvel = velocity / 127.f;
Expand Down
2 changes: 1 addition & 1 deletion src/common/dsp/SurgeVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class alignas(16) SurgeVoice
SurgeVoice(SurgeStorage *storage, SurgeSceneStorage *scene, pdata *params, int key,
int velocity, int channel, int scene_id, float detune, MidiKeyState *keyState,
MidiChannelState *mainChannelState, MidiChannelState *voiceChannelState,
bool mpeEnabled, int64_t voiceOrder, int voiceN, int polyLimit, int32_t host_note_id,
bool mpeEnabled, int64_t voiceOrder, int32_t host_note_id,
int16_t originating_host_key, int16_t originating_host_channel, float aegStart,
float fegStart);
~SurgeVoice();
Expand Down
2 changes: 1 addition & 1 deletion src/common/dsp/SurgeVoiceState.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct SurgeVoiceState
MidiKeyState *keyState;
MidiChannelState *mainChannelState;
MidiChannelState *voiceChannelState;
int key, velocity, channel, scene_id, releasevelocity, polyLimit, voiceN;
int key, velocity, channel, scene_id, releasevelocity, voiceMax;
float portasrc_key, portaphase;
bool porta_doretrigger;

Expand Down
Loading

0 comments on commit e38cb4c

Please sign in to comment.