memlnaut-nisps/codegen/templates/ts_schema.ts.template
w1n5t0n 129e28b207 Add codegen tool: schemas -> C++ headers + TS modules
bun-runnable TypeScript script (codegen/generate.ts) that:
- Validates each schemas/modes/*.json against the meta-schema via
  ajv (Draft 2020-12).
- Cross-checks params.length == ml.output_size and
  ml.input_channels.length == ml.input_size.
- Emits constexpr C++ data into nisps/modes/generated/ (one
  schema_types.hpp + one <mode_id>_schema.hpp per mode). Uses
  std::string_view + std::array; no std::vector, no heap, .f
  suffixed float literals (perf contract §3.3).
- Emits TS modules into playground/src/modes/generated/ (one
  types.ts + one <mode_id>_schema.ts + index.ts barrel).
- Idempotent: re-running yields byte-identical output.
- Exits non-zero on schema validation failure.

Reference templates live in codegen/templates/ (not consumed at
codegen time -- for human reviewers).

Golden test (codegen/tests/golden_test.ts) snapshots
paf_synth_schema.{hpp,ts} and verifies regeneration matches the
golden + that a second run is idempotent.

Until stream 1 lands nisps/core/math.hpp, schema_types.hpp ships
its own minimal Curve enum with a TODO marker pointing at the
eventual include.
2026-04-29 15:29:08 +03:00

44 lines
1.3 KiB
Text

// AUTOGENERATED — do not edit. Source: schemas/modes/{{SOURCE_FILE}}. Run `bun run codegen/generate.ts` to regenerate.
//
// Reference template for the TypeScript codegen output. Not consumed at runtime
// (the codegen builds strings programmatically in emitModeTs). Lives here for
// human reviewers — placeholders use {{NAME}} syntax.
import type { ModeSchema } from './types';
export interface {{ModeId}}Params {
readonly {{param_name_0}}: number;
/* ... */
}
export const {{ModeId}}Schema: ModeSchema = {
mode_id: '{{mode_id}}',
engine_id: '{{engine_id}}',
ml: {
input_channels: ['{{input_channel_0}}', /* ... */],
input_size: {{input_size}},
hidden_layers: [/* ... */],
output_size: {{output_size}},
default_spread: {{default_spread}},
default_learning_rate: {{default_lr}},
default_max_iterations: {{default_iter}},
},
params: [
{
name: '{{name}}',
label: '{{label}}',
min: {{min}},
max: {{max}},
default: {{default}},
curve: '{{curve}}',
group: '{{group}}',
},
/* ... */
],
voice_spaces: [/* ... */],
ui: {
primary_input: '{{primary_input}}',
show_voice_space_selector: {{show_voice_space_selector}},
show_synth_visualizer: {{show_synth_visualizer}},
},
};