-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.rs
More file actions
969 lines (898 loc) · 36.7 KB
/
Copy pathbuild.rs
File metadata and controls
969 lines (898 loc) · 36.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
//! Generates `params_gen.rs` — a top-level `pub struct GeneratedParams` with
//! 1404 `FloatParam` fields for graph nodes, tilt/offset, curvature, and matrix
//! sends, plus a `Default` impl and an `extend_param_map` method.
//!
//! The generated file is `include!`d at the top of `src/params.rs`. The main
//! `SpectralForgeParams` struct holds a `generated: GeneratedParams` field and
//! forwards `param_map()` entries through `extend_param_map`.
//!
//! Keep IDs in sync with src/param_ids.rs — any formatting change here
//! that diverges from param_ids.rs breaks saved automation.
//!
//! NOTE: `NUM_MATRIX_ROWS = 9` here matches `src/param_ids.rs` (real slots only).
//! The DSP-layer `dsp::modules::MAX_MATRIX_ROWS = 13` includes T/S Split virtual
//! rows and is intentionally different; exposing virtual rows as automation
//! targets is out of scope for this generator.
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
const NUM_SLOTS: usize = 9;
const NUM_CURVES: usize = 7;
const NUM_NODES: usize = 6;
const NUM_MATRIX_ROWS: usize = 9; // destinations (slots only)
const NUM_MATRIX_SOURCES: usize = 13; // sources: 9 slots + 4 T/S virtual rows
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=src/param_ids.rs");
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let out_path = out_dir.join("params_gen.rs");
let mut f = File::create(&out_path).expect("create params_gen.rs");
writeln!(f, "// AUTO-GENERATED — do not edit. See build.rs.").unwrap();
writeln!(f, "//").unwrap();
writeln!(
f,
"// This file is `include!`d at the top of src/params.rs. It defines"
)
.unwrap();
writeln!(
f,
"// `GeneratedParams` (1404 FloatParams), its Default, and a helper"
)
.unwrap();
writeln!(
f,
"// method that extends the plugin's `param_map()` vector with"
)
.unwrap();
writeln!(f, "// (id, ptr, group) tuples for every generated field.").unwrap();
writeln!(f).unwrap();
// ─── struct GeneratedParams { ... } ────────────────────────────────────
writeln!(f, "pub struct GeneratedParams {{").unwrap();
emit_graph_node_fields(&mut f);
emit_tilt_offset_fields(&mut f);
emit_curvature_fields(&mut f);
emit_matrix_fields(&mut f);
emit_past_scalar_fields(&mut f);
emit_life_scalar_fields(&mut f);
emit_kinetics_scalar_fields(&mut f);
emit_circuit_scalar_fields(&mut f);
emit_modulate_scalar_fields(&mut f);
emit_contrast_scalar_fields(&mut f);
writeln!(f, "}}").unwrap();
writeln!(f).unwrap();
// ─── impl Default for GeneratedParams ──────────────────────────────────
writeln!(f, "impl Default for GeneratedParams {{").unwrap();
writeln!(f, " fn default() -> Self {{").unwrap();
writeln!(f, " Self {{").unwrap();
emit_graph_node_inits(&mut f);
emit_tilt_offset_inits(&mut f);
emit_curvature_inits(&mut f);
emit_matrix_inits(&mut f);
emit_past_scalar_inits(&mut f);
emit_life_scalar_inits(&mut f);
emit_kinetics_scalar_inits(&mut f);
emit_circuit_scalar_inits(&mut f);
emit_modulate_scalar_inits(&mut f);
emit_contrast_scalar_inits(&mut f);
writeln!(f, " }}").unwrap();
writeln!(f, " }}").unwrap();
writeln!(f, "}}").unwrap();
writeln!(f).unwrap();
// ─── impl GeneratedParams { fn extend_param_map(...) } ─────────────────
writeln!(f, "impl GeneratedParams {{").unwrap();
writeln!(
f,
" /// Push one `(id, ParamPtr, group)` tuple per generated field into `out`."
)
.unwrap();
writeln!(
f,
" pub fn extend_param_map(&self, out: &mut Vec<(String, ParamPtr, String)>) {{"
)
.unwrap();
emit_graph_node_map_entries(&mut f);
emit_tilt_offset_map_entries(&mut f);
emit_curvature_map_entries(&mut f);
emit_matrix_map_entries(&mut f);
emit_past_scalar_map_entries(&mut f);
emit_life_scalar_map_entries(&mut f);
emit_kinetics_scalar_map_entries(&mut f);
emit_circuit_scalar_map_entries(&mut f);
emit_modulate_scalar_map_entries(&mut f);
emit_contrast_scalar_map_entries(&mut f);
writeln!(f, " }}").unwrap();
writeln!(f, "}}").unwrap();
// ─── Dispatch macros for typed accessors ───────────────────────────────
writeln!(f).unwrap();
emit_graph_node_dispatch(&mut f);
writeln!(f).unwrap();
emit_tilt_dispatch(&mut f);
writeln!(f).unwrap();
emit_offset_dispatch(&mut f);
writeln!(f).unwrap();
emit_curvature_dispatch(&mut f);
writeln!(f).unwrap();
emit_matrix_dispatch(&mut f);
writeln!(f).unwrap();
emit_past_scalar_dispatch(&mut f);
writeln!(f).unwrap();
emit_life_scalar_dispatch(&mut f);
writeln!(f).unwrap();
emit_kinetics_scalar_dispatch(&mut f);
writeln!(f).unwrap();
emit_circuit_scalar_dispatch(&mut f);
writeln!(f).unwrap();
emit_modulate_scalar_dispatch(&mut f);
writeln!(f).unwrap();
emit_contrast_scalar_dispatch(&mut f);
}
// ── Field declarations (bare, no initializers) ──────────────────────────────
fn emit_graph_node_fields(f: &mut File) {
for s in 0..NUM_SLOTS {
for c in 0..NUM_CURVES {
for n in 0..NUM_NODES {
for field in ['x', 'y', 'q'] {
let rust_name = format!("s{}c{}n{}_{}", s, c, n, field);
writeln!(f, " pub {rust_name}: FloatParam,").unwrap();
}
}
}
}
}
fn emit_tilt_offset_fields(f: &mut File) {
for s in 0..NUM_SLOTS {
for c in 0..NUM_CURVES {
for kind in ["tilt", "offset"] {
let rust_name = format!("s{}c{}_{}", s, c, kind);
writeln!(f, " pub {rust_name}: FloatParam,").unwrap();
}
}
}
}
fn emit_matrix_fields(f: &mut File) {
for r in 0..NUM_MATRIX_ROWS {
for col in 0..NUM_MATRIX_SOURCES {
let rust_name = format!("mr{}c{}", r, col);
writeln!(f, " pub {rust_name}: FloatParam,").unwrap();
}
}
}
// ── Default initializers ────────────────────────────────────────────────────
fn emit_graph_node_inits(f: &mut File) {
for s in 0..NUM_SLOTS {
for c in 0..NUM_CURVES {
for n in 0..NUM_NODES {
for field in ['x', 'y', 'q'] {
let id = format!("s{}c{}n{}{}", s, c, n, field);
let rust_name = format!("s{}c{}n{}_{}", s, c, n, field);
let (default, min, max) = graph_node_defaults(n, field);
writeln!(
f,
" {rust_name}: FloatParam::new(\"{id}\", {default}f32, \
FloatRange::Linear {{ min: {min}f32, max: {max}f32 }})\
.with_smoother(SmoothingStyle::Linear(1.0))\
.hide_in_generic_ui(),"
)
.unwrap();
}
}
}
}
}
fn graph_node_defaults(node: usize, field: char) -> (f32, f32, f32) {
match field {
'x' => {
// Default x positions: equally spaced across log-freq axis.
// Matches existing CurveNode default layout in src/editor/curve.rs.
let default = match node {
0 => 0.0,
1 => 0.2,
2 => 0.4,
3 => 0.6,
4 => 0.8,
5 => 1.0,
_ => 0.5,
};
(default, 0.0, 1.0)
}
'y' => (0.0, -1.0, 1.0),
'q' => (0.5, 0.0, 1.0),
_ => unreachable!(),
}
}
/// Return `true` when the curve at `(slot, curve)` — evaluated for the *default*
/// module type of that slot with `GainMode::Add` — has `y_natural == y_max`
/// (natural-at-max). These curves default their offset FloatParam to `+1.0`
/// so the user loads at `y_max` (e.g. 100% wet for MIX) and slides down.
///
/// Default module assignment (mirrors `params::Default::default()`):
/// slot 0 = Dynamics, slot 1 = Gain (Add mode), slots 2-7 = Empty, slot 8 = Master.
///
/// This is an explicit lookup table because build.rs cannot import the crate.
/// Keep in sync with `curve_config::curve_display_config()`.
fn offset_default_for_slot_curve(slot: usize, curve: usize) -> f32 {
// Dynamics (slot 0): MIX at local curve index 5 is natural-at-max
// (y_natural = 100.0 == y_max = 100.0).
// All other Dynamics curves: not natural-at-max.
// Gain/Add (slot 1): curve 0 y_natural=0.0 ≠ y_max=18.0; curve 1 y_natural=50 ≠ y_max=500.
// Empty / Master (slots 2-8): default_config y_natural=0.5 ≠ y_max=1.0.
if slot == 0 && curve == 5 {
1.0_f32
} else {
0.0_f32
}
}
fn emit_tilt_offset_inits(f: &mut File) {
for s in 0..NUM_SLOTS {
for c in 0..NUM_CURVES {
for kind in ["tilt", "offset"] {
let id = format!("s{}c{}{}", s, c, kind);
let rust_name = format!("s{}c{}_{}", s, c, kind);
let default = if kind == "offset" {
offset_default_for_slot_curve(s, c)
} else {
0.0_f32
};
writeln!(
f,
" {rust_name}: FloatParam::new(\"{id}\", {default}f32, \
FloatRange::Linear {{ min: -1.0f32, max: 1.0f32 }})\
.with_smoother(SmoothingStyle::Linear(2.0))\
.hide_in_generic_ui(),"
)
.unwrap();
}
}
}
}
fn emit_matrix_inits(f: &mut File) {
// Param ID convention: mr{row}c{col} where row = DESTINATION slot, col = SOURCE slot.
// This is the TRANSPOSE of RouteMatrix.send[src][dst] (first index = source).
// When building RouteMatrix from params: send[col][r] = mr{r}c{col}.value()
//
// Default routing: Dynamics (slot 0) → Gain (slot 1) → Master (slot 8).
// Matches the default slot_module_types in params.rs / presets.rs.
// mr1c0 = 1.0 (col 0 → row 1) and mr8c1 = 1.0 (col 1 → row 8); rest are 0.
for r in 0..NUM_MATRIX_ROWS {
for col in 0..NUM_MATRIX_SOURCES {
let id = format!("mr{}c{}", r, col);
let rust_name = format!("mr{}c{}", r, col);
let default: f32 = if (r == 1 && col == 0) || (r == 8 && col == 1) { 1.0 } else { 0.0 };
writeln!(
f,
" {rust_name}: FloatParam::new(\"{id}\", {default}f32, \
FloatRange::Linear {{ min: -1.0f32, max: 1.0f32 }})\
.with_smoother(SmoothingStyle::Linear(100.0))\
.hide_in_generic_ui(),"
)
.unwrap();
}
}
}
// ── extend_param_map body ───────────────────────────────────────────────────
fn emit_graph_node_map_entries(f: &mut File) {
for s in 0..NUM_SLOTS {
for c in 0..NUM_CURVES {
for n in 0..NUM_NODES {
for field in ['x', 'y', 'q'] {
let id = format!("s{}c{}n{}{}", s, c, n, field);
let rust_name = format!("s{}c{}n{}_{}", s, c, n, field);
writeln!(
f,
" out.push(({id:?}.to_string(), self.{rust_name}.as_ptr(), String::new()));"
)
.unwrap();
}
}
}
}
}
fn emit_tilt_offset_map_entries(f: &mut File) {
for s in 0..NUM_SLOTS {
for c in 0..NUM_CURVES {
for kind in ["tilt", "offset"] {
let id = format!("s{}c{}{}", s, c, kind);
let rust_name = format!("s{}c{}_{}", s, c, kind);
writeln!(
f,
" out.push(({id:?}.to_string(), self.{rust_name}.as_ptr(), String::new()));"
)
.unwrap();
}
}
}
}
fn emit_matrix_map_entries(f: &mut File) {
for r in 0..NUM_MATRIX_ROWS {
for col in 0..NUM_MATRIX_SOURCES {
let id = format!("mr{}c{}", r, col);
let rust_name = format!("mr{}c{}", r, col);
writeln!(
f,
" out.push(({id:?}.to_string(), self.{rust_name}.as_ptr(), String::new()));"
)
.unwrap();
}
}
}
// ── Dispatch macros for typed accessors ────────────────────────────────────
fn emit_graph_node_dispatch(f: &mut File) {
writeln!(f, "macro_rules! graph_node_dispatch {{").unwrap();
writeln!(f, " ($self:expr, $s:expr, $c:expr, $n:expr) => {{").unwrap();
writeln!(f, " match ($s, $c, $n) {{").unwrap();
for s in 0..NUM_SLOTS {
for c in 0..NUM_CURVES {
for n in 0..NUM_NODES {
writeln!(
f,
" ({s}, {c}, {n}) => (\
&$self.generated.s{s}c{c}n{n}_x, \
&$self.generated.s{s}c{c}n{n}_y, \
&$self.generated.s{s}c{c}n{n}_q),"
)
.unwrap();
}
}
}
writeln!(f, " _ => unreachable!(),").unwrap();
writeln!(f, " }}").unwrap();
writeln!(f, " }};").unwrap();
writeln!(f, "}}").unwrap();
}
fn emit_tilt_dispatch(f: &mut File) {
writeln!(f, "macro_rules! tilt_dispatch {{").unwrap();
writeln!(f, " ($self:expr, $s:expr, $c:expr) => {{").unwrap();
writeln!(f, " match ($s, $c) {{").unwrap();
for s in 0..NUM_SLOTS {
for c in 0..NUM_CURVES {
writeln!(f, " ({s}, {c}) => &$self.generated.s{s}c{c}_tilt,").unwrap();
}
}
writeln!(f, " _ => unreachable!(),").unwrap();
writeln!(f, " }}").unwrap();
writeln!(f, " }};").unwrap();
writeln!(f, "}}").unwrap();
}
fn emit_offset_dispatch(f: &mut File) {
writeln!(f, "macro_rules! offset_dispatch {{").unwrap();
writeln!(f, " ($self:expr, $s:expr, $c:expr) => {{").unwrap();
writeln!(f, " match ($s, $c) {{").unwrap();
for s in 0..NUM_SLOTS {
for c in 0..NUM_CURVES {
writeln!(f, " ({s}, {c}) => &$self.generated.s{s}c{c}_offset,").unwrap();
}
}
writeln!(f, " _ => unreachable!(),").unwrap();
writeln!(f, " }}").unwrap();
writeln!(f, " }};").unwrap();
writeln!(f, "}}").unwrap();
}
fn emit_matrix_dispatch(f: &mut File) {
writeln!(f, "macro_rules! matrix_dispatch {{").unwrap();
writeln!(f, " ($self:expr, $r:expr, $col:expr) => {{").unwrap();
writeln!(f, " match ($r, $col) {{").unwrap();
for r in 0..NUM_MATRIX_ROWS {
for col in 0..NUM_MATRIX_SOURCES {
writeln!(f, " ({r}, {col}) => &$self.generated.mr{r}c{col},").unwrap();
}
}
writeln!(f, " _ => unreachable!(),").unwrap();
writeln!(f, " }}").unwrap();
writeln!(f, " }};").unwrap();
writeln!(f, "}}").unwrap();
}
fn emit_curvature_fields(f: &mut File) {
for s in 0..NUM_SLOTS {
for c in 0..NUM_CURVES {
let rust_name = format!("s{}c{}_curv", s, c);
writeln!(f, " pub {rust_name}: FloatParam,").unwrap();
}
}
}
fn emit_curvature_inits(f: &mut File) {
for s in 0..NUM_SLOTS {
for c in 0..NUM_CURVES {
let id = format!("s{}c{}curv", s, c);
let rust_name = format!("s{}c{}_curv", s, c);
writeln!(
f,
" {rust_name}: FloatParam::new(\"{id}\", 0.0f32, \
FloatRange::Linear {{ min: 0.0f32, max: 1.0f32 }})\
.with_smoother(SmoothingStyle::Linear(2.0))\
.hide_in_generic_ui(),"
).unwrap();
}
}
}
fn emit_curvature_map_entries(f: &mut File) {
for s in 0..NUM_SLOTS {
for c in 0..NUM_CURVES {
let id = format!("s{}c{}curv", s, c);
let rust_name = format!("s{}c{}_curv", s, c);
writeln!(
f,
" out.push(({id:?}.to_string(), self.{rust_name}.as_ptr(), String::new()));"
).unwrap();
}
}
}
fn emit_curvature_dispatch(f: &mut File) {
writeln!(f, "macro_rules! curv_dispatch {{").unwrap();
writeln!(f, " ($self:expr, $s:expr, $c:expr) => {{").unwrap();
writeln!(f, " match ($s, $c) {{").unwrap();
for s in 0..NUM_SLOTS {
for c in 0..NUM_CURVES {
writeln!(f, " ({s}, {c}) => &$self.generated.s{s}c{c}_curv,").unwrap();
}
}
writeln!(f, " _ => unreachable!(),").unwrap();
writeln!(f, " }}").unwrap();
writeln!(f, " }};").unwrap();
writeln!(f, "}}").unwrap();
}
// ── Past UX Overhaul: per-slot scalar params ────────────────────────────────
//
// Five new per-slot params for the Past module (5 × 9 = 45 fields):
// - past_floor_hz Skewed 20..2000 Hz, default 230
// - past_reverse_window_s Linear 0.05..30 s, default 1.0
// - past_stretch_rate Skewed 0.05..4.0 ×, default 1.0
// - past_stretch_dither Linear 0..1, default 0.0
// - past_soft_clip Bool, default true
//
// See docs/superpowers/specs/2026-05-04-past-module-ux-design.md §2 + §3.
fn emit_past_scalar_fields(f: &mut File) {
for s in 0..NUM_SLOTS {
writeln!(f, " pub s{s}_past_floor_hz: FloatParam,").unwrap();
writeln!(f, " pub s{s}_past_reverse_window_s: FloatParam,").unwrap();
writeln!(f, " pub s{s}_past_stretch_rate: FloatParam,").unwrap();
writeln!(f, " pub s{s}_past_stretch_dither: FloatParam,").unwrap();
writeln!(f, " pub s{s}_past_soft_clip: BoolParam,").unwrap();
}
}
fn emit_past_scalar_inits(f: &mut File) {
for s in 0..NUM_SLOTS {
writeln!(
f,
" s{s}_past_floor_hz: FloatParam::new(\"s{s}past_floor_hz\", 230.0f32, \
FloatRange::Skewed {{ min: 20.0f32, max: 2000.0f32, factor: FloatRange::skew_factor(-2.0) }})\
.with_smoother(SmoothingStyle::Logarithmic(50.0))\
.with_unit(\" Hz\")\
.hide_in_generic_ui(),"
).unwrap();
writeln!(
f,
" s{s}_past_reverse_window_s: FloatParam::new(\"s{s}past_reverse_window_s\", 1.0f32, \
FloatRange::Linear {{ min: 0.05f32, max: 30.0f32 }})\
.with_smoother(SmoothingStyle::Linear(50.0))\
.with_unit(\" s\")\
.hide_in_generic_ui(),"
).unwrap();
writeln!(
f,
" s{s}_past_stretch_rate: FloatParam::new(\"s{s}past_stretch_rate\", 1.0f32, \
FloatRange::SymmetricalSkewed {{ min: 0.05f32, max: 4.0f32, \
factor: FloatRange::skew_factor(-1.0), center: 1.0f32 }})\
.with_smoother(SmoothingStyle::Logarithmic(50.0))\
.with_unit(\"\u{00d7}\")\
.hide_in_generic_ui(),"
).unwrap();
// Dither: stored as 0..100 with unit \"%\" so the host's automation lane
// displays \"50 %\" rather than \"0.50 %\". DSP rescales /100 → [0, 1].
writeln!(
f,
" s{s}_past_stretch_dither: FloatParam::new(\"s{s}past_stretch_dither\", 0.0f32, \
FloatRange::Linear {{ min: 0.0f32, max: 100.0f32 }})\
.with_smoother(SmoothingStyle::Linear(20.0))\
.with_unit(\" %\")\
.hide_in_generic_ui(),"
).unwrap();
writeln!(
f,
" s{s}_past_soft_clip: BoolParam::new(\"s{s}past_soft_clip\", true)\
.hide_in_generic_ui(),"
).unwrap();
}
}
fn emit_past_scalar_map_entries(f: &mut File) {
for s in 0..NUM_SLOTS {
for suffix in ["floor_hz", "reverse_window_s", "stretch_rate", "stretch_dither", "soft_clip"] {
let id = format!("s{s}past_{suffix}");
let rust_name = format!("s{s}_past_{suffix}");
writeln!(
f,
" out.push(({id:?}.to_string(), self.{rust_name}.as_ptr(), String::new()));"
).unwrap();
}
}
}
fn emit_past_scalar_dispatch(f: &mut File) {
for suffix in ["floor_hz", "reverse_window_s", "stretch_rate", "stretch_dither", "soft_clip"] {
writeln!(f, "macro_rules! past_{suffix}_dispatch {{").unwrap();
writeln!(f, " ($self:expr, $s:expr) => {{").unwrap();
writeln!(f, " match $s {{").unwrap();
for s in 0..NUM_SLOTS {
writeln!(f, " {s} => &$self.generated.s{s}_past_{suffix},").unwrap();
}
writeln!(f, " _ => unreachable!(),").unwrap();
writeln!(f, " }}").unwrap();
writeln!(f, " }};").unwrap();
writeln!(f, "}}").unwrap();
writeln!(f).unwrap();
}
}
// ── Life Scalars: per-slot per-mode multiplier params ──────────────────────
//
// Eight new per-slot params for Life mode-specific multipliers (8 × 9 = 72 fields):
// - life_viscosity_scale Linear 0..2, default 1.0
// - life_surface_tension_scale Linear 0..2, default 1.0
// - life_non_newtonian_scale Linear 0..2, default 1.0
// - life_stiction_scale Linear 0..2, default 1.0
// - life_yield_scale Linear 0..2, default 1.0
// - life_capillary_scale Linear 0..2, default 1.0
// - life_sandpaper_scale Linear 0..2, default 1.0
// - life_brownian_scale Linear 0..2, default 1.0
//
// See docs/superpowers/specs/2026-05-09-prototyping-exposable-scalars-design.md §1.
const LIFE_SCALAR_SUFFIXES: &[&str] = &[
"viscosity_scale",
"surface_tension_scale",
"non_newtonian_scale",
"stiction_scale",
"yield_scale",
"capillary_scale",
"sandpaper_scale",
"brownian_scale",
];
fn emit_life_scalar_fields(f: &mut File) {
for s in 0..NUM_SLOTS {
for suffix in LIFE_SCALAR_SUFFIXES {
writeln!(f, " pub s{s}_life_{suffix}: FloatParam,").unwrap();
}
}
}
fn emit_life_scalar_inits(f: &mut File) {
for s in 0..NUM_SLOTS {
for suffix in LIFE_SCALAR_SUFFIXES {
writeln!(
f,
" s{s}_life_{suffix}: FloatParam::new(\"s{s}life_{suffix}\", 1.0f32, \
FloatRange::Linear {{ min: 0.0f32, max: 2.0f32 }})\
.with_smoother(SmoothingStyle::Linear(50.0))\
.hide_in_generic_ui(),"
).unwrap();
}
}
}
fn emit_life_scalar_map_entries(f: &mut File) {
for s in 0..NUM_SLOTS {
for suffix in LIFE_SCALAR_SUFFIXES {
let id = format!("s{s}life_{suffix}");
let rust_name = format!("s{s}_life_{suffix}");
writeln!(
f,
" out.push(({id:?}.to_string(), self.{rust_name}.as_ptr(), String::new()));"
).unwrap();
}
}
}
fn emit_life_scalar_dispatch(f: &mut File) {
for suffix in LIFE_SCALAR_SUFFIXES {
writeln!(f, "macro_rules! life_{suffix}_dispatch {{").unwrap();
writeln!(f, " ($self:expr, $s:expr) => {{").unwrap();
writeln!(f, " match $s {{").unwrap();
for s in 0..NUM_SLOTS {
writeln!(f, " {s} => &$self.generated.s{s}_life_{suffix},").unwrap();
}
writeln!(f, " _ => unreachable!(),").unwrap();
writeln!(f, " }}").unwrap();
writeln!(f, " }};").unwrap();
writeln!(f, "}}").unwrap();
writeln!(f).unwrap();
}
}
// ── Kinetics Scalars: per-slot mode-specific tuning params ─────────────────
//
// Seven new per-slot params for Kinetics mode-specific scalars (7 × 9 = 63 fields):
// - kinetics_sc_envelope_tau_hops Linear 0.5..4.0, default 1.0
// - kinetics_sc_mass_rate_scale Linear 0.5..10.0, default 5.0
// - kinetics_tuning_fork_min_sep Linear 1.0..16.0, default 4.0 (used as usize)
// - kinetics_orbital_sat_half_window Linear 4.0..32.0, default 16.0 (used as usize)
// - kinetics_orbital_peak_threshold_factor Linear 1.0..5.0, default 2.0
// - kinetics_static_well_baseline Linear 1.0..2.0, default 1.05
// - kinetics_sc_well_threshold_frac Linear 0.1..0.9, default 0.4
//
// See docs/superpowers/specs/2026-05-09-prototyping-exposable-scalars-design.md §2.
struct KineticsScalarSpec {
suffix: &'static str,
default: f32,
min: f32,
max: f32,
}
const KINETICS_SCALAR_SPECS: &[KineticsScalarSpec] = &[
KineticsScalarSpec { suffix: "sc_envelope_tau_hops", default: 1.0, min: 0.5, max: 4.0 },
KineticsScalarSpec { suffix: "sc_mass_rate_scale", default: 5.0, min: 0.5, max: 10.0 },
KineticsScalarSpec { suffix: "tuning_fork_min_sep", default: 4.0, min: 1.0, max: 16.0 },
KineticsScalarSpec { suffix: "orbital_sat_half_window", default: 16.0, min: 4.0, max: 32.0 },
KineticsScalarSpec { suffix: "orbital_peak_threshold_factor", default: 2.0, min: 1.0, max: 5.0 },
KineticsScalarSpec { suffix: "static_well_baseline", default: 1.05, min: 1.0, max: 2.0 },
KineticsScalarSpec { suffix: "sc_well_threshold_frac", default: 0.4, min: 0.1, max: 0.9 },
];
fn emit_kinetics_scalar_fields(f: &mut File) {
for s in 0..NUM_SLOTS {
for spec in KINETICS_SCALAR_SPECS {
let suffix = spec.suffix;
writeln!(f, " pub s{s}_kinetics_{suffix}: FloatParam,").unwrap();
}
}
}
fn emit_kinetics_scalar_inits(f: &mut File) {
for s in 0..NUM_SLOTS {
for spec in KINETICS_SCALAR_SPECS {
let suffix = spec.suffix;
let default = spec.default;
let min = spec.min;
let max = spec.max;
writeln!(
f,
" s{s}_kinetics_{suffix}: FloatParam::new(\"s{s}kinetics_{suffix}\", {default}f32, \
FloatRange::Linear {{ min: {min}f32, max: {max}f32 }})\
.with_smoother(SmoothingStyle::Linear(50.0))\
.hide_in_generic_ui(),"
).unwrap();
}
}
}
fn emit_kinetics_scalar_map_entries(f: &mut File) {
for s in 0..NUM_SLOTS {
for spec in KINETICS_SCALAR_SPECS {
let suffix = spec.suffix;
let id = format!("s{s}kinetics_{suffix}");
let rust_name = format!("s{s}_kinetics_{suffix}");
writeln!(
f,
" out.push(({id:?}.to_string(), self.{rust_name}.as_ptr(), String::new()));"
).unwrap();
}
}
}
fn emit_kinetics_scalar_dispatch(f: &mut File) {
for spec in KINETICS_SCALAR_SPECS {
let suffix = spec.suffix;
writeln!(f, "macro_rules! kinetics_{suffix}_dispatch {{").unwrap();
writeln!(f, " ($self:expr, $s:expr) => {{").unwrap();
writeln!(f, " match $s {{").unwrap();
for s in 0..NUM_SLOTS {
writeln!(f, " {s} => &$self.generated.s{s}_kinetics_{suffix},").unwrap();
}
writeln!(f, " _ => unreachable!(),").unwrap();
writeln!(f, " }}").unwrap();
writeln!(f, " }};").unwrap();
writeln!(f, "}}").unwrap();
writeln!(f).unwrap();
}
}
// ── Circuit Scalars: per-slot Vactrol time-constant params ─────────────────
//
// Two new per-slot params for Circuit Vactrol mode (2 × 9 = 18 fields):
// - circuit_vactrol_fast_ms Linear 1.0..50.0, default 8.0 (converted ms→s in kernel)
// - circuit_vactrol_slow_ms Linear 50.0..1000.0, default 250.0 (converted ms→s in kernel)
//
// See docs/superpowers/specs/2026-05-09-prototyping-exposable-scalars-design.md §3.
struct CircuitScalarSpec {
suffix: &'static str,
default: f32,
min: f32,
max: f32,
unit: &'static str,
}
const CIRCUIT_SCALAR_SPECS: &[CircuitScalarSpec] = &[
CircuitScalarSpec { suffix: "vactrol_fast_ms", default: 8.0, min: 1.0, max: 50.0, unit: " ms" },
CircuitScalarSpec { suffix: "vactrol_slow_ms", default: 250.0, min: 50.0, max: 1000.0, unit: " ms" },
];
fn emit_circuit_scalar_fields(f: &mut File) {
for s in 0..NUM_SLOTS {
for spec in CIRCUIT_SCALAR_SPECS {
let suffix = spec.suffix;
writeln!(f, " pub s{s}_circuit_{suffix}: FloatParam,").unwrap();
}
}
}
fn emit_circuit_scalar_inits(f: &mut File) {
for s in 0..NUM_SLOTS {
for spec in CIRCUIT_SCALAR_SPECS {
let suffix = spec.suffix;
let default = spec.default;
let min = spec.min;
let max = spec.max;
let unit = spec.unit;
writeln!(
f,
" s{s}_circuit_{suffix}: FloatParam::new(\"s{s}circuit_{suffix}\", {default}f32, \
FloatRange::Linear {{ min: {min}f32, max: {max}f32 }})\
.with_smoother(SmoothingStyle::Linear(50.0))\
.with_unit({unit:?})\
.hide_in_generic_ui(),"
).unwrap();
}
}
}
fn emit_circuit_scalar_map_entries(f: &mut File) {
for s in 0..NUM_SLOTS {
for spec in CIRCUIT_SCALAR_SPECS {
let suffix = spec.suffix;
let id = format!("s{s}circuit_{suffix}");
let rust_name = format!("s{s}_circuit_{suffix}");
writeln!(
f,
" out.push(({id:?}.to_string(), self.{rust_name}.as_ptr(), String::new()));"
).unwrap();
}
}
}
fn emit_circuit_scalar_dispatch(f: &mut File) {
for spec in CIRCUIT_SCALAR_SPECS {
let suffix = spec.suffix;
writeln!(f, "macro_rules! circuit_{suffix}_dispatch {{").unwrap();
writeln!(f, " ($self:expr, $s:expr) => {{").unwrap();
writeln!(f, " match $s {{").unwrap();
for s in 0..NUM_SLOTS {
writeln!(f, " {s} => &$self.generated.s{s}_circuit_{suffix},").unwrap();
}
writeln!(f, " _ => unreachable!(),").unwrap();
writeln!(f, " }}").unwrap();
writeln!(f, " }};").unwrap();
writeln!(f, "}}").unwrap();
writeln!(f).unwrap();
}
}
// ── Modulate Scalars: per-slot PllTear tuning params ──────────────────────────
//
// Two new per-slot params for Modulate PllTear mode (2 × 9 = 18 fields):
// - modulate_damping Linear 0.1..2.0, default 0.707
// - modulate_tear_angle_rad Linear π/8..π (radians), default π/2 ≈ 1.5707963
//
// See docs/superpowers/specs/2026-05-09-prototyping-exposable-scalars-design.md §4.
struct ModulateScalarSpec {
suffix: &'static str,
default: f32,
min: f32,
max: f32,
unit: &'static str,
}
const MODULATE_SCALAR_SPECS: &[ModulateScalarSpec] = &[
ModulateScalarSpec { suffix: "damping", default: 0.707, min: 0.1, max: 2.0, unit: "" },
ModulateScalarSpec { suffix: "tear_angle_rad", default: 1.5707963, min: 0.39269908, max: 3.14159265, unit: " rad" },
];
fn emit_modulate_scalar_fields(f: &mut File) {
for s in 0..NUM_SLOTS {
for spec in MODULATE_SCALAR_SPECS {
let suffix = spec.suffix;
writeln!(f, " pub s{s}_modulate_{suffix}: FloatParam,").unwrap();
}
}
}
fn emit_modulate_scalar_inits(f: &mut File) {
for s in 0..NUM_SLOTS {
for spec in MODULATE_SCALAR_SPECS {
let suffix = spec.suffix;
let default = spec.default;
let min = spec.min;
let max = spec.max;
let unit = spec.unit;
writeln!(
f,
" s{s}_modulate_{suffix}: FloatParam::new(\"s{s}modulate_{suffix}\", {default}f32, \
FloatRange::Linear {{ min: {min}f32, max: {max}f32 }})\
.with_smoother(SmoothingStyle::Linear(50.0))\
.with_unit({unit:?})\
.hide_in_generic_ui(),"
).unwrap();
}
}
}
fn emit_modulate_scalar_map_entries(f: &mut File) {
for s in 0..NUM_SLOTS {
for spec in MODULATE_SCALAR_SPECS {
let suffix = spec.suffix;
let id = format!("s{s}modulate_{suffix}");
let rust_name = format!("s{s}_modulate_{suffix}");
writeln!(
f,
" out.push(({id:?}.to_string(), self.{rust_name}.as_ptr(), String::new()));"
).unwrap();
}
}
}
fn emit_modulate_scalar_dispatch(f: &mut File) {
for spec in MODULATE_SCALAR_SPECS {
let suffix = spec.suffix;
writeln!(f, "macro_rules! modulate_{suffix}_dispatch {{").unwrap();
writeln!(f, " ($self:expr, $s:expr) => {{").unwrap();
writeln!(f, " match $s {{").unwrap();
for s in 0..NUM_SLOTS {
writeln!(f, " {s} => &$self.generated.s{s}_modulate_{suffix},").unwrap();
}
writeln!(f, " _ => unreachable!(),").unwrap();
writeln!(f, " }}").unwrap();
writeln!(f, " }};").unwrap();
writeln!(f, "}}").unwrap();
writeln!(f).unwrap();
}
}
// ── Contrast Scalars: per-slot Spatial/Tilt tuning params ─────────────────
//
// Three per-slot params for Contrast mode-specific scalars (3 × 9 = 27 fields):
// - contrast_mean_window_st Linear 0.1..48.0, default 1.0 (Spatial only)
// - contrast_tilt_slope_db_per_oct Linear -6.0..6.0, default 0.0 (Tilt only)
// - contrast_gr_smoothing_st Linear 0.1..48.0, default 1.0 (all modes)
//
// See docs/superpowers/specs/2026-05-09-prototyping-exposable-scalars-design.md §5.
struct ContrastScalarSpec {
suffix: &'static str,
default: f32,
min: f32,
max: f32,
unit: &'static str,
}
const CONTRAST_SCALAR_SPECS: &[ContrastScalarSpec] = &[
ContrastScalarSpec { suffix: "mean_window_st", default: 1.0, min: 0.1, max: 48.0, unit: " st" },
ContrastScalarSpec { suffix: "tilt_slope_db_per_oct", default: 0.0, min: -6.0, max: 6.0, unit: " dB/oct" },
ContrastScalarSpec { suffix: "gr_smoothing_st", default: 1.0, min: 0.1, max: 48.0, unit: " st" },
];
fn emit_contrast_scalar_fields(f: &mut File) {
for s in 0..NUM_SLOTS {
for spec in CONTRAST_SCALAR_SPECS {
let suffix = spec.suffix;
writeln!(f, " pub s{s}_contrast_{suffix}: FloatParam,").unwrap();
}
}
}
fn emit_contrast_scalar_inits(f: &mut File) {
for s in 0..NUM_SLOTS {
for spec in CONTRAST_SCALAR_SPECS {
let suffix = spec.suffix;
let default = spec.default;
let min = spec.min;
let max = spec.max;
let unit = spec.unit;
writeln!(
f,
" s{s}_contrast_{suffix}: FloatParam::new(\"s{s}contrast_{suffix}\", {default}f32, \
FloatRange::Linear {{ min: {min}f32, max: {max}f32 }})\
.with_smoother(SmoothingStyle::Linear(50.0))\
.with_unit({unit:?})\
.hide_in_generic_ui(),"
).unwrap();
}
}
}
fn emit_contrast_scalar_map_entries(f: &mut File) {
for s in 0..NUM_SLOTS {
for spec in CONTRAST_SCALAR_SPECS {
let suffix = spec.suffix;
let id = format!("s{s}contrast_{suffix}");
let rust_name = format!("s{s}_contrast_{suffix}");
writeln!(
f,
" out.push(({id:?}.to_string(), self.{rust_name}.as_ptr(), String::new()));"
).unwrap();
}
}
}
fn emit_contrast_scalar_dispatch(f: &mut File) {
for spec in CONTRAST_SCALAR_SPECS {
let suffix = spec.suffix;
writeln!(f, "macro_rules! contrast_{suffix}_dispatch {{").unwrap();
writeln!(f, " ($self:expr, $s:expr) => {{").unwrap();
writeln!(f, " match $s {{").unwrap();
for s in 0..NUM_SLOTS {
writeln!(f, " {s} => &$self.generated.s{s}_contrast_{suffix},").unwrap();
}
writeln!(f, " _ => unreachable!(),").unwrap();
writeln!(f, " }}").unwrap();
writeln!(f, " }};").unwrap();
writeln!(f, "}}").unwrap();
writeln!(f).unwrap();
}
}