Skip to content

Commit 44a53fb

Browse files
committed
Liveprog: allow live variable manipulation + engine freeze
1 parent 2d06443 commit 44a53fb

File tree

7 files changed

+51
-10
lines changed

7 files changed

+51
-10
lines changed

libjamesdsp/libjamesdsp.pro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ DEFINES += LIBJAMESDSP_PLUGIN
55

66
CONFIG += c++17
77

8-
QMAKE_CFLAGS += -std=gnu11 -O2
8+
# TODO: remove debug mode
9+
# QMAKE_CFLAGS += -std=gnu11 -O2
10+
QMAKE_CFLAGS += -std=gnu11 -g3 -Og -gdwarf-2 -finline-functions
911

1012
CONFIG += warn_off # Disable warnings for library
1113

libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/eel2/nseel-compiler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7711,4 +7711,4 @@ opcodeRec *nseel_translate(compileContext *ctx, const char *tmp, size_t tmplen)
77117711
return nseel_createCompiledValue(ctx, (float)rv);
77127712
}
77137713
return nseel_createCompiledValue(ctx, (float)atof(tmp));
7714-
}
7714+
}

libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/liveprogWrapper.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
void NSEEL_HOSTSTUB_EnterMutex() { }
22
void NSEEL_HOSTSTUB_LeaveMutex() { }
33
#include "../jdsp_header.h"
4+
45
void LiveProgConstructor(JamesDSPLib *jdsp)
56
{
67
LiveProg *pg = &jdsp->eel;
8+
pg->active = 1;
79
pg->compileSucessfully = 0;
810
pg->codehandleInit = 0;
911
pg->codehandleProcess = 0;
@@ -146,7 +148,7 @@ int LiveProgStringParser(JamesDSPLib *jdsp, char *eelCode)
146148
void LiveProgProcess(JamesDSPLib *jdsp, size_t n)
147149
{
148150
LiveProg *eel = &jdsp->eel;
149-
if (eel->compileSucessfully)
151+
if (eel->compileSucessfully && eel->active)
150152
{
151153
for (size_t i = 0; i < n; i++)
152154
{

libjamesdsp/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/jdsp_header.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ typedef struct
364364
NSEEL_CODEHANDLE codehandleInit, codehandleProcess;
365365
float *vmFs, *input1, *input2;
366366
int compileSucessfully;
367+
int active;
367368
} LiveProg;
368369
typedef struct
369370
{

src/audio/base/DspHost.cpp

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -725,22 +725,22 @@ std::vector<EelVariable> DspHost::enumEelVariables()
725725
{
726726
std::vector<EelVariable> vars;
727727

728-
compileContext *c = (compileContext*)cast(this->_dsp)->eel.vm;
729-
for (int i = 0; i < c->varTable_numBlocks; i++)
728+
compileContext *ctx = (compileContext*)cast(this->_dsp)->eel.vm;
729+
for (int i = 0; i < ctx->varTable_numBlocks; i++)
730730
{
731731
for (int j = 0; j < NSEEL_VARS_PER_BLOCK; j++)
732732
{
733733
EelVariable var;
734-
char *valid = (char*)GetStringForIndex(c->m_string_context, c->varTable_Values[i][j], 0);
734+
char *valid = (char*)GetStringForIndex(ctx->m_string_context, ctx->varTable_Values[i][j], 0);
735735
var.isString = valid;
736736

737-
if (c->varTable_Names[i][j])
737+
if (ctx->varTable_Names[i][j])
738738
{
739-
var.name = c->varTable_Names[i][j];
739+
var.name = ctx->varTable_Names[i][j];
740740
if(var.isString)
741741
var.value = valid;
742742
else
743-
var.value = c->varTable_Values[i][j];
743+
var.value = ctx->varTable_Values[i][j];
744744

745745
vars.push_back(var);
746746
}
@@ -750,6 +750,40 @@ std::vector<EelVariable> DspHost::enumEelVariables()
750750
return vars;
751751
}
752752

753+
bool DspHost::manipulateEelVariable(const char* name, float value)
754+
{
755+
compileContext *ctx = (compileContext*)cast(this->_dsp)->eel.vm;
756+
for (int i = 0; i < ctx->varTable_numBlocks; i++)
757+
{
758+
for (int j = 0; j < NSEEL_VARS_PER_BLOCK; j++)
759+
{
760+
if(!ctx->varTable_Names[i][j] || std::strcmp(ctx->varTable_Names[i][j], name) != 0)
761+
{
762+
continue;
763+
}
764+
765+
char *validString = (char*)GetStringForIndex(ctx->m_string_context, ctx->varTable_Values[i][j], 0);
766+
if(validString)
767+
{
768+
Log::error(QString("DspHost::manipulateEelVariable: variable '%1' is a string; currently only numerical variables can be manipulated").arg(name));
769+
return false;
770+
}
771+
772+
ctx->varTable_Values[i][j] = value;
773+
return true;
774+
}
775+
}
776+
777+
Log::error(QString("DspHost::manipulateEelVariable: variable '%1' not found").arg(name));
778+
return false;
779+
}
780+
781+
void DspHost::freezeLiveprogExecution(bool freeze)
782+
{
783+
cast(this->_dsp)->eel.active = !freeze;
784+
Log::debug("DspHost::freezeLiveprogExecution: Liveprog execution has been " + (freeze ? QString("frozen") : "resumed"));
785+
}
786+
753787
void DspHost::dispatch(Message msg, std::any value)
754788
{
755789
_extraFunc(msg, value);

src/audio/base/DspHost.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class DspHost
3131
void updateFromCache();
3232
void reloadLiveprog(DspConfig* config = nullptr);
3333
std::vector<EelVariable> enumEelVariables();
34+
bool manipulateEelVariable(const char *name, float value);
35+
void freezeLiveprogExecution(bool freeze);
3436
void dispatch(Message msg, std::any value);
3537

3638
private:

src/subprojects/EELEditor

0 commit comments

Comments
 (0)