Background
kMethcla_Trigger (0x1) is already defined in Methcla_PortFlags in include/methcla/plugin.h, and SynthDef::portDescriptor() already exposes Methcla_PortDescriptor (which carries the flags field). The engine never acts on this flag, however — the reset loop was scaffolded but never completed, and was removed as dead code in #148.
What needs to happen
After each process cycle, any control input port flagged `kMethcla_Trigger` should be reset to `0.f` (one-shot / edge-trigger semantics). The sending side writes a non-zero value once; the engine zeros it on the next block so the synth sees exactly one non-zero sample.
Required changes
All changes are internal to the engine; the plugin API (kMethcla_Trigger) is already public.
src/Methcla/Audio/Synth.hpp — Synth::Flags
Add a hasTriggerInput bit:
struct Flags
{
unsigned int state : 2;
unsigned int hasTriggerInput : 1;
};
src/Methcla/Audio/Synth.cpp — construction
After the port-counting loop (around line 100), scan control input port descriptors and set the flag:
Methcla_PortDescriptor desc;
for (Methcla_PortCount i = 0; i < numControlInputs; i++) {
synthDef.portDescriptor(options, controlInputPortIndex(i), &desc);
if (desc.flags & kMethcla_Trigger) {
synth->m_flags.hasTriggerInput = 1;
break;
}
}
(The exact port index arithmetic depends on how control input indices map to global port indices — verify against the existing counting loop.)
src/Methcla/Audio/Synth.cpp — Synth::doProcess
At the end of the kStateActive block, after the output-write loop:
if (m_flags.hasTriggerInput) {
Methcla_PortDescriptor desc;
for (Methcla_PortCount i = 0; i < numControlInputs(); i++) {
synthDef().portDescriptor(nullptr, controlInputPortIndex(i), &desc);
if (desc.flags & kMethcla_Trigger)
controlInput(i) = 0.f;
}
}
Note: portDescriptor takes a Methcla_SynthOptions*; pass nullptr here since options are only needed at construction. Verify this is safe with the existing implementation in SynthDef.cpp.
Out of scope
- Changes to
plugin.h or the public C API
- Exposing trigger-port semantics through the OSC/C++ client API
Background
kMethcla_Trigger(0x1) is already defined inMethcla_PortFlagsininclude/methcla/plugin.h, andSynthDef::portDescriptor()already exposesMethcla_PortDescriptor(which carries theflagsfield). The engine never acts on this flag, however — the reset loop was scaffolded but never completed, and was removed as dead code in #148.What needs to happen
After each process cycle, any control input port flagged `kMethcla_Trigger` should be reset to `0.f` (one-shot / edge-trigger semantics). The sending side writes a non-zero value once; the engine zeros it on the next block so the synth sees exactly one non-zero sample.
Required changes
All changes are internal to the engine; the plugin API (
kMethcla_Trigger) is already public.src/Methcla/Audio/Synth.hpp—Synth::FlagsAdd a
hasTriggerInputbit:src/Methcla/Audio/Synth.cpp— constructionAfter the port-counting loop (around line 100), scan control input port descriptors and set the flag:
(The exact port index arithmetic depends on how control input indices map to global port indices — verify against the existing counting loop.)
src/Methcla/Audio/Synth.cpp—Synth::doProcessAt the end of the
kStateActiveblock, after the output-write loop:Note:
portDescriptortakes aMethcla_SynthOptions*; passnullptrhere since options are only needed at construction. Verify this is safe with the existing implementation inSynthDef.cpp.Out of scope
plugin.hor the public C API