Skip to content

Implement trigger control input reset in Synth::doProcess #149

Description

@kaoskorobase

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions