hookmod

inlet value passed through after hitting control value. unhooked by rising edge on unhook input.
Author: Johannes Taelman & Stephen Hughes
License: BSD
Github: hc/ctrl/hookmod.axo

Inlets

frac32.positive input

bool32.rising unhook

Outlets

frac32.positive output

bool32 hooked

Parameters

frac32.u.map value

Declaration
int32_t nhooked; // 0:hooked, 1:gt, 2:lt, 4:unhooked
int32_t param_cache;
bool unhook;
Init
nhooked = 4;
unhook = 0;
Control Rate
// 0:hooked, 1:gt, 2:lt, 4:unhooked

if (inlet_unhook)
  unhook = 1;

if (nhooked) {
  outlet_out = param_value;
  if (param_value >= inlet_in) {
    nhooked |= 1;
    if (nhooked == 7) {
      nhooked = 0;
      param_cache = param_value;
    }
  } else {
    nhooked |= 2;
    if (nhooked == 7) {
      nhooked = 0;
      param_cache = param_value;
    }
  }
} else {
  outlet_out = inlet_in;
  if (param_cache != param_value || unhook) {
    nhooked = 4;
    unhook = 0;
  } else {
    PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_value],
                       inlet_in, 0xFFFD);
    param_cache = inlet_in;
  }
}
outlet_hooked = !nhooked;

Privacy

© 2024 Zrna Research