{
  "$type": "at.atmosynth.module",
  "descriptionVersion": 1,
  "moduleId": "stepper",
  "versionKey": "1",
  "name": "Stepper",
  "description": "A row of values played one after another, in time with the loops. It counts from the same downbeat every sequencer in the patch does, so its first step falls on their bar 1 and stays there however the tempo moves; with no loop running it counts on its own at the one tempo, and Play brings it back to the top with them. There is no tempo knob here and no rate in hertz, and that is the point: a second clock would be free to drift from the first.\n\nSteps is how many go round, and Step length how long each lasts, counted against the one tempo: at sixteen sixteenths the row is one bar. Each step is a value from nothing to one. All sixteen are kept whatever Steps says, so shortening the row and lengthening it again gives back the steps it had.\n\nTwo things leave. Out is whatever arrives at In with the steps on its level: a pad through it at sixteenths is the gate every trance record is built on, a drum loop through it is a stutter. Depth is how far the steps reach there, so at nothing the signal passes untouched and at everything a step at nothing is silence. Steps is the row itself, for any modulation input: into a filter's Cutoff it is the acid line's other half, into a pan it throws the sound from side to side on the beat. How far it moves what it arrives at is set there, as it is for the LFO.\n\nGate is how much of each step holds its value before it falls to nothing, so two steps at the same level are two pulses rather than one long one. Glide is how much of each step is spent travelling from where the last one left off; after a short gate that is from nothing, which is a swell on every step. Both are fractions of the step, so they mean the same at every length and every tempo. The level at Out is always smoothed over a couple of milliseconds, since a gain cut mid-wave is a click; the Steps output is not, because a step that arrives sloped is not a step.\n\nSwitched off, Out is In untouched and Steps is silent. Per voice or shared, every copy counts from the same downbeat, so a chord through it is cut together.\n\nThis module carries code because nothing in the vocabulary divides one number by another and keeps the remainder, which is what turning a count of beats into a step is.",
  "audioInputs": [
    {
      "id": "in",
      "label": "In"
    }
  ],
  "audioOutputs": [
    {
      "id": "out",
      "label": "Out"
    },
    {
      "id": "steps",
      "label": "Steps"
    }
  ],
  "midiInputs": [],
  "nodes": [
    {
      "id": "in",
      "kind": "moduleInput",
      "options": {
        "input": "in"
      }
    },
    {
      "id": "position",
      "kind": "constantSource",
      "options": {
        "signal": "position"
      }
    },
    {
      "id": "steps",
      "kind": "dsp",
      "options": {
        "code": "// A row of values played one after another, in time with the loops.\n//\n// What it is handed is where the transport is, in beats (a constant source\n// declaring the `position` signal), and not a clock of its own: a stepper\n// counting from wherever it was built would be in tempo and still out of time\n// with every loop in the patch. Nothing in the vocabulary divides one number by\n// another and keeps the remainder, so there is no wiring of nodes that turns a\n// count of beats into which step it is — and that is the whole of what this\n// code does. The step's value is then only a lookup.\n//\n// Two things leave. The first output is the steps themselves, a value from\n// nothing to one, for patching into anything a modulation input moves. The\n// second is the level the steps put on the signal passing through, for the gain\n// that signal passes: Depth is how far the steps reach, so at nothing it passes\n// untouched and at everything a step at nothing is silence. What arrives at a\n// param is added to its own value, and a gain's own value is one, so the level\n// leaves less one — the same arithmetic the graphic equaliser's constants do.\n//\n// Gate is how much of each step holds its value before it falls to nothing, so\n// that two steps at the same level are two pulses rather than one long one.\n// Glide is how much of each step is spent travelling from where the last one\n// left off, which after a gate is nothing, so a short gate with a glide is a\n// swell on every step. Both are fractions of the step, so they mean the same at\n// every step length and every tempo.\n//\n// The level is smoothed over a couple of milliseconds, always: a gain stepped\n// from one to nothing mid-wave is a click, and a gate is made of exactly those\n// steps. The steps output is not, because a step that arrives sloped is not a\n// step — Glide is what slopes it, when that is wanted.\n//\n// Written again in DSP JS, it computes every sample the number it did. The\n// worklet named its sixteen steps in a list of strings and read each step's\n// parameter by its name from that list; here each is declared and read by its\n// own name. \"Not yet\" was `null`, and is a flag beside the value now. Each\n// output is the one channel the browser gave it.\nimport { AtmoProcessor } from \"atmosynth:dsp\";\n\n/** How many steps there are, each a parameter of its own, `step1` to `step16`. */\nconst STEPS = 16;\n\n/** How many Step lengths there are; `lengthsInBeats` lists them. */\nconst LENGTHS = 8;\n\n// How long the level takes to settle, in seconds: short enough that a gate is\n// still a gate, long enough that the cut is not a click.\nconst DECLICK_SECONDS = 0.002;\n\n// How many beats each Step length is, in the order the parameter lists them.\nfunction lengthsInBeats() {\n  const lengths = new Float64Array(LENGTHS);\n  lengths[0] = 1 / 8;\n  lengths[1] = 1 / 6;\n  lengths[2] = 1 / 4;\n  lengths[3] = 1 / 3;\n  lengths[4] = 1 / 2;\n  lengths[5] = 1;\n  lengths[6] = 2;\n  lengths[7] = 4;\n  return lengths;\n}\n\nexport default class AtmosynthStepper extends AtmoProcessor {\n  static spec = 1;\n  static inputs = [];\n  static outputs = [1, 1];\n  // Not smoothed here: a knob's move reaches these already eased, and the\n  // transport's position is followed exactly.\n  static params = {\n    // Where the transport is, in beats. Read at audio rate, because a step\n    // that changed at the start of a block would change up to three\n    // milliseconds early. It is a count that only grows, so it has no top\n    // worth naming.\n    position: { min: -1e9, max: 1e9, default: 0, rate: \"a\", smooth: 0 },\n    // How many steps go round, less one: a choice reaching an AudioParam is\n    // given its place in the list, and the list begins at one.\n    count: { min: 0, max: 15, default: 15, rate: \"k\", smooth: 0 },\n    // Which of the Step lengths, by its position.\n    length: { min: 0, max: 7, default: 2, rate: \"k\", smooth: 0 },\n    gate: { min: 0, max: 1, default: 1, rate: \"k\", smooth: 0 },\n    glide: { min: 0, max: 1, default: 0, rate: \"k\", smooth: 0 },\n    depth: { min: 0, max: 1, default: 1, rate: \"k\", smooth: 0 },\n    // The steps, by the names their parameters reach.\n    step1: { min: 0, max: 1, default: 1, rate: \"k\", smooth: 0 },\n    step2: { min: 0, max: 1, default: 1, rate: \"k\", smooth: 0 },\n    step3: { min: 0, max: 1, default: 1, rate: \"k\", smooth: 0 },\n    step4: { min: 0, max: 1, default: 1, rate: \"k\", smooth: 0 },\n    step5: { min: 0, max: 1, default: 1, rate: \"k\", smooth: 0 },\n    step6: { min: 0, max: 1, default: 1, rate: \"k\", smooth: 0 },\n    step7: { min: 0, max: 1, default: 1, rate: \"k\", smooth: 0 },\n    step8: { min: 0, max: 1, default: 1, rate: \"k\", smooth: 0 },\n    step9: { min: 0, max: 1, default: 1, rate: \"k\", smooth: 0 },\n    step10: { min: 0, max: 1, default: 1, rate: \"k\", smooth: 0 },\n    step11: { min: 0, max: 1, default: 1, rate: \"k\", smooth: 0 },\n    step12: { min: 0, max: 1, default: 1, rate: \"k\", smooth: 0 },\n    step13: { min: 0, max: 1, default: 1, rate: \"k\", smooth: 0 },\n    step14: { min: 0, max: 1, default: 1, rate: \"k\", smooth: 0 },\n    step15: { min: 0, max: 1, default: 1, rate: \"k\", smooth: 0 },\n    step16: { min: 0, max: 1, default: 1, rate: \"k\", smooth: 0 },\n  };\n\n  constructor() {\n    super();\n    /** Which step the count was last in, counted from the downbeat, once there is one. */\n    this.step = 0;\n    this.stepped = false;\n    /** What the steps output last was, and where the current step set off from. */\n    this.value = 0;\n    this.from = 0;\n    /** Where the smoothed level has got to, once there has been a first sample. */\n    this.level = 0;\n    this.levelled = false;\n    this.settle = 1 - Math.exp(-1 / (DECLICK_SECONDS * sampleRate));\n    this.values = new Float32Array(STEPS);\n    this.lengths = lengthsInBeats();\n  }\n\n  process(inputs, outputs, parameters) {\n    const steps = outputs[0][0];\n    const levels = outputs[1][0];\n    const count = Math.round(parameters.count[0]) + 1;\n    // A choice past the end of the list, which the parameter's range never\n    // reaches, is the quarter beat it defaults to.\n    const choice = Math.round(parameters.length[0]);\n    const length = choice >= 0 && choice < LENGTHS ? this.lengths[choice] : this.lengths[2];\n    const gate = parameters.gate[0];\n    const glide = parameters.glide[0];\n    const depth = parameters.depth[0];\n    const values = this.values;\n    values[0] = parameters.step1[0];\n    values[1] = parameters.step2[0];\n    values[2] = parameters.step3[0];\n    values[3] = parameters.step4[0];\n    values[4] = parameters.step5[0];\n    values[5] = parameters.step6[0];\n    values[6] = parameters.step7[0];\n    values[7] = parameters.step8[0];\n    values[8] = parameters.step9[0];\n    values[9] = parameters.step10[0];\n    values[10] = parameters.step11[0];\n    values[11] = parameters.step12[0];\n    values[12] = parameters.step13[0];\n    values[13] = parameters.step14[0];\n    values[14] = parameters.step15[0];\n    values[15] = parameters.step16[0];\n    const positions = parameters.position;\n\n    for (let index = 0; index < steps.length; index += 1) {\n      const counted = positions[index] / length;\n      const step = Math.floor(counted);\n      const within = counted - step;\n      // Below nothing is the bar before the downbeat, so the remainder is\n      // taken the way a clock face takes it rather than the way `%` does.\n      const target = values[((step % count) + count) % count];\n      if (!this.stepped || step !== this.step) {\n        // Set off from where the output actually is, so a glide interrupted by\n        // a step it did not finish in does not jump.\n        this.from = this.stepped ? this.value : target;\n        this.step = step;\n        this.stepped = true;\n      }\n      let value = glide > 0 && within < glide ? this.from + (target - this.from) * (within / glide) : target;\n      if (within >= gate) value = 0;\n      this.value = value;\n      steps[index] = value;\n\n      const wanted = 1 - depth + depth * value;\n      this.level = this.levelled ? this.level + (wanted - this.level) * this.settle : wanted;\n      this.levelled = true;\n      levels[index] = this.level - 1;\n    }\n    return true;\n  }\n}\n"
      }
    },
    {
      "id": "vca",
      "kind": "gain",
      "options": {}
    },
    {
      "id": "out",
      "kind": "moduleOutput",
      "options": {
        "output": "out"
      }
    },
    {
      "id": "stepsout",
      "kind": "moduleOutput",
      "options": {
        "output": "steps"
      }
    }
  ],
  "connections": [
    {
      "from": {
        "node": "in",
        "output": 0
      },
      "to": {
        "node": "vca",
        "input": 0
      }
    },
    {
      "from": {
        "node": "vca",
        "output": 0
      },
      "to": {
        "node": "out",
        "input": 0
      }
    },
    {
      "from": {
        "node": "position",
        "output": 0
      },
      "to": {
        "node": "steps",
        "param": "position"
      }
    },
    {
      "from": {
        "node": "steps",
        "output": 0
      },
      "to": {
        "node": "stepsout",
        "input": 0
      }
    },
    {
      "from": {
        "node": "steps",
        "output": 1
      },
      "to": {
        "node": "vca",
        "param": "gain"
      }
    }
  ],
  "automation": [],
  "parameters": [
    {
      "id": "count",
      "label": "Steps",
      "values": [
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        "9",
        "10",
        "11",
        "12",
        "13",
        "14",
        "15",
        "16"
      ],
      "default": "16",
      "targets": [
        {
          "node": "steps",
          "param": "count"
        }
      ]
    },
    {
      "id": "length",
      "label": "Step length",
      "values": [
        "1/32",
        "1/16 triplet",
        "1/16",
        "1/8 triplet",
        "1/8",
        "1/4",
        "1/2",
        "1 bar"
      ],
      "default": "1/16",
      "targets": [
        {
          "node": "steps",
          "param": "length"
        }
      ]
    },
    {
      "id": "gate",
      "label": "Gate",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "1",
      "targets": [
        {
          "node": "steps",
          "param": "gate"
        }
      ]
    },
    {
      "id": "glide",
      "label": "Glide",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "0",
      "targets": [
        {
          "node": "steps",
          "param": "glide"
        }
      ]
    },
    {
      "id": "depth",
      "label": "Depth",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "1",
      "targets": [
        {
          "node": "steps",
          "param": "depth"
        }
      ]
    },
    {
      "id": "step1",
      "label": "Step 1",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "1",
      "targets": [
        {
          "node": "steps",
          "param": "step1"
        }
      ]
    },
    {
      "id": "step2",
      "label": "Step 2",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "0.25",
      "targets": [
        {
          "node": "steps",
          "param": "step2"
        }
      ]
    },
    {
      "id": "step3",
      "label": "Step 3",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "0.5",
      "targets": [
        {
          "node": "steps",
          "param": "step3"
        }
      ]
    },
    {
      "id": "step4",
      "label": "Step 4",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "0.25",
      "targets": [
        {
          "node": "steps",
          "param": "step4"
        }
      ]
    },
    {
      "id": "step5",
      "label": "Step 5",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "1",
      "targets": [
        {
          "node": "steps",
          "param": "step5"
        }
      ]
    },
    {
      "id": "step6",
      "label": "Step 6",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "0.25",
      "targets": [
        {
          "node": "steps",
          "param": "step6"
        }
      ]
    },
    {
      "id": "step7",
      "label": "Step 7",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "0.5",
      "targets": [
        {
          "node": "steps",
          "param": "step7"
        }
      ]
    },
    {
      "id": "step8",
      "label": "Step 8",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "0.25",
      "targets": [
        {
          "node": "steps",
          "param": "step8"
        }
      ]
    },
    {
      "id": "step9",
      "label": "Step 9",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "1",
      "targets": [
        {
          "node": "steps",
          "param": "step9"
        }
      ]
    },
    {
      "id": "step10",
      "label": "Step 10",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "0.25",
      "targets": [
        {
          "node": "steps",
          "param": "step10"
        }
      ]
    },
    {
      "id": "step11",
      "label": "Step 11",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "0.5",
      "targets": [
        {
          "node": "steps",
          "param": "step11"
        }
      ]
    },
    {
      "id": "step12",
      "label": "Step 12",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "0.25",
      "targets": [
        {
          "node": "steps",
          "param": "step12"
        }
      ]
    },
    {
      "id": "step13",
      "label": "Step 13",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "1",
      "targets": [
        {
          "node": "steps",
          "param": "step13"
        }
      ]
    },
    {
      "id": "step14",
      "label": "Step 14",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "0.25",
      "targets": [
        {
          "node": "steps",
          "param": "step14"
        }
      ]
    },
    {
      "id": "step15",
      "label": "Step 15",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "0.5",
      "targets": [
        {
          "node": "steps",
          "param": "step15"
        }
      ]
    },
    {
      "id": "step16",
      "label": "Step 16",
      "range": {
        "min": "0",
        "max": "1"
      },
      "default": "0.25",
      "targets": [
        {
          "node": "steps",
          "param": "step16"
        }
      ]
    }
  ],
  "sampleSlots": [],
  "createdAt": "2026-09-28T00:00:00.000Z"
}