pikopiko 0.1.0

MML parser, compiler and chiptune player for games, with diagnostics designed for tools and AI.
Documentation
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
//! `va` 音源の説明:パラメータの表(`PARAMS`)、音色・オプション・つまみの一覧と、
//! 一覧にまとめた `SynthSpec`(`VA`)。
//!
//! 音を作る実体(`VaSynth`)は `engine/mod.rs`。ここは静的な説明だけで、音は作らない。
//! `PARAMS` の並びは [`super::param`] の番号と同じ順(`param::COUNT` 個。`mod.rs` の
//! `synth_params` の添字にも使う)なので、新しいパラメータは `ids.rs` の番号と一緒に末尾へ足す。

use super::*;

const fn p(name: &'static str, min: u32, max: u32, default: u32, scope: Scope) -> ParamInfo {
    ParamInfo {
        name,
        min,
        max,
        default,
        scope,
    }
}

pub(super) const PARAMS: [ParamInfo; param::COUNT] = [
    p("cutoff", 0, 127, 127, Scope::Track),
    p("res", 0, 100, 10, Scope::Track),
    p("fenv", 0, 127, 0, Scope::Track),
    p("fdecay", 1, 255, 20, Scope::Track),
    p("attack", 0, 255, 0, Scope::Track),
    p("decay", 1, 255, 30, Scope::Track),
    p("sustain", 0, 100, 100, Scope::Track),
    p("release", 1, 255, 10, Scope::Track),
    p("detune", 0, 100, 30, Scope::Track),
    p("width", 0, 100, 70, Scope::Track),
    p("pan", 0, 16, 8, Scope::Track),
    p("gain", 0, 400, 100, Scope::Track),
    p("duck", 0, 100, 0, Scope::Track),
    p("rev", 0, 100, 0, Scope::Track),
    p("dly", 0, 100, 0, Scope::Track),
    p("drive", 0, 100, 0, Scope::Track),
    p("sub", 0, 100, 0, Scope::Track),
    p("ftype", 0, 3, 0, Scope::Track),
    p("fslope", 0, 1, 0, Scope::Track),
    p("hpf", 0, 127, 0, Scope::Track),
    p("pw", 5, 95, 50, Scope::Track),
    p("lfo_wave", 0, 4, 0, Scope::Track),
    p("lfo_rate", 1, 200, 50, Scope::Track),
    p("lfo_sync", 0, 64, 0, Scope::Track),
    p("lfo_depth", 0, 100, 0, Scope::Track),
    p("lfo_dest", 0, LFO_DEST_MAX, 0, Scope::Track),
    p("lfo_key", 0, 1, 0, Scope::Track),
    p("voices", 1, 15, 7, Scope::Track),
    p("osc2", 0, 3, 0, Scope::Track),
    p("osc2_oct", 0, 4, 2, Scope::Track),
    p("osc2_fine", 0, 100, 50, Scope::Track),
    p("osc2_mix", 0, 100, 50, Scope::Track),
    p("cho", 0, 100, 0, Scope::Track),
    p("duck_release", 1, 100, 18, Scope::Synth),
    p("dly_steps", 1, 16, 3, Scope::Synth),
    p("dly_fb", 0, 90, 40, Scope::Synth),
    p("rev_size", 0, 100, 70, Scope::Synth),
    p("master", 0, 200, 100, Scope::Synth),
    p("bass_boost", 0, 24, 0, Scope::Synth),
    p("sat", 0, 100, 0, Scope::Synth),
    p("cho_rate", 1, 100, 8, Scope::Synth),
    p("cho_depth", 0, 100, 50, Scope::Synth),
    p("rev_pre", 0, 200, 0, Scope::Synth),
    p("rev_damp", 0, 100, 30, Scope::Synth),
    p("dly_tone", 1, 100, 40, Scope::Synth),
    p("dly_lowcut", 0, 127, 0, Scope::Synth),
    p("duck_attack", 0, 50, 5, Scope::Synth),
    p("shimmer", 0, 100, 0, Scope::Synth),
    p("phaser", 0, 100, 0, Scope::Track),
    p("ph_rate", 1, 200, 5, Scope::Track),
    p("ph_fb", 0, 90, 40, Scope::Track),
    p("flanger", 0, 100, 0, Scope::Track),
    p("fl_rate", 1, 200, 3, Scope::Track),
    p("fl_fb", 0, 90, 50, Scope::Track),
    p("crush_bits", 0, 16, 0, Scope::Track),
    p("crush_rate", 0, 480, 0, Scope::Track),
    p("comp", 0, 100, 0, Scope::Track),
    p("comp_attack", 1, 100, 10, Scope::Track),
    p("comp_release", 1, 100, 15, Scope::Track),
    p("eq_freq", 0, 127, 64, Scope::Track),
    p("eq_gain", 0, 48, 24, Scope::Track),
    p("eq_q", 1, 100, 10, Scope::Track),
    p("lfo2_wave", 0, 4, 0, Scope::Track),
    p("lfo2_rate", 1, 200, 50, Scope::Track),
    p("lfo2_sync", 0, 64, 0, Scope::Track),
    p("lfo2_depth", 0, 100, 0, Scope::Track),
    p("lfo2_dest", 0, LFO_DEST_MAX, 0, Scope::Track),
    p("lfo2_key", 0, 1, 0, Scope::Track),
    p("penv", 0, 96, 48, Scope::Track),
    p("pdecay", 1, 255, 10, Scope::Track),
    p("fm_ratio", 1, 1600, 100, Scope::Track),
    p("fm_index", 0, 100, 20, Scope::Track),
    p("fm_env", 0, 100, 0, Scope::Track),
    p("fm_decay", 1, 255, 30, Scope::Track),
    p("fm_fb", 0, 100, 0, Scope::Track),
    p("formant", 0, 100, 0, Scope::Track),
    p("vowel", 0, 400, 0, Scope::Track),
    p("formant_shift", 0, 24, 12, Scope::Track),
    p("body", 0, 100, 0, Scope::Track),
    p("body_shift", 0, 36, 24, Scope::Track),
    p("bow", 0, 100, 0, Scope::Track),
    p("scratch", 0, 100, 0, Scope::Track),
    p("lfo_fade", 0, 255, 0, Scope::Track),
    p("lfo2_fade", 0, 255, 0, Scope::Track),
    p("poly", 0, 1, 0, Scope::Track),
    p("humanize", 0, 100, 0, Scope::Track),
    p("vel_cutoff", 0, 100, 0, Scope::Track),
    p("eq_type", 0, 6, 0, Scope::Track),
    p("eq_pre", 0, 1, 0, Scope::Track),
    p("eq2_type", 0, 6, 0, Scope::Track),
    p("eq2_freq", 0, 127, 64, Scope::Track),
    p("eq2_gain", 0, 48, 24, Scope::Track),
    p("eq2_q", 1, 100, 10, Scope::Track),
    p("eq2_pre", 0, 1, 0, Scope::Track),
    p("eq3_type", 0, 6, 0, Scope::Track),
    p("eq3_freq", 0, 127, 64, Scope::Track),
    p("eq3_gain", 0, 48, 24, Scope::Track),
    p("eq3_q", 1, 100, 10, Scope::Track),
    p("eq3_pre", 0, 1, 0, Scope::Track),
    p("eq4_type", 0, 6, 0, Scope::Track),
    p("eq4_freq", 0, 127, 64, Scope::Track),
    p("eq4_gain", 0, 48, 24, Scope::Track),
    p("eq4_q", 1, 100, 10, Scope::Track),
    p("eq4_pre", 0, 1, 0, Scope::Track),
    p("tdrive", 0, 100, 0, Scope::Track),
    p("tdrive_type", 0, 3, 0, Scope::Track),
    p("drive_type", 0, 3, 0, Scope::Track),
    p("tdrive_os", 0, 1, 0, Scope::Track),
    p("ord_tdrive", 0, 9, 1, Scope::Track),
    p("ord_crush", 0, 9, 2, Scope::Track),
    p("ord_eq", 0, 9, 3, Scope::Track),
    p("ord_comp", 0, 9, 4, Scope::Track),
    p("ord_phaser", 0, 9, 5, Scope::Track),
    p("ord_flanger", 0, 9, 6, Scope::Track),
    p("expr", 0, 100, 100, Scope::Track),
    p("grain", 0, 100, 0, Scope::Track),
    p("gr_size", 5, 500, 30, Scope::Track),
    p("gr_density", 1, 5000, 50, Scope::Track),
    p("gr_sync", 0, 32, 0, Scope::Track),
    p("gr_pos", 0, 100, 10, Scope::Track),
    p("gr_spread", 0, 100, 20, Scope::Track),
    p("gr_pitch", 0, 48, 24, Scope::Track),
    p("gr_jitter", 0, 100, 0, Scope::Track),
    p("gr_rev", 0, 100, 0, Scope::Track),
    p("gr_width", 0, 100, 50, Scope::Track),
    p("gr_freeze", 0, 1, 0, Scope::Track),
    p("gr_track", 0, 1, 0, Scope::Track),
    p("ord_grain", 0, 9, 0, Scope::Track),
    p("gr_count", 0, 64, 0, Scope::Track),
    p("gr_chord", 0, 11, 0, Scope::Track),
    p("gr_crange", 1, 16, 4, Scope::Track),
    p("gr_strum", 0, 3, 0, Scope::Track),
    p("gr_atk", 0, 100, 50, Scope::Track),
    p("gr_dcy", 0, 100, 50, Scope::Track),
    p("gr_curve", 0, 100, 50, Scope::Track),
    p("gr_tjit", 0, 100, 0, Scope::Track),
    p("gr_ljit", 0, 100, 0, Scope::Track),
    p("gr_align", 0, 1, 0, Scope::Track),
    p("harm", 0, 100, 0, Scope::Track),
    p("harm_mode", 0, 1, 1, Scope::Track),
    p("harm_int", 0, 48, 31, Scope::Track),
    p("harm_int2", 0, 48, 24, Scope::Track),
    p("harm_key", 0, 11, 0, Scope::Track),
    p("harm_scale", 0, 6, 0, Scope::Track),
    p("harm_det", 0, 50, 0, Scope::Track),
    p("harm_width", 0, 100, 50, Scope::Track),
    p("ord_harm", 0, 9, 7, Scope::Track),
    p("mbc", 0, 100, 0, Scope::Track),
    p("mbc_low", 40, 400, 120, Scope::Track),
    p("mbc_high", 1000, 8000, 2500, Scope::Track),
    p("mbc_speed", 1, 100, 50, Scope::Track),
    p("ord_mbc", 0, 9, 4, Scope::Track),
    p("mst_mbc", 0, 100, 0, Scope::Synth),
    p("mst_mbc_low", 40, 400, 120, Scope::Synth),
    p("mst_mbc_high", 1000, 8000, 2500, Scope::Synth),
    // 0〜7 は内蔵の表、8 は `@wave` で書いた波形
    p("wt", 0, WT_TABLES as u32, 0, Scope::Track),
    p("wt_pos", 0, 100, 0, Scope::Track),
    p("wt_warp", 0, 100, 0, Scope::Track),
    p("fm_uni", 1, 4, 1, Scope::Track),
    p("fm_det", 0, 100, 0, Scope::Track),
    p("fm_drift", 0, 100, 0, Scope::Track),
    p("bus", 0, 32, 0, Scope::Track),
    p("smp", 0, SAMPLE_SLOTS as u32 - 1, 0, Scope::Track),
    p("smp_loop", 0, 1, 0, Scope::Track),
    p("smp_start", 0, 100, 0, Scope::Track),
    p("rrev", 0, 100, 0, Scope::Track),
    p("rrev_len", 20, 500, 300, Scope::Track),
    p("fmx_ops", 2, 6, 2, Scope::Track),
    p("fmx_algo", 0, 63, 0, Scope::Track),
    p("fmx_fb", 0, 100, 0, Scope::Track),
    p("fmx1_ratio", 0, 3200, 100, Scope::Track),
    p("fmx1_level", 0, 400, 100, Scope::Track),
    p("fmx1_env", 0, 400, 0, Scope::Track),
    p("fmx1_decay", 1, 500, 30, Scope::Track),
    p("fmx1_det", 0, 200, 100, Scope::Track),
    p("fmx2_ratio", 0, 3200, 100, Scope::Track),
    p("fmx2_level", 0, 400, 50, Scope::Track),
    p("fmx2_env", 0, 400, 0, Scope::Track),
    p("fmx2_decay", 1, 500, 30, Scope::Track),
    p("fmx2_det", 0, 200, 100, Scope::Track),
    p("fmx3_ratio", 0, 3200, 100, Scope::Track),
    p("fmx3_level", 0, 400, 30, Scope::Track),
    p("fmx3_env", 0, 400, 0, Scope::Track),
    p("fmx3_decay", 1, 500, 30, Scope::Track),
    p("fmx3_det", 0, 200, 100, Scope::Track),
    p("fmx4_ratio", 0, 3200, 100, Scope::Track),
    p("fmx4_level", 0, 400, 20, Scope::Track),
    p("fmx4_env", 0, 400, 0, Scope::Track),
    p("fmx4_decay", 1, 500, 30, Scope::Track),
    p("fmx4_det", 0, 200, 100, Scope::Track),
    p("fmx5_ratio", 0, 3200, 100, Scope::Track),
    p("fmx5_level", 0, 400, 15, Scope::Track),
    p("fmx5_env", 0, 400, 0, Scope::Track),
    p("fmx5_decay", 1, 500, 30, Scope::Track),
    p("fmx5_det", 0, 200, 100, Scope::Track),
    p("fmx6_ratio", 0, 3200, 100, Scope::Track),
    p("fmx6_level", 0, 400, 10, Scope::Track),
    p("fmx6_env", 0, 400, 0, Scope::Track),
    p("fmx6_decay", 1, 500, 30, Scope::Track),
    p("fmx6_det", 0, 200, 100, Scope::Track),
    p("tape", 0, 100, 0, Scope::Track),
    p("tape_wow", 0, 200, 100, Scope::Track),
    p("tape_flutter", 0, 200, 100, Scope::Track),
    p("tape_sat", 0, 200, 100, Scope::Track),
    p("tape_tone", 0, 200, 100, Scope::Track),
    p("ord_tape", 0, 9, 9, Scope::Track),
    p("tstop", 0, 100, 0, Scope::Track),
    p("ord_tstop", 0, 9, 8, Scope::Track),
    p("mst_crk", 0, 100, 0, Scope::Synth),
    p("mst_crk_lvl", 0, 100, 50, Scope::Synth),
    p("mst_crk_big", 0, 100, 10, Scope::Synth),
    p("rot", 0, 100, 0, Scope::Track),
    p("rot_speed", 0, 100, 0, Scope::Track),
    p("rot_horn", 0, 100, 50, Scope::Track),
    p("ord_rot", 0, 9, 8, Scope::Track),
    p("ts_atk", 0, 200, 100, Scope::Track),
    p("ts_sus", 0, 200, 100, Scope::Track),
    p("ord_ts", 0, 9, 4, Scope::Track),
    p("fold", 0, 100, 0, Scope::Track),
    p("fold_sym", 0, 100, 0, Scope::Track),
    p("ord_fold", 0, 9, 1, Scope::Track),
    p("comb", 0, 100, 0, Scope::Track),
    p("comb_fb", 0, 99, 60, Scope::Track),
    p("comb_neg", 0, 1, 0, Scope::Track),
    p("comb_track", 0, 1, 1, Scope::Track),
    p("comb_hz", 20, 2000, 220, Scope::Track),
    p("ord_comb", 0, 9, 6, Scope::Track),
    p("mute", 0, 100, 0, Scope::Track),
    p("mute_vel", 0, 100, 0, Scope::Track),
    p("nharm", 0, 3, 0, Scope::Track),
    p("nharm_mix", 0, 100, 100, Scope::Track),
    p("fbk", 0, 100, 0, Scope::Track),
    p("fbk_time", 50, 4000, 800, Scope::Track),
    p("gr_src", 0, SAMPLE_SLOTS as u32, 0, Scope::Track),
    p("gr_voices", 0, 1, 0, Scope::Track),
    p("add_n", 1, 32, 16, Scope::Track),
    p("add_tilt", 0, 24, 6, Scope::Track),
    p("add_decay", 1, 255, 40, Scope::Track),
    p("add_dtilt", 0, 100, 50, Scope::Track),
    p("add_inh", 0, 100, 8, Scope::Track),
    p("add_hammer", 0, 50, 12, Scope::Track),
    p("add_after", 0, 100, 0, Scope::Track),
    p("add_key", 0, 100, 0, Scope::Track),
    p("add_fund", 0, 24, 0, Scope::Track),
    p("add_thump", 0, 100, 0, Scope::Track),
    p("add_thump_hz", 20, 400, 80, Scope::Track),
    p("add_even", 0, 24, 0, Scope::Track),
    p("add_vel", 0, 100, 0, Scope::Track),
    p("add_thump_var", 0, 100, 0, Scope::Track),
    p("add_click", 0, 100, 0, Scope::Track),
    p("add_body", 0, 100, 0, Scope::Track),
    p("add_beat", 0, 100, 0, Scope::Track),
    p("add_strike", 0, 100, 0, Scope::Track),
    p("add_lev", 0, 100, 50, Scope::Track),
    p("rev_low", 0, 100, 0, Scope::Synth),
    p("pedal", 0, 1, 0, Scope::Track),
    // 256 番以降(2 ページ目)
    p("poly_norm", 0, 100, 100, Scope::Track),
    p("reso", 0, 100, 0, Scope::Track),
    p("reso_decay", 0, 100, 50, Scope::Synth),
    p("add_tilt_key", 0, 100, 50, Scope::Track),
    p("add_inh_key", 0, 100, 50, Scope::Track),
    p("mod1_src", 0, MOD_SRC_MAX, 0, Scope::Track),
    p("mod1_dst", 0, LFO_DEST_MAX, 0, Scope::Track),
    p("mod1_amt", 0, 200, 100, Scope::Track),
    p("mod2_src", 0, MOD_SRC_MAX, 0, Scope::Track),
    p("mod2_dst", 0, LFO_DEST_MAX, 0, Scope::Track),
    p("mod2_amt", 0, 200, 100, Scope::Track),
    p("mod3_src", 0, MOD_SRC_MAX, 0, Scope::Track),
    p("mod3_dst", 0, LFO_DEST_MAX, 0, Scope::Track),
    p("mod3_amt", 0, 200, 100, Scope::Track),
    p("mod4_src", 0, MOD_SRC_MAX, 0, Scope::Track),
    p("mod4_dst", 0, LFO_DEST_MAX, 0, Scope::Track),
    p("mod4_amt", 0, 200, 100, Scope::Track),
    p("fattack", 0, 255, 0, Scope::Track),
    p("fsustain", 0, 100, 0, Scope::Track),
    p("frelease", 0, 255, 0, Scope::Track),
    p("menv1_attack", 0, 255, 0, Scope::Track),
    p("menv1_decay", 1, 255, 30, Scope::Track),
    p("menv1_sustain", 0, 100, 0, Scope::Track),
    p("menv1_release", 1, 255, 10, Scope::Track),
    p("menv2_attack", 0, 255, 0, Scope::Track),
    p("menv2_decay", 1, 255, 30, Scope::Track),
    p("menv2_sustain", 0, 100, 0, Scope::Track),
    p("menv2_release", 1, 255, 10, Scope::Track),
    p("sync", 0, 1, 0, Scope::Track),
    p("sync_pitch", 0, 48, 0, Scope::Track),
    p("ring", 0, 100, 0, Scope::Track),
    p("osc2_voices", 1, 7, 1, Scope::Track),
    p("osc2_det", 0, 100, 30, Scope::Track),
    p("noise", 0, 100, 0, Scope::Track),
    p("noise_tone", 0, 100, 100, Scope::Track),
    p("dly_mode", 0, 2, 0, Scope::Synth),
    p("dly_steps_r", 0, 16, 0, Scope::Synth),
    p("dly_feel", 0, 2, 0, Scope::Synth),
    p("dly_wow", 0, 100, 0, Scope::Synth),
    p("dly_sat", 0, 100, 0, Scope::Synth),
    p("rev_type", 0, 4, 0, Scope::Synth),
    p("rev_len", 1, 100, 30, Scope::Synth),
    p("fmode", 0, 1, 0, Scope::Track),
    p("fdrive", 0, 100, 0, Scope::Track),
    p("f2", 0, 2, 0, Scope::Track),
    p("f2_type", 0, 3, 0, Scope::Track),
    p("f2_cut", 0, 127, 64, Scope::Track),
    p("step_n", 1, 16, 8, Scope::Track),
    p("step_rate", 1, 16, 1, Scope::Track),
    p("step_glide", 0, 100, 0, Scope::Track),
    p("stp1", 0, 100, 0, Scope::Track),
    p("stp2", 0, 100, 0, Scope::Track),
    p("stp3", 0, 100, 0, Scope::Track),
    p("stp4", 0, 100, 0, Scope::Track),
    p("stp5", 0, 100, 0, Scope::Track),
    p("stp6", 0, 100, 0, Scope::Track),
    p("stp7", 0, 100, 0, Scope::Track),
    p("stp8", 0, 100, 0, Scope::Track),
    p("stp9", 0, 100, 0, Scope::Track),
    p("stp10", 0, 100, 0, Scope::Track),
    p("stp11", 0, 100, 0, Scope::Track),
    p("stp12", 0, 100, 0, Scope::Track),
    p("stp13", 0, 100, 0, Scope::Track),
    p("stp14", 0, 100, 0, Scope::Track),
    p("stp15", 0, 100, 0, Scope::Track),
    p("stp16", 0, 100, 0, Scope::Track),
    p("mseg_l1", 0, 100, 100, Scope::Track),
    p("mseg_l2", 0, 100, 60, Scope::Track),
    p("mseg_l3", 0, 100, 60, Scope::Track),
    p("mseg_l4", 0, 100, 0, Scope::Track),
    p("mseg_t1", 0, 255, 10, Scope::Track),
    p("mseg_t2", 0, 255, 10, Scope::Track),
    p("mseg_t3", 0, 255, 10, Scope::Track),
    p("mseg_t4", 0, 255, 10, Scope::Track),
    p("mseg_loop", 0, 1, 0, Scope::Track),
    p("gate_th", 0, 100, 0, Scope::Track),
    p("gate_rel", 1, 100, 20, Scope::Track),
    p("ord_gate", 0, 9, 0, Scope::Track),
    p("deess", 0, 100, 0, Scope::Track),
    p("deess_freq", 0, 127, 100, Scope::Track),
    p("deess_th", 1, 100, 30, Scope::Track),
    p("ord_deess", 0, 9, 5, Scope::Track),
    p("exc", 0, 100, 0, Scope::Track),
    p("exc_freq", 0, 127, 90, Scope::Track),
    p("ord_exc", 0, 9, 6, Scope::Track),
    p("img", 0, 200, 100, Scope::Track),
    p("img_mono", 0, 127, 0, Scope::Track),
    p("ord_img", 0, 9, 9, Scope::Track),
    p("fshift", 0, 200, 100, Scope::Track),
    p("fshift_mix", 0, 100, 50, Scope::Track),
    p("ord_fshift", 0, 9, 7, Scope::Track),
    p("stut", 0, 96, 0, Scope::Track),
    p("stut_gate", 1, 100, 100, Scope::Track),
    p("ord_stut", 0, 9, 9, Scope::Track),
    p("smp_end", 0, 100, 100, Scope::Track),
    p("gate_hold", 0, 100, 0, Scope::Track),
    p("step_key", 0, 1, 0, Scope::Track),
    p("fshift_fb", 0, 95, 0, Scope::Track),
    p("stut_dot", 0, 2, 0, Scope::Track),
];

const TONES: [ToneInfo; 17] = [
    ToneInfo { id: tone::SAW },
    ToneInfo { id: tone::SUPERSAW },
    ToneInfo { id: tone::SQUARE },
    ToneInfo { id: tone::SINE },
    ToneInfo { id: tone::NOISE },
    ToneInfo { id: tone::KICK },
    ToneInfo { id: tone::CLAP },
    ToneInfo { id: tone::HAT },
    ToneInfo { id: tone::SNARE },
    ToneInfo { id: tone::TOM },
    ToneInfo { id: tone::CYMBAL },
    ToneInfo { id: tone::KICK808 },
    ToneInfo { id: tone::FM },
    ToneInfo {
        id: tone::WAVETABLE,
    },
    ToneInfo { id: tone::SAMPLER },
    ToneInfo { id: tone::FMX },
    ToneInfo { id: tone::ADD },
];

/// `#synth va` のオプション。テンポは `Synth::set_tempo` で曲から受け取るので、`bpm` は持たない
/// (曲の `t` と二重に書かずに済み、食い違わない)。
const OPTIONS: [OptionInfo; 1] = [OptionInfo {
    name: "rrev_lead",
    kind: crate::synth::OptionKind::Range {
        min: 0,
        max: crate::synth::va::rrev::MAX_LEAD_MS,
    },
    default: "0",
}];

/// 大まかなつまみ([`crate::synth::Knob`])。生成 AI が作った音色を人が画面で寄せるための 10 個。
///
/// 変化量は「5 段(端)で、そのつまみの効き目がはっきり分かるが、音が壊れない」を目安にした暫定の値
/// (聴いて見直す)。どれも音源の計算は変えず、`%名前=値` の値を動かすだけ。
/// - `bright`(明るさ):フィルターの開き具合と、音の頭でフィルターが開く量。
/// - `thick`(厚み):スーパーソウのずれ・声の数と、コーラス。
/// - `attack`(立ち上がりの遅さ):音量の立ち上がり。上げるほど柔らかく、下げるほど鋭い。
/// - `tail`(余韻):音を離してからの消え方と、鳴っている間の減り方。
/// - `space`(広がり):左右の広がりとリバーブ。
/// - `drive`(歪み):歪み。FM の音が「綺麗すぎて浮く」ときに倍音を足す用途も想定する。
/// - `tape`(テープ)、`fold`(折り返し)、`rot`(ロータリー)、`comb`(コム):後から足したエフェクトの量
///   (既定は 0 で何もしない。下げても 0 で止まる)。細かい調整は同じ名前で始まるパラメータで行う。
const KNOBS: [crate::synth::Knob; 10] = [
    crate::synth::Knob {
        name: "bright",
        targets: &[("cutoff", 8), ("fenv", 4)],
    },
    crate::synth::Knob {
        name: "thick",
        targets: &[("detune", 6), ("voices", 1), ("cho", 6)],
    },
    crate::synth::Knob {
        name: "attack",
        targets: &[("attack", 10)],
    },
    crate::synth::Knob {
        name: "tail",
        targets: &[("release", 15), ("decay", 8)],
    },
    crate::synth::Knob {
        name: "space",
        targets: &[("width", 8), ("rev", 8)],
    },
    crate::synth::Knob {
        name: "drive",
        targets: &[("drive", 10)],
    },
    crate::synth::Knob {
        name: "tape",
        targets: &[("tape", 12)],
    },
    crate::synth::Knob {
        name: "fold",
        targets: &[("fold", 12)],
    },
    crate::synth::Knob {
        name: "rot",
        targets: &[("rot", 12)],
    },
    crate::synth::Knob {
        name: "comb",
        targets: &[("comb", 12)],
    },
];

/// 音の高さを持たない音色(`SynthSpec::unpitched_tones` と、再生中の移調の対象外)。
pub(super) const UNPITCHED_TONES: [u8; 5] = [
    tone::NOISE,
    tone::CLAP,
    tone::HAT,
    tone::SNARE,
    tone::CYMBAL,
];

/// `va` 音源の説明。`#synth va` で選ぶ。
pub const VA: SynthSpec = SynthSpec {
    texts: crate::synth::va::text_table::CATALOGS,
    name: "va",
    aliases: &["trance"],
    max_tracks: 26,
    polyphony: POLYPHONY as u8,
    tones: &TONES,
    default_tone: tone::SUPERSAW,
    unpitched_tones: &UNPITCHED_TONES,
    duty_tones: false,
    wave_memory: true,
    params: &PARAMS,
    options: &OPTIONS,
    presets: crate::synth::va::presets::PRESETS,
    knobs: &KNOBS,
    tone_files: crate::synth::tones::va::FILES,
    check_sample: Some(crate::synth::va::sample::check_wav),
    key_range: |_| (0, 127),
    create: |cfg, sr, n| Box::new(VaSynth::new(cfg, sr, n)),
};

#[cfg(test)]
mod tests {
    use super::*;
    use std::collections::HashMap;

    /// `ids.rs` の `param` モジュールの `pub const 名前: 型 = 数;` を (名前, 数) で読む。
    /// 数が数字だけの行だけを読む(`ids.rs` の約束:番号は数字で書く)。
    fn id_consts() -> Vec<(String, usize)> {
        let src = include_str!("ids.rs");
        let body = &src[src.find("pub mod param").expect("param モジュール")..];
        body.lines()
            .filter_map(|l| {
                let rest = l.trim().strip_prefix("pub const ")?;
                let (name, rest) = rest.split_once(':')?;
                let (_, num) = rest.split_once('=')?;
                let num = num.trim().strip_suffix(';')?.trim().parse().ok()?;
                Some((name.trim().to_string(), num))
            })
            .collect()
    }

    /// 番号の定数ではない(個数・オフセットで、名前が `PARAMS` の名前と対応しない)もの。
    /// `FMX_*` はオペレーターごとの並びの中の位置(`fmxN_ratio` などの N を除いた部分)。
    const NOT_IDS: &[&str] = &[
        "COUNT",
        "TRACK_COUNT",
        "FMX_OP_BASE",
        "FMX_OP_PARAMS",
        "FMX_RATIO",
        "FMX_LEVEL",
        "FMX_ENV",
        "FMX_DECAY",
        "FMX_DET",
    ];

    /// 定数の名前と `PARAMS` の名前が違うもの(定数名 → パラメータ名)。
    const RENAMED: &[(&str, &str)] = &[("NOISE_AMT", "noise")];

    /// `ids.rs` の番号の定数は、`PARAMS` の同じ番号の名前(小文字)と一致する。
    /// 並びをずらしたり、途中に足したりしたときの取り違えを見つける。
    #[test]
    fn id_consts_match_param_names() {
        let mut wrong = Vec::new();
        for (name, id) in id_consts() {
            if NOT_IDS.contains(&name.as_str()) {
                continue;
            }
            let want = RENAMED
                .iter()
                .find(|(c, _)| *c == name)
                .map_or_else(|| name.to_lowercase(), |(_, p)| (*p).to_string());
            match PARAMS.get(id) {
                Some(info) if info.name == want => {}
                other => wrong.push(format!(
                    "{name} = {id}: PARAMS の名前は {:?}({want} のはず)",
                    other.map(|i| i.name)
                )),
            }
        }
        assert!(
            wrong.is_empty(),
            "番号と名前が合わない:\n{}",
            wrong.join("\n")
        );
    }

    /// 番号の定数が重ならない(別の名前で同じ番号を指さない)。
    #[test]
    fn id_consts_are_unique() {
        let mut seen: HashMap<usize, String> = HashMap::new();
        for (name, id) in id_consts() {
            if NOT_IDS.contains(&name.as_str()) {
                continue;
            }
            if let Some(prev) = seen.insert(id, name.clone()) {
                panic!("番号 {id} を {prev} と {name} が指している");
            }
        }
    }

    /// 定数のない `PARAMS` の名前は、番号を計算で求める組(`fmxN_*`・`stpN`・`mseg_lN`・`mseg_tN`)
    /// だけ。新しいパラメータを `PARAMS` に足して `ids.rs` に定数を足し忘れたときに気づく。
    #[test]
    fn params_without_const_are_computed_groups() {
        let has_const: std::collections::HashSet<usize> = id_consts()
            .into_iter()
            .filter(|(n, _)| !NOT_IDS.contains(&n.as_str()))
            .map(|(_, id)| id)
            .collect();
        let computed = |n: &str| {
            let digits = |s: &str| !s.is_empty() && s.chars().all(|c| c.is_ascii_digit());
            n.strip_prefix("fmx")
                .and_then(|r| r.split_once('_'))
                .is_some_and(|(d, _)| digits(d))
                || n.strip_prefix("stp").is_some_and(digits)
                || n.strip_prefix("mseg_l").is_some_and(digits)
                || n.strip_prefix("mseg_t").is_some_and(digits)
        };
        let missing: Vec<String> = PARAMS
            .iter()
            .enumerate()
            .filter(|(i, info)| !has_const.contains(i) && !computed(info.name))
            .map(|(i, info)| format!("{i}: {}", info.name))
            .collect();
        assert!(
            missing.is_empty(),
            "ids.rs に番号の定数がない(計算で求める組でもない):\n{}",
            missing.join("\n")
        );
    }

    /// パラメータの名前が重ならない(`%名前` が 1 つに決まる)。
    #[test]
    fn param_names_are_unique() {
        let mut seen = std::collections::HashSet::new();
        for info in &PARAMS {
            assert!(seen.insert(info.name), "名前 {} が重なっている", info.name);
        }
    }
}