Repository navigation
Expand file tree
/
Copy pathfour.lua
More file actions
5091 lines (4912 loc) · 228 KB
/
Copy pathfour.lua
File metadata and controls
5091 lines (4912 loc) · 228 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
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- four: a 4-track sampler
-- record any sound, then
-- loop, stretch and grain
-- it on four tracks.
--
-- START
-- 1 plug a sound into the
-- norns input.
-- 2 press K2 to record.
-- press K2 again. your
-- take loops, clean.
-- 3 turn E1 to walk the
-- pages.
--
-- ON EVERY PAGE
-- E1 change the page
-- E2 E3 the two knobs
-- K2 K3 the two keys
-- (the foot of the
-- screen names them)
-- K1 hold for a second
-- pair of knobs
-- K1+E1 pick track 1 to 4
-- K1+K2 stop or start all
-- K1+K3 tap: all effects
-- off. hold: erase
-- what the page holds
--
-- KEYS
-- tap a key and it stays
-- on. hold it and it is on
-- only while you hold.
--
-- PAGES
-- TAKE record a sound
-- and set its loop
-- VOICE how the track
-- plays the sound:
-- PLAY a clean loop
-- GRAIN a cloud of
-- small pieces
-- WARP slow or fast,
-- same pitch
-- PV freeze, smear
-- CLOUD texture
-- TRACKS the four tracks:
-- on, level, and
-- sends (hold K1)
-- TAPE loop the whole
-- output
-- FILTER tone and drive
-- EFFECT two for a track:
-- chorus, flange,
-- wobble, reson,
-- ring, echo
-- DELAY echo, shared
-- REVERB space, shared
-- MIX the levels
-- PADS 8 slices to play
-- MOTION record a knob
-- move, set LFOs
-- SCENE keep a sound,
-- call it back,
-- morph to it
--
-- GOOD TO KNOW
-- each track has its own
-- sound. pick a track with
-- K1+E1, then TAKE records
-- into it.
-- a fresh take plays dry.
-- you add the effects.
-- every knob maps to MIDI
-- in PARAMS.
-- a grid is welcome, and
-- never needed.
--
-- the full guide is in
-- README.md
-- -----------------------------------------------------------------------------
-- this file is the orchestrator: state + params + key/encoder handlers. the
-- rest lives in lib/ modules (script-internal, NOT norns engines): mfont (pixel
-- font), mtape (the softcut tape + the mix law), mdeck (the loop deck law),
-- minput (midi/keyboard notes), mgrid (grid surface), mmotion (the gesture
-- looper), mscenes (scenes, morph, orbit, the way back), mpages (the screen and
-- the wav file reader), mplugin (installs four's own SuperCollider plugin).
-- they share one `ctx` table and params are the single source of truth. the
-- plan: doc/plan.md. the history: doc/changelog.md.
engine.name = "Four"
-- bring-up diagnostics: load milestones in maiden. If "script file executed"
-- appears without "init() called", the engine died in alloc — check the SC tab.
print("four: script file executed")
local mu = require "musicutil"
local min, max = math.min, math.max
-- ============================================================================
-- state (shared with the lib/ modules through ctx)
-- ============================================================================
-- twelve stations, ordered by FAMILY so neighbours belong together:
-- the take (TAKE VOICE TRACKS) · the loop deck (TAPE) · the tone
-- (FILTER EFFECT DELAY REVERB) · the console (MIX) · the performance layer
-- (PADS MOTION SCENE). EROSION and ORBIT are no longer pages: erosion only
-- ever worked in PLAY mode, so its controls live on VOICE's PLAY face (the
-- alt pair, which was a redundant scan/pitch copy there); the orbit drives
-- the scene machinery, and its knobs live in PARAMS (orbit), its RUN switch
-- on the grid/PARAMS/MIDI. SCENE's alt pair picks the crossfader's A end.
-- The params are UNCHANGED (ids are never renamed), only their surfaces
-- moved.
local PAGES = {
"TAKE", "VOICE", "TRACKS", "TAPE", "FILTER", "EFFECT", "DELAY", "REVERB",
"MIX", "PADS", "MOTION", "SCENE",
}
local FPS = 15
local tape_arm_phase -- head position when tape rec opened a pass; nil = none
local tape_arm_was -- the loop that pass widened, put back if it is declined
local tape_arm_jumped -- that pass moved the head to the tape's start (it plays forward)
local rec_open = false -- an engine record pass is open (armed by a real 1)
local rec_wrapped = false -- that pass came round the end of its buffer
local rec_last = 0 -- ...read from the write head's last poll
local polls = {}
local redraw_clock
local beat_clock -- ctx.on_beat, on every beat of the clock
local prev_midi_add, prev_midi_remove -- norns' hot-plug callbacks, restored
-- ============================================================================
-- helpers
-- ============================================================================
local function clamp(x, lo, hi)
if x < lo then return lo elseif x > hi then return hi else return x end
end
local function ptoggle(id)
params:set(id, params:get(id) == 0 and 1 or 0)
end
local function pget(id, default)
if params.lookup[id] then return params:get(id) end
return default
end
-- current window edges (sorted) and span
-- (four) the take window is the FOCUSED track's: its own material and
-- its own window. ctx.focus_take rewrites WIN.
local WIN = { "pos_start", "pos_end" }
local function window_bounds()
local a = pget(WIN[1], 0)
local b = pget(WIN[2], 1)
local lo, hi = min(a, b), max(a, b)
return lo, hi, max(hi - lo, 0.001)
end
-- zoom-aware fine control: window/loop edge params scale their encoder
-- deltas by the current span, so steps shrink as the region tightens —
-- a wide-open window moves fast, a tight loop nudges by milliseconds.
-- (combined with the 0.002 quantum on these specs: ~10ms at the finest.)
-- every value other than "win" is the param-id prefix of a loop pair.
local FINE_IDS = { pos_start = "win", pos_end = "win",
loop_start = "loop", loop_end = "loop",
t2_pos_start = "t2_pos", t2_pos_end = "t2_pos",
t3_pos_start = "t3_pos", t3_pos_end = "t3_pos",
t4_pos_start = "t4_pos", t4_pos_end = "t4_pos" }
-- interpolate between two values of one param in its controlspec's WARPED
-- space (unmap, lerp, map): linear in the space the encoder moves in, so an
-- exponential param (cutoff, pitch) sweeps evenly. Returns the value and the
-- normalized position. The scene morph and the motion depth both blend
-- through here.
local function warped_lerp(cs, a, b, t)
local na = clamp(cs:unmap(a), 0, 1)
local tn = na + (clamp(cs:unmap(b), 0, 1) - na) * t
return cs:map(tn), tn
end
local function fine_delta(id, d)
local kind = FINE_IDS[id]
if not kind then return d end
local span
if kind == "win" then
local _, _, s = window_bounds()
span = s
else
span = math.abs(pget(kind .. "_end", 1) - pget(kind .. "_start", 0))
end
return d * clamp(math.max(span, 0.001) * 4, 0.08, 1)
end
-- ============================================================================
-- ctx: the one table the lib/ modules see
-- ============================================================================
-- helpers and stable table refs are bound by each module at init; the
-- mutable scalars below are written here (polls, handlers, the clock) and
-- read by the modules each call.
local ctx = {
-- wiring
pget = pget, ptoggle = ptoggle, clamp = clamp,
window_bounds = window_bounds, warped_lerp = warped_lerp,
PAGES = PAGES, FPS = FPS,
-- ui state
page = 1,
alt = false, -- K1 held
last_input = 0, -- frame of the last key/encoder touch (idle dim)
idle_dim = false,
held = {}, -- held[n] = true while key n is down (page-independent)
frame = 0, -- redraw frame counter (drives the REC blink)
flash_id = nil, -- the param whose footer word swells (turning)
flash_until = 0,
-- engine/system signals
play_phase = 0, -- engine poll: normalized playhead in the buffer
play_phases = { 0, 0, 0, 0 }, -- the same for tracks 2 to 4 (four)
rec_phase = 0, -- engine poll: normalized write-head position
rec_arm_phase = 0, -- write-head position when rec was armed
rec_reset_at = nil, -- the frame a new take put the write head at 0 (see head_poll)
rec_poll_time = nil, -- when the write head's last poll came (util.time)
rec_amp = 0, -- engine poll: amplitude of what's being written
rec_waiting = false, -- armed to start on sound, none heard yet (TAKE: WAIT)
amp_in = { 0, 0 }, -- system polls: live input amplitude L/R
amp_out = { 0, 0 }, -- system polls: output amplitude L/R
cpu_high = false, -- the load is near the limit: the header says CPU
tape_phase = 0, -- softcut phase event: tape head, normalized
tape_heard = nil, -- an open tape pass: has it heard a sound yet (nil: no pass)
tape_quiet = 0, -- frames of silence at the tape's source while it records
tape_msg = nil, -- what the last tape pass did, for TAPE to say
-- display-model flags (mpages paints them)
wave_any = false, -- false until something audible lands in the buffer
twave_any = false,
-- normalized 0..1 high-water mark of buffer content worth saving (from frame
-- 0): the take end at rec-stop, a loaded sample's length, or 1 when regen has
-- filled the whole buffer. write_take bounds the PSET save to it. 0 = empty.
take_len = 0,
-- pad bank: 8 slice pads, per-pad type (0 grain / 1 slice), a screen
-- cursor for standalone select/audition. shared by the PADS page + the
-- MIDI/grid note routing (they map an incoming note to a pad index).
-- SOUND-LOCKS: per-pad voice (0 grain / 1 slice) + pitch (semitones). the
-- `pad_voice`/`pad_pitch` params are the cursor EDITOR (Elektron data-knob
-- style — they read/write the pad under pad_cursor); these arrays hold the 8
-- locks and ride the PSET (ctx.padlock_pset_*). note_on reads them per pad.
pad_type = {}, -- per-pad voice (0 grain / 1 slice); every read is `or 0`
pad_pitch = {}, -- per-pad pitch (semitones); every read is `or 0`
pad_sync = false, -- guard: syncing the editor params FROM the arrays
pad_cursor = 0,
pad_n = 8,
pad_held = {}, -- voice id -> pad index while sounding
pad_order = {}, -- the same ids in press order, for the steal below
}
local Mfont = include "lib/mfont"
local Mui = include "lib/mui"
local Mtape = include "lib/mtape"
local Mdeck = include "lib/mdeck"
local Minput = include "lib/minput"
local Mgrid = include "lib/mgrid"
local Mmotion = include "lib/mmotion"
local Mseq = include "lib/mseq"
local Mlfo = include "lib/mlfo"
local Mout = include "lib/mout"
local Mosc = include "lib/mosc"
local Mscenes = include "lib/mscenes"
local Mwav = include "lib/mwav"
local Mpages = include "lib/mpages"
local Mplugin = include "lib/mplugin"
local Msample = include "lib/msample"
ctx.font = Mfont
ctx.ui = Mui -- THE KIT (doc/ui-design.md): mpages draws with it as ctx.ui
ctx.wav = Mwav -- the wav file layer; mpages paints strips through it
ctx.grid = Mgrid
ctx.motion = Mmotion
ctx.seq = Mseq
ctx.lfo = Mlfo
ctx.osc = Mosc
-- the tape display model lives in mpages; mtape clears it when a pset restores
-- an empty tape, so it needs a way to reach it
ctx.clear_twave = Mpages.clear_twave
-- ...and repaints it from the PSET wav on restore
ctx.repaint_twave = Mpages.repaint_twave
ctx.clear_bins = Mpages.clear_bins -- a deck erase stops its own repaint
ctx.wav_info = Mwav.wav_info
-- any hand on the instrument counts as presence for the idle dim: keys and
-- encoders here, the grid and MIDI in their own modules
function ctx.touch_input() ctx.last_input = ctx.frame end
-- THE TIMEBASE. These two numbers place everything in the instrument: every
-- window edge, pad slice, waveform bin and PSET bound is a fraction of them.
-- Both are set by the ENGINE (lib/Engine_Four.sc allocates
-- `s.sampleRate * bufSecs`, and norns runs its server at 48k) and lua cannot
-- read either off the server — so they are mirrored ONCE here and shared
-- through ctx. They used to be bare literals in several modules plus the .sc:
-- miss one when the buffer length changes and PSET saves silently truncate the
-- take, or every waveform, window bracket and pad slice draws against the
-- wrong clock with no error anywhere.
ctx.BUF_SECS = 60 -- must match `bufSecs` in lib/Engine_Four.sc
-- How many bytes per sample `write_take` puts on disk. MUST match the format
-- in that command (`int24`, so 3). The export works out how big the file
-- should be from this and waits for it to get there, so a number that is too
-- small calls the file finished while a third of it is still being written.
ctx.TAKE_BYTES = 3 -- must match write_take's format in Engine_Four.sc
ctx.SERVER_SR = 48000 -- norns' scsynth sample rate
local BUF_SECS, SERVER_SR = ctx.BUF_SECS, ctx.SERVER_SR
Mwav.init(ctx)
-- THE tempo read. Guarded (the offscreen sim has no clock) and defaulted once,
-- so every caller agrees about what "the tempo" is.
function ctx.tempo()
if clock and clock.get_tempo then
local ok, t = pcall(clock.get_tempo)
if ok and t and t > 0 then return t end
end
return 120
end
-- THE CLOCK'S BEATS (the sixty-ninth change): the norns clock, and in the
-- offscreen norns (no clock) a count from the frames at the tempo.
function ctx.beats()
if clock and clock.get_beats then
local ok, b = pcall(clock.get_beats)
if ok and type(b) == "number" then return b end
end
return (ctx.frame or 0) / FPS * ctx.tempo() / 60
end
-- A TAKE ON THE CLOCK: how many beats its line is (0 = FREE), and its word
local REC_SYNC_BEATS, REC_SYNC_WORD = { 0, 1, 4 }, { "", "BEAT", "BAR" }
function ctx.rec_sync_beats()
return REC_SYNC_BEATS[math.floor(pget("rec_sync", 1) + 0.5)] or 0
end
function ctx.rec_sync_word()
return REC_SYNC_WORD[math.floor(pget("rec_sync", 1) + 0.5)] or ""
end
-- An arm or a stop the instrument makes itself (a clear, UNDO, a change of
-- track, a full ONE-SHOT track): at once, never on the clock
function ctx.rec_set(v)
ctx.rec_force = true
params:set("rec", v)
ctx.rec_force = false
end
-- the EFFECTIVE softcut record source: the cut_source knob. The SRC flag and
-- the meters read THIS, never the raw param, so one place decides it.
function ctx.eff_cut_source()
return pget("cut_source", 1)
end
-- ONE writer for the softcut input sends, so the routing can never disagree
-- with the flags.
function ctx.update_cut_source()
Mtape.set_source(ctx.eff_cut_source())
end
-- what the softcut decks RECORD right now, for the meters: the ADC tap, the
-- engine output (WET), or the blend. the law of the tape picture (mpages).
function ctx.cut_rec_amp()
local cs = ctx.eff_cut_source()
return max(ctx.amp_in[1], ctx.amp_in[2]) * (1 - cs)
+ max(ctx.amp_out[1], ctx.amp_out[2]) * cs
end
Mtape.init(ctx, Mdeck) -- the tape borrows the deck mechanics (see mtape)
-- THE deck gain law (eng, tape, master) lives in mtape; the MIX page draws
-- the same numbers update_mix sends, so it reads them from here
ctx.mix_gains = Mtape.gains
ctx.TAPE_LEN = Mtape.TAPE_LEN -- the tape's own length (not BUF_SECS)
ctx.tape_deck = Mtape.deck -- read only: the page asks where its material is
ctx.paint_bins = Mpages.paint_bins -- a deck paints its own picture
ctx.set_pair = Mdeck.set_pair -- THE way to move a start/end pair
Mdeck.init(ctx)
-- a compound encoder target ("@...") resolves to a REAL param id: the one the
-- footer should print and the dial should point at. Pair-movers report their
-- anchor, the low edge. ONE resolver, because the encoder, the footer value and
-- the footer dial each need the same answer and two of them used to not have it
-- (a compound target read "--" and drew no pointer).
function ctx.enc_target(id)
if id == "@win_move" then return WIN[1] end
if id == "@mo_sel" then
return pget("mod_focus", 1) > 1.5 and "mod_focus" or "motion_lane"
end
if id == "@route_amt" then return ctx.route_cur().id end
if id == "@route_to" then return "route_sel" end
if id == "@trk_level" then return ctx.LEVEL_ID[ctx.tsel()] end
-- THE MIX POP's E2: the focused track's pan, or on DELAY and REVERB its
-- send into that effect (the ninety-fourth change)
if id == "@trk_pan" then return ctx.TRK_PAN[ctx.tsel()] end
if id == "@pop_send" then
local t = ctx.tsel()
local fx = PAGES[ctx.page] == "DELAY" and "fx_dly" or "fx_rev"
return t == 1 and fx or ("t" .. t .. "_" .. fx)
end
if id == "@rec_src" then return "rec_source" end
if id == "@tempo" then return "clock_tempo" end
return id
end
-- THE CLOCK IN WORDS (the seventieth change): "120 BPM" on the norns's own
-- clock, "120 MIDI" (LINK, CROW) when another one leads it. Built again only
-- when the tempo or the source changes: the redraw allocates nothing.
local CLOCK_WORD = { internal = "BPM", midi = "MIDI", link = "LINK", crow = "CROW" }
local clock_cache = { t = -1, src = nil, word = "" }
function ctx.clock_source()
if not params.lookup["clock_source"] then return "internal" end
return string.lower(params:string("clock_source") or "internal")
end
function ctx.clock_word()
local t, src = math.floor(ctx.tempo() + 0.5), ctx.clock_source()
if t ~= clock_cache.t or src ~= clock_cache.src then
clock_cache.t, clock_cache.src = t, src
clock_cache.word = t .. " " .. (CLOCK_WORD[src] or string.upper(src))
end
return clock_cache.word
end
-- where a loop deck's MATERIAL is (Mdeck.extent), for the scene clamp. The
-- one key is "tape". nil = no material, which leaves a stored loop exactly as
-- it was.
function ctx.material(key)
if key == "tape" then
if not ctx.twave_any then return nil end
return Mdeck.extent(Mtape.deck)
end
end
-- ---------------------------------------------------------------------------
-- the musical ratios a loop length snaps to
-- ---------------------------------------------------------------------------
-- A hand-played length is never exactly the length you meant. Two loops that
-- are an exact double, half or three-to-two of each other stay together
-- indefinitely. The motion looper rounds a first pass onto the clock with
-- these (ctx.clock_length).
local SNAP_RATIOS = {
{ 1 / 8, "1/8" }, { 1 / 6, "1/6" }, { 1 / 4, "1/4" }, { 1 / 3, "1/3" },
{ 1 / 2, "1/2" }, { 2 / 3, "2/3" }, { 3 / 4, "3/4" }, { 1, "1" },
{ 4 / 3, "4/3" }, { 3 / 2, "3/2" }, { 2, "2" }, { 3, "3" },
{ 4, "4" }, { 6, "6" }, { 8, "8" },
}
-- how close a hand-played length has to be for the automatic snap to take it.
-- 6% is the slop of someone trying to land on the beat; anything further out
-- is a length you chose, and it is left exactly as you played it.
local SNAP_TOL = math.log(1.06)
-- the musical ratio of `ref` nearest to `cur`, compared in LOG space so 1/2
-- and 2 are equally near, the way an ear hears them (a linear nearest would
-- pull everything toward the top). returns the ratio, its label, the error.
local function nearest_ratio(cur, ref)
local best, label, err = 1, "1", math.huge
for _, r in ipairs(SNAP_RATIOS) do
local e = math.abs(math.log(cur / (ref * r[1])))
if e < err then err, best, label = e, r[1], r[2] end
end
return best, label, err
end
-- a gesture loop's length on the clock: the nearest musical length to a bar
-- when what was played is already within the snap tolerance, else nil (a
-- length you clearly chose stays exactly as played). the motion looper asks
-- this when a first pass closes.
function ctx.clock_length(secs)
local bar = 240 / ctx.tempo()
local best, _, err = nearest_ratio(secs, bar)
if err > SNAP_TOL then return nil end
return bar * best
end
-- TAKE says what K3's SNAP and UNDO just did, on its top row, and prints the
-- full story to the log
local function take_say(msg, detail)
ctx.take_msg, ctx.take_msg_at = msg, ctx.frame or 0
Mui.say(msg, detail)
end
ctx.take_say = take_say
-- THE SAY (the ninety-second change): what the page just did, in the title
-- row for 1.2 s, on every page. It prints the story to the log too.
ctx.say = Mui.say
Mui.init(ctx)
Minput.init(ctx)
Mgrid.init(ctx)
Mmotion.init(ctx)
Mseq.init(ctx)
Mlfo.init(ctx)
Mout.init(ctx)
Msample.init(ctx)
Mosc.init(ctx)
Mscenes.init(ctx) -- sets ctx.scene (the module; its bank is ctx.scene.slots)
Mpages.init(ctx)
-- ============================================================================
-- keys: the punch law
-- ============================================================================
-- ONE physical rule for every key:
-- press = engage NOW · release within TAP_FRAMES = it latches ·
-- held past TAP_FRAMES = it was a punch, release disengages ·
-- already latched = any press turns it off.
-- defs come in two shapes:
-- { label, act } -- tap-cycle: fires on PRESS, no punch
-- { label, pon, poff, lit } -- punchable; lit() feeds the footer
-- (gate = true -- always momentary, e.g. the PADS pad)
-- K1+K2 = STOP and K1+K3 = DRY (tap) / ERASE (1s arc) are GLOBAL — no page
-- claims them, so the rescue reflexes are unconditional muscle memory.
local TAP_FRAMES = 5 -- <=4 frames (~300ms at 15fps) reads as a tap
local ERASE_FRAMES = 15 -- K1+K3 held ~1s (the drawn arc) erases material
-- per-key press bookkeeping for the punch law: the def is resolved at the
-- PRESS and the release routes back to it, so an alt released mid-hold can
-- never hand the release to the wrong action (the grid learned this the hard way)
local key_state = { [2] = {}, [3] = {} }
-- punchable binary param: the common case
local function pk(label, id)
return {
label = label,
lit = function() return pget(id, 0) > 0 end,
pon = function() params:set(id, 1) end,
poff = function() params:set(id, 0) end,
}
end
-- throw: engage() applies a gesture and returns {id=prior} to restore on
-- disengage. hold = ride it and come back, tap = latch, tap again = back.
local throw_mem = {}
-- a throw's snapshot is only good until something ELSE moves the instrument.
-- A scene recall, a morph, a chaos throw or DRY installs values wholesale;
-- un-latching afterwards would write a snapshot taken BEFORE all that straight
-- over the top of it — silently undoing the recall. Drop the snapshots
-- instead. The pill goes dark, which is the honest signal: there is no longer
-- a "back" to come back to.
-- EVERY THROW IS A PARAM (the 104th change): `throw_<word>` is 1 exactly while
-- its snapshot exists. ctx.THROWS[pid] is the def, ctx.THROW_KEY[key] its pid.
-- A key, a grid pad, MIDI and PARAMS all go through the param; whatever drops
-- a snapshot sets the param back to 0 silently, so the law holds.
ctx.THROWS, ctx.THROW_KEY = {}, {}
function ctx.throw_param_off(key)
local pid = ctx.THROW_KEY[key]
if pid and params.lookup[pid] then params:set(pid, 0, true) end
end
function ctx.throws_forget()
for k in pairs(throw_mem) do
throw_mem[k] = nil
ctx.throw_param_off(k)
end
end
local function throw_restore(label)
local mem = throw_mem[label]
if not mem then return end
throw_mem[label] = nil
ctx.throw_param_off(label)
for id, v in pairs(mem) do params:set(id, v) end
end
-- a throw: `ids` are the params it owns, `apply` sets the new values, and the
-- snapshot to restore on release is built FROM ids — so what gets put back can
-- never drift from what gets set. Hold = ride it and come back, tap = latch,
-- tap again = back.
--
-- Engaging first un-latches any OTHER throw holding one of the same params,
-- restoring it. Two throws over one param used to STACK: the second cached
-- what the first had already displaced, so releasing them out of order left
-- the param at a value nobody chose under a lit pill. MIX's ENG/TAPE carried a
-- hand-written pair for exactly this and EROSION's HEAL/SCAR did not; keying
-- the conflict on the PARAMS makes it automatic for every throw, present and
-- future.
-- `key` (optional) names the snapshot when two throws share a word (OPEN on
-- either track); it defaults to the label.
-- `pid` is the throw's param, `page` (and `n`, a track) where its key lives: a
-- throw engaged while another page shows says so in THE SAY.
local function throw(label, ids, apply, key, pid, page, n)
key = key or label
local def
def = {
label = label, pid = pid, page = page, n = n,
say_on = label, say_off = label .. " OFF",
lit = function() return throw_mem[key] ~= nil end,
pon = function() params:set(pid, 1) end,
poff = function() params:set(pid, 0) end,
engage = function()
for other, mem in pairs(throw_mem) do
if other == "DRY" and key ~= "DRY" then
-- DRY holds the whole wet path: another throw takes only its own
-- ids out of DRY's memory (they are its now), and the rest of DRY
-- stays as it is, and comes back on DRY's second tap
for k = 1, #ids do mem[ids[k]] = nil end
elseif other ~= key then
for k = 1, #ids do
if mem[ids[k]] ~= nil then throw_restore(other); break end
end
end
end
local mem = {}
for k = 1, #ids do mem[ids[k]] = params:get(ids[k]) end
throw_mem[key] = mem
apply()
ctx.throw_say(def, true)
end,
release = function()
if throw_mem[key] == nil then return end
throw_restore(key)
ctx.throw_say(def, false)
end,
}
ctx.THROWS[pid] = def
ctx.THROW_KEY[key] = pid
return def
end
-- a throw from a page that does not show its key says what it did
function ctx.throw_say(def, on)
if not def.page then return end
local here = PAGES[ctx.page] == def.page
if here and def.n then
here = math.floor(pget("track_sel", 1) + 0.5) == def.n
end
if not here then ctx.say(on and def.say_on or def.say_off, false) end
end
-- pulse a momentary param (the footswitch-shaped SCENE binaries: their
-- actions fire on the rising edge, so 1-then-0 is one clean press)
local function pulse(id)
params:set(id, 1)
params:set(id, 0)
end
-- the grid drives the same momentary params (read lazily at press time, so
-- defining it after the ctx wiring above is safe)
ctx.pulse = pulse
-- "open" cutoff for the current filter type — the ONE definition of what an
-- open filter means, shared by FILTER's OPEN throw and ctx.fx_dry
local function filter_open_cutoff(ft)
return ft == 2 and 20 or (ft == 3 and 1000 or 20000)
end
-- TAKE K3: window full <-> back where you had it (a round trip, so a
-- fat-fingered snap is always recoverable)
local snap_mem
-- the window bounds SNAP remembers are only meaningful for the material they
-- were taken from. New audio in the buffer makes them a pointer into something
-- that no longer exists — a SNAP after CLR used to restore the erased take's
-- bounds — so whoever replaces the buffer forgets them.
function ctx.snap_forget() snap_mem = nil end
local function snap_window()
local lo, hi = pget("pos_start", 0), pget("pos_end", 1)
if hi < lo then lo, hi = hi, lo end
if hi - lo > 0.98 then
if snap_mem then
params:set("pos_start", snap_mem[1])
params:set("pos_end", snap_mem[2])
take_say("SNAP - WINDOW BACK")
else
-- full window, nothing remembered — the state on every fresh load, where
-- this key used to do nothing at all and say nothing about it. Snap to
-- the TAKE instead: the same "window = what you recorded" law the
-- rec-stop applies, which is the only useful meaning left here.
local tl = ctx.take_len or 0
if ctx.wave_any and tl > 0.001 and tl < 0.98 then
snap_mem = { lo, hi }
params:set("pos_start", 0)
params:set("pos_end", tl)
take_say("SNAP - WINDOW ON THE TAKE")
else
take_say("SNAP - ALREADY WHOLE",
"SNAP — the window is already the whole buffer")
end
end
else
snap_mem = { lo, hi }
params:set("pos_start", 0)
params:set("pos_end", 1)
take_say("SNAP - WHOLE BUFFER")
end
end
-- ---- the tracks (four) ------------------------------------------------
-- Four engine tracks and ONE focus. `track_sel` is the focused track, and
-- TAKE, VOICE and FILTER all edit it: their titles read TAKE 2, VOICE 2 ...
-- and the same knobs and keys reach the `t<n>_` params. TRACKS is the hub:
-- the four tracks in a list, E2 picks the focus, and with K1 held the
-- focused track's sends. A HOLD of K3 on VOICE or FILTER also steps the
-- focus 1 > 2 > 3 > 4 > 1 (the tap keeps MODE / TYPE). What only track 1 has
-- (the erosion) is out of reach on the others, and what all share (drive,
-- dry/wet) stays the same param.
local NTRACKS = 4
-- the engine voice of a track. APPEND-ONLY: a PSET stores the index
local MODE_NAMES = { "OFF", "GRAIN", "WARP", "PV", "PLAY", "CLOUD", "LIVE" }
-- the effect slot of a track (fxSlot in the engine). APPEND-ONLY, like the modes
-- (PITCH, SHIFT and VOWEL are the new effects, after ECHO)
local EFFECT_NAMES = { "OFF", "CHORUS", "FLANGE", "WOBBLE", "RESON", "RING", "ECHO",
"PITCH", "SHIFT", "VOWEL" }
local TRACK_PAGES = { TAKE = true, VOICE = true, FILTER = true, EFFECT = true }
local function tsel() return clamp(math.floor(pget("track_sel", 1) + 0.5), 1, NTRACKS) end
local function track2() return tsel() > 1 end -- any track but track 1
-- TID[n][id] = "t<n>_<id>", each string built once and cached: the redraw
-- path reads these every frame and must not allocate
local TID = {}
for n = 2, NTRACKS do
TID[n] = setmetatable({}, { __index = function(t, id)
local v = "t" .. n .. "_" .. id
t[id] = v
return v
end })
end
-- track n's id for a track 1 id: itself on track 1, or when track n has no
-- such param
local function tid_n(n, id)
if id and n > 1 then
local t = TID[n][id]
if params.lookup[t] then return t end
end
return id
end
local function tid(id) return tid_n(tsel(), id) end
ctx.tid, ctx.tid_n, ctx.tsel = tid, tid_n, tsel
-- each track's mode and level (track 1's level is the engine's grain_level)
local MODE_ID, LEVEL_ID = { "mode" }, { "grain_level" }
for n = 2, NTRACKS do
MODE_ID[n], LEVEL_ID[n] = "t" .. n .. "_mode", "t" .. n .. "_level"
end
ctx.MODE_ID, ctx.LEVEL_ID = MODE_ID, LEVEL_ID
-- MUTE AND SOLO (the seventy-third change, doc/mix-plan.md). The engine gets
-- a track's level times its gain here, 0 or 1 (the level's eng_map, so a
-- modulator's sends go through it too). The param keeps the level, and the
-- head runs on. ctx.solo is the track held alone (TRACKS K2 held), or nil:
-- it is heard muted or not, and no other track is.
ctx.MUTE_ID = { "mute_1", "mute_2", "mute_3", "mute_4" }
ctx.TRK_PAN = { "pan", "t2_pan", "t3_pan", "t4_pan" }
function ctx.track_gain(n)
if ctx.solo then return n == ctx.solo and 1 or 0 end
return pget(ctx.MUTE_ID[n], 0) == 1 and 0 or 1
end
-- one track's level to the engine again (its gain changed)
function ctx.level_send(n)
local id = LEVEL_ID[n]
if not (params.lookup[id] and engine[id]) then return end
local v = pget(id, 1)
if ctx.lfo and ctx.lfo.swinging(id) then v = ctx.lfo.swung(id, v) end
engine[id](v * ctx.track_gain(n))
end
function ctx.set_solo(n)
ctx.solo = n
for k = 1, NTRACKS do ctx.level_send(k) end
end
-- THE LEVEL IN dB: E3 on TRACKS goes in steps of 0.5 dB, from silence
-- (below LEVEL_FLOOR) to the top of the param. Its range and its id are the
-- old ones, so a preset, a scene and a MIDI map hold.
ctx.LEVEL_FLOOR, ctx.LEVEL_TOP = -40, 1.5
function ctx.level_db(v)
return v > 0 and 20 * math.log(v, 10) or -math.huge
end
function ctx.level_step(id, d)
local k, floor_k = nil, ctx.LEVEL_FLOOR * 2
local db = ctx.level_db(pget(id, 1))
k = db < ctx.LEVEL_FLOOR and floor_k - 1 or math.floor(db * 2 + 0.5)
k = k + d
if k < floor_k then params:set(id, 0)
else params:set(id, math.min(ctx.LEVEL_TOP, 10 ^ (k / 40))) end
end
-- MODE cycles PLAY->GRAIN->WARP->PV->CLOUD->LIVE->PLAY, skipping OFF (a
-- silence pothole mid-set; stopping is STOP's job — OFF stays reachable in
-- PARAMS). Tracks 2 to 4 start OFF, so their first tap lands on PLAY. The
-- options are append-only (a PSET stores the index): CLOUD is the sixth and
-- LIVE the seventh.
-- (the ninety-seventh change: LIVE left the cycle. It is GRAIN with the
-- source LIVE, picked on K3 held; from it the cycle goes on as from GRAIN)
local MODE_NEXT = { 5, 3, 4, 6, 2, 5, 3 }
local function cycle_mode(id)
local m = math.floor(pget(id, 5) + 0.5)
params:set(id, MODE_NEXT[m] or 5)
end
local function cycle_type(id) params:set(id, (pget(id, 1) % 3) + 1) end
-- the EFFECT page's keys on track n. K2 is ON under the punch law (a tap
-- latches, a hold sounds the effect only while held), and off remembers the
-- type, so on brings back the effect you had; the first on is CHORUS. K3
-- steps the type and skips OFF (K2 is the off switch); held, it steps the
-- focus like VOICE and FILTER.
local last_effect = {}
local function effect_keys(n)
local id = n == 1 and "effect" or ("t" .. n .. "_effect")
last_effect[n] = 2
return {
k2 = {
label = "ON",
lit = function() return pget(id, 1) ~= 1 end,
pon = function() params:set(id, last_effect[n]) end,
poff = function()
local e = pget(id, 1)
if e ~= 1 then last_effect[n] = e end
params:set(id, 1)
end,
},
-- K3: a tap steps the type, a hold is THE PICKER (E2 the slot, E3 the
-- type: the second slot's type has a key at last)
k3 = ctx.type_k3("EFFECT", n, function()
local e = math.floor(pget(id, 1) + 0.5)
params:set(id, e >= #EFFECT_NAMES and 2 or e + 1)
end),
}
end
-- TAKE's SNAP on tracks 2 to 4: the track's window onto track 1's (the take
-- as you recorded it), and back. Through set_pair, widening edge first.
local snap_n = {}
local function snap_track(n)
local a, b = tid_n(n, "pos_start"), tid_n(n, "pos_end")
local lo, hi = pget(a, 0), pget(b, 1)
if hi < lo then lo, hi = hi, lo end
local l1, h1 = pget("pos_start", 0), pget("pos_end", 1)
if h1 < l1 then l1, h1 = h1, l1 end
if snap_n[n] and math.abs(lo - l1) < 1e-6 and math.abs(hi - h1) < 1e-6 then
Mdeck.set_pair(a, b, snap_n[n][1], snap_n[n][2])
snap_n[n] = nil
take_say("SNAP - WINDOW BACK")
else
snap_n[n] = { lo, hi }
Mdeck.set_pair(a, b, l1, h1)
take_say("SNAP - ON TRACK 1")
end
end
-- a track switched on with its window still at the default (the whole
-- 60s buffer) would play the empty buffer past the take for half its loop
-- (seen on the device): it starts on track 1's window instead
local function fit_new_track(n)
if n < 2 then return end
local a, b = tid_n(n, "pos_start"), tid_n(n, "pos_end")
if pget(a, 0) <= 1e-6 and pget(b, 1) >= 1 - 1e-6 then
local l1, h1 = pget("pos_start", 0), pget("pos_end", 1)
if h1 < l1 then l1, h1 = h1, l1 end
if h1 - l1 < 0.999 then Mdeck.set_pair(a, b, l1, h1) end
end
end
-- THE PICKER (the ninety-sixth change; doc/ui-design.md 2.8): K3 held past
-- a tap on VOICE and TRACKS. E3 turns the wheel, nothing moves while it
-- turns, and the choice lands ONCE, at the release. K1 closes it with no
-- change, and so do E1 and the norns menu. (Fields of ctx: this chunk is at
-- Lua's limit of 200 locals.)
-- THE FOLD (the ninety-seventh change): LIVE is GRAIN with the source LIVE.
-- The wheel has no LIVE: on GRAIN, E2 picks the source (TAKE or LIVE), and
-- GRAIN on LIVE is the engine's mode 6 (the param's option 7) as before.
-- The ninety-eighth change: the same picker on FILTER (LP HP BP) and EFFECT
-- (E2 the slot, E3 its type).
-- THE ROWS (the 114th change): a choice can bring a short list of its own
-- knobs at the picker's right (GRAIN: SRC, SCALE, REV, AMP, and SYNC on
-- LIVE). E2 turns the row in the hand and K2 steps to the next row. SRC is
-- part of the choice and lands with it; the other rows are knobs and move at
-- once, so they are heard while they turn. K1 puts them back as they were.
-- (a row's `names` is the ctx table that names an option's values, `pct` a
-- knob read in percent: the picker draws them from tables, built once)
ctx.PICK_ROW = {
SRC = { word = "SRC", src = true },
SCALE = { word = "SCALE", id = "grain_scale", names = "GRAIN_SCALES" },
REV = { word = "REV", id = "grain_rev", pct = true },
AMP = { word = "AMP", id = "grain_amp", pct = true },
SYNC = { word = "SYNC", id = "live_sync", names = "LIVE_SYNC_NAMES" },
}
do
local R = ctx.PICK_ROW
ctx.PICK_ROWS = {
GRAIN = { R.SRC, R.SCALE, R.REV, R.AMP },
LIVE = { R.SRC, R.SCALE, R.REV, R.AMP, R.SYNC },
}
end
ctx.PICK = {
VOICE = { words = { "OFF", "PLAY", "GRAIN", "WARP", "PV", "CLOUD" },
vals = { 1, 5, 2, 3, 4, 6 }, src = { "TAKE", "LIVE" }, enc = "@pick",
rows = function(p)
if ctx.PICK.VOICE.vals[p.sel] ~= 2 then return nil end
return p.src == 2 and ctx.PICK_ROWS.LIVE or ctx.PICK_ROWS.GRAIN
end },
FILTER = { words = { "LP", "HP", "BP" }, vals = { 1, 2, 3 }, enc = "@pick_type" },
EFFECT = { words = EFFECT_NAMES, vals = {}, slots = { "1", "2" },
enc = "@pick_type" },
}
for i = 1, #EFFECT_NAMES do ctx.PICK.EFFECT.vals[i] = i end
-- the param a picker of `kind` sets on track n (EFFECT: in slot `slot`)
function ctx.pick_id(kind, n, slot)
local base = kind == "FILTER" and "filt_type" or (kind == "EFFECT"
and (slot == 2 and "effect2" or "effect") or "mode")
return n == 1 and base or ("t" .. n .. "_" .. base)
end
-- K3 on FILTER and EFFECT for track n: a tap is `tap`, a hold the picker
function ctx.type_k3(kind, n, tap)
return { label = "TYPE", tap = tap,
hold = function() ctx.pick_open(kind, ctx.pick_id(kind, n, 1), n) end, hold_at = TAP_FRAMES,
hold_label = "TYPE", release = function() ctx.pick_close(true) end, pick = true }
end
-- THE SEND (the 122nd change): K3 held on DELAY and REVERB. The wheel is the
-- track (E3) and lands as the focus at the release; its one row is that
-- track's send into the page's effect (E2), heard at once while it turns, on
-- the sends row of the floor. K1 puts the sends back. A tap is the page's
-- throw, KILL or BLOOM, as before (its hold, KILL while held, is its param
-- `throw_kill` or `throw_bloom` for MIDI). It replaces K1+E1 then E2 as the
-- way the page names (the user, 2026-11-29: "a bit hidden"); the mix pop's
-- E2 still sends too.
ctx.SEND_BASE = { DELAY = "fx_dly", REVERB = "fx_rev" }
ctx.PICK_ROWS.SEND = { { word = "SEND", id = "send", pct = true } }
ctx.PICK.SEND = { words = { "T1", "T2", "T3", "T4" }, vals = { 1, 2, 3, 4 },
enc = "@pick_track",
opened = function(p) p.base = ctx.SEND_BASE[PAGES[p.page]] end,
rows = function() return ctx.PICK_ROWS.SEND end,
row_id = function(p) return tid_n(ctx.PICK.SEND.vals[p.sel], p.base) end,
commit = function(p, v)
if math.floor(pget("track_sel", 1) + 0.5) ~= v then params:set("track_sel", v) end
end }
-- K3 on DELAY and REVERB: a tap is the throw `th`, a hold THE SEND
function ctx.send_k3(th)
return { label = th.label, lit = th.lit, pid = th.pid,
tap = function() if th.lit() then th.poff() else th.pon() end end,
hold = function() ctx.pick_open("SEND", "track_sel", nil) end, hold_at = TAP_FRAMES,
hold_label = "SEND", release = function() ctx.pick_close(true) end, pick = true }
end
function ctx.pick_open(kind, id, n)
local P = ctx.PICK[kind]
local cur, sel = math.floor(pget(id, 1) + 0.5), 1
local src = (kind == "VOICE" and cur == 7) and 2 or 1
if kind == "VOICE" and cur == 7 then cur = 2 end
for i, v in ipairs(P.vals) do if v == cur then sel = i end end
ctx.pick = { kind = kind, id = id, n = n, sel = sel, page = ctx.page, src = src, slot = 1,
row = 1, orig = {} }
if P.opened then P.opened(ctx.pick) end
end
-- the rows the wheel's choice brings now (nil for none)
function ctx.pick_rows()
local p = ctx.pick
local P = p and ctx.PICK[p.kind]
local rows = P and P.rows and P.rows(p)
if rows and p.row > #rows then p.row = #rows end
return rows
end
-- the param a row turns (nil for SRC)
function ctx.pick_row_id(row)
local p = ctx.pick
if not (p and row and row.id) then return nil end
local P = ctx.PICK[p.kind]
if P.row_id then return P.row_id(p, row) end
return tid_n(p.n or 1, row.id)
end
-- the row in the hand, and its word (the footer's E2 word in the picker)
function ctx.pick_row()
local rows = ctx.pick_rows()
return rows and rows[ctx.pick.row] or nil
end
function ctx.pick_row_word()
local r = ctx.pick_row()
return r and r.word or "--"
end
-- E2 in the picker: the row in the hand
function ctx.pick_row_turn(d)
local p, row = ctx.pick, ctx.pick_row()
if not row then return end
if row.src then
p.src = clamp(p.src + d, 1, #(ctx.PICK[p.kind].src or { 1 }))
return
end
local id = ctx.pick_row_id(row)
if not (id and params.lookup[id]) then return end
if p.orig[id] == nil then p.orig[id] = params:get(id) end
params:delta(id, d)
end
-- K2 in a picker with rows: the next row, round
ctx.PICK_NEXT = { label = "NEXT", act = function()
local rows = ctx.pick_rows()
if rows then ctx.pick.row = ctx.pick.row % #rows + 1 end
end }
-- EFFECT's E2 in the picker: the slot, and the wheel goes to its type
function ctx.pick_slot(d)
local p = ctx.pick
local s = clamp(p.slot + d, 1, 2)
if s == p.slot then return end
p.slot, p.id = s, ctx.pick_id("EFFECT", p.n, s)
p.sel = clamp(math.floor(pget(p.id, 1) + 0.5), 1, #EFFECT_NAMES)
end
-- what the say reads after slot 2's type is picked, built once
ctx.EFFECT_SAY = {}
for i, w in ipairs(EFFECT_NAMES) do
ctx.EFFECT_SAY[i] = i == 1 and "SLOT 2 OFF" or ("SLOT 2 " .. w .. " - K1 SHAPES")
end
ctx.throw_mem = throw_mem -- (FILTER draws OPEN's carved curve as a ghost)
function ctx.pick_close(commit)
local p = ctx.pick
ctx.pick = nil
if not p then return end
if not commit then
-- K1, E1, the menu: the rows' knobs go back as they were
for id, v in pairs(p.orig) do params:set(id, v) end
return
end
local P = ctx.PICK[p.kind]
local v = P.vals[p.sel]
if P.commit then return P.commit(p, v) end
if p.kind ~= "VOICE" then
if math.floor(pget(p.id, 1) + 0.5) ~= v then params:set(p.id, v) end
-- the knobs stay on slot 1: say where slot 2's are (the review, finding 8)