memlnaut-nisps/codegen/templates/cpp_schema.hpp.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

53 lines
1.9 KiB
Text

// AUTOGENERATED — do not edit. Source: schemas/modes/{{SOURCE_FILE}}. Run `bun run codegen/generate.ts` to regenerate.
//
// This file is a reference template showing the shape of each generated C++
// header. It is NOT consumed at codegen time — `codegen/generate.ts` builds the
// strings programmatically (see emitModeHpp). The template lives here so that:
// 1. reviewers can see the intended structure at a glance,
// 2. anyone tweaking the codegen has a "what should this look like?" anchor.
//
// Placeholders use {{NAME}} syntax purely for documentation.
#ifndef NISPS_GENERATED_{{MODE_ID_UPPER}}_SCHEMA_HPP
#define NISPS_GENERATED_{{MODE_ID_UPPER}}_SCHEMA_HPP
#include "schema_types.hpp"
namespace nisps::modes::generated {
inline constexpr std::string_view k{{ModeId}}ModeId = "{{mode_id}}";
inline constexpr std::string_view k{{ModeId}}EngineId = "{{engine_id}}";
inline constexpr std::array<std::string_view, {{N_INPUTS}}> k{{ModeId}}InputChannels = {{
"{{input_channel_0}}",
/* ... */
}};
inline constexpr std::array<std::size_t, {{N_HIDDEN}}> k{{ModeId}}HiddenLayers = {{
/* ... */
}};
inline constexpr MLConfig k{{ModeId}}MLConfig = {
{{input_size}}u, {{output_size}}u,
{{default_spread}}f, {{default_lr}}f, {{default_iter}}u,
};
inline constexpr std::size_t k{{ModeId}}ParamCount = {{N_PARAMS}}u;
inline constexpr std::array<Param, k{{ModeId}}ParamCount> k{{ModeId}}Params = {{
Param{ "{{name}}", "{{label}}", {{min}}f, {{max}}f, {{default}}f, Curve::{{Curve}}, "{{group}}" },
/* ... */
}};
inline constexpr std::size_t k{{ModeId}}VoiceSpaceCount = {{N_VS}}u;
inline constexpr std::array<std::string_view, k{{ModeId}}VoiceSpaceCount> k{{ModeId}}VoiceSpaces = {{
/* ... */
}};
inline constexpr UIConfig k{{ModeId}}UI = {
PrimaryInput::{{PrimaryInput}},
{{show_voice_space_selector}}, {{show_synth_visualizer}},
};
} // namespace nisps::modes::generated
#endif // NISPS_GENERATED_{{MODE_ID_UPPER}}_SCHEMA_HPP