memlnaut-nisps/nisps/modes/generated/memlcelium_schema.hpp
monkey-w1n5t0n b16f26e6ab refactor(ml): one runtime-configurable training default (S26)
The operator's call: "there should be one default learning rate and one
default max iterations and they should both be configurable at runtime."

There were SIX copies, not the four the audit described, and they did not
agree:

  nisps/ml/mlp.hpp        no-arg train() hardcoding 1.f / 1000u / 0.001f —
                          and firmware's ONLY training path calls exactly
                          this, so firmware had no runtime knob at all
  wasm-iml.ts             train() and trainAsync() TS default params (x2)
  engine-api.ts           learningRate ?? 1.0, with no maxIterations knob
  vcv/src/iml.hpp         200 / 0.1 / 0.00001 — silently divergent
  external_synth_midi.hpp its own kDefaultLearningRate/kDefaultMaxIterations
  schemas/modes/*.json    x9, identical, read by nobody at runtime

Now: schemas/ml_defaults.json is the single declaration (validated against a
sibling meta-schema, matching the midi_device.schema.json convention), codegen
emits it to C++ and TS in the same run, and MLPCore carries a TrainConfig whose
default member initialisers read the generated constant.
set_train_config()/nisps_ml_set_train_config() make it runtime-overridable on
every target; the explicit-argument train() overload is untouched. min_error
joins the tuple — it was duplicated identically and belongs with the other two.

The per-mode ml block loses default_learning_rate/default_max_iterations.
default_spread stays (genuinely wired on both targets) and input_channels stays
(codegen-time validated, real information for sound_analysis_midi).

VCV BEHAVIOUR CHANGE, deliberate: MEMLNaut.cpp constructs IML positionally and
relies on those defaults, so the module moves to 1000/1.0/0.001 — 5x the max
iterations, 10x the learning rate, and a 100x looser early-stop threshold. The
old values were never justified anywhere; they arrived with fbc68eb alongside
an unrelated module rewrite and no tuning rationale. Firmware and WASM have
shipped 1.0/1000 all along. It is now runtime-settable if this turns out worse.

The generated header lands in nisps/ml/generated/, not nisps/modes/generated/
where the rest of codegen output lives: training hyperparameters are an ML
fact, and nisps/ml sits below nisps/modes, so emitting them there would make
mlp.hpp include upward. The agent that built this flagged the directory-crossing
rather than hiding it; this is the fix. CI's generated-freshness gate learns the
new directory.

Gates: run-all-tests.sh ALL GREEN — 4/4 ctest, parity PASS (max delta 2.38e-7),
lint clean, manifold typecheck + 17 unit + 33 e2e (which exercise train() and
trainAsync() through a real browser).
2026-07-21 17:20:10 +02:00

568 lines
10 KiB
C++

// AUTOGENERATED — do not edit. Source: schemas/modes/memlcelium.json. Run `bun run codegen/generate.ts` to regenerate.
#ifndef NISPS_GENERATED_MEMLCELIUM_SCHEMA_HPP
#define NISPS_GENERATED_MEMLCELIUM_SCHEMA_HPP
#include "schema_types.hpp"
#include "../../ml/mlp.hpp"
namespace nisps::modes::generated {
inline constexpr std::string_view kMemlceliumModeId = "memlcelium";
inline constexpr std::string_view kMemlceliumEngineId = "memlcelium";
inline constexpr std::array<std::string_view, 4> kMemlceliumInputChannels = {{
"joy_x",
"joy_y",
"joy_z",
"joy_w",
}};
inline constexpr std::array<std::size_t, 3> kMemlceliumHiddenLayers = {{
10u,
14u,
18u,
}};
inline constexpr MLConfig kMemlceliumMLConfig = {
4u,
56u,
0.6f,
};
inline constexpr std::size_t kMemlceliumParamCount = 56u;
inline constexpr std::array<Param, kMemlceliumParamCount> kMemlceliumParams = {{
Param{
"seq0_ratio0",
"Seq0 Ratio 0",
0.0f,
1.0f,
0.5f,
Curve::linear,
"sequencer",
},
Param{
"seq0_ratio1",
"Seq0 Ratio 1",
0.0f,
1.0f,
0.5f,
Curve::linear,
"sequencer",
},
Param{
"seq0_ratio2",
"Seq0 Ratio 2",
0.0f,
1.0f,
0.5f,
Curve::linear,
"sequencer",
},
Param{
"seq0_phasor_mul",
"Seq0 Phasor Mul",
0.0f,
1.0f,
0.0f,
Curve::linear,
"sequencer",
},
Param{
"seq0_phase_off",
"Seq0 Phase Off",
0.0f,
1.0f,
0.0f,
Curve::linear,
"sequencer",
},
Param{
"seq0_amp0",
"Seq0 Amp 0",
0.0f,
1.0f,
0.5f,
Curve::linear,
"sequencer",
},
Param{
"seq0_amp1",
"Seq0 Amp 1",
0.0f,
1.0f,
0.5f,
Curve::linear,
"sequencer",
},
Param{
"seq1_ratio0",
"Seq1 Ratio 0",
0.0f,
1.0f,
0.5f,
Curve::linear,
"sequencer",
},
Param{
"seq1_ratio1",
"Seq1 Ratio 1",
0.0f,
1.0f,
0.5f,
Curve::linear,
"sequencer",
},
Param{
"seq1_ratio2",
"Seq1 Ratio 2",
0.0f,
1.0f,
0.5f,
Curve::linear,
"sequencer",
},
Param{
"seq1_phasor_mul",
"Seq1 Phasor Mul",
0.0f,
1.0f,
0.0f,
Curve::linear,
"sequencer",
},
Param{
"seq1_phase_off",
"Seq1 Phase Off",
0.0f,
1.0f,
0.0f,
Curve::linear,
"sequencer",
},
Param{
"seq1_amp0",
"Seq1 Amp 0",
0.0f,
1.0f,
0.5f,
Curve::linear,
"sequencer",
},
Param{
"seq1_amp1",
"Seq1 Amp 1",
0.0f,
1.0f,
0.5f,
Curve::linear,
"sequencer",
},
Param{
"v0_base_freq",
"V0 Base Freq",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v0_synth",
},
Param{
"v0_paf0_cf",
"V0 PAF0 CF",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v0_synth",
},
Param{
"v0_paf1_cf",
"V0 PAF1 CF",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v0_synth",
},
Param{
"v0_paf2_cf",
"V0 PAF2 CF",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v0_synth",
},
Param{
"v0_paf0_bw",
"V0 PAF0 BW",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v0_synth",
},
Param{
"v0_paf1_bw",
"V0 PAF1 BW",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v0_synth",
},
Param{
"v0_paf2_bw",
"V0 PAF2 BW",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v0_synth",
},
Param{
"v0_paf_vib",
"V0 PAF Vib",
0.0f,
1.0f,
0.0f,
Curve::square,
"v0_synth",
},
Param{
"v0_paf_vfr",
"V0 PAF Vib Rate",
0.0f,
1.0f,
0.5f,
Curve::square,
"v0_synth",
},
Param{
"v0_paf0_shift",
"V0 PAF0 Shift",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v0_synth",
},
Param{
"v0_paf1_shift",
"V0 PAF1 Shift",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v0_synth",
},
Param{
"v0_paf2_shift",
"V0 PAF2 Shift",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v0_synth",
},
Param{
"v0_amp_attack",
"V0 Amp Attack",
0.0f,
1.0f,
0.0f,
Curve::linear,
"v0_env",
},
Param{
"v0_amp_decay",
"V0 Amp Decay",
0.0f,
1.0f,
0.3f,
Curve::square,
"v0_env",
},
Param{
"v0_amp_sustain",
"V0 Amp Sustain",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v0_env",
},
Param{
"v0_amp_release",
"V0 Amp Release",
0.0f,
1.0f,
0.3f,
Curve::square,
"v0_env",
},
Param{
"v0_pitch_attack",
"V0 Pitch Attack",
0.0f,
1.0f,
0.0f,
Curve::linear,
"v0_env",
},
Param{
"v0_pitch_decay",
"V0 Pitch Decay",
0.0f,
1.0f,
0.3f,
Curve::square,
"v0_env",
},
Param{
"v0_pitch_emph",
"V0 Pitch Emph",
0.0f,
1.0f,
0.0f,
Curve::linear,
"v0_env",
},
Param{
"v0_shape_gain",
"V0 Shape Gain",
0.0f,
1.0f,
0.0f,
Curve::linear,
"v0_synth",
},
Param{
"v0_shape_asym",
"V0 Shape Asym",
0.0f,
1.0f,
0.0f,
Curve::linear,
"v0_synth",
},
Param{
"v0_shape_mix",
"V0 Shape Mix",
0.0f,
1.0f,
0.0f,
Curve::linear,
"v0_synth",
},
Param{
"v0_rm_gain",
"V0 RingMod Gain",
0.0f,
1.0f,
0.0f,
Curve::linear,
"v0_synth",
},
Param{
"v1_base_freq",
"V1 Base Freq",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v1_synth",
},
Param{
"v1_detune1",
"V1 Detune 1",
0.0f,
1.0f,
0.0f,
Curve::linear,
"v1_synth",
},
Param{
"v1_detune2",
"V1 Detune 2",
0.0f,
1.0f,
0.0f,
Curve::linear,
"v1_synth",
},
Param{
"v1_paf0_cf",
"V1 PAF0 CF",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v1_synth",
},
Param{
"v1_paf1_cf",
"V1 PAF1 CF",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v1_synth",
},
Param{
"v1_paf2_cf",
"V1 PAF2 CF",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v1_synth",
},
Param{
"v1_paf0_bw",
"V1 PAF0 BW",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v1_synth",
},
Param{
"v1_paf1_bw",
"V1 PAF1 BW",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v1_synth",
},
Param{
"v1_paf2_bw",
"V1 PAF2 BW",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v1_synth",
},
Param{
"v1_paf0_shift",
"V1 PAF0 Shift",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v1_synth",
},
Param{
"v1_paf1_shift",
"V1 PAF1 Shift",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v1_synth",
},
Param{
"v1_paf2_shift",
"V1 PAF2 Shift",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v1_synth",
},
Param{
"v1_amp_attack",
"V1 Amp Attack",
0.0f,
1.0f,
0.0f,
Curve::linear,
"v1_env",
},
Param{
"v1_amp_decay",
"V1 Amp Decay",
0.0f,
1.0f,
0.3f,
Curve::square,
"v1_env",
},
Param{
"v1_amp_sustain",
"V1 Amp Sustain",
0.0f,
1.0f,
0.5f,
Curve::linear,
"v1_env",
},
Param{
"v1_amp_release",
"V1 Amp Release",
0.0f,
1.0f,
0.3f,
Curve::square,
"v1_env",
},
Param{
"v1_pitch_attack",
"V1 Pitch Attack",
0.0f,
1.0f,
0.0f,
Curve::linear,
"v1_env",
},
Param{
"v1_pitch_decay",
"V1 Pitch Decay",
0.0f,
1.0f,
0.3f,
Curve::square,
"v1_env",
},
Param{
"v1_pitch_emph",
"V1 Pitch Emph",
0.0f,
1.0f,
0.0f,
Curve::linear,
"v1_env",
},
}};
inline constexpr std::size_t kMemlceliumVoiceSpaceCount = 1u;
inline constexpr std::array<std::string_view, kMemlceliumVoiceSpaceCount> kMemlceliumVoiceSpaces = {{
"Direct",
}};
inline constexpr UIConfig kMemlceliumUI = {
PrimaryInput::XYPad,
false,
true,
};
using MemlceliumMLP = ::nisps::ml::MLP<kMemlceliumMLConfig.input_size, kMemlceliumHiddenLayers[0], kMemlceliumHiddenLayers[1], kMemlceliumHiddenLayers[2], kMemlceliumMLConfig.output_size>;
inline constexpr ::nisps::ParamSchema kMemlceliumSchema = {
kMemlceliumModeId,
kMemlceliumEngineId,
std::span<const std::string_view>(kMemlceliumInputChannels),
kMemlceliumMLConfig.input_size,
std::span<const std::size_t>(kMemlceliumHiddenLayers),
kMemlceliumMLConfig.output_size,
kMemlceliumMLConfig.default_spread,
std::span<const Param>(kMemlceliumParams),
std::span<const std::string_view>(kMemlceliumVoiceSpaces),
kMemlceliumUI,
};
} // namespace nisps::modes::generated
#endif // NISPS_GENERATED_MEMLCELIUM_SCHEMA_HPP