Skip to content

Commit

Permalink
- fix #617
Browse files Browse the repository at this point in the history
- fix SNEX timer node not working in custom mode
  • Loading branch information
christoph-hart committed Jan 20, 2025
1 parent bd999e2 commit baf9cd1
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 57 deletions.
9 changes: 0 additions & 9 deletions hi_scripting/scripting/scriptnode/snex_nodes/SnexSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,10 @@ void SnexSource::rebuildCallbacksAfterChannelChange(int numChannelsToProcess)

if (wb != nullptr)
{

wb->setNumChannels(currentChannelCount);

if (wasZero)
wb->triggerRecompile();

#if 0
if (auto objPtr = wb->getLastResult().mainClassPtr)
{
if (lastResult.wasOk())
lastResult = getCallbackHandler().recompiledOk(objPtr);
}
#endif
}
}

Expand Down
123 changes: 84 additions & 39 deletions hi_scripting/scripting/scriptnode/snex_nodes/SnexTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,65 +39,110 @@ using namespace snex;

namespace control
{
String snex_timer::getEmptyText(const Identifier& id) const
{
String snex_timer::getEmptyText(const Identifier& id) const
{
#if HISE_INCLUDE_SNEX
cppgen::Base c(cppgen::Base::OutputType::AddTabs);
cppgen::Base c(cppgen::Base::OutputType::AddTabs);

cppgen::Struct s(c, id, {}, { TemplateParameter(NamespacedIdentifier("NumVoices"), 0, false) });
cppgen::Struct s(c, id, {}, { TemplateParameter(NamespacedIdentifier("NumVoices"), 0, false) });

addSnexNodeId(c, id);
addSnexNodeId(c, id);

c.addComment("Calculate a new timer value here", snex::cppgen::Base::CommentType::Raw);
c << "double getTimerValue()\n";
c << "{\n return 0.0;\n}\n";
c.addComment("Calculate a new timer value here", snex::cppgen::Base::CommentType::Raw);
c << "double getTimerValue()\n";
c << "{\n return 0.0;\n}\n";

c.addComment("Reset any state here", snex::cppgen::Base::CommentType::Raw);
c << "void reset()\n";
c << "{\n \n}\n";
c.addComment("Reset any state here", snex::cppgen::Base::CommentType::Raw);
c << "void reset()\n";
c << "{\n \n}\n";

c.addComment("Initialise the processing", snex::cppgen::Base::CommentType::Raw);
c << "void prepare(PrepareSpecs ps)\n";
c << "{\n \n}\n";
c.addComment("Initialise the processing", snex::cppgen::Base::CommentType::Raw);
c << "void prepare(PrepareSpecs ps)\n";
c << "{\n \n}\n";

String pf;
c.addEmptyLine();
addDefaultParameterFunction(pf);
c << pf;
String pf;
c.addEmptyLine();
addDefaultParameterFunction(pf);
c << pf;

s.flushIfNot();
s.flushIfNot();

return c.toString();
return c.toString();
#else
return {};
return {};
#endif
}
}

double snex_timer::getTimerValue()
{
double v;
double snex_timer::getTimerValue()
{
double v;

switch (currentMode)
{
case TimerMode::Ping: v = pingTimer.getTimerValue(); break;
switch (currentMode)
{
case TimerMode::Ping: v = pingTimer.getTimerValue(); break;

case TimerMode::Custom:
case TimerMode::Custom:
#if HISE_INCLUDE_SNEX
v = callbacks.getTimerValue();
v = callbacks.getTimerValue();
#else
jassertfalse;
v = 0.0;
jassertfalse;
v = 0.0;
#endif
break;
case TimerMode::Toggle: v = toggleTimer.getTimerValue(); break;
case TimerMode::Random: v = randomTimer.getTimerValue(); break;
default: v = 0.0f; break;
}
break;
case TimerMode::Toggle: v = toggleTimer.getTimerValue(); break;
case TimerMode::Random: v = randomTimer.getTimerValue(); break;
default: v = 0.0f; break;
}

lastValue.setModValue(v);
return v;
}

bool snex_timer::preprocess(String& code)
{
OptionalSnexSource::preprocess(code);

using namespace cppgen;

Base b(Base::OutputType::AddTabs);

lastValue.setModValue(v);
return v;
auto NV = String(getParentNode()->isPolyphonic() ? NUM_POLYPHONIC_VOICES : 1);

String instanceType = getCurrentClassId().toString() + "<" + NV + ">";


b << String("void prepare(" + instanceType + "& instance, PrepareSpecs ps)");
{
StatementBlock sb(b, false);
b << "instance.prepare(ps);";
}

b << String("void setExternalData(" + instanceType + "& instance, ExternalData& d, int index)");
{
StatementBlock sb(b, false);
b << "instance.setExternalData(d, index);";
}

b << String("void reset(" + instanceType + "& instance)");
{
StatementBlock sb(b, false);
b << "instance.reset();";
}

b << String("double getTimerValue(" + instanceType + "& instance)");
{
StatementBlock sb(b, false);
b << "return instance.getTimerValue();";
}

auto x = b.toString();
code << x;

DBG(code);

return true;
}

#if HISE_INCLUDE_SNEX
snex_timer::editor::editor(snex_timer* t, PooledUIUpdater* updater) :
ScriptnodeExtraComponent<snex_timer>(t, updater),
Expand Down
20 changes: 11 additions & 9 deletions hi_scripting/scripting/scriptnode/snex_nodes/SnexTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ struct snex_timer : public OptionalSnexSource
auto newReset = getFunctionAsObjectCallback("reset");
auto newPrepare = getFunctionAsObjectCallback("prepare");

auto r = newTc.validateWithArgs(Types::ID::Double, {});
auto r = newTc.validateWithArgs(Types::ID::Double, { Types::ID::Pointer });

if (r.wasOk())
r = newReset.validateWithArgs(Types::ID::Void, {});
r = newReset.validateWithArgs(Types::ID::Void, { Types::ID::Pointer });

if (r.wasOk())
r = newPrepare.validateWithArgs("void", { "PrepareSpecs" });
r = newPrepare.validateWithArgs(Types::ID::Void, { Types::ID::Pointer, Types::ID::Pointer });

{
SimpleReadWriteLock::ScopedWriteLock l(getAccessLock());
Expand Down Expand Up @@ -257,6 +257,10 @@ struct snex_timer : public OptionalSnexSource
void updateMode(Identifier, var newValue)
{
currentMode = (TimerMode)getModes().indexOf(newValue.toString());

auto pn = getParentNode();
pn->getRootNetwork()->getExceptionHandler().removeError(pn);

reset();
}

Expand All @@ -281,15 +285,13 @@ struct snex_timer : public OptionalSnexSource
}
}

bool preprocess(String& code) override
{
OptionalSnexSource::preprocess(code);
return true;
}
bool preprocess(String& code) override;

/** Initialises the processing. */
/** Initialises the processing. */
void prepare(PrepareSpecs ps)
{
rebuildCallbacksAfterChannelChange(ps.numChannels);

callbacks.prepare(ps);
toggleTimer.prepare(ps);
randomTimer.prepare(ps);
Expand Down

0 comments on commit baf9cd1

Please sign in to comment.