Skip to content

Commit

Permalink
Remove Lua script simply because it's not related to this
Browse files Browse the repository at this point in the history
  • Loading branch information
james34602 committed Dec 26, 2021
1 parent 9e78208 commit b8dede7
Show file tree
Hide file tree
Showing 62 changed files with 4 additions and 27,813 deletions.
66 changes: 3 additions & 63 deletions Plugin/LiveProgrammableEffect.jucer
Original file line number Diff line number Diff line change
Expand Up @@ -7,66 +7,6 @@
defines="JUCE_DONT_AUTO_OPEN_MIDI_DEVICES_ON_MOBILE
TURN_ON_VST"
jucerFormatVersion="1">
<MAINGROUP id="wVx5gn" name="LiveProgrammableEffect">
<GROUP id="{4B1B3607-B636-DAD6-EBE2-B958C1BDC23F}" name="Lua">
<FILE id="x70m9U" name="lapi.c" compile="1" resource="0" file="Source/Lua/lapi.c"/>
<FILE id="iUlCWo" name="lapi.h" compile="0" resource="0" file="Source/Lua/lapi.h"/>
<FILE id="bvLPvt" name="lauxlib.c" compile="1" resource="0" file="Source/Lua/lauxlib.c"/>
<FILE id="yLAXJk" name="lauxlib.h" compile="0" resource="0" file="Source/Lua/lauxlib.h"/>
<FILE id="UxTKXe" name="lbaselib.c" compile="1" resource="0" file="Source/Lua/lbaselib.c"/>
<FILE id="yjRkjm" name="lcode.c" compile="1" resource="0" file="Source/Lua/lcode.c"/>
<FILE id="XFAeR5" name="lcode.h" compile="0" resource="0" file="Source/Lua/lcode.h"/>
<FILE id="U1YsRi" name="lcorolib.c" compile="1" resource="0" file="Source/Lua/lcorolib.c"/>
<FILE id="ecxQ0v" name="lctype.c" compile="1" resource="0" file="Source/Lua/lctype.c"/>
<FILE id="w077S5" name="lctype.h" compile="0" resource="0" file="Source/Lua/lctype.h"/>
<FILE id="dmmfRd" name="ldblib.c" compile="1" resource="0" file="Source/Lua/ldblib.c"/>
<FILE id="pR2s2B" name="ldebug.c" compile="1" resource="0" file="Source/Lua/ldebug.c"/>
<FILE id="pI62lQ" name="ldebug.h" compile="0" resource="0" file="Source/Lua/ldebug.h"/>
<FILE id="onnpdk" name="ldo.c" compile="1" resource="0" file="Source/Lua/ldo.c"/>
<FILE id="aBv3ji" name="ldo.h" compile="0" resource="0" file="Source/Lua/ldo.h"/>
<FILE id="pFD7wh" name="ldump.c" compile="1" resource="0" file="Source/Lua/ldump.c"/>
<FILE id="lwpvQg" name="lfunc.c" compile="1" resource="0" file="Source/Lua/lfunc.c"/>
<FILE id="gmCwux" name="lfunc.h" compile="0" resource="0" file="Source/Lua/lfunc.h"/>
<FILE id="RCg5wI" name="lgc.c" compile="1" resource="0" file="Source/Lua/lgc.c"/>
<FILE id="FNfCZE" name="lgc.h" compile="0" resource="0" file="Source/Lua/lgc.h"/>
<FILE id="xIbJRb" name="linit.c" compile="1" resource="0" file="Source/Lua/linit.c"/>
<FILE id="uJlth8" name="liolib.c" compile="1" resource="0" file="Source/Lua/liolib.c"/>
<FILE id="LW0Kge" name="ljumptab.h" compile="0" resource="0" file="Source/Lua/ljumptab.h"/>
<FILE id="IRcWm7" name="llex.c" compile="1" resource="0" file="Source/Lua/llex.c"/>
<FILE id="xnRv2l" name="llex.h" compile="0" resource="0" file="Source/Lua/llex.h"/>
<FILE id="FTZoRw" name="llimits.h" compile="0" resource="0" file="Source/Lua/llimits.h"/>
<FILE id="sbhMh9" name="lmathlib.c" compile="1" resource="0" file="Source/Lua/lmathlib.c"/>
<FILE id="OnPsC3" name="lmem.c" compile="1" resource="0" file="Source/Lua/lmem.c"/>
<FILE id="sCfZPx" name="lmem.h" compile="0" resource="0" file="Source/Lua/lmem.h"/>
<FILE id="eAfzrw" name="loadlib.c" compile="1" resource="0" file="Source/Lua/loadlib.c"/>
<FILE id="PJUx2B" name="lobject.c" compile="1" resource="0" file="Source/Lua/lobject.c"/>
<FILE id="BNEaSa" name="lobject.h" compile="0" resource="0" file="Source/Lua/lobject.h"/>
<FILE id="LWCjK2" name="lopcodes.c" compile="1" resource="0" file="Source/Lua/lopcodes.c"/>
<FILE id="zNywZ8" name="lopcodes.h" compile="0" resource="0" file="Source/Lua/lopcodes.h"/>
<FILE id="cwMEKp" name="lopnames.h" compile="0" resource="0" file="Source/Lua/lopnames.h"/>
<FILE id="tuMYlN" name="loslib.c" compile="1" resource="0" file="Source/Lua/loslib.c"/>
<FILE id="QKKR22" name="lparser.c" compile="1" resource="0" file="Source/Lua/lparser.c"/>
<FILE id="Eg0KoF" name="lparser.h" compile="0" resource="0" file="Source/Lua/lparser.h"/>
<FILE id="MlBn5F" name="lprefix.h" compile="0" resource="0" file="Source/Lua/lprefix.h"/>
<FILE id="iPtuda" name="lstate.c" compile="1" resource="0" file="Source/Lua/lstate.c"/>
<FILE id="G9xyPk" name="lstate.h" compile="0" resource="0" file="Source/Lua/lstate.h"/>
<FILE id="ZkFS34" name="lstring.c" compile="1" resource="0" file="Source/Lua/lstring.c"/>
<FILE id="nc9rmi" name="lstring.h" compile="0" resource="0" file="Source/Lua/lstring.h"/>
<FILE id="i87I4D" name="lstrlib.c" compile="1" resource="0" file="Source/Lua/lstrlib.c"/>
<FILE id="Regzmg" name="ltable.c" compile="1" resource="0" file="Source/Lua/ltable.c"/>
<FILE id="i9i1l0" name="ltable.h" compile="0" resource="0" file="Source/Lua/ltable.h"/>
<FILE id="OicFDn" name="ltablib.c" compile="1" resource="0" file="Source/Lua/ltablib.c"/>
<FILE id="IQL2Yj" name="ltm.c" compile="1" resource="0" file="Source/Lua/ltm.c"/>
<FILE id="YQrNMa" name="ltm.h" compile="0" resource="0" file="Source/Lua/ltm.h"/>
<FILE id="lDNsHv" name="luaconf.h" compile="0" resource="0" file="Source/Lua/luaconf.h"/>
<FILE id="sllfo0" name="lualib.h" compile="0" resource="0" file="Source/Lua/lualib.h"/>
<FILE id="QRrz2V" name="lundump.c" compile="1" resource="0" file="Source/Lua/lundump.c"/>
<FILE id="nxKAnf" name="lundump.h" compile="0" resource="0" file="Source/Lua/lundump.h"/>
<FILE id="CFpuR0" name="lutf8lib.c" compile="1" resource="0" file="Source/Lua/lutf8lib.c"/>
<FILE id="b1wKmT" name="lvm.c" compile="1" resource="0" file="Source/Lua/lvm.c"/>
<FILE id="d1PCDN" name="lvm.h" compile="0" resource="0" file="Source/Lua/lvm.h"/>
<FILE id="K6VxoE" name="lzio.c" compile="1" resource="0" file="Source/Lua/lzio.c"/>
<FILE id="fDSG6Z" name="lzio.h" compile="0" resource="0" file="Source/Lua/lzio.h"/>
</GROUP>
<GROUP id="{D5F3E85C-C74C-DD52-FD20-16126D69020F}" name="LZMA">
<GROUP id="{18353F9A-E402-D787-9B71-F4474DDFB64B}" name="easylzma">
<FILE id="hGsmTq" name="common.h" compile="0" resource="0" file="lzma/easylzma/common.h"/>
Expand Down Expand Up @@ -114,6 +54,7 @@
</GROUP>
<GROUP id="{FDC7D40D-3BDD-00BA-E2B1-46DD35CB5E88}" name="EEL2">
<GROUP id="{028F0C70-E6C2-B821-086B-D7C1FF5BE85B}" name="NumericSystem">
<FILE id="foCTlH" name="polyphase.h" compile="0" resource="0" file="../numericSys/polyphase.h"/>
<GROUP id="{3D2C8887-4381-6B9A-7727-BE9C25B0BCAB}" name="libsamplerate">
<FILE id="iFl0Ex" name="common.h" compile="0" resource="0" file="../numericSys/libsamplerate/common.h"/>
<FILE id="ybuqE9" name="samplerate.c" compile="1" resource="0" file="../numericSys/libsamplerate/samplerate.c"/>
Expand Down Expand Up @@ -205,9 +146,8 @@
</XCODE_MAC>
<VS2017 targetFolder="Builds/VisualStudio2017">
<CONFIGURATIONS>
<CONFIGURATION isDebug="0" name="Release" fastMath="1" optimisation="3" winArchitecture="Win32"
useRuntimeLibDLL="0"/>
<CONFIGURATION isDebug="1" name="Debug" fastMath="1" winArchitecture="Win32"/>
<CONFIGURATION isDebug="0" name="Release" fastMath="1" optimisation="3" useRuntimeLibDLL="0"/>
<CONFIGURATION isDebug="1" name="Debug" fastMath="1"/>
</CONFIGURATIONS>
<MODULEPATHS>
<MODULEPATH id="juce_gui_extra" path="../../../../JUCE/modules"/>
Expand Down
222 changes: 1 addition & 221 deletions Plugin/Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ LiveProgrammableDSP::LiveProgrammableDSP() : treeState(*this, nullptr, "Paramete
compileSucessfully = 0;
codehandleInit = 0;
codehandleProcess = 0;
actualLuaVM = 0;
luaStructRef = LUA_NOREF;
luaProcessRef = LUA_NOREF;
NSEEL_start();
vm = NSEEL_VM_alloc(); // create virtual machine
vmFs = NSEEL_VM_regvar(vm, "srate");
Expand Down Expand Up @@ -96,14 +93,6 @@ LiveProgrammableDSP::~LiveProgrammableDSP()
NSEEL_VM_free(vm);
}
NSEEL_quit();
if (actualLuaVM)
{
if (luaProcessRef != LUA_NOREF)
luaL_unref(actualLuaVM, LUA_REGISTRYINDEX, luaProcessRef);
if (luaStructRef != LUA_NOREF)
luaL_unref(actualLuaVM, LUA_REGISTRYINDEX, luaStructRef);
lua_close(actualLuaVM);
}
}
AudioProcessorValueTreeState::ParameterLayout LiveProgrammableDSP::createParameterLayout()
{
Expand All @@ -124,26 +113,6 @@ void LiveProgrammableDSP::prepareToPlay(double sampleRate, int samplesPerBlock)
ScopedLock lock(criticalSection);
NSEEL_code_execute(codehandleInit);
}
if (compileSucessfully == 2)
{
ScopedLock lock(criticalSection);
int top = lua_gettop(actualLuaVM);
int retType = lua_getglobal(actualLuaVM, "init"); // function to be called
lua_pushnumber(actualLuaVM, fs); // push 1st argument
// do the call (1 arguments, 1 table)
lua_call(actualLuaVM, 1, LUA_MULTRET);
// check the return value
if (lua_gettop(actualLuaVM) - top) {
// store userdata to a pointer
luaStructRef = luaL_ref(actualLuaVM, LUA_REGISTRYINDEX);
}
else
{
char erMsg[70] = "Lua: Fail to get reference while re-set sample rate, stop compiling\n";
EEL_STRING_STDOUT_WRITE(erMsg, 69);
lua_close(actualLuaVM);
}
}
}
const String LiveProgrammableDSP::getName() const
{
Expand Down Expand Up @@ -203,6 +172,7 @@ void LiveProgrammableDSP::processBlock(AudioBuffer<float>& buffer, MidiBuffer&)
{
// number of samples per buffer
const int n = buffer.getNumSamples();
const int pcmChannels = 6;
// input channels
const float *inputs[6] = { buffer.getReadPointer(0), buffer.getReadPointer(1), buffer.getReadPointer(2), buffer.getReadPointer(3), buffer.getReadPointer(4), buffer.getReadPointer(5) };
// output channels
Expand All @@ -227,30 +197,6 @@ void LiveProgrammableDSP::processBlock(AudioBuffer<float>& buffer, MidiBuffer&)
outputs[5][i] = (float)*input6;
}
}
if (compileSucessfully == 2)
{
ScopedLock lock(criticalSection);
for (int i = 0; i < n; i++)
{
lua_rawgeti(actualLuaVM, LUA_REGISTRYINDEX, luaProcessRef);
lua_rawgeti(actualLuaVM, LUA_REGISTRYINDEX, luaStructRef);
// Push variable to stack
lua_pushnumber(actualLuaVM, inputs[0][i]);
lua_pushnumber(actualLuaVM, inputs[1][i]);
lua_pushnumber(actualLuaVM, inputs[2][i]);
lua_pushnumber(actualLuaVM, inputs[3][i]);
lua_pushnumber(actualLuaVM, inputs[4][i]);
lua_pushnumber(actualLuaVM, inputs[5][i]);
lua_call(actualLuaVM, 7, 6);
outputs[0][i] = (float)lua_tonumber(actualLuaVM, -6);
outputs[1][i] = (float)lua_tonumber(actualLuaVM, -5);
outputs[2][i] = (float)lua_tonumber(actualLuaVM, -4);
outputs[3][i] = (float)lua_tonumber(actualLuaVM, -3);
outputs[4][i] = (float)lua_tonumber(actualLuaVM, -2);
outputs[5][i] = (float)lua_tonumber(actualLuaVM, -1);
lua_pop(actualLuaVM, 6);
}
}
}
bool LiveProgrammableDSP::hasEditor() const
{
Expand Down Expand Up @@ -350,177 +296,11 @@ int LiveProgrammableDSP::compileEEL(const char *eelCode, size_t strLen)
free(codeTextProcess);
return 1;
}
int LiveProgrammableDSP::validateLua(const char *luaCode, size_t strLen)
{
lua_State *L = luaL_newstate(); // create state
luaL_openlibs(L); // open standard libraries
lua_settop(L, 0);
char *concatedStr = (char*)malloc(strLen + 256);
int outLen = stbsp_snprintf(concatedStr, strLen + 256, "%s\nprocess(init(%lf), %lf, %lf)", luaCode, nseel_int_rand(192000.0), nseel_int_rand(1.0), nseel_int_rand(1.0));
int err = luaL_loadbuffer(L, concatedStr, outLen, "LiveProg");
free(concatedStr);
EEL_STRING_STDOUT_WRITE("Lua: Test run\n", 14);
if (err)
{
char erMsg[256] = { 0 };
int msgLen = stbsp_snprintf(erMsg, 256, "Lua error %d\n%s\n", err, lua_tostring(L, -1));
EEL_STRING_STDOUT_WRITE(erMsg, msgLen);
lua_pop(L, 1); // pop error message from the stack
lua_close(L);
return -1;
}
err = lua_pcall(L, 0, 0, 0);
if (err)
{
char erMsg[256] = { 0 };
int msgLen = stbsp_snprintf(erMsg, 256, "Lua error %d\n%s\n", err, lua_tostring(L, -1));
EEL_STRING_STDOUT_WRITE(erMsg, msgLen);
lua_pop(L, 1); // pop error message from the stack
lua_close(L);
return -1;
}
// Table return
int userDataRef = LUA_NOREF;
int top = lua_gettop(L);
int retType = lua_getglobal(L, "init"); // function to be called
lua_pushnumber(L, fs); // push 1st argument
// do the call (1 arguments, 1 table)
if (lua_pcall(L, 1, LUA_MULTRET, 0) != 0)
{
char erMsg[256] = { 0 };
int msgLen = stbsp_snprintf(erMsg, 256, "Lua error %d\nerror running function 'init': %s\n", err, lua_tostring(L, -1));
EEL_STRING_STDOUT_WRITE(erMsg, msgLen);
lua_pop(L, 1); // pop error message from the stack
lua_close(L);
return 1;
}
int retClass = lua_istable(L, -1);
if (!retClass)
{
char erMsg[55] = "Lua: init function must return table, stop compiling\n";
EEL_STRING_STDOUT_WRITE(erMsg, 54);
lua_close(L);
return 2;
}
// check the return value
if (lua_gettop(L) - top) {
// store userdata to a pointer
userDataRef = luaL_ref(L, LUA_REGISTRYINDEX);
}
else
{
char erMsg[45] = "Lua: Fail to get reference, stop compiling\n";
EEL_STRING_STDOUT_WRITE(erMsg, 44);
lua_close(L);
return 3;
}
lua_getglobal(L, "process"); // function to be called
int process = luaL_ref(L, LUA_REGISTRYINDEX);
if (userDataRef != LUA_NOREF && userDataRef != LUA_REFNIL)
{
lua_rawgeti(L, LUA_REGISTRYINDEX, process);
lua_rawgeti(L, LUA_REGISTRYINDEX, userDataRef);
// Push variable to stack
lua_pushnumber(L, 0.5);
lua_pushnumber(L, -0.15);
if (lua_pcall(L, 3, 2, 0) != 0)
{
char erMsg[256] = { 0 };
int msgLen = stbsp_snprintf(erMsg, 256, "Lua error %d\nerror running function 'process': %s\n", err, lua_tostring(L, -1));
EEL_STRING_STDOUT_WRITE(erMsg, msgLen);
lua_pop(L, 1); // pop error message from the stack
lua_close(L);
return 1;
}
double y1 = lua_tonumber(L, -2);
double y2 = lua_tonumber(L, -1);
lua_pop(L, 2);
}
else
{
char erMsg[42] = "Lua: Reference go wrong, stop compiling\n";
EEL_STRING_STDOUT_WRITE(erMsg, 41);
}
luaL_unref(L, LUA_REGISTRYINDEX, process);
luaL_unref(L, LUA_REGISTRYINDEX, userDataRef);
lua_close(L);
return LUA_OK;
}
void LiveProgrammableDSP::LoadLuaCode(const char *luaCode, size_t strLen)
{
ScopedLock lock(criticalSection);
compileSucessfully = 0;
int i;
if (actualLuaVM)
{
if (luaProcessRef != LUA_NOREF)
luaL_unref(actualLuaVM, LUA_REGISTRYINDEX, luaProcessRef);
luaProcessRef = LUA_NOREF;
if (luaStructRef != LUA_NOREF)
luaL_unref(actualLuaVM, LUA_REGISTRYINDEX, luaStructRef);
luaStructRef = LUA_NOREF;
lua_close(actualLuaVM);
actualLuaVM = 0;
}
actualLuaVM = luaL_newstate(); // create state
luaL_openlibs(actualLuaVM); // open standard libraries
lua_settop(actualLuaVM, 0);
int err = luaL_loadbuffer(actualLuaVM, luaCode, strLen, "LiveProg");
if (err)
{
char erMsg[256] = { 0 };
int msgLen = stbsp_snprintf(erMsg, 256, "Lua error %d\n%s\nFatal code loading error after validation\n", err, lua_tostring(actualLuaVM, -1));
EEL_STRING_STDOUT_WRITE(erMsg, msgLen);
lua_pop(actualLuaVM, 1); // pop error message from the stack
lua_close(actualLuaVM);
return;
}
lua_call(actualLuaVM, 0, 0);
int top = lua_gettop(actualLuaVM);
int retType = lua_getglobal(actualLuaVM, "init"); // function to be called
lua_pushnumber(actualLuaVM, fs); // push 1st argument
// do the call (1 arguments, 1 table)
lua_call(actualLuaVM, 1, LUA_MULTRET);
// check the return value
if (lua_gettop(actualLuaVM) - top) {
// store userdata to a pointer
luaStructRef = luaL_ref(actualLuaVM, LUA_REGISTRYINDEX);
}
else
{
char erMsg[105] = "Lua: Fail to get reference after validation, stop compiling\nFatal get reference error after validation\n";
EEL_STRING_STDOUT_WRITE(erMsg, 104);
lua_close(actualLuaVM);
return;
}
lua_getglobal(actualLuaVM, "process"); // function to be called
luaProcessRef = luaL_ref(actualLuaVM, LUA_REGISTRYINDEX);
compileSucessfully = 2;
EEL_STRING_STDOUT_WRITE("Lua: Code looks OK\n", 16);
}
int LiveProgrammableDSP::compileLua(const char *luaCode, size_t strLen)
{
EEL_STRING_STDOUT_WRITE("Code text is not EEL, compiling code as Lua\n", 45);
int ret = validateLua(luaCode, strLen);
if (ret != LUA_OK)
{
EEL_STRING_STDOUT_WRITE("Lua compilation failed\n", 24);
compileSucessfully = 0;
return 0;
}
else
{
LoadLuaCode(luaCode, strLen);
return 1;
}
}
void LiveProgrammableDSP::playButtonClicked(String codetext)
{
int strLen = codetext.length();
const char *textbuf = codetext.toRawUTF8();
int eelSuccess = compileEEL(textbuf, strLen);
if (!eelSuccess)
int luaSuccess = compileLua(textbuf, strLen);
}
AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
Expand Down
12 changes: 0 additions & 12 deletions Plugin/Source/PluginProcessor.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#pragma once
#include "../JuceLibraryCode/JuceHeader.h"
#include "../../eelCommon.h"
extern "C"
{
#include "lua/lua.h"
#include "lua/lauxlib.h"
#include "lua/lualib.h"
}
class LiveProgrammableDSP : public AudioProcessor, public AudioProcessorValueTreeState::Listener
{
public:
Expand Down Expand Up @@ -41,15 +35,9 @@ class LiveProgrammableDSP : public AudioProcessor, public AudioProcessorValueTre
NSEEL_VMCTX vm;
NSEEL_CODEHANDLE codehandleInit, codehandleProcess;
float *vmFs, *input1, *input2, *input3, *input4, *input5, *input6;
// Lua VM
lua_State *actualLuaVM;
int luaStructRef, luaProcessRef;
//
void LoadEELCode(char *codeTextInit, char *codeTextProcess);
void LoadLuaCode(const char *eelCode, size_t strLen);
int compileEEL(const char *eelCode, size_t strLen);
int validateLua(const char *eelCode, size_t strLen);
int compileLua(const char *eelCode, size_t strLen);
void playButtonClicked(String codetext);
String restoredText;

Expand Down
Loading

0 comments on commit b8dede7

Please sign in to comment.