// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown // SPDX-License-Identifier: GPL-3.0-or-later #pragma once #include #include "sizzle/Params.hpp" namespace sizzle { namespace sampler { class SampleStore; } /** * One playable instrument: a pool of voices for a ToolboxType, the way AudioEngine * plays one mixer channel's instrument (8 voices, a free voice first, else the * round-robin one; synth voices are cut when stolen, sample voices declick). * Used by the AUv3 instruments and the in-app host until the full engine is ported. * * Threads: construct and call update()/noteOn()/noteOff()/render() from the audio * thread only (the AU wrapper hands parameter changes over itself). No allocation * after construction. */ class Instrument { public: virtual ~Instrument() = default; /** New settings (and tempo): rebuild the patch, and let held notes follow it * where the Kotlin engine does (synth voices take the new patch). */ virtual void update(const Params &p, float tempoBpm) = 0; virtual void noteOn(int midi, int velocity) = 0; /** Release the held note(s) at [midi]. */ virtual void noteOff(int midi) = 0; /** Release everything (MIDI all-notes-off, transport stop). */ virtual void allNotesOff() = 0; /** Hard stop, no release tails. */ virtual void kill() = 0; /** Before each render block of [frames]: advances the Morph Pad's shared clock * and lets the sample store reclaim memory. */ virtual void blockStart(int frames) = 0; /** One mono output sample. */ virtual float render() = 0; static constexpr int POLYPHONY = 8; /** The instrument for ToolboxType [type] (NES_SYNTH, MORPH_PAD, WAVETABLE, * GRAIN_CLOUD, SAMPLER, SOUNDFONT), or nullptr. [store] supplies samples for * the Sampler, SF2/XI loader and Grain Cloud custom sources (may be null: * those then stay silent); it must outlive the instrument. */ static std::unique_ptr create(const char *type, int sampleRate, sampler::SampleStore *store); }; } // namespace sizzle