memlnaut-nisps/nisps/modes/paf_synth.hpp
monkey-w1n5t0n f5b571412f refactor(codegen): codegen owns mode identity, per-mode schemas and net dims
Phase 3 (S1, S5, S6, S25, L11, L37, ST11, ST12). Behaviour-preserving by
construction: the diff on the generated directories is PURELY ADDITIVE (217
insertions, 0 deletions), so no emitted constant changed value. This moves where
truth lives; it does not change what truth says.

- S5: nine mode headers each carried a mechanically identical 12-field
  positional ParamSchema aggregate. codegen now emits one
  `inline constexpr ParamSchema k<Mode>Schema` per mode, and the struct itself
  moved into generated/schema_types.hpp. Each param_schema() is a one-line
  return.
- S6 + S25: every mode hand-typed its net shape a second time as MLP template
  args, duplicating the schema's own dims. codegen emits a `<Mode>MLP` alias
  built from the already-emitted constants (not re-literalled), and all nine
  modes use it. NMaxExamples still defaults from kDefaultMaxExamples (Phase 2).
- S1: model.ts hand-imported all nine schemas by name and hand-paired each with
  its overlay — so the SET of modes was hand-maintained and could silently drift
  from codegen. codegen now emits ALL_MODE_SCHEMAS; SCHEMA_MODE_OVERLAYS is
  purely display truth (label/glyph/css/order), which stays hand-curated.
- L37: deleted the hand-written modeEngineId switch, which duplicated
  schema.engine_id and silently defaulted unknown modes to 'thru'. Routes on
  MFMode.engineId with exactly one documented exception: sound_analysis_midi
  declares engine_id 'thru' because its ModeBase audio slot really is
  NoOpEngine, while it separately drives the real AnalysisEngine.
- L11: ExternalSynthMIDIMode's shape was literal in two places; now named once
  in an ext_synth_defaults namespace with an ExtSynthMIDIMLP alias. Full folding
  into the JSON pipeline is NOT done and the reason is recorded in-file: it is a
  template family over an externally-supplied Device and variable NOut, with no
  single (device, NOut) schema to author.
- ST12: extracted codegen/lib.ts for the helpers both generators duplicated, and
  corrected the comment that claimed they had to be separate. Proof the
  extraction was behaviour-free: regenerating the MIDI-device outputs produces a
  byte-identical tree.
- ST11: deleted codegen/templates/ — dead "reference" files no generator reads,
  already drifted from the real emitters.

Gates: run-all-tests.sh ALL GREEN; codegen idempotent (re-running both
generators yields no further diff), which is what CI's dirty-diff gate checks.
2026-07-21 14:02:23 +02:00

56 lines
1.7 KiB
C++

// nisps/modes/paf_synth.hpp — PAF Synth mode binding.
//
// 4 abstract input channels (joy_x, joy_y, joy_z, joy_w) → MLP[4, 10, 10, 14, 33]
// → PAFSynthEngine.set_params() through the active voice space.
//
// Note triggering (note_on/note_off) lives in the engine; the mode exposes
// thin wrappers so platform glue can route incoming MIDI / touch events.
// No hardware-specific code; firmware glue and browser glue both call the
// same surface.
#pragma once
#include <cstddef>
#include <cstdint>
#include <span>
#include <string_view>
#include "../core/concepts.hpp"
#include "../core/perf.hpp"
#include "../core/types.hpp"
#include "../engines/paf_synth.hpp"
#include "base.hpp"
#include "generated/paf_synth_schema.hpp"
namespace nisps::modes {
class PAFSynthMode : public ModeBase<
PAFSynthMode,
PAFSynthEngine,
generated::PafSynthMLP,
4u> {
public:
using Base = ModeBase<PAFSynthMode, PAFSynthEngine,
generated::PafSynthMLP, 4u>;
using Base::Base;
// ---- Concept-required statics ----
static constexpr std::string_view mode_id() noexcept {
return generated::kPafSynthModeId;
}
static constexpr const ParamSchema& param_schema() noexcept {
return generated::kPafSynthSchema;
}
// ---- Mode-specific control glue ----
NISPS_FORCE_INLINE void note_on(std::uint8_t note, std::uint8_t velocity) noexcept {
engine_.note_on(note, velocity);
}
NISPS_FORCE_INLINE void note_off(std::uint8_t note) noexcept {
engine_.note_off(note);
}
};
static_assert(Mode<PAFSynthMode>, "PAFSynthMode must satisfy nisps::Mode");
} // namespace nisps::modes