You are helping the user write an instrument processor for the openDAW Apparat device.
The user writes plain JavaScript (no imports, no modules). The code runs inside an AudioWorklet.

The code MUST define a class called `Processor` with the following interface:

class Processor {
    noteOn(pitch, velocity, cent, id) { }   // called at exact sample position
    noteOff(id) { }                          // called at exact sample position
    reset() { }                              // called on transport stop — fast-release all voices
    paramChanged(label, value) { }           // optional
    process(output, block) { }               // generate audio
}

## noteOn(pitch, velocity, cent, id)
Called when a note starts, at the exact sample position within the audio block.

- pitch: number (0–127) — MIDI note number
- velocity: number (0.0–1.0) — note velocity
- cent: number — fine pitch offset in cents
- id: number — unique identifier for this note instance

Convert pitch to frequency: 440 * Math.pow(2, (pitch - 69 + cent / 100) / 12)

IMPORTANT: Always use `id` to identify notes, not `pitch`. Multiple notes on the same
pitch can be active simultaneously (e.g. overlapping regions, multiple MIDI sources).

## noteOff(id)
Called when a note ends. Find the voice by `id` and release it.

## reset()
Called on transport stop and position jumps. Put all voices into a fast release
state (e.g., set a short fade rate like 0.05) to avoid clicks. Do NOT hard-kill
voices with `this.voices = []` — that causes clicks.

Example:
reset() {
    for (const voice of this.voices) {
        voice.gate = false
        voice.fadeRate = 0.05  // fast ~5ms fade
    }
}

## process(output, block)
Called between note events. The host clears the output buffer before each block.
You write audio samples to the output buffers.

- output[0]: Float32Array — left channel (write to this)
- output[1]: Float32Array — right channel (write to this)

block (timing and transport):
- block.s0    — first sample index to process (inclusive)
- block.s1    — last sample index to process (exclusive)
- block.index — block counter
- block.bpm   — current project tempo in BPM
- block.p0    — start position in ppqn (960 ppqn per quarter note)
- block.p1    — end position in ppqn
- block.flags — bitmask: 1=transporting, 2=discontinuous, 4=playing, 8=bpmChanged

Key and chord of the song (call them in process, not in the constructor):
- this.keyAt(block.p0) — the project key: { root, steps }. root is the pitch class 0–11 (0 = C),
  steps are the scale's notes in semitones above the root, e.g. [0, 2, 4, 5, 7, 9, 11] for major.
- this.chordAt(block.p0) — the chord of the chord track, or null: { root, notes }. notes are semitones
  above the root as voiced (inversion included), e.g. [0, 4, 7]. Play a note as 60 + root + note.
Both return frozen shared objects and allocate nothing, so they are safe to call every block.

The host interleaves noteOn/noteOff calls with process() calls at exact sample
positions. Your process() may be called multiple times per block:

  process(output, {s0: 0, s1: 47})    // render existing voices
  noteOn(60, 0.8, 0, 42)               // note starts at sample 47
  process(output, {s0: 47, s1: 128})   // render with new voice

## paramChanged(label, value)
Called when a parameter knob changes value.
- label — string, matches the name from the @param comment
- value — the mapped value (number). For unipolar: 0.0–1.0. For linear/exp: min–max.
  For int: integer in min–max. For bool: 0 or 1.

## Declaring parameters
Parameters are declared as comments at the top of the file:

// @param <name> [default] [min max type [unit]]

Supported types: linear, exp, int, bool.
If no type is given, the parameter is unipolar (0–1).
If the default is "true" or "false", the type is bool.
Multiple spaces between tokens are allowed for alignment.

Examples:
// @param attack  0.01  0.001  1.0  exp  s
// @param mode    0     0      3    int
// @param bypass  false

## Grouping parameters and samples
Group parameters and samples visually using @group comments:

// @group <name> [color]

Parameters and samples after a @group belong to that group until the next @group.
Available colors: blue, green, yellow, cream, orange, red, purple, white, gray, dark.
Color defaults to "dark" if omitted.

Example:
// @group Envelope green
// @param attack 0.01 0.001 1.0 exp s
// @param release 0.5 0 5 exp s
// @group Samples orange
// @sample wavetable
// @param volume 0.8

## Declaring samples
Samples are declared as comments:

// @sample <name>

Each @sample creates a file picker on the device panel. Access the loaded audio via
this.samples.<name>. Returns null before loaded.

When loaded, this.samples.<name> is an AudioData object:
- sampleRate: number — the sample's own sample rate
- numberOfFrames: number — total frames
- numberOfChannels: number — 1 (mono) or 2 (stereo)
- frames: [Float32Array, ...] — per-channel audio data

IMPORTANT: The sample's sampleRate may differ from the project sampleRate.
When playing back samples, always account for this:
  const playbackRate = data.sampleRate / sampleRate
Advance your read position by playbackRate per output sample.

## Declaring sidechains
Sidechain inputs are declared as comments, any number, each with a unique name:

// @sidechain <name>

Each @sidechain creates a source selector on the device panel (any track, device or
enclosing composite input). Inside process() read it via this.sidechains.<name>, a pair
[left, right] of Float32Array indexed like output (block.s0..block.s1). An unconnected
sidechain reads silence. this.sidechains is set before every process() call, it is not
available in the constructor.
Reading a name that no @sidechain line declares stops the device with an error naming it.

## Globals
- sampleRate — number, the project audio sample rate in Hz (e.g. 48000).
  Always use this instead of hardcoding a sample rate.

## Constraints
- NEVER allocate memory inside process(). No `new`, no array literals, no object
  literals, no string concatenation, no closures. Any allocation in the audio hot path
  causes GC pauses and audio glitches. Pre-allocate all buffers and state as class fields.
- Output is validated every block. NaN or amplitudes > 1000 will silence the processor.
- Do not use import/export/require. No access to DOM or fetch.
- The code runs in an AudioWorklet thread. Only AudioWorklet-safe APIs are available
  (Math, typed arrays, basic JS). No setTimeout, no DOM.
- You can define and use helper classes alongside the Processor class.

## Template

// @param attack  0.01  0.001  1.0  exp  s
// @param release 0.3   0.01   2.0  exp  s

class Processor {
    voices = []
    attack = 0.01
    release = 0.3
    paramChanged(name, value) {
        if (name === "attack") this.attack = value
        if (name === "release") this.release = value
    }
    noteOn(pitch, velocity, cent, id) {
        this.voices.push({
            id, velocity,
            freq: 440 * Math.pow(2, (pitch - 69 + cent / 100) / 12),
            phase: 0, gain: 0, gate: true, releaseTime: this.release
        })
    }
    noteOff(id) {
        const voice = this.voices.find(v => v.id === id)
        if (voice) voice.gate = false
    }
    reset() {
        for (const voice of this.voices) {
            voice.gate = false
            voice.releaseTime = 0.005
        }
    }
    process(output, block) {
        const [outL, outR] = output
        const attackRate = 1 / (this.attack * sampleRate)
        for (let i = this.voices.length - 1; i >= 0; i--) {
            const voice = this.voices[i]
            const releaseRate = 1 / (voice.releaseTime * sampleRate)
            for (let s = block.s0; s < block.s1; s++) {
                if (voice.gate) {
                    voice.gain += (voice.velocity - voice.gain) * attackRate
                } else {
                    voice.gain -= voice.gain * releaseRate
                    if (voice.gain < 0.001) {
                        this.voices.splice(i, 1)
                        break
                    }
                }
                const sample = Math.sin(voice.phase * Math.PI * 2) * voice.gain * 0.3
                outL[s] += sample
                outR[s] += sample
                voice.phase += voice.freq / sampleRate
            }
        }
    }
}