Iterating through InputId, InputId(i) responds as desired, but InputId(i+1) also responds

I’m attempting to iterate through a section of my inputs, checking if each has reached a threshold, and if so, to set the value of the corresponding parameter. It almost works, but for some reason it turns on/off not only the InputId(i), but also InputId(i+1).

{34549D51-A816-4246-B5E2-B6411DD74B17}

{36F4B1C2-7CE2-4BBA-857C-D5F70602A49F}

I’ve tinkered with other i values–if i is decrementing, then high gates trigger InputId(i) and InputId(i-1); if i is incrementing by 2, then InputId(i) and InputId(i+2) (and InputIds with even values never get triggered at all); and so on.

I’m aware that iterating through enums in this way might not be the best practice. I’m trying to avoid coding 16 nearly identical if-else statements to cover each input.

I’m new to coding in general, and VERY new to C++ and the Rack API, so feel free to roast me or provided constructive feedback unrelated to the question.

Here are my suggestions:

  • Use a for loop instead of while.
  • Iterate i from 0 to 15 and add it your first gate input’s ID, instead of starting at the first gate ID and ending at the last. This allows you to use the gate’s index, rather than its arbitrary input ID.
  • You must have a BooleanTrigger for each input, since it stores its state. Use an array of 16.
  • You’re calling BooleanTrigger::processEvent() (up to) twice per frame. You should only call it once. You don’t need the second condition, just use else {
  • Use SchmittTrigger instead, between 0.1 V and 1 V or so.
  • Avoiding setting params. You should generally only read param values. You’re also setting params 3 to 18, and I don’t see 19 params on your module, so you’re accessing an array out of bounds.
4 Likes