SMK-37: Rhythmer's control layout on V10.8.48, all 37 keys through the FM-1's key path, TRS MIDI OUT

The layout of Rhythmer (Jazzy Rhythmer's GPL-3.0 fork of JIANT, its SMK-37 Pro build), adapted to V10.8.48; the board
details checked against genkigenki's hardware-proven SMK-37 layer (Felucca smk37) and porting reference.

- K1 MASTER, K2 SELECT, K3 ALGORITHM, K4 PRESETS, K5..K8 KNOB 1..4 (panel "PNS7"); the buttons as before
  (PATCH HOME / MENU held, PARA EDIT, CHORD ENV, NOTE REPEAT LFO, BT SAVE ...), < > the page.
- Keys: ids 5..31 are the FM-1's 27 keys again (fm1_in.notes), the outer ten go through seq.c's key path as keys
  27..36 (KB_NK 37 on the SMK: kb_map, key_on / key_off, CHORD, ARP, LATCH, recording, MIDI OUT), MIDI 48..84 at OCT 0;
  silent in a layer, NAME, the DRUM grid. A re-strike of a central key via notes_retrig. The pedal sustains the keys.
- Pads: KNOB BANK PLAY (the 16 white keys) <-> STEPS (the page's 16 steps, locks, the playhead); the change waits for
  the pads' release.
- Faders: FADER BANK LEVEL -> PAN -> REVERB -> DELAY of T1..T4, T5 / T6 selected: F1 F2; pick-up re-armed by a bank
  or window change.
- Wheels: a self-calibrating range on the measured travel (genkigenki: pitch ~445..640, mod ~474..629); the old
  0..1023 scaling gave a sixth of the bend and a quarter of MOD.
- TRS MIDI OUT on PC7 (UART1 TX, after Rhythmer's driver), following MENU > CONTROL > MIDI OUT; FELUCCA_SMK_TRS=0
  builds without it.
- Macros, track pads and page shortcuts of the first V10.8.48 SMK layout removed.

FM-1 build byte-identical (felucca.bin, .fwsc, ota.bin, bt.bin). SMK Pro 580664 B (3672 B free), Elite 580668 B.
tests/smk_map_test.c walks all 37 key ids through the HAL and the key path; docs/SMK37.md has the table and credits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UVqsRpEnNJfjWWrH3C4opq
This commit is contained in:
Claude committed 2026-11-27 16:23:00 +00:00
1 parent 906e3f0ba3
commit 0d353032fe
20 files changed
+3211 -2771

No files matched your search

+138 -87
View File
@@ -1,7 +1,7 @@
# JIANT FM on the M-VAVE SMK-37 Pro / Elite
**Status: experimental.** The previous SMK-37 build (main, v0.9.18 line) has run on one owner's unit. This one is
the port of that support to the public firmware **V10.8.48**, with a new control layout the owner approved. Everything
the port of that support to the public firmware **V10.8.48**, with **Rhythmer's control layout** (below). Everything
new here was built and checked on the host only: every item marked *untested on hardware* must be checked on a unit.
The SMK-37 has the same JieLi AC791N chip as the FM-1. It also has the same SPL and the same chip key (0x980F)
@@ -15,6 +15,17 @@ with hardware notes at https://github.com/genkigenki/fm1-to-smk37). `hal/smk_inp
owner tag, the LCD wiring, the pad LEDs and the panel table are adapted from Melodee and keep its attribution lines.
M-VAVE's open SMK firmware was used for hardware facts only. No M-VAVE SDK binary is linked or copied.
Credits for this layout and its hardware details (all GPL-3.0; adapted, their notices kept in the files' headers):
- **Rhythmer** by **Jazzy Rhythmer** (https://github.com/JazzyRhythmer/Rhythmer), a fork of JIANT for the FM-1 with an
SMK-37 Pro build (0.1.2-smk3 guide, 0.1.2 source): the control layout (K1..K8, the buttons, KNOB BANK's PLAY / STEPS
pads, FADER BANK's four banks with the T5 / T6 window and pick-up), all 37 keys through the original key path with
the outer ten as extra notes, and the TRS MIDI OUT driver (`smk_map.h`, `smk.c`, `smk_kb.c`, `smk_uart_tx.h`,
`smk_midi_out.h`).
- **genkigenki** (M. Geisler): the SMK-37 board layer (https://github.com/genkigenki/Felucca, branch `smk37`), which
`hal/smk_input.h` is, and the porting reference https://github.com/genkigenki/fm1-to-smk37 (`docs/01-hardware.md`:
the key matrix, the encoders' order, the pads' rows, the mux addresses, the wheels' measured ranges, the TRS MIDI
OUT pin).
## Build
```sh
@@ -41,93 +52,136 @@ What the SMK build changes:
| Bluetooth (`FELUCCA_BT`) | on: the segment at 0xEA000-0xFBFFF | **off** (`#error` if on): those sectors are the SMK's USRFLASH marker, store C and USR. GEN, the lyrics dictionary and the other code the FM-1 keeps in the segment are in the app image instead |
| USB HOST (`FELUCCA_USB_HOST`) | on | off (the keybed is the keyboard; its flash is needed) |
| TRS MIDI IN (UART1, PH8) | on | off: PH8 is a key-matrix row on the SMK (`#error` if turned on) |
| TRS MIDI OUT (`FELUCCA_SMK_TRS`) | none | on: UART1 TX on PC7, following MENU > CONTROL > MIDI OUT |
| key velocity | `src/vel.c`, `vel_diag.c` (the FM-1's carbon pills) | the HAL's two-contact time and pad peaks (`hal/smk_input.h`); MENU > CONTROL > VELOCITY sets its curve (OFF = 100) |
| LCD | SPI1 group B, PC7 CS, backlight PA2 | SPI1 group A: PB6 CLK, PB7 DO, PC8 CS, PB5 D/C, no backlight control |
| input HAL | `hal/fm1_input.h`, `hal/fm1_adc.h` | `hal/smk_input.h` (it stands in for `fm1_adc.h`: PB6 is the LCD clock) |
| the sound's pinned flash layout | `tools/audio_layout.txt` | `tools/audio_layout_smk37.txt` (its own, both models; `FELUCCA_REPIN=1` records it anew) |
The app slot (0x8EA90 bytes) is the FM-1's. The encrypted region still ends at 0x92FFE inside the SMK's
0x9D000 app area. The SMK image (V10.8.48 + SMK) is **581072 B of the 584336 B slot: 3264 B free**; RAM .data+.bss
92740 B of 98304; the pool's spare 11776 B; RAM code 32660 B of 34816. Everything SMK-only is compiled for the SMK
board only (`firmware/src/smk.c`, `smk_kb.c`, `smk_map.h`, `#if BOARD_SMK37`).
0x9D000 app area. The SMK image (V10.8.48 + SMK, Rhythmer's layout, TRS MIDI OUT) is **580664 B of the 584336 B
slot: 3672 B free** (Elite: 580668 B, 3668 B free; the TRS jack costs ~1.2 KB); RAM .data+.bss 92828 B of 98304; the
pool's spare 11552 B; RAM code 32184 B of 34816. Everything SMK-only is compiled for the SMK board only
(`firmware/src/smk.c`, `smk_kb.c`, `smk_map.h`, `smk_midi_out.h`, `hal/smk_uart_tx.h`, `#if BOARD_SMK37`).
## The control mapping (V10.8 layout)
## The control mapping (Rhythmer's layout)
The owner's layout: the keybed always plays, the pads are steps / tracks / shortcuts, the knobs and faders have banks.
The code: `firmware/src/smk.c` (UI side), `firmware/src/smk_kb.c` (audio side), `firmware/src/smk_map.h` (the rules,
host-tested), `firmware/src/panel.c` (the buttons and knobs).
The layout is **Rhythmer's** SMK-37 Pro layout (Rhythmer OS 0.1.2-smk3, a GPL-3.0 fork of JIANT for the FM-1 by
Jazzy Rhythmer), adapted to V10.8.48. The keybed goes through the FM-1's own key path, the pads are the FM-1's white
keys or the page's steps, the faders have four banks. The code: `firmware/src/smk.c` (UI side), `firmware/src/smk_kb.c`
(the keys' block's SMK step: the outer keys, the pedal, the wheels), `firmware/src/smk_map.h` (the rules, host-tested),
`firmware/src/seq.c` (the FM-1's key path, holding 37 keys on the SMK), `firmware/src/panel.c` (the buttons and knobs).
### Keys, wheels, pedal
| SMK-37 | JIANT |
| SMK-37 (printed) | JIANT V10.8.48 |
|---|---|
| the 37 keys (C3..C6, all of them, both ends) | **always play the selected track**, at the velocity they are struck with. OCT- / OCT+ (-3..+3, both: 0) move the whole keyboard: key 1 is C3 + 12 x OCT, key 37 C6 + 12 x OCT; the window is moved, never folded, so every key stays a note of its own in 0..127. They go in as MIDI in on the selected track's channel (the firmware's own MIDI path: ARP, recording, DRUM-X's MIDI map, MIDI LEARN, the matrix's VEL), and out to MIDI OUT as the FM-1's keys do. A key held while the track or the octave changes ends the note it started. They play chromatically (the FM-1 keys' SCL key maps, QNT WHITE / SNAP and CHORD, are the FM-1 keys'). |
| PITCH wheel | pitch bend on the selected track (its rest at power-on is the centre, a small dead zone; the track's bend range, RPN 0) |
| MOD wheel | CC1 on the selected track: the matrix's MOD WHEEL source (0 at its rest) |
| SUSTAIN pedal | CC64 on the selected track: the notes held while it is down (either polarity: its reading at power-on is "up") |
| another track picked | the old track's bend, CC1 and pedal let go; the new one gets them |
| K1 | **MASTER** (a virtual pot: 24 steps a detent, 724 at power-on) |
| K2 | **SELECT** (the section's pages) |
| K3 | **ALGORITHM** (the track, as on the FM-1) |
| K4 | **PRESETS** |
| K5..K8 | **KNOB 1..4** (the screen's four page knobs) |
| PATCH | HOME (held ~0.7 s: the MENU, as the FM-1's HOME) |
| PARA | EDIT |
| CHORD | ENV |
| NOTE REPEAT | LFO |
| SCALE / FX / GLOBE / ARP / SEQ | SCL / FX / GLO / ARP / SEQ |
| BT | SAVE (not Bluetooth) |
| SEQ PLAY | PLAY (again: STOP) |
| SEQ REC | REC |
| OCTAVE- / OCTAVE+ | OCT- / OCT+: the octave, and back / YES on action pages and dialogs, as on the FM-1 |
| < / > | the page before / after (one SELECT detent; not in a dialog) |
| KNOB BANK | the pads **PLAY <-> STEPS** (its LED lit in STEPS; blinking while a change waits for the pads) |
| FADER BANK | the faders **LEVEL -> PAN -> REVERB -> DELAY** (its LED lit for PAN, REVERB, DELAY) |
| the 37 keys | all through the FM-1's key path (below) |
| 16 pads | PLAY: the FM-1's 16 white keys; STEPS: the page's 16 steps (below) |
| F1..F4 | the bank's value of T1..T4; with T5 or T6 selected F1 / F2 are T5 / T6 (F3, F4 nothing) |
| PITCH / MOD wheels | pitch bend / modulation (CC1, the matrix's MOD WHEEL) of the selected track |
| SUSTAIN pedal | sustain (JIANT's; Rhythmer has none) |
| TRS MIDI OUT (3.5 mm) | what MENU > CONTROL > MIDI OUT sends over USB, also out of the jack, track n on channel n |
### Keys
All 37 keys go through the FM-1's **original key path** (`seq.c` keyboard_block, kb_map, key_on / key_off), with
velocity: SCL's key maps (QUANT WHITE / SNAP), CHORD, STRUM, ARP, LATCH, KEY SPLIT, recording, DRONE CLAY, MIDI OUT.
- **The central 27 (the 6th to the 32nd key, F3..G5)**, are the FM-1's 27 keys (`fm1_in.notes`): everything the FM-1's keys do
they do, on every page: the layers' shortcuts (GLO + G4 UNDO ...), NAME's letters, the DRUM grid, step entry while
stopped, SCENE.
- **The outer ten (C3..E3 and G#5..C6)** play extra notes: MIDI 48..52 and 80..84 at OCT 0 (the keybed is MIDI
48..84), moved by OCT, through the same key path (a DRUM track: a lane each). Where the FM-1's keys are the UI's
(a layer's button held, NAME, the DRUM grid) and under the splash they are silent.
- A key struck again before a full lift sounds again (a release, then the new note at its new velocity); a key held
while the track or the octave changes ends the note it started.
- Key ids: the HAL's key k (0 = C3 .. 36 = C6, genkigenki's matrix table, verified in use on an SMK-37 Pro); ids
5..31 are the FM-1's keys 0..26, ids 0..4 the key path's keys 27..31 and ids 32..36 keys 32..36 (Rhythmer's
order; `smk_map.h` smk_kb_key).
**SUSTAIN pedal**: a key let go while it is down keeps sounding until the pedal is up, or the key is struck again; it
is also CC64 on the selected track (for notes from MIDI) and to MIDI OUT. Either polarity: its reading at power-on is
"up". **Wheels**: as MIDI in on the selected track's channel (its bend range, RPN 0), and to MIDI OUT with the keys;
another track picked: the old one's bend, CC1 and pedal let go.
### Pads (16, velocity)
Pad n is hardware pad n - 1: **1..8 the top row, 9..16 the bottom row**, left to right. What they do depends on the
page (`smk_pads_rule`):
Pad n is hardware pad n - 1: **1..8 the top row, 9..16 the bottom row**, left to right (genkigenki: verified with
`padtest`). KNOB BANK picks what they are:
| where | the pads |
| KNOB BANK | the pads |
|---|---|
| a layer (a button held: GLO, SEQ, EDIT, FX, SCL, REC, SAVE ...), NAME, SEQ > STEP on a DRUM track (the grid), STEP FX, the song pages | **the FM-1's 16 white keys** F3..G5, pad n the n-th: the layers' shortcuts (GLO + pad 9 = G4 UNDO, SEQ + pad 16 = G5 CLR STEP, SAVE + pad 12 = C5 NAME ...), NAME's letters, the DRUM grid's steps 1..16 (hold + KNOB 1..4: a lock), STEP FX's components. Black-key functions are not on the pads. |
| the other SEQ pages (STEP, NOTE, PATTERN, EUCLID ... on a melodic track; the non-grid pages on DRUM) | **the 16 steps of the bar shown**: a pad on an empty step writes it (melodic: the keybed's last note at the pad's velocity; DRUM: the lane picked); on a full step it clears it when let go. **Hold a pad + K1..K4**: a parameter lock on that step (as the FM-1's held step; then it is not cleared). The cursor follows the pad. |
| everywhere else | **1..6** select track T1..T6 (an asleep T5 / T6 says so); **PATCH held + 1..6**: that track's **mute** (no HOME tap, no MENU); **7** UNDO (as GLO + G4); **8** TAP tempo (as GLO's TAP); **9..16** page shortcuts: 9 GLO > MIXER, 10 EDIT > FILTER, 11 ENV > ENV, 12 LFO > MOD (the matrix), 13 FX > DLY, 14 FX > REVERB, 15 HOME > SONG > ARRANGE, 16 HOME > GENERATOR (GEN) |
| the MENU, a dialog | nothing (dark) |
| **PLAY** (dark) | **the FM-1's 16 white keys** F3..G5, pad n the n-th: on each page they do what the FM-1's white keys do there (notes, the steps of SEQ's pages, the layers' shortcuts, NAME's letters, the DRUM grid, STEP FX ...), at the velocity they are hit with. |
| **STEPS** (lit) | **the 16 steps of the SEQ page shown** (the cursor's bar; the DRUM grid: the lane picked): a pad on an empty step writes it (melodic: the keys' last note at the pad's velocity; DRUM: the lane); on a full step it clears it when let go. **Hold a pad + KNOB 1..4 (K5..K8)**: a parameter lock on that step (then it is not cleared). In the MENU, a dialog, a layer or NAME the pads do nothing. |
The pads' LEDs show it: white keys as the FM-1's key LEDs (lit, blinking, the grid's glow); steps in the track's
colour (the cursor white, the playhead bright, past LEN dark, the first of each four dim); tracks in their colours
(the selected one bright, a muted one red, an asleep one dark), 7 / 8 dim white, the shortcuts dim blue (the page
shown bright).
Switching while a pad is held waits until every pad is let go (no stray note, no half a step). The pads' LEDs: PLAY
the FM-1 keys' picture (lit white, breathing blinking, the DRUM grid's glow); STEPS the steps in the track's colour,
the cursor white, **the playhead bright**, past LEN dark.
### Knobs, faders, buttons
### Faders
| SMK-37 (printed) | JIANT |
|---|---|
| K1..K4 | KNOB 1..4 (the page's four cards) |
| K5 | SELECT (the page chain) |
| K6 | PRESETS |
| K7 | ALGORITHM (the track) |
| K8 | MASTER (a virtual pot: 24 steps a detent, 724 at power-on) |
| **KNOB BANK** (its LED lit = MACROS) | K1..K8 become 8 fixed macros: **K1..K6 the cutoff of T1..T6** (the engine's own brightness as CC74 finds it, else the FILTER page's CUT), **K7 the delay's MIX**, **K8 the reverb's SIZE**. The screen says the bank, then each value (`T3 CUT 64`). Tap again: the page's knobs (and MASTER) back. |
| F1..F4, **FADER BANK** A (its LED dark) | the **levels of T1..T4** |
| F1..F4, FADER BANK B (its LED lit) | **T5 level, T6 level, the selected track's DLY send, its REV send** |
| faders: pick-up | a fader moves its value only once it meets it (within 2 / 127, or crossing it); until then the screen says `F2 PICK UP: UP` / `DOWN`. A value changed elsewhere (a knob, a load, the other bank) is picked up again. |
| < / > | the page before / after (one SELECT step) |
| FX | FX |
| SCALE | SCL |
| CHORD | ENV |
| NOTE REPEAT | LFO |
| PARA | EDIT |
| GLOBE | GLO |
| PATCH | HOME (and the mute modifier for pads 1..6) |
| BT | SAVE |
| ARP | ARP |
| SEQ | SEQ |
| SEQ PLAY | PLAY |
| SEQ REC | REC |
| OCTAVE- / OCTAVE+ | OCT- / OCT+ (the keybed's octave; back / YES on action pages and dialogs, as on the FM-1) |
V10.8.48's twelve FM-1 buttons are the same as before (HOME ENV LFO FX SCL EDIT GLO SAVE ARP SEQ PLAY REC), so the
printed-button table is the one the owner already uses; only K5..K8 changed (they were K5 MASTER, K6 SELECT,
K7 ALGORITHM, K8 PRESETS). The panel table's magic is now `PNS6`, so the old calibration is replaced by these defaults
once.
FADER BANK cycles **LEVEL -> PAN -> REVERB -> DELAY** (the reverb and delay sends) and the screen says the bank
(`FADERS PAN T1-T4`). F1..F4 are T1..T4; with T5 or T6 selected, F1 and F2 are T5 and T6 and F3, F4 do nothing.
**Pick-up**: a fader moves its value only once it meets it (within 2 / 127, or crossing it); until then the screen
says `F2 PICK UP: UP` / `DOWN`. A bank change, a change of track window, or the value changed elsewhere (a knob, a
load) arms the pick-up again, so loading a project never jumps to the faders' positions.
Other behaviour:
- OCTAVE- + OCTAVE+ held at power-on opens HARDWARE CALIBRATION. It asks for each FM-1 function by its printed SMK
name, and for the knobs by K5 (SELECT), K7 (ALGORITHM), K6 (PRESETS) and K1..K4. The table's magic is `PNS6`, so an
FM-1 table (or the previous SMK layout's) is never taken.
- OCTAVE- + OCTAVE+ held for 5 s enters UBOOT, as on the FM-1.
- A key struck again before a full lift sounds again (a release, then the new note at its new velocity).
name, and for the knobs by K2 (SELECT), K3 (ALGORITHM), K4 (PRESETS) and K5..K8. The table's magic is now `PNS7`,
so an older table (V10.8.48's first SMK layout `PNS6`, the FM-1's) is replaced by these defaults once.
- OCTAVE- + OCTAVE+ held for 5 s while running enters UBOOT, as on the FM-1 (a different path from the calibration).
- Button LEDs are on or off. What breathes on the FM-1 blinks at about 1 Hz here. The FM-1's dim idle glow has no
level on the SMK, so idle buttons are dark, as with MENU > LEDS OFF. MENU > LEDS INV lights the idle buttons, as
on the FM-1. SEQ PLAY shows its green LED while playing. KNOB BANK and FADER BANK light for MACROS and B.
on the FM-1. SEQ PLAY shows its green LED while playing.
- The screen texts still name the FM-1's controls (for example HOME, SCL, KNOB 1).
- MENU > CONTROL's AFTERTOUCH and VEL LEARN do nothing on the SMK (they are the FM-1's carbon pills).
- MENU > CONTROL's AFTERTOUCH and VEL LEARN do nothing on the SMK (they are the FM-1's carbon pills); VELOCITY sets
the keys' and pads' curve.
### TRS MIDI OUT
The 3.5 mm jack is a MIDI OUT (UART1 TX on PC7, 31250 baud; `firmware/hal/smk_uart_tx.h`, `firmware/src/smk_midi_out.h`,
after Rhythmer's driver; the pin and the register setup are the stock v016's as genkigenki documented them). It follows
**MENU > CONTROL > MIDI OUT** as USB does: KEYS (the keys, chords, the wheels and the pedal), CLOCK (and the clock with
START / STOP on the internal tempo), ALL (and the sequencer's and the arp's notes), OFF (the jack silent). Track n is
channel n. USB MIDI keeps working beside it. SysEx (the editor's, the update's) never goes to the jack. A full queue or
a UART that stops answering sends CC64 0 / CC120 / CC121 / CC123 on every channel rather than leave a note hanging;
after four timeouts in a row the jack stops until MIDI OUT is set again. A change of MIDI OUT lets the jack's held
notes go. Build without it: `FELUCCA_SMK_TRS=0`. *Untested on hardware* (the jack's signal, the adapter's wiring, the
timing).
## Hardware details from the references
JIANT's SMK board layer (`firmware/hal/smk_input.h`) is genkigenki's (via Melodee); it was compared with genkigenki's
Felucca `smk37` branch, its porting reference (`docs/01-hardware.md`) and Rhythmer's 0.1.2 source:
| item | genkigenki's status | JIANT |
|---|---|---|
| key matrix (37 x 2 contacts, k 0 = C3 .. 36 = C6) | verified in use | identical table; the outer keys' codes were right: the old build's silent ends were its routing (it drained them) |
| buttons (18), their printed names | verified | identical |
| encoders K1..K8 order | **verified** | identical (the old note "order to confirm" is gone) |
| pads: top row = hardware pads 0..7 (mux A) | verified (padtest) | identical |
| faders: mux C 0..3 -> F2 F3 F4 F1, full scale 1023 | verified | identical |
| wheels: PITCH mux C 4, rest ~535, travel ~445..640; MOD 5, ~474..629, up = lower | verified | **corrected**: JIANT scaled them on 0..1023 (a full bend needed 1023, so the real travel gave about a sixth of the bend and a quarter of MOD); now a self-calibrating range as genkigenki's and Rhythmer's (`smk_map.h`) |
| pedal: mux C 6, ~985 with nothing plugged | analysis | kept (either polarity from its power-on reading) |
| button LEDs, SEQ REC's at 0x1b | verified for the LEDs driven | identical (the table's 17 / 18 order as confirmed on a unit) |
| TRS MIDI OUT: UART1 TX, PC7, BAUD 383 | analysis | new, as Rhythmer's |
## Flash: RAM-only by default
@@ -198,30 +252,29 @@ steps, as they do on the unmodified V10.8.48 tree; the SMK steps pass when run a
- `tests/smk_ldr_test.c` checks the SMK update loader on a simulated SMK (and refuses an SMK package with a bt.bin).
- `tests/ota_test.c`, SMK build: staging at 0xBB000, the model's record, the board check.
- `tests/smk_pkg_test.py` checks the package: identity, size, region table, no bt.bin, and app.bin.
- `tests/smk_map_test.c` checks the control mapping: the buttons and knobs; **all 37 key ids through the HAL's queue and
`smk_kb.c`, at every octave and on every track: a distinct note each, on the selected track, at its velocity, its
release ending it** (also across a track / octave change, a re-strike, the splash); the wheels and the pedal; the
pads' rule, numbers and white keys; the banks' targets; the faders' pick-up.
- A check that every page shortcut of pads 9..16 is a page of its section's chain.
- `tests/smk_map_test.c` checks the control mapping: the printed buttons and K1..K8 ("PNS7"); **all 37 key ids
through the HAL and the key path** (`smk_kb.c` and keyboard_block's loop as seq.c has it): ids 5..31 as the FM-1's
keys, the outer ten through the queue, **at OCT -3..+3 on T1..T6 a key_on each of a note of its own (C3 + id + 12
OCT, both ends), at its velocity, its release a key_off on the track it started on**; a re-strike (central and
outer), a layer / NAME / the DRUM grid / the splash (the outer keys silent), a DRUM track; the pedal's sustain; the
wheels on genkigenki's measured ranges; the pads PLAY (white keys) / STEPS (the UI's) and KNOB BANK's change waiting
for the pads; FADER BANK's cycle, the T5 / T6 window, the pick-up's context and the pick-up.
- A check that seq.c's key path holds 37 keys on the SMK (`KB_NK`, the outer ten mapped, the 27 from smk_kb_block).
- `tests/smk_keys_test.c` is Melodee's keybed test, run on `hal/smk_input.h`.
## Untested on hardware
Everything that touches the SMK. In particular, new in this V10.8.48 port:
- **The outer keys.** The previous build played only F3..G5; the 10 outer keys (C3..E3 = key ids 0..4, G#5..C6 = ids
32..36) were drained, which is why the owner heard nothing from the first and last keys. They now play. Their matrix
codes are Melodee's stock table (`SMK_KEYC`, from M-VAVE's v016 firmware) and were never heard in JIANT: please
play C3, C#3, D3, D#3, E3 and G#5, A5, A#5, B5, C6 and report any key that is silent or plays the wrong note.
- Which mux C address is the PITCH wheel and which the MOD wheel (the HAL reads addresses 4 and 5; JIANT takes 4 as
PITCH, 5 as MOD), the wheels' ranges and the pitch wheel's centre, the pedal's address (6) and its reading pressed /
released (JIANT takes "far from the power-on reading" as pressed, either polarity; with no pedal plugged it must
read steady).
- The faders' addresses (0..3 -> F2 F3 F4 F1, Melodee's `SMK_FADMUX`) and direction (0 at the bottom assumed).
- The pads' numbering on the unit (JIANT: 1..8 the top row, 9..16 the bottom, as the HAL's mux A / B) and their
colours (WS2812 GRB order, the 250-byte latch).
- KNOB BANK's and FADER BANK's LEDs (LED ids 0 and 1 assumed to be under those buttons, as Melodee's table says).
- The encoders' K1..K8 order (Melodee: "K1..K8 order to confirm"); if K5..K8 come out swapped, HARDWARE CALIBRATION
re-teaches SELECT, ALGORITHM and PRESETS (not MASTER, which is fixed at encoder 7).
Everything that touches the SMK. In particular, new in this layout:
- **The keys through the key path**, the outer ten above all: please play C3, C#3, D3, D#3, E3 and G#5, A5, A#5, B5,
C6 (they are MIDI 48..52 and 80..84 at OCT 0) and report any that is silent or plays the wrong note. Their matrix
codes are genkigenki's verified table; the path from the queue to key_on is host-tested only.
- The pads in PLAY (the FM-1's white keys on every page) and STEPS (steps, locks, the playhead on the LEDs); KNOB
BANK's LED (LED id 0 under it, as genkigenki's table says) and FADER BANK's.
- The fader banks PAN / REVERB / DELAY and the T5 / T6 window; the faders' direction (0 at the bottom assumed).
- The wheels' self-calibration on other units (the ranges are one unit's), the pedal (address 6, either polarity;
with no pedal plugged it must read steady) and its sustain.
- **TRS MIDI OUT**: the jack's signal on PC7, the adapter's wiring (type A in a spec sheet, not measured), the timing,
USB MIDI beside it.
- The image without the Bluetooth segment: GEN, the lyrics dictionary and the rest of the segment's code now run from
the app image (never on an FM-1 that way).
- From before: the SMK SPL booting this app (as the previous build did on the owner's unit), the stock updater
@@ -232,10 +285,8 @@ Everything that touches the SMK. In particular, new in this V10.8.48 port:
## Not done yet
- TRS MIDI out on PC7.
- The factory velocity curves from USRTRIM (read-only).
- A boot-stub rescue (OCTAVE- at power-on).
- SMK models in `tools/fm1_install.py`, including refusing cross-model installs.
- An SMK mode for the browser emulator (this tree has no `web/emu/devices.html`).
- The keybed through the FM-1 keys' own path (SCL's key maps, CHORD, KEY SPLIT, step entry while stopped on STEP):
the keybed is MIDI in to the firmware, so those stay the FM-1 keys'.
- The outer ten keys in SCENE and in step entry while stopped (the central 27 have both, as the FM-1's keys).
+40 -21
View File
@@ -1,9 +1,12 @@
/* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments
* SMK-37 port: Copyright (C) 2026 M. Geisler (genkigenki/makkuro)
* (JIANT: Melodee's hal/smk_input.h, BOARD_SMK37 builds only; JIANT's additions and changes are marked "(JIANT)":
* the V10.8 layout sends all 37 keys through the queue, the pads are white keys only where the UI asks, K8 is MASTER.
* Untested on hardware in JIANT: docs/SMK37.md) */
* (JIANT: Melodee's hal/smk_input.h, BOARD_SMK37 builds only; JIANT's additions and changes are marked "(JIANT)".
* V10.8.48, Rhythmer's layout (Rhythmer by Jazzy Rhythmer, GPL-3.0; its board layer is genkigenki's
* github.com/genkigenki/Felucca smk37, as this one): keys 5..31 are the FM-1's 27 keys (fm1_in.notes), the 10 outer
* keys go through the queue to seq.c's key path too; the pads are the 16 white keys in PLAY, the UI's in STEPS;
* K1 is MASTER (genkigenki's place). Matrix codes, encoder order, pad rows, mux C addresses and the wheels' raw
* ranges: genkigenki's docs/01-hardware.md (verified on an SMK-37 Pro there). docs/SMK37.md) */
/* SMK-37 input HAL: velocity keybed, buttons, encoders, button LEDs, pads, faders, wheels.
* The FM-1 counterpart is fm1_input.h + fm1_adc.h; this header keeps their API (fm1_in, fm1_input_init,
* fm1_input_tick, fm1_input_scan, fm1_enc_take, fm1_input_edges, fm1_input_note_edges, fm1_led_key) so
@@ -90,7 +93,8 @@ static const uint8_t SMK_KEYC[FM1_NKEY][2] = {
* 10 GLOBE, 11 BT, 12 PATCH, 13 PARA, 14 FX, 15 SEQ, 16 SEQ PLAY, 17 SEQ REC */
static const uint8_t SMK_BTNC[FM1_NBTN] = {0x26, 0x76, 0x96, 0x56, 0x66, 0x36, 0x75, 0x65, 0x25,
0x45, 0x15, 0x86, 0x95, 0x55, 0x85, 0x35, 0x16, 0x46};
/* encoder i: A and B matrix codes (stock table; K1..K8 order to confirm) */
/* encoder i: A and B matrix codes (stock table; encoder i is the printed K(i+1): verified in this order on an SMK-37
* Pro, genkigenki's docs/01-hardware.md 5.4) */
static const uint8_t SMK_ENCC[FM1_NENC][2] = {{0x97, 0xa7}, {0x37, 0x47}, {0x17, 0x27}, {0xb7, 0xc7},
{0x57, 0x67}, {0x77, 0x87}, {0xd7, 0xe7}, {0xf7, 0x07}};
/* LED i (= button i): group << 4 | bit in the 595 low half (stock table, its order differs at the end).
@@ -113,9 +117,9 @@ static const uint8_t SMK_WHITE_NOTE[SMK_NPAD] = {0, 2, 4, 6, 7, 9, 11, 12, 14, 1
* layouts here: KEYS the 16 white keys, low notes on the bottom row; GRID the same as steps 1-8 on the top row and
* 9-16 below (the FM-1's grids: patterns, NAME, the layers); PIANO C4 .. C5 whites on top, the black keys between
* them below (C#4 D#4 - F#4 G#4 A#4 - C#5; SCALE held); NONE every pad the UI's */
/* (JIANT, V10.8 layout: docs/SMK37.md) only GRID and NONE are used: the keybed plays the notes, the pads are the
* white keys only where the FM-1 gives its keys to the UI (a layer, NAME, the DRUM grid, STEP FX, the song pages:
* firmware/src/smk.c smk_pads_mode); everywhere else every pad is the UI's (steps, tracks, page shortcuts) */
/* (JIANT, Rhythmer's layout: docs/SMK37.md) only GRID and NONE are used: PLAY (KNOB BANK dark) GRID, pad n the
* FM-1's n-th white key, 1..8 the top row (hardware pads 0..7, mux A: verified with padtest, genkigenki); STEPS (KNOB
* BANK lit) NONE, every pad the UI's: the page's 16 steps (firmware/src/smk.c) */
static const int8_t SMK_PK_GRID[SMK_NPAD] = {0, 2, 4, 6, 7, 9, 11, 12, 14, 16, 18, 19, 21, 23, 24, 26};
static const int8_t SMK_PK_NONE[SMK_NPAD] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
static const int8_t *volatile smk_pad_key = SMK_PK_NONE;
@@ -159,7 +163,7 @@ static volatile struct {
uint32_t notes_retrig; /* note keys struck again while down (their bit in notes stays set): seq.c restarts them */
uint64_t keys; /* all 37 keybed keys: bit k = key k (0 = lowest C), set while its note sounds */
uint8_t key_vel[FM1_NKEY]; /* MIDI velocity 1..127 of each key's last press */
uint8_t pad_vel[27]; /* (JIANT) a pad's velocity, by the white key it pressed (seq.c: kb_velx) */
uint8_t note_vel[27]; /* (JIANT) note key n's last press's velocity, a key's or a pad's (seq.c: kb_velx) */
uint8_t raw[FM1_NCOL]; /* last frame, rows packed, 1 = closed */
uint8_t cnt[FM1_NBTN]; /* button debounce */
uint8_t ks_stab[FM1_NKEY]; /* the contacts' settled state: 0 open, 1 contact 1, 3 both */
@@ -182,7 +186,8 @@ static volatile struct {
uint32_t frames;
} fm1_in;
/* key events beyond the FM-1's 27 (keybed keys 0..4 and 32..36): key << 8 | velocity (0 = release) */
/* key events beyond the FM-1's 27 (keybed keys 0..4 and 32..36): key << 8 | velocity (0 = release); a re-strike
* is a release and a press (JIANT: smk.c smk_kb_block plays them through seq.c's key path) */
#define SMK_EXTQ 32u
static volatile uint16_t smk_extq[SMK_EXTQ];
static volatile uint8_t smk_extq_w, smk_extq_r;
@@ -361,13 +366,26 @@ static void smk__extq(uint32_t k, uint32_t vel)
smk_extq_w = (uint8_t)((w + 1u) % SMK_EXTQ);
}
/* (JIANT, V10.8 layout) every one of the 37 keys goes to the queue: the audio block plays it on the selected track
* (firmware/src/smk.c smk_kb_block); none is an FM-1 key any more (fm1_in.notes: the pads alone) */
/* keys 5..31 (F3..G5) are the FM-1's 27 note keys (bits 0..26 of fm1_in.notes, with the pads as white keys): the
* keys' block (seq.c keyboard_block) and the UI (fm1_input_note_edges) take them as the FM-1's; the 10 outer keys
* (0..4 C3..E3, 32..36 G#5..C6) go to the queue (smk.c smk_kb_block: seq.c's key path, extra notes) */
static void smk__key_event(uint32_t k, uint32_t vel) /* vel 0 = release */
{
if (vel)
fm1_in.key_vel[k] = (uint8_t)vel;
smk__extq(k, vel);
if (k - SMK_KEY_F3 < 27u) {
uint32_t n = k - SMK_KEY_F3, bit = 1u << n;
if (vel) {
fm1_in.note_vel[n] = (uint8_t)vel;
fm1_in.knotes |= bit;
fm1_in.notes_pressed |= bit;
} else {
fm1_in.knotes &= ~bit;
}
fm1_in.notes = fm1_in.knotes | fm1_in.pnotes;
} else {
smk__extq(k, vel);
}
if (vel)
fm1_in.keys |= (uint64_t)1u << k;
else
@@ -380,8 +398,10 @@ static void smk__strike(uint32_t k, uint32_t now, uint32_t again)
{
uint32_t T = 10u + (now - fm1_in.ks_t1[k]) / (100u * FM1_TICKS_PER_US); /* stock 0.1 ms frames */
uint32_t x = T <= 0x3FEu ? 0x3FFu - T : 1u, v = smk_curve(smk_trim_key[k], x), vel = smk_vel7(v);
if (again) /* struck again while down: end it, then the new note */
smk__key_event(k, 0); /* (both through the queue) */
if (again && k - SMK_KEY_F3 < 27u) /* struck again while down: a note key's bit stays set, */
fm1_in.notes_retrig |= 1u << (k - SMK_KEY_F3); /* seq.c lets it go and strikes it again; */
else if (again)
smk__key_event(k, 0); /* an outer key: a release and a press in the queue */
smk__key_event(k, vel);
smk__log(k | (again ? 0x40u : 0u), vel, T, v);
}
@@ -546,13 +566,13 @@ static void smk__padq(uint32_t pad, uint32_t vel) /* a pad hit (vel) or rele
n = (uint32_t)n0;
bit = 1u << n;
if (vel) {
fm1_in.pad_vel[n] = (uint8_t)vel;
fm1_in.note_vel[n] = (uint8_t)vel;
fm1_in.pnotes |= bit;
fm1_in.notes_pressed |= bit;
} else {
fm1_in.pnotes &= ~bit;
}
fm1_in.notes = fm1_in.pnotes;
fm1_in.notes = fm1_in.knotes | fm1_in.pnotes;
}
static void smk__pad(uint32_t p, uint32_t raw)
@@ -758,12 +778,12 @@ static void fm1_led_key(uint32_t id, int on)
fm1_led[id] = (uint8_t)(on != 0);
}
/* fm1_adc.h stand-ins for main.c: the battery comes from mux C; the FM-1's MASTER pot is knob K5 here, as a
/* fm1_adc.h stand-ins for main.c: the battery comes from mux C; the FM-1's MASTER pot is knob K1 here, as a
* virtual pot (0..1023, 24 a detent; starts at 724: master_q12 2048, the level the firmware starts with) */
enum { FM1_ADC_BATT = 3, FM1_ADC_MASTER = 4 };
#define SMK_ENC_MASTER 7u /* (JIANT, V10.8 layout) K8: K1..K4 the page's knobs, K5 SELECT, K6 PRESETS, K7 ALGORITHM */
#define SMK_ENC_MASTER 0u /* K1, where the FM-1 has its MASTER pot (top left; Rhythmer's layout: K2 SELECT,
* K3 ALGORITHM, K4 PRESETS, K5..K8 the page's four knobs, panel.c) */
static int32_t smk_master = 724;
static uint8_t smk_kbank; /* (JIANT) KNOB BANK: 1 = K1..K8 the macros (smk.c); K8 is not the MASTER then */
static void fm1_adc_init(void) {}
static int32_t fm1_enc_take(uint32_t e);
static int32_t fm1_adc_read(uint32_t ch)
@@ -771,8 +791,7 @@ static int32_t fm1_adc_read(uint32_t ch)
if (ch == FM1_ADC_BATT)
return fm1_in.batt ? (int32_t)fm1_in.batt : -1;
if (ch == FM1_ADC_MASTER) {
if (!smk_kbank)
smk_master += fm1_enc_take(SMK_ENC_MASTER) * 24;
smk_master += fm1_enc_take(SMK_ENC_MASTER) * 24;
smk_master = smk_master < 0 ? 0 : smk_master > 1023 ? 1023 : smk_master;
return smk_master;
}
+38
View File
@@ -0,0 +1,38 @@
/* SPDX-License-Identifier: GPL-3.0-only
* SMK-37 TRS MIDI OUT: UART1 TX on PC7, after Rhythmer's hal/smk_uart_tx.h (Jazzy Rhythmer, 2026, GPL-3.0), whose
* register setup follows the stock v016 analysis documented by genkigenki: github.com/genkigenki/fm1-to-smk37
* docs/01-hardware.md section 9 (status there: analysis, not yet confirmed on a unit).
* (JIANT: BOARD_SMK37 builds only, src/smk_midi_out.h drives it. The registers are hal/fm1_uart.h's, the FM-1's
* verified UART1: CON0 0x12100, BAUD 0x12108 (383: 31250 baud from the 48 MHz UART clock), BUF 0x1210C, the UART
* clock in 0x10010 [11:10], IOMAP_CON3 0x51028.) No RX, no DMA, no interrupt: TIMER5 sends one byte at a time. */
#pragma once
#include <stdint.h>
#include "fm1_gpio.h"
#include "fm1_uart.h"
#define SMK_UT1_BUF (*(volatile uint32_t *)0x1210Cu)
static void smk_uart_tx_restart(void)
{
FM1_UT1_CON0 = 0x3400u; /* off, pendings cleared */
FM1_UT1_CON1 = 0;
FM1_UT1_BAUD = 48000000u / 31250u / 4u - 1u; /* 383 */
__asm__ volatile("csync" ::: "memory");
FM1_UT1_CON0 = 0x3401u; /* UTEN: TX only */
}
static void smk_uart_tx_init(void) /* before timer5_start() */
{
FM1_UM_CLK_CON1 = (FM1_UM_CLK_CON1 & ~(3u << 10)) | (1u << 10); /* the UART clock: PLL48M */
FM1_UM_IOMAP3 = (FM1_UM_IOMAP3 & ~(0x80u | (15u << 20))) | (1u << 20); /* UT1 TX onto its output channel */
FM1_PR(FM1_PC, FM1_PU) |= 1u << 7; /* (stock: PC7 pull-up and pull-down both set) */
FM1_PR(FM1_PC, FM1_PD) |= 1u << 7;
FM1_PR(FM1_PC, FM1_OUT) &= ~(1u << 7);
FM1_PR(FM1_PC, FM1_DIR) &= ~(1u << 7); /* an output */
FM1_PR(FM1_PC, FM1_DIE) |= 1u << 7;
smk_uart_tx_restart();
}
static int smk_uart_tx_done(void) { return (FM1_UT1_CON0 & 0x8000u) != 0u; } /* TPND: the last byte has gone */
static void smk_uart_tx_byte(uint8_t b)
{
FM1_UT1_CON0 |= 0x2000u; /* clear TPND */
SMK_UT1_BUF = b;
__asm__ volatile("csync" ::: "memory");
}
+6
View File
@@ -54,6 +54,12 @@
#define FELUCCA_BT 1 /* (V10.12) MENU > SYSTEM > BLUETOOTH: bt.c, bt_hw.c, the segment firmware/bt/bt_seg.c */
#endif
#endif
#ifndef FELUCCA_SMK_TRS
#define FELUCCA_SMK_TRS BOARD_SMK37 /* (SMK-37) TRS MIDI OUT on the 3.5 mm jack (UART1 TX, PC7: src/smk_midi_out.h) */
#endif
#if FELUCCA_SMK_TRS && !BOARD_SMK37
#error "FELUCCA_SMK_TRS is the SMK-37's jack (PC7 is the FM-1's LCD chip select)"
#endif
#if BOARD_SMK37 && FELUCCA_BT
#error "SMK-37: the Bluetooth segment would land on the SMK's USRFLASH / USR; FELUCCA_BT must be 0"
#endif
+6
View File
@@ -70,6 +70,9 @@ void fm1_timer5_irq(void)
#if FELUCCA_UART
if (owed & 2u)
uart_midi_poll();
#endif
#if BOARD_SMK37 && FELUCCA_SMK_TRS
smk_mo_poll(); /* (SMK-37) TRS MIDI OUT: a byte when the last has gone */
#endif
owed = 0;
}
@@ -348,6 +351,9 @@ static void fm1_main(void)
usb_start();
#if FELUCCA_UART
uart_midi_init();
#endif
#if BOARD_SMK37 && FELUCCA_SMK_TRS
smk_mo_init(); /* (SMK-37) TRS MIDI OUT: UART1 TX on PC7 */
#endif
boot_leds();
timer5_start();
+1 -1
View File
@@ -102,7 +102,7 @@ static int midi_note_held(const track_t *t, uint32_t note)
static int midi_local_held(const track_t *t, uint32_t note)
{
uint32_t k;
for (k = 0; k < 27u; k++)
for (k = 0; k < KB_NK; k++)
if (kb_on[k] && kb_trk[k] == trk_index(t)) { /* (0.6.81: a key's chord, the notes started) */
uint32_t i;
for (i = 0; i < kb_on[k]; i++)
+9 -9
View File
@@ -12,13 +12,13 @@ enum { B_FX, B_SCL, B_ENV, B_LFO, B_EDIT, B_GLO, B_HOME, B_SAVE, B_ARP, B_SEQ, B
enum { EN_SELECT, EN_ALGO, EN_PRESET, EN_K1, EN_K2, EN_K3, EN_K4, NE };
#if BOARD_SMK37
/* (SMK-37, after Melodee's panel.c) HARDWARE CALIBRATION asks for each FM-1 function by the control that has it by
* default (PANEL_DEFAULT): the printed button names, and (V10.8 layout, docs/SMK37.md) K5 SELECT, K7 ALGORITHM,
* K6 PRESETS, K1..K4 for KNOB 1..4 (K8 is MASTER, hal/smk_input.h) */
* default (PANEL_DEFAULT): the printed button names, and (Rhythmer's layout, docs/SMK37.md) K2 SELECT, K3 ALGORITHM,
* K4 PRESETS, K5..K8 for KNOB 1..4 (K1 is MASTER, hal/smk_input.h) */
static const char *const B_NAME[NB] = {"FX", "SCALE", "CHORD", "NOTE REPEAT", "PARA", "GLOBE", "PATCH", "BT",
"ARP", "SEQ", "SEQ PLAY", "SEQ REC", "OCTAVE-", "OCTAVE+"};
static const char *const E_NAME[NE] = {"K5", "K7", "K6", "K1", "K2", "K3", "K4"};
#define PANEL_MAGIC 0x504E5336u /* "PNS6" (SMK-37, the V10.8 layout; "PNS5" was K6 SELECT K7 ALGO K8 PRESETS):
* bump when PANEL_DEFAULT changes */
static const char *const E_NAME[NE] = {"K2", "K3", "K4", "K5", "K6", "K7", "K8"};
#define PANEL_MAGIC 0x504E5337u /* "PNS7" (SMK-37, Rhythmer's layout; "PNS6" was K5 SELECT K6 PRESETS K7 ALGO,
* "PNS5" K6 SELECT K7 ALGO K8 PRESETS): bump when PANEL_DEFAULT changes */
#define PANEL_NBTN FM1_NBTN /* the matrix's buttons (18) and encoders (8): hal/smk_input.h */
#define PANEL_NENC FM1_NENC
typedef uint32_t ui_btnmask_t; /* a mask of button ids (0..17) */
@@ -45,13 +45,13 @@ panel_t panel __attribute__((section(".noinit")));
/* (SMK-37, Melodee's table; hal/smk_input.h's button ids, confirmed by Melodee on an Elite) the printed SMK label ->
* the FM-1 function: FX = FX, SCALE = SCL, CHORD = ENV, NOTE REPEAT = LFO, PARA = EDIT, GLOBE = GLO, PATCH = HOME,
* BT = SAVE, ARP and SEQ as printed, SEQ PLAY = PLAY, SEQ REC = REC, OCTAVE- / + = OCT- / OCT+. KNOB BANK, FADER BANK,
* < and > are the SMK's own (smk.c smk_input_frame). Knobs (V10.8 layout): K1..K4 = KNOB 1..4, K5 = SELECT,
* K6 = PRESETS, K7 = ALGORITHM, K8 = MASTER. HARDWARE CALIBRATION (OCTAVE- + OCTAVE+ at power-on) re-teaches all of
* it but MASTER. */
* < and > are the SMK's own (smk.c smk_input_frame). Knobs (Rhythmer's layout; the encoders' order K1..K8 is
* genkigenki's, verified on a unit): K1 = MASTER, K2 = SELECT, K3 = ALGORITHM, K4 = PRESETS, K5..K8 = KNOB 1..4.
* HARDWARE CALIBRATION (OCTAVE- + OCTAVE+ at power-on) teaches all of it again but MASTER. */
static const panel_t PANEL_DEFAULT = {
PANEL_MAGIC,
{14, 8, 9, 7, 13, 10, 12, 11, 6, 15, 16, 17, 4, 5},
{4, 6, 5, 0, 1, 2, 3},
{1, 2, 3, 4, 5, 6, 7},
{1, 1, 1, 1, 1, 1, 1},
};
#else
+45 -14
View File
@@ -42,11 +42,21 @@ static const uint16_t SCALE_MASK[] = {
};
#define KB_SILENT 255u
#if BOARD_SMK37
#include "smk_map.h" /* (SMK-37) the keybed's keys as the key path's (smk_kb_off) */
#define KB_NK 37u /* (SMK-37) the FM-1's 27 keys and the keybed's outer ten (smk_kb.c, smk_map.h) */
#define KB_BIT(k) ((uint64_t)1u << (k))
typedef uint64_t kb_bits_t;
#else
#define KB_NK 27u
#define KB_BIT(k) (1u << (k))
typedef uint32_t kb_bits_t;
#endif
static uint32_t kb_prev;
static volatile uint8_t kb_boot_hold; /* #137: set from power-on to the end of the splash (main.c): the keys sound nothing,
* and one held across its end stays silent until it is let go and pressed again */
static uint8_t kb_note[27], kb_trk[27]; /* per key: the note it started and on which track */
static int8_t kb_oct[27]; /* (0.8.5) .. on a DRUM track, the kit's octave it plays (OCT then: seq.c dxo_on) */
static uint8_t kb_note[KB_NK], kb_trk[KB_NK]; /* per key: the note it started and on which track */
static int8_t kb_oct[KB_NK]; /* (0.8.5) .. on a DRUM track, the kit's octave it plays (OCT then: seq.c dxo_on) */
static volatile uint8_t kb_asleep; /* MENU > SCREEN OFF (ui.c): the screen dark or waking, a key pressed now only
* wakes it (silent, no layer, its release nothing) */
static uint8_t last_note = 60;
@@ -134,7 +144,8 @@ static uint32_t mo_key(const track_t *t) /* a key's note goes out: not with OF
* its channel and its note-off not yet. A note let go ends there if it went out, whatever MIDI OUT or the ARP are by
* then (they were asked again at the key-up: a note-on out with no note-off); kb_lt bit k: key k's press latched (LATCH
* then: a HOLD turned on under a key latched nothing, its key-up left the voice sounding for good) */
static uint32_t mo_ks[NTRK][4] __attribute__((section(".pool"))), kb_lt __attribute__((section(".pool")));
static uint32_t mo_ks[NTRK][4] __attribute__((section(".pool")));
static kb_bits_t kb_lt __attribute__((section(".pool")));
static void mo_kon(uint32_t i, uint32_t x, uint32_t vel) /* key note x of track i out (note-on) */
{
mo_ks[i % NTRK][(x >> 5) & 3u] |= 1u << (x & 31u);
@@ -251,7 +262,7 @@ static __attribute__((noinline)) void mo_block(uint32_t n) /* events_block: th
* track routing one takes it off the pitch (OCT+: no bend, nor its pitch bend out; OCT-: no pitch vibrato, CC1 still) */
#include "vel_kb.h" /* (V10.6z6) the keys' velocity and pressure */
_Static_assert(VK_NTRK == NTRK, "vel_kb.h VK_NTRK: the tracks");
static uint8_t kb_on[27]; /* (below: how many of a key's notes sound) */
static uint8_t kb_on[KB_NK]; /* (below: how many of a key's notes sound) */
static volatile uint8_t kx_g[2] KX_BSS; /* the keys' gates: tracks (bit i) with OCT- (vibrato), OCT+ (bend) held */
/* (kx_semi, kx_amt, kx_ph: mod.c, the sources OCT+ / OCT- read them) */
static uint8_t kx_mo[NTRK][2] KX_BSS; /* MIDI OUT's last CC1, bend MSB - 64 */
@@ -355,9 +366,19 @@ static uint32_t kb_map(const track_t *t, uint32_t k)
static const int8_t DEGREE[12] = {0, -1, 1, -1, 2, 3, -1, 4, -1, 5, -1, 6};
const engine_t *e = ENGINES[eng_idx(t->eng_req)]; /* (the engine it switches to) */
int32_t n;
#if BOARD_SMK37
if (k >= 27u) { /* (SMK-37) an outer key (smk_map.h): a DRUM track's lanes, */
if (drum_track(t)) /* else its note, C3..E3 / G#5..C6 at OCT 0 */
return DRUM_LANE_NOTE[(k - 27u) % NLANE];
n = 53 + smk_kb_off(k);
} else {
#endif
if (e->keys && (n = e->keys(t, k)) >= 0) /* the engine's own key map (DRUM's GM map, slices) */
return (uint32_t)n;
n = 53 + (int32_t)k;
#if BOARD_SMK37
}
#endif
if (t->p[P_QUANT] == QN_SNAP || t->p[P_QUANT] == QN_SEQ) /* SNAP (and SEQ): every key, rounded down */
return (uint32_t)clamp(scale_snap(t, n + 12 * song.octave), 0, 127); /* (0.6.81: TRANS as it sounds, voice.c) */
if (t->p[P_QUANT] == QN_WHITE) { /* WHITE: white keys walk the scale, black keys are silent */
@@ -389,8 +410,8 @@ static uint32_t kb_map(const track_t *t, uint32_t k)
/* the notes key k plays (kb_sn: how many, its chord; kb_on: how many of them started, the rest strummed in later) */
#define KB_CH 4u
static uint8_t kb_snd[27][KB_CH], kb_sn[27], kb_on[27];
static uint16_t kb_sdue[27]; /* (0.6.81) samples to the strum's next note */
static uint8_t kb_snd[KB_NK][KB_CH], kb_sn[KB_NK], kb_on[KB_NK];
static uint16_t kb_sdue[KB_NK]; /* (0.6.81) samples to the strum's next note */
/* (V10.6z6) key velocity (vel_kb.h KB_VEL: each key's press's, 100 with VELOCITY OFF; its chord, strum, recording and
* MIDI OUT use it) */
#define ARP_VEL(t) (vs.arpv[trk_index(t)] ^ 100u) /* (stored ^ 100: 0, as zeroed, 100) */
@@ -1611,10 +1632,14 @@ static void key_next(uint32_t k, track_t *t)
static int clay_kb(uint32_t k, track_t *t); /* (clay.c, V10.8.31: DRONE CLAY ON, KEYS ON: the keys its gestures) */
static void key_on(uint32_t k, track_t *t)
{
#if BOARD_SMK37
if (k < 27u && clay_kb(k, t)) /* (SMK-37: DRONE CLAY has the FM-1's 27 keys) */
#else
if (clay_kb(k, t))
#endif
return;
uint32_t n = chord_build(t, kb_note[k], kb_snd[k]), gap = n > 1u ? chord_gap(t) : 0u, i;
kb_lt = key_latch(t) ? kb_lt | 1u << k : kb_lt & ~(1u << k);
kb_lt = key_latch(t) ? kb_lt | KB_BIT(k) : kb_lt & ~KB_BIT(k);
if (key_latch(t)) { /* LATCH: a new chord lets the last one go */
uint32_t j;
if (!t->arp_phys)
@@ -1645,7 +1670,7 @@ static void key_on(uint32_t k, track_t *t)
static void keys_strum(uint32_t n)
{
uint32_t k;
for (k = 0; k < 27u; k++) {
for (k = 0; k < KB_NK; k++) {
if (kb_on[k] >= kb_sn[k] || !kb_on[k])
continue;
if (kb_sdue[k] > n) {
@@ -1856,7 +1881,12 @@ static __attribute__((noinline)) void scene_follow(track_t *lt, uint32_t note, u
/* (the keys' block is RAM code: SCENE's call goes through a pointer, out of the direct calls' +-4 MiB reach check;
* a key event, not every block) */
static void (*volatile scene_fp)(uint32_t, int) = scene_key;
static void (*volatile key_off_fp)(uint32_t, track_t *) = key_off; /* (stuck notes: a key-up's, likewise) */
#if BOARD_SMK37
static void smk_key_up(uint32_t k, track_t *t); /* (smk_kb.c: the pedal holds it) */
static void (*volatile key_off_fp)(uint32_t, track_t *) = smk_key_up;
#else
static void (*volatile key_off_fp)(uint32_t, track_t *) = key_off;
#endif /* (stuck notes: a key-up's, likewise) */
#ifdef FM1_INPUT_LAT
/* the press latency stats (hal/fm1_input.h fm1_in_stat, console `inp`): from the first scan that saw
@@ -1877,16 +1907,17 @@ static __attribute__((noinline)) void kb_lat(uint32_t k)
#endif
#if BOARD_SMK37
static void smk_kb_block(void); /* (smk.c) */
static uint32_t smk_kb_block(void); /* (smk_kb.c) */
#endif
static void keyboard_block(void)
{
uint32_t cur = fm1_in.notes & ~vk_hold, ch, k; /* (V10.6z6: a press waiting for its strike, vel_kb.h: not yet) */
uint32_t lay, fx;
#if BOARD_SMK37
smk_kb_block(); /* (SMK-37, smk.c) the keybed, the wheels and the pedal: MIDI in on the
* selected track; the pads' velocities as the white keys' */
uint32_t cur = smk_kb_block(), ch, k; /* (SMK-37, smk_kb.c) the 27 keys (a re-strike let go first), their
* velocities; the outer ten, the wheels and the pedal played there */
#else
uint32_t cur = fm1_in.notes & ~vk_hold, ch, k; /* (V10.6z6: a press waiting for its strike, vel_kb.h: not yet) */
#endif
uint32_t lay, fx;
keys_strum(CTL); /* (0.6.81) the chords' strums */
ch = cur ^ kb_prev; /* keys also sound while entering steps */
if (!ch)
+98 -216
View File
@@ -1,21 +1,21 @@
/* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) */
/* (SMK-37, BOARD_SMK37 builds only: felucca.c includes it after ui_layer.c) The SMK-37's own controls in the V10.8
* layout the owner approved (docs/SMK37.md "The control mapping"; the pure rules: smk_map.h):
* KEYBED the 37 keys always play the selected track, at their velocity, C3..C6 moved by OCT- / OCT+ (song.octave):
* as MIDI in on the selected track's channel (seq.c midi_event: notes, ARP, recording, DRUM's MIDI map),
* from the audio block (smk_kb_block, seq.c keyboard_block), their notes to MIDI OUT as the FM-1's keys'
* WHEELS PITCH: pitch bend, MOD: CC1 (the matrix's MOD WHEEL), PEDAL: CC64 (the notes held), the selected track's
* PADS smk_map.h smk_pads_rule: the FM-1's white keys where the FM-1's keys are the UI's, the steps on the
* other SEQ pages, else the tracks, UNDO, TAP and eight page shortcuts
* K1..K8 KNOB 1..4, SELECT, PRESETS, ALGORITHM, MASTER (panel.c, hal/smk_input.h); KNOB BANK: the 8 macros
* F1..F4 FADER BANK A / B (smk_map.h SMK_FADER), with pick-up
* Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant)
* The layout is Rhythmer's SMK-37 Pro layout, adapted to V10.8.48: Rhythmer (a GPL-3.0 fork of JIANT for the FM-1) by
* Jazzy Rhythmer (its smk_runtime.c: KNOB BANK's PLAY / STEPS pads, FADER BANK's four banks and track window with
* pick-up); the board layer under it is genkigenki's (github.com/genkigenki/Felucca smk37, the porting reference
* github.com/genkigenki/fm1-to-smk37). */
/* (SMK-37, BOARD_SMK37 builds only: felucca.c includes it after ui_layer.c) The SMK-37's own controls
* (docs/SMK37.md "The control mapping"; the pure rules: smk_map.h):
* KEYBED all 37 keys through the FM-1's key path (smk_kb.c, seq.c keyboard_block): the central 27 are the FM-1's
* keys, the outer ten extra notes (C3..E3, G#5..C6 at OCT 0), at their velocity
* WHEELS pitch bend and MOD (CC1) of the selected track; PEDAL: sustain (smk_kb.c)
* PADS KNOB BANK: PLAY (the FM-1's 16 white keys) <-> STEPS (the page's 16 steps; KNOB BANK lit)
* K1..K8 MASTER, SELECT, ALGORITHM, PRESETS, KNOB 1..4 (hal/smk_input.h, panel.c)
* F1..F4 FADER BANK: LEVEL -> PAN -> REVERB -> DELAY of T1..T4 (T5 / T6 selected: F1 F2 = T5 T6), with pick-up
* < > one SELECT detent each (the page before / after)
* Untested on hardware: see docs/SMK37.md. */
#include "smk_map.h"
_Static_assert(SMK_S_HOME == SEC_HOME && SMK_S_EDIT == SEC_EDIT && SMK_S_SEQ == SEC_SEQ && SMK_S_FX == SEC_FX &&
SMK_S_GLO == SEC_GLO && SMK_S_ENV == SEC_ENV && SMK_S_LFO == SEC_LFO, "smk_map.h: the sections' order");
_Static_assert(FM1_NKEY == SMK_KEYS, "smk_map.h: the keybed's 37 keys");
_Static_assert(FM1_NKEY == SMK_KEYS && SMK_KEY_F3 == SMK_KB_F3 && KB_NK == SMK_KEYS, "smk_map.h: the keybed's 37 keys");
/* --------------------------------------------------------------- velocity --- */
/* MENU > CONTROL > VELOCITY (vel_kb.h VEL_SET: OFF SOFT NORMAL HARD) as the HAL's curve (hal/smk_input.h smk_vel_curve:
@@ -31,119 +31,73 @@ static void vel_poll(void)
/* ------------------------------------------------------------- the UI side --- */
static struct {
uint8_t mode; /* the pads now (SMK_PM_*) */
uint8_t fbank; /* FADER BANK: 0 A, 1 B */
smk_pads_t pads; /* KNOB BANK: PLAY / STEPS (and a change waiting for the pads' release) */
uint8_t fbank; /* FADER BANK: SMK_FB_* */
uint8_t fctx; /* the pick-ups' context (bank, track window) + 1: 0 none yet */
uint8_t ptrk; /* STEPS: the track the held pads' steps are on */
uint8_t fval[4]; /* the faders as last read */
uint16_t held; /* STEPS: the pads held (bit n - 1) */
uint16_t used; /* .. held for a lock (a knob turned): no toggle when let go */
uint16_t drop; /* .. whose step had something: cleared when let go, unless used */
uint8_t note; /* STEPS: a melodic step's note (the keybed's last) */
uint8_t init; /* the pick-ups reset (the pool is zeroed at boot: last 0 would read as a fader) */
uint8_t note; /* STEPS: a melodic step's note (the keys' last) */
smk_pick_t pick[4];
} smk __attribute__((section(".pool")));
static int smk_seq_page(void) { return !ui.home && !ui.menu && cur_page()->fam == FAM_SEQ; }
static uint32_t smk_pads_mode(void)
/* fader f's value: the track's LEVEL, PAN, REVERB or DELAY send; 0..127 over its range */
static const uint8_t SMK_FB_P[SMK_FB_N] = {P_LEVEL, P_PAN, P_REV, P_DLY};
static const char *const SMK_FB_NM[SMK_FB_N] = {"LEVEL", "PAN", "REVERB", "DELAY"};
static uint32_t smk_fv(track_t *t, uint32_t id, int32_t *lo, int32_t *hi)
{
return smk_pads_rule(ui.menu || dlg_on(), ui.ly || ui.layer || keys_own() || keys_mode() != 0u, smk_seq_page());
const param_desc_t *d = track_desc(t, id);
*lo = d->min, *hi = d->max;
return *hi > *lo ? (uint32_t)clamp((t->p[id] - *lo) * 127 / (*hi - *lo), 0, 127) : 0u;
}
/* target t: its value now, 0..127 over its range, and a turn / a fader's value set; *nm its name for the screen */
static track_t *smk_tgt_trk(smk_tgt_t t) { return &trk[t.trk == SMK_T_SEL ? song.sel % NTRK : t.trk % NTRK]; }
static uint32_t smk_tgt_id(smk_tgt_t t)
static void smk_bank_say(void)
{
track_t *k = smk_tgt_trk(t);
uint32_t e;
switch (t.what) {
case SMK_TG_LEVEL: return P_LEVEL;
case SMK_TG_DSEND: return P_DLY;
case SMK_TG_RSEND: return P_REV;
case SMK_TG_DMIX: return G_DMIX;
case SMK_TG_RSIZE: return G_RSIZE;
default: /* CUT: as CC74 (midi_control.c midi_cc_map), else the FILTER page's CUT */
e = MIDI_CC_ENG[eng_idx(k->eng_req)] >> 4 & 15u;
return e ? P_E0 + e - 1u : P_FCUT;
char b[20];
str_cpy(b, "FADERS ", sizeof b);
str_cpy(b + 7, SMK_FB_NM[smk.fbank % SMK_FB_N], sizeof b - 7);
ui_say(b, song.sel >= 4u ? " T5 T6" : " T1-T4");
}
static void smk_faders(void)
{
uint32_t f, ctx = smk_fader_ctx(smk.fbank, song.sel) + 1u, id = SMK_FB_P[smk.fbank % SMK_FB_N];
if (ctx != smk.fctx) { /* another bank or track window: picked up again */
for (f = 0; f < 4u; f++)
smk_pick_reset(&smk.pick[f]);
if (smk.fctx && (smk.fctx - 1u) / 2u == smk.fbank)
smk_bank_say(); /* (the window moved: say so; a bank change says it itself) */
smk.fctx = (uint8_t)ctx;
}
}
static void smk_tgt_range(smk_tgt_t t, int16_t **vp, int32_t *lo, int32_t *hi)
{
uint32_t id = smk_tgt_id(t);
if (t.trk == SMK_T_G) {
*vp = &song.g[id];
*lo = GP[id].min, *hi = GP[id].max;
} else {
const param_desc_t *d = track_desc(smk_tgt_trk(t), id);
*vp = &smk_tgt_trk(t)->p[id];
*lo = d->min, *hi = d->max;
}
}
static uint32_t smk_tgt_get(smk_tgt_t t)
{
int16_t *vp;
int32_t lo, hi;
smk_tgt_range(t, &vp, &lo, &hi);
return hi > lo ? (uint32_t)clamp((*vp - lo) * 127 / (hi - lo), 0, 127) : 0u;
}
static void smk_tgt_say(smk_tgt_t t, int32_t v)
{
static const char *const NM[6] = {"LEVEL", "CUT", "DLY SEND", "REV SEND", "DLY MIX", "REV SIZE"};
char b[24];
if (t.trk == SMK_T_G) {
b[0] = 0;
} else {
b[0] = 'T', b[1] = (char)('1' + (smk_tgt_trk(t) - trk)), b[2] = ' ', b[3] = 0;
}
str_cpy(b + str_len(b), NM[t.what % 6u], sizeof b - str_len(b));
str_cpy(b + str_len(b), " ", sizeof b - str_len(b));
fmt_int(b + str_len(b), v);
ui_message(b);
}
static void smk_tgt_put(smk_tgt_t t, int32_t v) /* v: the value itself */
{
int16_t *vp;
int32_t lo, hi;
smk_tgt_range(t, &vp, &lo, &hi);
v = clamp(v, lo, hi);
if (*vp == v)
if (fm1_in.frames < 128u) /* (~0.2 s: the faders' filters settle from 0 first, no false cross) */
return;
*vp = (int16_t)v;
if (t.trk != SMK_T_G)
motion_capture(smk_tgt_trk(t), smk_tgt_id(t), (int16_t)v); /* (recorded as a knob move, armed and playing) */
smk_tgt_say(t, v);
}
static void smk_macro_turn(uint32_t k, int32_t s)
{
smk_tgt_t t = SMK_MACRO[k & 7u];
int16_t *vp;
int32_t lo, hi;
smk_tgt_range(t, &vp, &lo, &hi);
smk_tgt_put(t, *vp + accel(EN_K1 + (k & 3u), s, hi - lo));
}
static void smk_page(uint32_t n) /* pad n (9..16): its page */
{
const ch_t *c;
uint32_t i = n - SMK_PAD_PAGE0, sec = SMK_PAGES[i % 8u].sec, e;
c = nav_ch(sec);
for (e = 0; e < c->n; e++) {
const char *nm = c->e[e].nm ? c->e[e].nm : c->e[e].t;
if (nm && str_eq(nm, SMK_PAGES[i % 8u].nm) && nv_ok(sec, e)) {
nav_go(sec, e, nav_sec() != sec);
return;
for (f = 0; f < 4u; f++) {
uint32_t v = fm1_in.fader[f], first = smk.pick[f].last == 0xFFu, cur;
int ti = smk_fader_track(f, song.sel);
int32_t lo, hi;
track_t *t;
if (ti < 0 || (v == smk.fval[f] && !first))
continue;
smk.fval[f] = (uint8_t)v;
t = &trk[ti];
cur = smk_fv(t, id, &lo, &hi);
if (smk_pickup(&smk.pick[f], v, cur)) {
int32_t x = clamp(lo + ((int32_t)v * (hi - lo) + 63) / 127, lo, hi);
char b[24];
if (t->p[id] == x)
continue;
t->p[id] = (int16_t)x;
motion_capture(t, id, (int16_t)x); /* (recorded as a knob move, armed and playing) */
b[0] = 'T', b[1] = (char)('1' + ti), b[2] = ' ', b[3] = 0;
str_cpy(b + 3, SMK_FB_NM[smk.fbank % SMK_FB_N], sizeof b - 3);
str_cpy(b + str_len(b), " ", sizeof b - str_len(b));
fmt_int(b + str_len(b), x);
ui_message(b);
} else if (!first) { /* (moved, not yet met: which way to go) */
char m[8] = {'F', (char)('1' + f), ' ', 0};
ui_say(m, cur > v ? "PICK UP: UP" : "PICK UP: DOWN");
}
}
ui_message("NO SUCH PAGE HERE");
}
static int smk_page_shown(uint32_t n) /* the page of pad n is the one shown */
{
uint32_t i = n - SMK_PAD_PAGE0, sec = SMK_PAGES[i % 8u].sec, e;
const ch_t *c;
if (ui.menu || nav_sec() != sec)
return 0;
c = nav_ch(sec);
e = nav_cur();
return e < c->n && str_eq(c->e[e].nm ? c->e[e].nm : c->e[e].t ? c->e[e].t : "", SMK_PAGES[i % 8u].nm);
}
/* STEPS: pad n's step on the page shown (the bar of the cursor, ui.bank) */
@@ -209,105 +163,44 @@ static uint64_t smk_steps_held(void)
m |= (uint64_t)1 << smk_step_of(n);
return m;
}
static void smk_tracks_press(uint32_t n)
{
char b[16];
if (n <= NTRK) {
uint32_t i = n - 1u;
if ((fm1_in.buttons >> panel.btn[B_HOME]) & 1u) { /* PATCH (HOME) held: the mute; no HOME tap, no MENU */
ui.home_t0 |= 2u;
trk[i].p[P_MUTE] = (int16_t)!trk[i].p[P_MUTE];
b[0] = 'T', b[1] = (char)('1' + i), b[2] = 0;
ui_say(b, trk[i].p[P_MUTE] ? " MUTED" : " ON");
} else if (i >= trk_live) {
ui_message("T5-T6 ASLEEP: TRACKS 6");
} else {
track_select(i);
}
} else if (n == SMK_PAD_UNDO) {
undo_ui();
} else if (n == SMK_PAD_TAP) {
glo_tap();
if (!song.g[G_CLOCK]) {
str_cpy(b, "TAP ", sizeof b);
fmt_int(b + 4, song.g[G_BPM]);
ui_message(b);
}
} else if (n >= SMK_PAD_PAGE0 && n <= 16u) {
smk_page(n);
}
}
static int smk_steps_off(void) { return ui.menu || dlg_on() || ui.layer || name_on(); } /* STEPS: the pads idle */
/* each UI frame, first (ui_input.c ui_input_frame) */
static void smk_input_frame(uint32_t *pressed)
{
uint32_t labels = 0, b, mode, f;
uint32_t labels = 0, b, f, down = 0;
int32_t d = (int32_t)((*pressed >> SMK_BTN_RIGHT) & 1u) - (int32_t)((*pressed >> SMK_BTN_LEFT) & 1u), e;
for (b = 0; b < NB; b++)
labels |= 1u << panel.btn[b];
if (d && !((labels >> SMK_BTN_LEFT) & 1u) && !((labels >> SMK_BTN_RIGHT) & 1u)) { /* < >: a SELECT detent */
if (d && !((labels >> SMK_BTN_LEFT) & 1u) && !((labels >> SMK_BTN_RIGHT) & 1u) && !dlg_on()) { /* < >: SELECT */
uint32_t l = fm1__lock();
fm1_in.enc_steps[panel.enc[EN_SELECT]] = (int16_t)(fm1_in.enc_steps[panel.enc[EN_SELECT]] + d * panel.dir[EN_SELECT]);
fm1__unlock(l);
}
if ((*pressed >> SMK_BTN_KNOB_BANK) & 1u && !((labels >> SMK_BTN_KNOB_BANK) & 1u)) {
smk_kbank ^= 1u;
ui_say(smk_kbank ? "KNOBS: MACROS " : "KNOBS: PAGE ", smk_kbank ? "K1-6 CUT K7 DLY K8 REV" : "K5 SEL K8 MASTER");
smk_pads_toggle(&smk.pads);
ui_say("PADS ", (smk.pads.mode == SMK_PADS_STEPS) == !smk.pads.gate ? "STEPS" : "PLAY");
}
if ((*pressed >> SMK_BTN_FADER_BANK) & 1u && !((labels >> SMK_BTN_FADER_BANK) & 1u)) {
smk.fbank ^= 1u;
for (f = 0; f < 4u; f++)
smk_pick_reset(&smk.pick[f]);
ui_say(smk.fbank ? "FADERS B: " : "FADERS A: ", smk.fbank ? "T5 T6 DLY REV" : "T1 T2 T3 T4");
smk.fbank = (uint8_t)smk_fb_next(smk.fbank);
smk_bank_say();
}
*pressed &= labels;
if (!smk.init) {
for (f = 0; f < 4u; f++)
smk_pick_reset(&smk.pick[f]);
smk.init = 1;
}
if (smk_kbank) /* KNOB BANK: K1..K8 the macros, before the panel reads them */
for (f = 0; f < FM1_NENC; f++)
if ((e = fm1_enc_take(f)) != 0)
smk_macro_turn(f, e);
for (f = 0; f < 4u; f++) { /* the faders, with pick-up */
uint32_t v = fm1_in.fader[f], first = smk.pick[f].last == 0xFFu;
smk_tgt_t t = SMK_FADER[smk.fbank & 1u][f];
if (fm1_in.frames < 128u) /* (~0.2 s: the faders' filters settle from 0 first, no false cross) */
continue;
if (v == smk.fval[f] && !first)
continue;
smk.fval[f] = (uint8_t)v;
if (smk_pickup(&smk.pick[f], v, smk_tgt_get(t))) {
int16_t *vp;
int32_t lo, hi;
smk_tgt_range(t, &vp, &lo, &hi);
smk_tgt_put(t, lo + ((int32_t)v * (hi - lo) + 63) / 127);
} else if (!first) { /* (moved, not yet met: which way to go) */
char m[8] = {'F', (char)('1' + f), ' ', 0};
ui_say(m, smk_tgt_get(t) > v ? "PICK UP: UP" : "PICK UP: DOWN");
}
}
mode = smk_pads_mode();
if (mode != smk.mode) { /* another kind of page: the pads held let go first */
smk_faders();
for (f = 0; f < SMK_NPAD; f++)
down |= fm1_in.pad_st[f];
if (smk_pads_settle(&smk.pads, down != 0u)) /* (KNOB BANK's change, once no pad is down) */
while (smk.held)
smk_step_release((uint32_t)__builtin_ctz(smk.held) + 1u);
smk.mode = (uint8_t)mode;
}
smk_pad_key = mode == SMK_PM_WHITE ? SMK_PK_GRID : SMK_PK_NONE; /* (the HAL takes it at the next hit) */
while ((e = smk_pad_take()) >= 0) {
smk_pad_key = smk_pads_white(&smk.pads) ? SMK_PK_GRID : SMK_PK_NONE; /* (the HAL takes it at the next hit) */
while ((e = smk_pad_take()) >= 0) { /* STEPS (a change waiting: releases only) */
uint32_t n = smk_pad_num(((uint32_t)e >> 8) & 15u), vel = (uint32_t)e & 127u;
if (mode == SMK_PM_STEPS) {
if (vel)
smk_step_press(n, vel);
else
smk_step_release(n);
} else if (mode == SMK_PM_TRACKS && vel) {
smk_tracks_press(n);
}
if (!vel)
smk_step_release(n);
else if (smk.pads.mode == SMK_PADS_STEPS && !smk.pads.gate && !smk_steps_off())
smk_step_press(n, vel);
}
if (mode == SMK_PM_STEPS && smk.held && smk.ptrk == song.sel && !smk_kbank) { /* a step held + K1..K4: its lock */
if (smk.held && smk.ptrk == song.sel) { /* a step held + KNOB 1..4 (K5..K8): its lock */
uint64_t h = smk_steps_held();
for (f = 0; f < 4u; f++)
if ((e = panel_enc(EN_K1 + f)) != 0) {
@@ -317,7 +210,7 @@ static void smk_input_frame(uint32_t *pressed)
ui.hot_t = 40, ui.knob_ms = fm1_ms;
}
}
{ /* the keybed's last note: a new melodic step's */
{ /* the keys' last note: a new melodic step's */
static uint8_t last;
if (last_note != last)
smk.note = last = last_note;
@@ -327,11 +220,11 @@ static void smk_input_frame(uint32_t *pressed)
/* ---------------------------------------------------------------- the LEDs --- */
/* The buttons: one on/off LED each (hal/smk_input.h SMK_LEDC; SEQ PLAY's green its own id 16). The FM-1's picture
* where the SMK can show it: lit = lit; what breathes on the FM-1 blinks (~1 Hz); no idle glow (as LEDS OFF; LEDS
* INV: the idle ones lit). The 16 RGB pads (lcd.c padled_set) show what they do now: WHITE the FM-1 keys' picture
* (lit white, breathing blinking, the DRUM grid's glow and beats dim); STEPS the page's steps (the track's colour,
* brighter with something on it, the cursor white, the playhead bright, past LEN dark); TRACKS 1..6 the tracks in
* their colours (the selected one bright, a muted one red, an asleep one dark), 7 UNDO and 8 TAP dim white, 9..16 the
* shortcuts dim blue (the page shown bright). Untested on hardware. */
* INV: the idle ones lit). KNOB BANK lit: the pads are STEPS; FADER BANK lit: a bank other than LEVEL. The 16 RGB pads
* (lcd.c padled_set): PLAY the FM-1 keys' picture (lit white, breathing blinking, the DRUM grid's glow and beats dim);
* STEPS the page's steps (the track's colour, brighter with something on it, the cursor white, the playhead bright,
* past LEN dark); dark while a KNOB BANK change waits or (STEPS) in the MENU, a dialog, a layer, NAME. Untested on
* hardware. */
#define SMK_PAD_LIT 72u /* the pads' levels (0..255 a channel: WS2812s are bright) */
#define SMK_PAD_MID 14u
#define SMK_PAD_DIM 3u
@@ -340,10 +233,10 @@ static void smk_pad_rgb(uint32_t hw, uint32_t rgb565, uint32_t lvl) /* a colou
uint32_t r = (rgb565 >> 11) & 31u, g = (rgb565 >> 5) & 63u, b = rgb565 & 31u;
padled_set(hw, (uint8_t)(r * lvl / 31u), (uint8_t)(g * lvl / 63u), (uint8_t)(b * lvl / 31u));
}
static void smk_pads_out(uint32_t mode, uint32_t blink)
static void smk_pads_out(uint32_t blink)
{
uint32_t p;
if (mode == SMK_PM_WHITE) {
if (smk_pads_white(&smk.pads)) {
uint32_t kb, c = key_leds(&kb), g = grid_on() && !ui.layer && !name_on() ? grid_glow() : 0u;
uint32_t beat = g ? grid_beats() & ~c : 0u, lit = c, br = blink ? kb : 0u, inv = settings_leds == LEDS_INV;
for (p = 0; p < SMK_NPAD; p++) {
@@ -353,7 +246,7 @@ static void smk_pads_out(uint32_t mode, uint32_t blink)
v = lit & bit ? 0u : v ? v : SMK_PAD_MID;
padled_set(p, (uint8_t)v, (uint8_t)v, (uint8_t)v);
}
} else if (mode == SMK_PM_STEPS) {
} else if (!smk.pads.gate && !smk_steps_off()) {
const track_t *t = TSEL;
uint32_t len = (uint32_t)clamp(t->p[P_SLEN], 1, NSTEP), col = trk_col(song.sel);
for (p = 0; p < SMK_NPAD; p++) {
@@ -372,19 +265,8 @@ static void smk_pads_out(uint32_t mode, uint32_t blink)
padled_set(p, (n - 1u) % 4u ? 0u : SMK_PAD_DIM, (n - 1u) % 4u ? 0u : SMK_PAD_DIM, (n - 1u) % 4u ? 0u : SMK_PAD_DIM);
}
} else {
for (p = 0; p < SMK_NPAD; p++) {
uint32_t n = smk_pad_num(p);
if (mode == SMK_PM_OFF)
padled_set(p, 0, 0, 0);
else if (n <= NTRK)
n - 1u >= trk_live ? padled_set(p, 0, 0, 0) :
trk[n - 1u].p[P_MUTE] ? padled_set(p, SMK_PAD_MID, 0, 0) :
smk_pad_rgb(p, trk_col(n - 1u), n - 1u == song.sel ? SMK_PAD_LIT : SMK_PAD_MID);
else if (n < SMK_PAD_PAGE0)
padled_set(p, SMK_PAD_DIM, SMK_PAD_DIM, SMK_PAD_DIM);
else
padled_set(p, 0, 0, smk_page_shown(n) ? SMK_PAD_LIT : SMK_PAD_DIM * 2u);
}
for (p = 0; p < SMK_NPAD; p++)
padled_set(p, 0, 0, 0);
}
padled_flush(); /* (only when a colour changed: ~0.8 ms) */
}
@@ -420,8 +302,8 @@ static void ui_leds(void)
else
fm1_led[id] = on[id];
}
fm1_led[SMK_BTN_KNOB_BANK] = smk_kbank; /* (the banks' own: lit = MACROS, B) */
fm1_led[SMK_BTN_FADER_BANK] = smk.fbank;
fm1_led[SMK_BTN_KNOB_BANK] = smk.pads.gate ? (uint8_t)blink : (uint8_t)(smk.pads.mode == SMK_PADS_STEPS);
fm1_led[SMK_BTN_FADER_BANK] = smk.fbank != SMK_FB_LEVEL;
#undef SMK_LED
smk_pads_out(smk.mode, blink);
smk_pads_out(blink);
}
+113 -58
View File
@@ -1,94 +1,149 @@
/* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) */
/* (SMK-37, BOARD_SMK37 only; included by smk.c) The audio side of the SMK-37's controls: the 37 keys, the PITCH and
* MOD wheels and the sustain pedal, as MIDI in on the selected track's channel, from the audio block (seq.c
* keyboard_block, ahead of the MIDI queue: the same context as every MIDI event, so no lock). Needs from the firmware:
* song (sel, octave), NPART, trk, midi_event, mo_key / mo_kon / mo_koff, kb_velx, kb_boot_hold, clamp, the HAL's
* fm1_in and smk_extkey_take; tests/smk_map_test.c gives it stand-ins and walks every key. */
* Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant)
* After Rhythmer's SMK-37 Pro port by Jazzy Rhythmer (GPL-3.0: all 37 keys through the original key path, the
* outer ten as extra notes; the wheels' self-calibration, which is genkigenki's, github.com/genkigenki/Felucca smk37). */
/* (SMK-37, BOARD_SMK37 only; included by smk.c) The audio side of the SMK-37's keybed, wheels and pedal, from the keys'
* block (seq.c keyboard_block calls smk_kb_block first and plays what it returns: the same context as the FM-1's keys):
* KEYS all 37 through seq.c's key path (kb_map, key_on / key_off: SCL's maps, CHORD, STRUM, ARP, LATCH, KEY SPLIT,
* recording, MIDI OUT, at the key's velocity). Ids 5..31 are the FM-1's 27 keys (fm1_in.notes: returned to
* keyboard_block, which does with them all the FM-1 does: the layers' shortcuts, NAME, the DRUM grid, SCENE);
* the outer ten (0..4, 32..36: smk_map.h smk_kb_key, keys 27..36) play extra notes from here (C3..E3 and
* G#5..C6 at OCT 0, moved by OCT), silent where the FM-1's keys are the UI's (a layer, NAME, the DRUM grid)
* PEDAL sustain: a key let go while it is down keeps sounding until it is up (or the key is struck again); also
* CC64 as MIDI in on the selected track (notes from MIDI) and to MIDI OUT with the keys
* WHEELS pitch bend and CC1 (the matrix's MOD WHEEL) as MIDI in on the selected track, and to MIDI OUT with the keys
* Needs from the firmware: song, NTRK, trk, kb_*, key_on, key_off, kb_map, split_*, drum_track, midi_event, mo_key,
* mo_send, kb_mask, fx_lock_on, kb_asleep, kb_boot_hold, clamp, the HAL's fm1_in, fm1__lock and smk_extkey_take;
* tests/smk_map_test.c gives it stand-ins and walks every key. */
#include "smk_map.h"
/* ------------------------------------------------- the audio side (keybed) --- */
/* each key sounding: its channel + 1 (0: none) and note, so its release ends that note whatever the track or the
* octave are by then; the wheels' and the pedal's rest readings (taken once the scan has settled) and what was sent */
static struct {
uint8_t ch[SMK_KEYS], note[SMK_KEYS];
uint8_t cal, mod, ped, sel; /* cal: rests taken; mod, ped: sent (CC1, CC64 >= 64); sel: their channel + 1 */
uint64_t sus; /* keys whose note the pedal holds (let go while it was down) */
uint16_t out; /* the outer keys sounding (bit k - 27) */
uint8_t cal, mod, ped, sel; /* cal: rests taken; mod, ped: sent (CC1, CC64 >= 64); sel: their track + 1 */
uint8_t mo; /* (TRS) MIDI OUT on + 1, as the jack last had it (0: not yet) */
int16_t bend; /* sent, -8192..8191 */
uint16_t rest[3]; /* the PITCH and MOD wheels' and the pedal's readings at rest */
uint16_t ped0; /* the pedal's reading at rest */
smk_wheels_t w;
} smk_kb __attribute__((section(".pool")));
#define SMK_BEND_DZ 24 /* the pitch wheel's dead zone round its rest (0..1023 counts) */
#define SMK_PED_ON 256 /* the pedal pressed: this far from its rest (either way: either polarity) */
static void smk_send(uint32_t st, uint32_t ch, uint32_t d1, uint32_t d2) { midi_event(st, ch & 15u, d1 & 127u, d2 & 127u); }
static int32_t smk_bend_of(uint32_t raw)
static void smk_send(uint32_t st, uint32_t ch, uint32_t d1, uint32_t d2, int out)
{
int32_t c = smk_kb.rest[0], d = (int32_t)raw - c;
if (d > -SMK_BEND_DZ && d < SMK_BEND_DZ)
return 0;
d += d > 0 ? -SMK_BEND_DZ : SMK_BEND_DZ;
return d > 0 ? clamp(d * 8191 / (1023 - c - SMK_BEND_DZ > 1 ? 1023 - c - SMK_BEND_DZ : 1), 0, 8191)
: clamp(d * 8192 / (c - SMK_BEND_DZ > 1 ? c - SMK_BEND_DZ : 1), -8192, 0);
midi_event(st, ch & 15u, d1 & 127u, d2 & 127u);
if (out && mo_key(&trk[ch % NTRK]))
mo_send(st | (ch & 15u), d1 & 127u, d2 & 127u);
}
static __attribute__((noinline)) void smk_kb_block(void) /* (out of the RAM mix: in flash) */
/* seq.c key_off_fp: a key let go; the pedal down: held until it is up */
static void smk_key_up(uint32_t k, track_t *t)
{
uint32_t ch = song.sel % NPART, k;
if (smk_kb.ped && k < SMK_KEYS) {
smk_kb.sus |= (uint64_t)1u << k;
return;
}
key_off(k, t);
}
static void smk_sus_end(uint32_t k) /* a held key's note ends now (pedal up, the key struck again) */
{
if ((smk_kb.sus >> k) & 1u) {
smk_kb.sus &= ~((uint64_t)1u << k);
key_off(k, &trk[kb_trk[k] % NTRK]);
}
}
/* an outer key (k 27..36) down (vel) or up: seq.c keyboard_block's press and release, for a key no layer has */
static void smk_outer(uint32_t k, uint32_t vel)
{
uint32_t b = 1u << (k - 27u), high = k >= 32u, n;
track_t *t;
if (smk_kb.out & b) { /* (its note before: a release, or struck again) */
smk_kb.out &= (uint16_t)~b;
key_off_fp(k, &trk[kb_trk[k] % NTRK]);
}
if (!vel)
return;
smk_sus_end(k);
kb_velx[k] = (uint8_t)(vel ^ 100u);
kb_trk[k] = (uint8_t)song.sel;
if (kb_boot_hold || kb_asleep || song.grid || (fm1_in.buttons & kb_mask) != 0u || fx_lock_on)
return; /* (the splash, SCREEN OFF, NAME / the DRUM grid, a layer: silent) */
if (split_cfg[0])
kb_trk[k] = (uint8_t)split_track(high);
t = &trk[kb_trk[k] % NTRK];
n = kb_map(t, k);
if (n == KB_SILENT)
return;
if (split_cfg[0] && !drum_track(t))
n = (uint32_t)clamp((int32_t)n + 12 * split_oct(high), 0, 127);
kb_note[k] = (uint8_t)n;
kb_oct[k] = 0; /* (a DRUM track: a lane's own note, kb_map) */
key_on(k, t);
smk_kb.out |= (uint16_t)b;
}
/* the keys' block's first step: returns the 27 keys' state for keyboard_block */
static __attribute__((noinline)) uint32_t smk_kb_block(void) /* (out of the RAM mix: in flash) */
{
uint32_t ch = song.sel % NTRK, k, cur, rt, fresh;
int32_t e;
for (k = 0; k < 27u; k++) /* the pads as white keys: their velocity (seq.c KB_VEL) */
kb_velx[k] = (uint8_t)(fm1_in.pad_vel[k] ^ 100u);
while ((e = smk_extkey_take()) >= 0) { /* the keybed, every key (hal/smk_input.h smk__key_event) */
uint32_t key = ((uint32_t)e >> 8) % SMK_KEYS, vel = (uint32_t)e & 127u;
if (smk_kb.ch[key]) { /* (its note before: a release, or struck again) */
uint32_t c = smk_kb.ch[key] - 1u, n = smk_kb.note[key];
smk_send(0x80u, c, n, 0);
mo_koff(c, n);
smk_kb.ch[key] = 0;
}
if (vel && !kb_boot_hold) { /* (#137: under the splash, silent) */
uint32_t n = smk_key_note(key, song.octave);
smk_send(0x90u, ch, n, vel);
if (mo_key(&trk[ch]))
mo_kon(ch, n, vel);
smk_kb.ch[key] = (uint8_t)(ch + 1u);
smk_kb.note[key] = (uint8_t)n;
{
uint32_t l = fm1__lock();
rt = fm1_in.notes_retrig; /* struck again while down: let go now, struck at the next block */
fm1_in.notes_retrig = 0;
cur = fm1_in.notes & ~rt;
fm1__unlock(l);
}
fresh = cur & ~kb_prev;
for (k = 0; k < 27u; k++) /* the key's or the pad's velocity (seq.c KB_VEL) */
if ((fresh >> k) & 1u) {
kb_velx[k] = (uint8_t)(fm1_in.note_vel[k] ^ 100u);
smk_sus_end(k); /* (a held note struck again: the old one ends first) */
}
#if FELUCCA_SMK_TRS
if (smk_kb.mo != (mo_lvl < MO_OFF) + 1u) { /* MIDI OUT's setting: the jack on or off (its held notes let go) */
smk_kb.mo = (uint8_t)((mo_lvl < MO_OFF) + 1u);
smk_mo_enable(mo_lvl < MO_OFF);
}
#endif
while ((e = smk_extkey_take()) >= 0) { /* the outer ten (hal/smk_input.h smk__key_event) */
k = smk_kb_key(((uint32_t)e >> 8) & 63u);
if (k >= 27u && k < SMK_KEYS)
smk_outer(k, (uint32_t)e & 127u);
}
if (!smk_kb.cal) { /* the rests, once the scan has read every analog slot a few times */
if (fm1_in.frames < 64u)
return;
smk_kb.rest[0] = fm1_in.wheel[0];
smk_kb.rest[1] = fm1_in.wheel[1];
smk_kb.rest[2] = fm1_in.pedal;
return cur;
smk_kb.ped0 = fm1_in.pedal;
smk_kb.cal = 1;
smk_kb.sel = (uint8_t)(ch + 1u);
}
if (smk_kb.sel != ch + 1u) { /* another track: the old one let go (centre, 0, pedal up) */
smk_wheels_feed(&smk_kb.w, fm1_in.wheel[0], fm1_in.wheel[1]);
if (smk_kb.sel != ch + 1u) { /* another track: the old one let go (centre, 0) */
uint32_t o = smk_kb.sel - 1u;
if (smk_kb.bend) smk_send(0xE0u, o, 0, 64);
if (smk_kb.mod) smk_send(0xB0u, o, 1, 0);
if (smk_kb.ped) smk_send(0xB0u, o, 64, 0);
if (smk_kb.bend) smk_send(0xE0u, o, 0, 64, 1);
if (smk_kb.mod) smk_send(0xB0u, o, 1, 0, 1);
if (smk_kb.ped) smk_send(0xB0u, o, 64, 0, 1);
smk_kb.bend = 0;
smk_kb.mod = smk_kb.ped = 0;
smk_kb.sel = (uint8_t)(ch + 1u);
}
{
int32_t b = smk_bend_of(fm1_in.wheel[0]), r = smk_kb.rest[1], w = fm1_in.wheel[1];
uint32_t m, p;
int32_t b = smk_bend14(&smk_kb.w, fm1_in.wheel[0]);
uint32_t m = smk_mod7(&smk_kb.w, fm1_in.wheel[1]), p;
if (b != smk_kb.bend && (b == 0 || b == 8191 || b == -8192 || b - smk_kb.bend > 31 || smk_kb.bend - b > 31)) {
uint32_t v = (uint32_t)(b + 8192);
smk_send(0xE0u, ch, v & 127u, v >> 7);
smk_send(0xE0u, ch, v & 127u, v >> 7, 1);
smk_kb.bend = (int16_t)b;
}
/* MOD: 0 at its rest, 127 at the other end (the end it rests at: either, as read at power-on) */
m = (uint32_t)clamp((r < 512 ? w - r : r - w) * 127 / (r < 512 ? 1023 - r > 1 ? 1023 - r : 1 : r > 1 ? r : 1),
0, 127);
if (m != smk_kb.mod && (m == 0u || m == 127u || m > smk_kb.mod + 1u || m + 1u < smk_kb.mod)) {
smk_send(0xB0u, ch, 1, m);
smk_send(0xB0u, ch, 1, m, 1);
smk_kb.mod = (uint8_t)m;
}
p = (uint32_t)((int32_t)fm1_in.pedal - smk_kb.rest[2] > SMK_PED_ON ||
(int32_t)smk_kb.rest[2] - fm1_in.pedal > SMK_PED_ON);
p = (uint32_t)((int32_t)fm1_in.pedal - smk_kb.ped0 > SMK_PED_ON || (int32_t)smk_kb.ped0 - fm1_in.pedal > SMK_PED_ON);
if (p != smk_kb.ped) {
smk_send(0xB0u, ch, 64, p ? 127u : 0u);
smk_send(0xB0u, ch, 64, p ? 127u : 0u, 1);
smk_kb.ped = (uint8_t)p;
if (!p) /* up: what it held ends */
for (k = 0; k < SMK_KEYS; k++)
smk_sus_end(k);
}
}
return cur;
}
+95 -55
View File
@@ -1,72 +1,67 @@
/* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) */
/* (SMK-37, BOARD_SMK37 only; docs/SMK37.md "The control mapping") The V10.8 layout's pure rules, no HAL and no UI
* state, so tests/smk_map_test.c checks them on the host: the keybed's notes, what the pads are on each kind of page,
* the pads' numbers, the knob and fader banks' targets and the faders' pick-up. firmware/src/smk.c applies them. */
* Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant)
* The layout is Rhythmer's SMK-37 Pro layout (Rhythmer, a GPL-3.0 fork of JIANT for the FM-1, by Jazzy Rhythmer:
* its smk_controls.h, the outer keys' order and the faders' banks, adapted here). */
/* (SMK-37, BOARD_SMK37 only; docs/SMK37.md "The control mapping") The layout's pure rules, no HAL and no UI state, so
* tests/smk_map_test.c checks them on the host: the keybed's keys as the key path's, the pads' two modes, the faders'
* banks and track window, the faders' pick-up. firmware/src/smk.c, smk_kb.c and seq.c apply them. */
#pragma once
#include <stdint.h>
/* ------------------------------------------------------------------ the keybed --- */
/* keybed key k (0 = the lowest C .. 36 = the top C, hal/smk_input.h) at OCT o (song.octave, -3..+3): C3 + k + 12 o,
* the whole window moved (never folded) so that all 37 notes stay in 0..127 and apart whatever the octave */
/* keybed key id (hal/smk_input.h: 0 = C3 .. 36 = C6) -> its key in seq.c's key path (kb_note[], key_on): ids 5..31
* (F3..G5) are the FM-1's 27 keys 0..26 (fm1_in.notes); the outer ones follow them: ids 0..4 (C3..E3) keys 27..31,
* ids 32..36 (G#5..C6) keys 32..36 (Rhythmer's order) */
#define SMK_KEYS 37u
#define SMK_KEY_C3 48
static inline uint32_t smk_key_note(uint32_t k, int32_t oct)
#define SMK_KB_F3 5u
static inline uint32_t smk_kb_key(uint32_t id)
{
int32_t b = SMK_KEY_C3 + 12 * oct;
b = b < 0 ? 0 : b > 127 - (int32_t)(SMK_KEYS - 1u) ? 127 - (int32_t)(SMK_KEYS - 1u) : b;
return (uint32_t)b + (k < SMK_KEYS ? k : SMK_KEYS - 1u);
return id - SMK_KB_F3 < 27u ? id - SMK_KB_F3 : id < SMK_KB_F3 ? 27u + id : id < SMK_KEYS ? id : 0xFFu;
}
/* key k of the key path: its semitones from F3 (kb_map: 53 + this, + 12 OCT; -5..31) */
static inline int32_t smk_kb_off(uint32_t k)
{
return k < 27u ? (int32_t)k : k < 32u ? (int32_t)k - 32 : (int32_t)k - 5;
}
/* the note keybed key id plays with no scale map (QUANT OFF, no CHORD) at OCT o: C3 + id + 12 o (48..84 at 0) */
static inline uint32_t smk_key_note(uint32_t id, int32_t oct)
{
int32_t n = 53 + smk_kb_off(smk_kb_key(id)) + 12 * oct;
return (uint32_t)(n < 0 ? 0 : n > 127 ? 127 : n);
}
/* -------------------------------------------------------------------- the pads --- */
/* pad n (1..16) is hardware pad n - 1: the top row 1..8, the bottom row 9..16, left to right (hal/smk_input.h:
* pads 0..7 mux A, the top row; 8..15 mux B, the bottom one) */
/* pad n (1..16) is hardware pad n - 1: the top row 1..8, the bottom row 9..16, left to right */
static inline uint32_t smk_pad_num(uint32_t hw) { return hw + 1u; }
/* what the pads are now:
* OFF the MENU, a dialog: nothing (their presses dropped, dark)
* WHITE the FM-1's 16 white keys, as GRID (hal/smk_input.h SMK_PK_GRID): wherever the FM-1 gives its keys to the
* UI: a layer's button down or its map up (the layers' shortcuts: GLO + G4 UNDO, SEQ + G5 CLR STEP ...),
* NAME, the DRUM grid (SEQ > STEP on a DRUM track: steps 1..16 of the page, with hold + KNOB locks), STEP
* FX and the song pages (keys_mode)
* STEPS the other SEQ pages: pad n the page's step n (toggle; held + K1..K4 a parameter lock)
* TRACKS everywhere else: 1..6 the track (PATCH held: its mute), 7 UNDO, 8 TAP, 9..16 the page shortcuts */
enum { SMK_PM_OFF, SMK_PM_WHITE, SMK_PM_STEPS, SMK_PM_TRACKS };
static inline uint32_t smk_pads_rule(int menu_or_dialog, int fm1_keys_ui, int seq_page)
/* KNOB BANK: PLAY (its LED dark) the pads are the FM-1's 16 white keys (hal/smk_input.h SMK_PK_GRID); STEPS (lit) the
* 16 steps of the page shown (on the DRUM grid the lane picked). A change asked while a pad is down waits for every
* pad to be let go (gate): no stray note, no half a step (Rhythmer's rule). */
enum { SMK_PADS_PLAY, SMK_PADS_STEPS };
typedef struct { uint8_t mode, gate; } smk_pads_t;
static inline void smk_pads_toggle(smk_pads_t *p) { p->gate = (uint8_t)!p->gate; } /* (again while waiting: undone) */
/* each frame: down, a pad is down; returns 1 when the mode changed now */
static inline int smk_pads_settle(smk_pads_t *p, int down)
{
return menu_or_dialog ? SMK_PM_OFF : fm1_keys_ui ? SMK_PM_WHITE : seq_page ? SMK_PM_STEPS : SMK_PM_TRACKS;
if (!p->gate || down)
return 0;
p->gate = 0;
p->mode = (uint8_t)!p->mode;
return 1;
}
#define SMK_PAD_UNDO 7u
#define SMK_PAD_TAP 8u
#define SMK_PAD_PAGE0 9u /* pads 9..16: SMK_PAGES[n - 9] */
/* the page shortcuts: a section (smk.c: ui_lens.c's SEC_*, in this order) and the page's name in its chain */
enum { SMK_S_HOME, SMK_S_EDIT, SMK_S_SEQ, SMK_S_FX, SMK_S_GLO, SMK_S_ENV, SMK_S_LFO };
static const struct { uint8_t sec; char nm[12]; } SMK_PAGES[8] = {
{SMK_S_GLO, "MIXER"}, /* 9 GLO > MIXER: the six levels, pans, mutes */
{SMK_S_EDIT, "FILTER"}, /* 10 EDIT > TONE > FILTER (FM6 and DRUM-X: theirs) */
{SMK_S_ENV, "ENV"}, /* 11 ENV > ENV */
{SMK_S_LFO, "MOD"}, /* 12 LFO > MOD: the matrix */
{SMK_S_FX, "DLY"}, /* 13 FX > DELAY */
{SMK_S_FX, "REVERB"}, /* 14 FX > REVERB */
{SMK_S_HOME, "ARRANGE"}, /* 15 HOME > SONG > ARRANGE */
{SMK_S_HOME, "GENERATOR 1"}, /* 16 HOME > GENERATOR (GEN, as HOME held + SELECT) */
};
/* the pads are white keys now (else the UI's: steps, or nothing while the change waits) */
static inline int smk_pads_white(const smk_pads_t *p) { return p->mode == SMK_PADS_PLAY && !p->gate; }
/* -------------------------------------------------------- the banks' targets --- */
/* a target: a track's parameter (trk 0..5, or SMK_T_SEL the selected track) or a global (trk SMK_T_G); id SMK_ID_CUT:
* the track's cutoff as CC74 finds it (the engine's own brightness, else the FILTER page's CUT: midi_control.c) */
#define SMK_T_SEL 6u
#define SMK_T_G 7u
#define SMK_ID_CUT 0xFFu
enum { SMK_TG_LEVEL, SMK_TG_CUT, SMK_TG_DSEND, SMK_TG_RSEND, SMK_TG_DMIX, SMK_TG_RSIZE }; /* (resolved in smk.c) */
typedef struct { uint8_t trk, what; } smk_tgt_t;
/* KNOB BANK's macros: K1..K6 the cutoff of T1..T6, K7 the delay's MIX, K8 the reverb's SIZE (the master effects) */
static const smk_tgt_t SMK_MACRO[8] = {{0, SMK_TG_CUT}, {1, SMK_TG_CUT}, {2, SMK_TG_CUT}, {3, SMK_TG_CUT},
{4, SMK_TG_CUT}, {5, SMK_TG_CUT}, {SMK_T_G, SMK_TG_DMIX}, {SMK_T_G, SMK_TG_RSIZE}};
/* FADER BANK: A the levels of T1..T4; B T5, T6 and the selected track's delay and reverb sends */
static const smk_tgt_t SMK_FADER[2][4] = {
{{0, SMK_TG_LEVEL}, {1, SMK_TG_LEVEL}, {2, SMK_TG_LEVEL}, {3, SMK_TG_LEVEL}},
{{4, SMK_TG_LEVEL}, {5, SMK_TG_LEVEL}, {SMK_T_SEL, SMK_TG_DSEND}, {SMK_T_SEL, SMK_TG_RSEND}},
};
/* ---------------------------------------------------------------- the faders --- */
/* FADER BANK: LEVEL -> PAN -> REVERB -> DELAY (the sends) -> LEVEL; faders 1..4 are T1..T4, or with T5 / T6 selected
* faders 1..2 T5 / T6 (3..4 nothing). The pick-up's context: the bank and the window (a change re-arms it) */
enum { SMK_FB_LEVEL, SMK_FB_PAN, SMK_FB_REVERB, SMK_FB_DELAY, SMK_FB_N };
static inline uint32_t smk_fb_next(uint32_t b) { return (b + 1u) % SMK_FB_N; }
static inline int smk_fader_track(uint32_t f, uint32_t sel) /* the track fader f (0..3) moves, -1 none */
{
uint32_t t = (sel >= 4u ? 4u : 0u) + f;
return f < 4u && t < 6u ? (int)t : -1;
}
static inline uint32_t smk_fader_ctx(uint32_t bank, uint32_t sel) { return bank * 2u + (sel >= 4u); }
/* ------------------------------------------------------------ the pick-up --- */
/* (soft takeover) a fader at f (0..127) moves a value now at v (0..127 on its range) only once it has met it: within
@@ -88,3 +83,48 @@ static inline int smk_pickup(smk_pick_t *p, uint32_t f, uint32_t v)
p->st = (uint8_t)(0x80u | (f & 0x7Fu));
return ok;
}
/* ---------------------------------------------------------------- the wheels --- */
/* (genkigenki's docs/01-hardware.md 6.5, verified on an SMK-37 Pro: the travel is short and differs between units:
* PITCH rests ~535 and moves ~445..640, MOD ~474..629 with up = the lower reading) A self-calibrating range, as
* genkigenki's and Rhythmer's: the pitch centre is the reading at rest (its drift followed while resting), each range
* widened to the extremes seen, from a start of +-SMK_W_SPAN0 round the centre (pitch) and SMK_W_MLO..SMK_W_MHI (mod). */
#define SMK_W_DEAD 12
#define SMK_W_SPAN0 80
#define SMK_W_MLO 485
#define SMK_W_MHI 615
typedef struct { int16_t pc, plo, phi, mlo, mhi; uint8_t rest, on; } smk_wheels_t;
static inline void smk_wheels_feed(smk_wheels_t *w, int32_t p, int32_t m) /* the raw readings, each audio block */
{
if (!w->on) {
w->on = 1;
w->pc = (int16_t)p, w->plo = (int16_t)(p - SMK_W_SPAN0), w->phi = (int16_t)(p + SMK_W_SPAN0);
w->mlo = (int16_t)(m < SMK_W_MLO ? m : SMK_W_MLO), w->mhi = (int16_t)(m > SMK_W_MHI ? m : SMK_W_MHI);
}
if (p < w->plo) w->plo = (int16_t)p;
if (p > w->phi) w->phi = (int16_t)p;
if (m < w->mlo) w->mlo = (int16_t)m;
if (m > w->mhi) w->mhi = (int16_t)m;
if (p - w->pc > -SMK_W_DEAD && p - w->pc < SMK_W_DEAD) {
if (++w->rest > 200u) { /* resting: the centre follows a slow drift */
w->pc = (int16_t)(w->pc + (p > w->pc) - (p < w->pc));
w->rest = 0;
}
} else {
w->rest = 0;
}
}
static inline int32_t smk_bend14(const smk_wheels_t *w, int32_t p) /* -8192..8191, 0 inside the dead zone */
{
int32_t d = p - w->pc, up = w->phi - w->pc - SMK_W_DEAD, dn = w->pc - w->plo - SMK_W_DEAD, b;
if (d > -SMK_W_DEAD && d < SMK_W_DEAD)
return 0;
b = d > 0 ? (d - SMK_W_DEAD) * 8191 / (up > 1 ? up : 1) : (d + SMK_W_DEAD) * 8192 / (dn > 1 ? dn : 1);
return b < -8192 ? -8192 : b > 8191 ? 8191 : b;
}
static inline uint32_t smk_mod7(const smk_wheels_t *w, int32_t m) /* 0 at rest (the high reading) .. 127 */
{
int32_t r = w->mhi - m - SMK_W_DEAD, span = w->mhi - w->mlo - SMK_W_DEAD;
r = r <= 0 ? 0 : r * 127 / (span > 1 ? span : 1);
return (uint32_t)(r > 127 ? 127 : r);
}
+157
View File
@@ -0,0 +1,157 @@
/* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant)
* After Rhythmer's src/smk_midi_out.h (bounded standalone TRS MIDI output, Jazzy Rhythmer, 2026, GPL-3.0). */
/* (SMK-37, BOARD_SMK37 && FELUCCA_SMK_TRS only; usb.c includes it) TRS MIDI OUT on the 3.5 mm jack: what MIDI OUT sends
* over USB (usb.c midi_out_event_at: MENU > CONTROL > MIDI OUT KEYS / CLOCK / ALL, track n on channel n), also out of
* the jack. One producer (the audio ISR, midi_out_event_at), one consumer (TIMER5, smk_midi_out_poll: a byte when the
* last has gone, never waiting), so neither USB nor the sound can be held up by it. Whole messages only: channel
* voice messages, song position / select, tune request and the realtime bytes (a realtime byte may go between a
* message's bytes, as MIDI allows); never SysEx (the editor's, the update's). A full queue, or a UART that stops
* answering, drops the queue and sends every channel's CC64 0, CC120, CC121, CC123 instead (no note left hanging);
* after four timeouts in a row the jack stops until MIDI OUT is set again. MIDI OUT OFF: silent (the held notes let
* go). The state is in the pool (zeroed at boot). Untested on hardware: docs/SMK37.md. */
#pragma once
#include <stdint.h>
#include "smk_uart_tx.h"
#define SMK_MQ 64u /* channel messages (USB-MIDI packets) waiting */
static struct {
uint32_t q[SMK_MQ];
uint8_t rt[16]; /* realtime bytes waiting */
volatile uint16_t w, r;
volatile uint8_t rw, rr, panic, reset, muted, fault;
uint8_t b[3], pos, len, busy, wait, fails, pstep, on;
uint32_t sent, dropped;
} smk_mo __attribute__((section(".pool"), aligned(4)));
#define SMK_MO_PUBLISH() __asm__ volatile("" ::: "memory")
static uint32_t smk_mo_len(uint32_t p) /* a USB-MIDI packet's bytes on the wire, 0: not sent */
{
uint32_t c = p & 15u, s = (p >> 8) & 255u, a = (p >> 16) & 255u, d = p >> 24;
if (c >= 8u && c <= 14u) {
if ((s >> 4) != c || a > 127u)
return 0;
return c == 12u || c == 13u ? 2u : d <= 127u ? 3u : 0u;
}
if (c == 2u && (s == 0xF1u || s == 0xF3u) && a <= 127u)
return 2;
if (c == 3u && s == 0xF2u && a <= 127u && d <= 127u)
return 3;
if (c == 5u && s == 0xF6u)
return 1;
if (c == 15u && (s == 0xF8u || s == 0xFAu || s == 0xFBu || s == 0xFCu || s == 0xFEu || s == 0xFFu))
return 1;
return 0;
}
static void smk_mo_init(void) /* main.c, before timer5_start() */
{
smk_uart_tx_init();
smk_mo.on = 1;
}
static void smk_mo_enable(uint32_t on) /* the audio ISR: MIDI OUT's setting changed (smk_kb.c) */
{
smk_mo.muted = (uint8_t)!on;
smk_mo.panic = 1; /* (the notes held out there let go either way) */
SMK_MO_PUBLISH();
smk_mo.reset = 1; /* (TIMER5 restarts the UART and sends the panic) */
}
static void smk_mo_packet(uint32_t p) /* the audio ISR (usb.c midi_out_event_at) */
{
uint32_t s = (p >> 8) & 255u;
if (!smk_mo.on || !smk_mo_len(p))
return;
if ((p & 15u) == 15u && s >= 0xF8u) { /* realtime */
uint8_t w = smk_mo.rw;
if (smk_mo.muted || smk_mo.fault || (uint8_t)(w - smk_mo.rr) >= 16u) {
smk_mo.dropped++;
return;
}
smk_mo.rt[w & 15u] = (uint8_t)s;
SMK_MO_PUBLISH();
smk_mo.rw = (uint8_t)(w + 1u);
return;
}
if (smk_mo.muted || smk_mo.panic || smk_mo.fault || smk_mo.reset) {
smk_mo.dropped++;
return;
}
{
uint16_t w = smk_mo.w;
if ((uint16_t)(w - smk_mo.r) >= SMK_MQ) { /* full: no message cut, every note let go instead */
smk_mo.dropped++;
SMK_MO_PUBLISH();
smk_mo.panic = 1;
return;
}
smk_mo.q[w % SMK_MQ] = p;
SMK_MO_PUBLISH();
smk_mo.w = (uint16_t)(w + 1u);
}
}
static void smk_mo_poll(void) /* TIMER5 (main.c), outside the render */
{
uint8_t byte;
if (!smk_mo.on)
return;
if (smk_mo.reset) {
smk_uart_tx_restart();
smk_mo.r = smk_mo.w;
smk_mo.rr = smk_mo.rw;
smk_mo.busy = smk_mo.pos = smk_mo.len = smk_mo.wait = 0;
smk_mo.fault = smk_mo.fails = smk_mo.pstep = 0;
smk_mo.reset = 0;
}
if (smk_mo.fault)
return;
if (smk_mo.busy) {
if (!smk_uart_tx_done()) {
if (++smk_mo.wait < 30u) /* (a byte takes 0.32 ms: 30 polls is far more) */
return;
smk_mo.wait = 0;
if (++smk_mo.fails >= 4u) {
smk_mo.fault = 1;
return;
}
smk_uart_tx_restart();
smk_mo.busy = smk_mo.pos = smk_mo.len = 0;
smk_mo.panic = 1;
smk_mo.pstep = 0;
} else {
smk_mo.busy = smk_mo.wait = smk_mo.fails = 0;
}
}
if (smk_mo.rr != smk_mo.rw) { /* realtime first */
byte = smk_mo.rt[smk_mo.rr & 15u];
smk_mo.rr++;
} else {
if (smk_mo.pos >= smk_mo.len) {
smk_mo.pos = smk_mo.len = 0;
if (smk_mo.panic) { /* CC64 0, CC120, CC121, CC123 on the 16 channels */
static const uint8_t CC[4] = {64, 120, 121, 123};
uint32_t at = smk_mo.pstep;
smk_mo.r = smk_mo.w;
if (at >= 64u) {
smk_mo.panic = smk_mo.pstep = 0;
return;
}
smk_mo.pstep++;
smk_mo.b[0] = (uint8_t)(0xB0u + at / 4u);
smk_mo.b[1] = CC[at % 4u];
smk_mo.b[2] = 0;
smk_mo.len = 3;
} else {
uint32_t p;
if (smk_mo.r == smk_mo.w)
return;
p = smk_mo.q[smk_mo.r % SMK_MQ];
smk_mo.r++;
smk_mo.len = (uint8_t)smk_mo_len(p);
if (!smk_mo.len)
return;
smk_mo.b[0] = (uint8_t)(p >> 8), smk_mo.b[1] = (uint8_t)(p >> 16), smk_mo.b[2] = (uint8_t)(p >> 24);
}
}
byte = smk_mo.b[smk_mo.pos++];
}
smk_uart_tx_byte(byte);
smk_mo.busy = 1;
smk_mo.sent++;
}
+1 -1
View File
@@ -416,7 +416,7 @@ static uint32_t pr_src(const track_t *t, uint32_t si, uint32_t len) /* the ste
static uint32_t pr_held(void)
{
uint32_t k, m = 0;
for (k = 0; k < 27u; k++)
for (k = 0; k < KB_NK; k++)
if (kb_on[k] && kb_trk[k] == song.sel) {
uint32_t i;
for (i = 0; i < kb_on[k]; i++) { /* (0.6.81: a chord's every note) */
+1 -1
View File
@@ -1862,7 +1862,7 @@ static uint8_t kx_recd KX_BSS; /* the selected track's
static __attribute__((noinline)) void oct_key(uint32_t b, uint32_t both)
{
uint32_t k, m = 0;
for (k = 0; k < 27u; k++)
for (k = 0; k < KB_NK; k++)
if (kb_on[k])
m |= 1u << (kb_trk[k] % NTRK);
if (kx_semi && m) {
+6
View File
@@ -287,8 +287,14 @@ struct bt_oq bt_oq; /* (V10.13) MIDI OUT ove
#ifndef USB_MIDI_TAP
#define USB_MIDI_TAP 0
#endif
#if BOARD_SMK37 && FELUCCA_SMK_TRS && !defined FELUCCA_LOADER
#include "smk_midi_out.h" /* (SMK-37) MIDI OUT out of the TRS jack too */
#endif
static void midi_out_event_at(uint32_t pkt, uint32_t due) /* from the audio ISR; due: fm1_ticks() it goes at, 0 now */
{
#if BOARD_SMK37 && FELUCCA_SMK_TRS && !defined FELUCCA_LOADER
smk_mo_packet(pkt); /* (at once: the jack has no host to time it) */
#endif
if ((usb.config || USB_MIDI_TAP) && mo_w - mo_r < MQ) {
midi_out_q[mo_w % MQ] = pkt;
midi_out_due[mo_w % MQ] = due;
+4
View File
@@ -39,7 +39,11 @@ typedef struct { /* (the bytes first: short offsets) */
uint8_t km[VK_NK]; /* (V10.7.10, vel.c) each key's recent strikes' mean (0: none yet): a press with no
* reading of its own plays it */
uint8_t n[VK_NK]; /* (vel.c) strikes learnt since a reset (to 24) */
#if BOARD_SMK37
uint8_t velx[37]; /* (SMK-37: the outer ten keys too, seq.c KB_NK) */
#else
uint8_t velx[27]; /* each key's press's velocity ^ 100 (0, as zeroed: 100) */
#endif
uint8_t raw; /* (V10.7.22, seq.c tvel) the latest note's velocity as played (padding before) */
uint32_t hold; /* the keys whose press waits for its strike's window (the scan's ISR, vel.c
* vel_note_on): the keys' block (seq.c) sees them pressed once let through */
+9 -7
View File
@@ -477,8 +477,16 @@ smk_driver_guard() { # the RAM driver checks FL_GUA
}
run "SMK-37 flash driver: fl_erase4k_ram / fl_prog_ram refuse what FL_GUARD refuses" smk_driver_guard
$CC -w -DBOARD_SMK37=1 -Ifirmware/hal -o "$OUT/smk_map_test" tests/smk_map_test.c
run "SMK-37 controls (V10.8 layout): the printed buttons, K1-K8, all 37 keys at every octave, pads, banks, wheels, pedal" \
run "SMK-37 controls (Rhythmer's layout): the printed buttons, K1-K8, all 37 key ids through the key path, pads PLAY / STEPS, fader banks, wheels, pedal" \
"$OUT/smk_map_test"
smk_key_path() { # seq.c's key path holds the 37 keys (KB_NK) and maps the outer ten
grep -q '^#define KB_NK 37u' firmware/src/seq.c && grep -q 'n = 53 + smk_kb_off(k);' firmware/src/seq.c &&
grep -q 'uint32_t cur = smk_kb_block(), ch, k;' firmware/src/seq.c &&
! grep -n 'kb_[a-z]*\[27\]' firmware/src/seq.c && grep -q 'for (k = 0; k < KB_NK; k++)' firmware/src/midi_control.c &&
grep -q 'uint8_t velx\[37\]' firmware/src/vel_kb.h
}
run "SMK-37 key path: seq.c's key arrays are 37 keys (KB_NK), the outer ten mapped (smk_kb_off), the 27 from smk_kb_block" \
smk_key_path
smk_ram_only() { # RAM-only unless FELUCCA_SMK_FLASH=1: the store's and the OTA's writes refuse
grep -q '^#define SMK_MAY_WRITE (FELUCCA_SMK_FLASH && flash_ok)$' firmware/src/storage_hw.c &&
[ "$(grep -c 'if (!SMK_MAY_WRITE)' firmware/src/storage_hw.c)" = 2 ] &&
@@ -488,12 +496,6 @@ smk_ram_only() { # RAM-only unless FELUCCA_SMK_
}
run "SMK-37 RAM-only by default: every store / OTA erase and write refused unless FELUCCA_SMK_FLASH=1; no Bluetooth segment" \
smk_ram_only
smk_pages() { # the pads' page shortcuts (smk_map.h) are pages of the chains (ui_lens.c)
sed -n '/SMK_PAGES\[8\]/,/^};/p' firmware/src/smk_map.h | grep -o '"[A-Z0-9 ]*"' | while read -r n; do
grep -q "NV($n,\|NV([^,]*, $n," firmware/src/ui_lens.c || { echo "no page $n"; return 1; }
done
}
run "SMK-37 pads 9..16: each page shortcut is a page of its section's chain" smk_pages
$CC -w -DBOARD_SMK37=1 -Ifirmware/hal -o "$OUT/smk_keys_test" tests/smk_keys_test.c
run "SMK-37 keybed (hal/smk_input.h, Melodee's test): two contacts, bounces, re-strikes, outer keys, pads, curves" \
"$OUT/smk_keys_test"
+2 -2
View File
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2026 Kerem Kilic (Ellic Studio)
* (JIANT: Melodee's tests/smk_keys_test.c, unchanged but for this line and, for the V10.8 layout, the pad check
* reading SMK_PK_GRID and pad_vel; it tests hal/smk_input.h, Melodee's too) */
* reading SMK_PK_GRID and note_vel; it tests hal/smk_input.h, Melodee's too) */
/* Host test of the SMK-37 velocity keybed (hal/smk_input.h smk__keys, smk__pad, smk_curve, smk_trim_load) against
* a model of the scan and of the two contacts of a key. The scan is the TIMER5 one (fm1_input_tick): one column
* every 100 us, the frame (smk__keys) after column 15; the consumer is seq.c's (keyboard_block: the level of
@@ -377,7 +377,7 @@ int main(void)
smk__pad(p, 30); /* the baseline settles */
for (j = 0; j < sizeof HIT / sizeof HIT[0]; j++) {
smk__pad(p, HIT[j]);
if (((fm1_in.notes >> n) & 1u) && !prev) { on++; v = fm1_in.pad_vel[n]; }
if (((fm1_in.notes >> n) & 1u) && !prev) { on++; v = fm1_in.note_vel[n]; }
if (!((fm1_in.notes >> n) & 1u) && prev) off++;
prev = (fm1_in.notes >> n) & 1u;
}
+293 -148
View File
@@ -1,17 +1,19 @@
/* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) */
/* Host test of the SMK-37's control mapping, the V10.8 layout (docs/SMK37.md), built with -DBOARD_SMK37=1:
* firmware/src/panel.c's SMK table, hal/smk_input.h's keybed / pad / knob maps, firmware/src/smk_map.h's rules and
* firmware/src/smk_kb.c (the keybed, wheels and pedal as MIDI in) on stand-ins:
/* Host test of the SMK-37's control mapping, Rhythmer's layout on V10.8.48 (docs/SMK37.md), built with -DBOARD_SMK37=1:
* firmware/src/panel.c's SMK table, hal/smk_input.h's keybed and pad routing, firmware/src/smk_map.h's rules and
* firmware/src/smk_kb.c (the keys' block's SMK step, the outer keys, the pedal's sustain, the wheels) on stand-ins of
* seq.c's key path (kb_map / key_on / key_off, keyboard_block's loop over the 27 keys as seq.c has it):
* - every FM-1 function's default control is the printed SMK control (FX->FX, SCALE->SCL, CHORD->ENV,
* NOTE REPEAT->LFO, PARA->EDIT, GLOBE->GLO, PATCH->HOME, BT->SAVE, ARP, SEQ, SEQ PLAY->PLAY, SEQ REC->REC,
* OCTAVE-/+ -> OCT-/+); K1..K4 = KNOB 1..4, K5 SELECT, K6 PRESETS, K7 ALGORITHM, K8 MASTER ("PNS6");
* - EVERY one of the 37 keys (ids 0..36, both ends, black and white) goes through the queue and plays a note of its
* own on the selected track, at its velocity, at every octave -8..+8 (always 0..127, never two keys the same);
* its release ends that note on the channel it started on, whatever the track and the octave are by then;
* - the pads: OFF / WHITE / STEPS / TRACKS by the page, as white keys only in WHITE, numbered 1..16;
* - the knob and fader banks' targets; the faders' pick-up;
* - the wheels: bend centred with a dead zone, both ends reached; MOD from its rest; the pedal either polarity. */
* OCTAVE-/+ -> OCT-/+); K1 MASTER, K2 SELECT, K3 ALGORITHM, K4 PRESETS, K5..K8 KNOB 1..4 ("PNS7");
* - EVERY one of the 37 keys (ids 0..36, both ends) through the HAL and the key path: ids 5..31 as the FM-1's keys
* 0..26 (fm1_in.notes), the outer ten through the queue as keys 27..36; each a key_on of a note of its own on the
* selected track at its velocity (MIDI 48..84 at OCT 0, moved by OCT), at OCT -3..+3 on T1..T6; each release a
* key_off of that key on the track it started on; struck again: off then on; a layer / NAME / the splash: the
* outer keys silent; the pedal holds a let-go key until it is up;
* - the wheels on genkigenki's measured ranges; the pads PLAY (white keys) / STEPS (the UI's), the change waiting
* for the pads' release; the fader banks, the track window, the pick-up. */
#include <stdint.h>
#include <stdio.h>
#include <string.h>
@@ -20,6 +22,8 @@
#include "../firmware/hal/smk_input.h"
#undef __attribute__
#define __attribute__(x)
#define fm1__lock() 0u /* (the HAL's cli / sti: not on the host) */
#define fm1__unlock(l) ((void)(l))
/* what panel.c needs from the rest of the firmware */
#define NPALETTES 8u
#define UI_JIANT_INDEX 0u
@@ -27,13 +31,42 @@ static uint8_t fx_lowcut;
static uint32_t palette_from_stored(uint32_t v) { return v; }
static void palette_set(uint32_t p) { (void)p; }
#include "../firmware/src/panel.c"
/* what smk_kb.c needs */
#define NPART 6
typedef struct { int16_t p[4]; } track_t;
static track_t trk[NPART];
static struct { uint8_t sel; int8_t octave; } song;
static uint8_t kb_velx[27], kb_boot_hold, mo_on = 1;
#include "../firmware/src/smk_map.h"
/* what smk_kb.c needs: seq.c's key path, as stand-ins that record */
#define NTRK 6
#define KB_NK 37u
#define KB_SILENT 255u
typedef struct { int16_t p[4]; int drum; } track_t;
static track_t trk[NTRK];
static struct { uint8_t sel, grid; int8_t octave; } song;
static uint8_t kb_velx[KB_NK], kb_note[KB_NK], kb_trk[KB_NK], kb_boot_hold, kb_asleep, fx_lock_on, mo_on = 1;
static int8_t kb_oct[KB_NK];
static uint8_t split_cfg[1];
static uint32_t kb_prev, kb_mask = 1u << 10; /* (a layer's button: GLOBE) */
static uint32_t split_track(uint32_t high) { return high; }
static int32_t split_oct(uint32_t high) { (void)high; return 0; }
static int32_t clamp(int32_t v, int32_t lo, int32_t hi) { return v < lo ? lo : v > hi ? hi : v; }
static int drum_track(const track_t *t) { return t->drum; }
static uint32_t kb_map(const track_t *t, uint32_t k) /* seq.c kb_map with QUANT OFF and no engine key map */
{
(void)t;
return (uint32_t)clamp((k < 27u ? 53 + (int32_t)k : 53 + smk_kb_off(k)) + 12 * song.octave, 0, 127);
}
typedef struct { uint8_t on, key, trk, note, vel; } kev_t;
static kev_t kev[256];
static uint32_t nkev;
static void key_on(uint32_t k, track_t *t)
{
if (nkev < 256u) kev[nkev] = (kev_t){1, (uint8_t)k, (uint8_t)(t - trk), kb_note[k], (uint8_t)(kb_velx[k] ^ 100u)};
nkev++;
}
static void key_off(uint32_t k, track_t *t)
{
if (nkev < 256u) kev[nkev] = (kev_t){0, (uint8_t)k, (uint8_t)(t - trk), kb_note[k], 0};
nkev++;
}
static void smk_key_up(uint32_t k, track_t *t);
static void (*key_off_fp)(uint32_t, track_t *) = smk_key_up;
typedef struct { uint8_t st, ch, d1, d2; } ev_t;
static ev_t ev[512];
static uint32_t nev, nout;
@@ -43,21 +76,47 @@ static void midi_event(uint32_t st, uint32_t ch, uint32_t d1, uint32_t d2)
nev++;
}
static uint32_t mo_key(const track_t *t) { (void)t; return mo_on; }
static void mo_kon(uint32_t i, uint32_t x, uint32_t v) { (void)i; (void)x; (void)v; nout++; }
static void mo_koff(uint32_t i, uint32_t x) { (void)i; (void)x; nout--; }
static void mo_send(uint32_t st, uint32_t d1, uint32_t d2) { (void)st; (void)d1; (void)d2; nout++; }
#include "../firmware/src/smk_kb.c"
#undef __attribute__
static int bad;
static void check(const char *what, int ok) { printf("smk map: %-100s %s\n", what, ok ? "ok" : "FAIL"); bad += !ok; }
/* smk_input.h: button id -> printed name (confirmed on a unit by Melodee) */
/* smk_input.h: button id -> printed name (confirmed on a unit, genkigenki's 01-hardware.md 5.3) */
static const char *const PRINTED[FM1_NBTN] = {"KNOB BANK", "FADER BANK", "<", ">", "OCTAVE-", "OCTAVE+", "ARP",
"NOTE REPEAT", "SCALE", "CHORD", "GLOBE", "BT", "PATCH", "PARA", "FX",
"SEQ", "SEQ PLAY", "SEQ REC"};
static const char *const NOTE[12] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
static void block(void) { fm1_in.frames = 100; smk_kb_block(); }
/* seq.c keyboard_block on the stand-ins: smk_kb_block, then the 27 keys' edges (press: kb_note = kb_map, key_on on
* the selected track; release: key_off_fp on the track it started on), as seq.c does with no layer, grid or SCENE */
static void block(void)
{
uint32_t cur, ch, k;
fm1_in.frames = 100;
cur = smk_kb_block();
ch = cur ^ kb_prev;
for (k = 0; k < 27u; k++) {
if (!((ch >> k) & 1u))
continue;
if ((cur >> k) & 1u) {
kb_trk[k] = song.sel;
if (kb_boot_hold) { kb_note[k] = KB_SILENT; continue; }
kb_note[k] = (uint8_t)kb_map(&trk[kb_trk[k]], k);
key_on(k, &trk[kb_trk[k]]);
} else if (kb_note[k] != KB_SILENT) {
key_off_fp(k, &trk[kb_trk[k] % NTRK]);
}
}
kb_prev = cur;
}
static void hal_reset(void)
{
fm1_in.notes = fm1_in.knotes = fm1_in.pnotes = fm1_in.notes_pressed = fm1_in.notes_retrig = 0;
fm1_in.keys = 0;
smk_extq_r = smk_extq_w = 0;
}
int main(void)
{
@@ -69,222 +128,308 @@ int main(void)
int32_t o;
memset(&panel, 0, sizeof panel);
panel_init();
check("panel_init: a blank table becomes the SMK default (\"PNS6\", the V10.8 layout)",
panel.magic == PANEL_MAGIC && PANEL_MAGIC == 0x504E5336u);
check("panel_init: a blank table becomes the SMK default (\"PNS7\", Rhythmer's layout)",
panel.magic == PANEL_MAGIC && PANEL_MAGIC == 0x504E5337u);
for (i = 0; i < sizeof WANT / sizeof WANT[0]; i++) {
uint32_t id = panel.btn[WANT[i].label];
ok &= id < FM1_NBTN && !strcmp(PRINTED[id], WANT[i].smk) && !strcmp(B_NAME[WANT[i].label], WANT[i].smk);
used |= 1u << id;
}
check("the 14 FM-1 functions on their printed SMK buttons; calibration asks by that name", ok && sizeof WANT / sizeof WANT[0] == NB);
check("the 14 FM-1 functions on their printed SMK buttons (PATCH HOME, PARA EDIT, CHORD ENV, NOTE REPEAT LFO, BT SAVE)",
ok && sizeof WANT / sizeof WANT[0] == NB);
check("KNOB BANK, FADER BANK, < and > carry no FM-1 function (ids 0..3)", (used & 0xFu) == 0 &&
panel_btn_of(SMK_BTN_KNOB_BANK) == NB && panel_btn_of(SMK_BTN_LEFT) == NB && panel_btn_of(SMK_BTN_RIGHT) == NB &&
panel_btn_of(SMK_BTN_FADER_BANK) == NB && panel.btn[B_OCTDN] == FM1_BTN_OCT_DOWN && panel.btn[B_OCTUP] == FM1_BTN_OCT_UP);
check("K1..K4 = KNOB 1..4 (encoders 0..3), K5 SELECT (4), K6 PRESETS (5), K7 ALGORITHM (6), clockwise +",
panel.enc[EN_K1] == 0 && panel.enc[EN_K2] == 1 && panel.enc[EN_K3] == 2 && panel.enc[EN_K4] == 3 &&
panel.enc[EN_SELECT] == 4 && panel.enc[EN_PRESET] == 5 && panel.enc[EN_ALGO] == 6 &&
!strcmp(E_NAME[EN_SELECT], "K5") && !strcmp(E_NAME[EN_PRESET], "K6") && !strcmp(E_NAME[EN_ALGO], "K7") &&
!strcmp(E_NAME[EN_K1], "K1") && panel.dir[0] == 1 && panel.dir[6] == 1);
check("K2 SELECT (encoder 1), K3 ALGORITHM (2), K4 PRESETS (3), K5..K8 KNOB 1..4 (4..7), clockwise +",
panel.enc[EN_SELECT] == 1 && panel.enc[EN_ALGO] == 2 && panel.enc[EN_PRESET] == 3 && panel.enc[EN_K1] == 4 &&
panel.enc[EN_K2] == 5 && panel.enc[EN_K3] == 6 && panel.enc[EN_K4] == 7 && !strcmp(E_NAME[EN_SELECT], "K2") &&
!strcmp(E_NAME[EN_ALGO], "K3") && !strcmp(E_NAME[EN_PRESET], "K4") && !strcmp(E_NAME[EN_K1], "K5") &&
!strcmp(E_NAME[EN_K4], "K8") && panel.dir[0] == 1 && panel.dir[6] == 1);
for (i = 0, k = 0; i < NE; i++)
k |= panel.enc[i] == SMK_ENC_MASTER;
check("K8 (encoder 7) is no panel role: the MASTER, a virtual pot from 724, 24 a detent",
!k && SMK_ENC_MASTER == 7u && smk_master == 724 && FM1_ADC_MASTER == 4);
check("K1 (encoder 0) is no panel role: the MASTER, a virtual pot from 724, 24 a detent",
!k && SMK_ENC_MASTER == 0u && smk_master == 724 && FM1_ADC_MASTER == 4);
panel.btn[B_FX] = 17u; panel.btn[B_REC] = 14u; /* a calibrated table with the high ids */
panel_init();
check("panel_init keeps a calibrated table with button ids up to 17 and knob 7", panel.btn[B_FX] == 17u && panel.enc[EN_ALGO] == 6u);
check("panel_init keeps a calibrated table with button ids up to 17 and knob 7", panel.btn[B_FX] == 17u && panel.enc[EN_K4] == 7u);
panel.btn[B_FX] = 18u;
panel_init();
check("... and refuses id 18 (back to the default)", panel.btn[B_FX] == 14u);
panel.enc[EN_K1] = 8u;
panel_init();
check("... and knob 8", panel.enc[EN_K1] == 0u);
check("... and knob 8", panel.enc[EN_K1] == 4u);
/* ---- the keybed: all 37 keys, every octave ---- */
/* ---- the keybed through the HAL: ids 5..31 the FM-1's keys, the outer ten the queue ---- */
for (k = 0, ok = 1; k < FM1_NKEY; k++) {
uint32_t q0 = smk_extq_w;
uint32_t c = k >= 5u && k <= 31u, bit = c ? 1u << (k - 5u) : 0u;
int32_t e;
hal_reset();
smk__key_event(k, 90);
ok &= fm1_in.notes == 0u && smk_extq_w != q0;
e = smk_extkey_take();
ok &= e == (int32_t)(k << 8 | 90u);
smk__key_event(k, 0);
e = smk_extkey_take();
ok &= e == (int32_t)(k << 8) && smk_extkey_take() < 0 && fm1_in.notes == 0u;
}
check("hal: every key 0..36 (C3..C6, the outer 10 too) through the queue with its velocity, none an FM-1 key", (int)ok);
{
uint32_t range = 1, distinct = 1, step = 1, c3 = 1;
for (o = -8; o <= 8; o++) {
uint8_t seen[128] = {0};
for (k = 0; k < SMK_KEYS; k++) {
uint32_t n = smk_key_note(k, o);
range &= n <= 127u;
distinct &= !seen[n & 127u];
seen[n & 127u] = 1;
step &= !k || n == smk_key_note(k - 1u, o) + 1u;
}
if (o >= -3 && o <= 3)
c3 &= smk_key_note(0, o) == (uint32_t)(48 + 12 * o) && smk_key_note(36, o) == (uint32_t)(84 + 12 * o);
if (c) {
ok &= fm1_in.notes == bit && fm1_in.notes_pressed == bit && fm1_in.note_vel[k - 5u] == 90u && smk_extkey_take() < 0;
} else {
e = smk_extkey_take();
ok &= fm1_in.notes == 0u && e == (int32_t)(k << 8 | 90u);
}
check("smk_key_note: at OCT -8..+8 all 37 notes in 0..127, one semitone apart, never two the same", range && distinct && step);
check("... OCT -3..+3 (the FM-1's range): key 0 = C3 + 12 OCT .. key 36 = C6 + 12 OCT, no window moved",
(int)c3 && smk_key_note(0, -4) == 0u && smk_key_note(36, 4) == 127u - 36u + 36u);
ok &= (uint32_t)(fm1_in.keys >> k) == 1u && fm1_in.key_vel[k] == 90u;
smk__key_event(k, 0);
ok &= fm1_in.notes == 0u && fm1_in.keys == 0u;
if (!c)
ok &= smk_extkey_take() == (int32_t)(k << 8) && smk_extkey_take() < 0;
}
{ /* smk_kb_block: each key down plays its note on the selected track, each release ends it */
uint32_t good = 1, outs = 1, vels = 1;
check("hal: ids 5..31 (F3..G5) are the FM-1's keys 0..26 (fm1_in.notes, the UI's edges, their velocity); "
"ids 0..4, 32..36 the queue", (int)ok);
{
uint32_t seen = 0, map = 1;
uint64_t all = 0;
for (k = 0; k < SMK_KEYS; k++) {
uint32_t L = smk_kb_key(k);
map &= L < SMK_KEYS && !((all >> L) & 1u) && smk_key_note(k, 0) == 48u + k;
all |= (uint64_t)1u << L;
seen += smk_kb_off(L) == (int32_t)k - 5;
}
check("smk_kb_key: the 37 ids onto keys 0..36 one to one (5..31 -> 0..26, 0..4 -> 27..31, 32..36 -> 32..36); "
"at OCT 0 id k plays MIDI 48 + k", map && seen == SMK_KEYS && all == ((uint64_t)1u << 37) - 1u &&
smk_kb_key(0) == 27u && smk_kb_key(4) == 31u && smk_kb_key(5) == 0u && smk_kb_key(31) == 26u &&
smk_kb_key(32) == 32u && smk_kb_key(36) == 36u && smk_kb_key(37) == 0xFFu);
}
/* ---- all 37 key ids through the key path, every octave and track ---- */
{
uint32_t good = 1, vels = 1, offs = 1, ends = 1;
memset(&smk_kb, 0, sizeof smk_kb);
fm1_in.wheel[0] = 535; fm1_in.wheel[1] = 629; fm1_in.pedal = 985;
for (o = -3; o <= 3; o++)
for (song.sel = 0; song.sel < NPART; song.sel++) {
for (song.sel = 0; song.sel < NTRK; song.sel++) {
uint8_t seen[128] = {0};
song.octave = (int8_t)o;
for (k = 0; k < SMK_KEYS; k++) {
uint32_t v = 1u + (k * 7u + (uint32_t)(o + 3)) % 127u;
nev = 0;
uint32_t v = 1u + (k * 7u + (uint32_t)(o + 3)) % 127u, n = smk_key_note(k, o);
nkev = 0;
smk__key_event(k, v);
block();
good &= nev >= 1u && ev[0].st == 0x90u && ev[0].ch == song.sel && !seen[ev[0].d1] &&
ev[0].d1 == smk_key_note(k, o);
vels &= ev[0].d2 == v;
seen[ev[0].d1] = 1;
good &= nkev == 1u && kev[0].on && kev[0].key == smk_kb_key(k) && kev[0].trk == song.sel &&
kev[0].note == n && !seen[n] && n == (uint32_t)(48 + 12 * o + (int32_t)k);
vels &= kev[0].vel == v;
seen[n] = 1;
}
outs &= nout == SMK_KEYS;
for (k = 0; k < SMK_KEYS; k++) {
nev = 0;
nkev = 0;
smk__key_event(k, 0);
block();
good &= nev >= 1u && ev[0].st == 0x80u && ev[0].ch == song.sel && ev[0].d1 == smk_key_note(k, o);
offs &= nkev == 1u && !kev[0].on && kev[0].key == smk_kb_key(k) && kev[0].trk == song.sel &&
kev[0].note == smk_key_note(k, o);
}
outs &= nout == 0u;
ends &= seen[48 + 12 * o] && seen[84 + 12 * o];
}
check("smk_kb_block: all 37 keys x OCT -3..+3 x T1..T6: a note-on each, on the selected track, 37 different notes",
(int)good);
check("... at the key's own velocity; each release a note-off of that note; MIDI OUT: as many offs as ons",
vels && outs);
printf("smk map: keys 0 / 36 at OCT 0: %s%d / %s%d\n", NOTE[smk_key_note(0, 0) % 12u], (int)smk_key_note(0, 0) / 12 - 1,
NOTE[smk_key_note(36, 0) % 12u], (int)smk_key_note(36, 0) / 12 - 1);
check("key path: all 37 key ids x OCT -3..+3 x T1..T6: a key_on each, on the selected track, 37 notes apart "
"(C3 + id + 12 OCT)", (int)good);
check("... at the key's own velocity; each release a key_off of that key on its track; both ends sound "
"(C3 / C6 at OCT 0)", vels && offs && ends);
printf("smk map: key ids 0 / 4 / 5 / 31 / 32 / 36 at OCT 0: %s%d %s%d %s%d %s%d %s%d %s%d\n",
NOTE[smk_key_note(0, 0) % 12u], (int)smk_key_note(0, 0) / 12 - 1, NOTE[smk_key_note(4, 0) % 12u],
(int)smk_key_note(4, 0) / 12 - 1, NOTE[smk_key_note(5, 0) % 12u], (int)smk_key_note(5, 0) / 12 - 1,
NOTE[smk_key_note(31, 0) % 12u], (int)smk_key_note(31, 0) / 12 - 1, NOTE[smk_key_note(32, 0) % 12u],
(int)smk_key_note(32, 0) / 12 - 1, NOTE[smk_key_note(36, 0) % 12u], (int)smk_key_note(36, 0) / 12 - 1);
}
{ /* held across a track and an octave change, struck again, under the splash */
{ /* held across a track and an octave change, struck again, layers, the splash */
uint32_t ok2;
song.sel = 2; song.octave = 1;
nev = 0;
nkev = 0;
smk__key_event(0, 80);
smk__key_event(20, 80);
smk__key_event(36, 80);
block();
song.sel = 4; song.octave = -2;
nev = 0;
nkev = 0;
smk__key_event(0, 0);
smk__key_event(20, 0);
smk__key_event(36, 0);
block();
ok2 = nkev == 3u && kev[0].trk == 2u && kev[1].trk == 2u && kev[2].trk == 2u && !kev[0].on && !kev[1].on &&
!kev[2].on;
check("keys held while the track and OCT change: each release ends the key on the track it started on (T3)", (int)ok2);
nkev = 0;
smk__key_event(10, 70); /* a central key struck again: the HAL's retrig bit */
block();
fm1_in.notes_retrig |= 1u << 5;
smk__key_event(10, 110);
block();
ok2 = nkev == 2u && kev[0].on && !kev[1].on;
block();
check("a central key struck again before a full lift (notes_retrig): off at this block, on at the next at the new "
"velocity", ok2 && nkev == 3u && kev[2].on && kev[2].vel == 110u && kev[2].key == 5u);
smk__key_event(10, 0);
block();
nkev = 0;
smk__key_event(33, 70);
smk__key_event(33, 0);
smk__key_event(33, 110);
block();
check("an outer key struck again (release + press in the queue): off, then on at the new velocity, in one block",
nkev == 3u && kev[0].on && !kev[1].on && kev[2].on && kev[2].vel == 110u && kev[2].key == 33u);
smk__key_event(33, 0);
block();
nkev = 0;
fm1_in.buttons = kb_mask; /* a layer's button held */
smk__key_event(1, 90);
block();
smk__key_event(1, 0);
block();
fm1_in.buttons = 0;
song.grid = 1; /* NAME / the DRUM grid */
smk__key_event(35, 90);
block();
smk__key_event(35, 0);
block();
song.grid = 0;
kb_boot_hold = 1;
smk__key_event(5, 90);
smk__key_event(0, 90);
block();
smk__key_event(5, 0);
smk__key_event(0, 0);
block();
kb_boot_hold = 0;
check("a layer, NAME / the DRUM grid, the splash: the outer keys silent (their release too); the splash the 27's",
nkev == 0u);
trk[3].drum = 1;
song.sel = 3;
song.octave = 0;
nkev = 0;
smk__key_event(0, 90);
smk__key_event(36, 90);
block();
smk__key_event(0, 0);
smk__key_event(36, 0);
block();
ok2 = nev >= 2u && ev[0].st == 0x80u && ev[0].ch == 2u && ev[0].d1 == 60u && ev[1].st == 0x80u && ev[1].ch == 2u &&
ev[1].d1 == 96u;
check("a key held while the track and OCT change: its release ends the note it started (T3, C4 / C7)", (int)ok2);
nev = 0;
smk__key_event(10, 70);
smk__key_event(10, 0);
smk__key_event(10, 110);
trk[3].drum = 0;
check("a DRUM track: the outer keys sound too (seq.c kb_map gives each a lane)", nkev == 4u && kev[0].on && kev[1].on);
}
{ /* the pedal: sustain */
uint32_t ok4;
memset(&smk_kb, 0, sizeof smk_kb);
song.sel = 0;
fm1_in.pedal = 985;
block(); /* (the rest taken) */
fm1_in.pedal = 20; /* pressed (reads low) */
nkev = nev = 0;
smk__key_event(12, 90);
smk__key_event(2, 90);
block();
check("struck again before a full lift (release + press in the queue): off, then on at the new velocity",
nev >= 3u && ev[0].st == 0x90u && ev[1].st == 0x80u && ev[2].st == 0x90u && ev[2].d2 == 110u);
smk__key_event(10, 0);
smk__key_event(12, 0);
smk__key_event(2, 0);
block();
kb_boot_hold = 1;
nev = 0;
smk__key_event(5, 90);
ok4 = nkev == 2u && kev[0].on && kev[1].on && nev >= 1u && ev[0].st == 0xB0u && ev[0].d1 == 64u && ev[0].d2 == 127u;
smk__key_event(12, 60); /* struck again while held by the pedal: the old note ends first */
block();
smk__key_event(5, 0);
ok4 &= nkev == 4u && !kev[2].on && kev[2].key == 7u && kev[3].on && kev[3].key == 7u;
smk__key_event(12, 0);
block();
check("under the splash (kb_boot_hold): silent, its release too", nev == 0u);
kb_boot_hold = 0;
ok4 &= nkev == 4u;
fm1_in.pedal = 985; /* up: both let go */
block();
check("SUSTAIN: keys let go with the pedal down keep sounding; struck again: off, on; pedal up: they end; CC64 sent",
ok4 && nkev == 6u && !kev[4].on && !kev[5].on && smk_kb.sus == 0u);
}
/* ---- the wheels and the pedal ---- */
/* ---- the wheels (genkigenki's measured ranges: PITCH rest ~535, 445..640; MOD 474..629, up = lower) ---- */
{
uint32_t ok3;
int32_t lo, hi;
memset(&smk_kb, 0, sizeof smk_kb);
song.sel = 1;
fm1_in.wheel[0] = 512; fm1_in.wheel[1] = 3; fm1_in.pedal = 1000;
fm1_in.wheel[0] = 535; fm1_in.wheel[1] = 629; fm1_in.pedal = 985;
nev = 0;
block();
ok3 = nev == 0u && smk_kb.cal;
fm1_in.wheel[0] = 530;
fm1_in.wheel[0] = 543;
block();
ok3 &= nev == 0u; /* (inside the dead zone) */
fm1_in.wheel[0] = 1023;
ok3 &= nev == 0u; /* (inside the dead zone) */
fm1_in.wheel[0] = 640;
block();
hi = nev ? (int32_t)(ev[nev - 1u].d1 | ev[nev - 1u].d2 << 7) - 8192 : 0;
fm1_in.wheel[0] = 0;
fm1_in.wheel[0] = 445;
block();
lo = nev ? (int32_t)(ev[nev - 1u].d1 | ev[nev - 1u].d2 << 7) - 8192 : 0;
fm1_in.wheel[0] = 512;
fm1_in.wheel[0] = 535;
block();
check("PITCH: centred at its rest (a dead zone), the top end +8191, the bottom -8192, back to 0, on T2's channel",
ok3 && hi == 8191 && lo == -8192 && ev[nev - 1u].st == 0xE0u && ev[nev - 1u].ch == 1u &&
check("PITCH: centred at its rest (a dead zone), its measured travel 445..640 the full -8192..+8191, back to 0, "
"on T2's channel", ok3 && hi == 8191 && lo == -8192 && ev[nev - 1u].st == 0xE0u && ev[nev - 1u].ch == 1u &&
ev[nev - 1u].d1 == 0u && ev[nev - 1u].d2 == 64u);
nev = 0;
fm1_in.wheel[1] = 1023;
fm1_in.wheel[1] = 474;
block();
check("MOD: CC1 from 0 at its rest to 127 at the other end", nev == 1u && ev[0].st == 0xB0u && ev[0].d1 == 1u && ev[0].d2 == 127u);
ok3 = nev == 1u && ev[0].st == 0xB0u && ev[0].d1 == 1u && ev[0].d2 == 127u;
fm1_in.wheel[1] = 629;
block();
check("MOD: CC1 0 at its rest (629) to 127 at the top of its travel (474: up = the lower reading)",
ok3 && nev == 2u && ev[1].d2 == 0u);
nev = 0;
fm1_in.pedal = 20; /* (a pedal that reads low when pressed) */
song.sel = 3; /* another track: nothing was off centre, nothing let go */
fm1_in.wheel[0] = 640;
block();
ok3 = nev == 1u && ev[0].d1 == 64u && ev[0].d2 == 127u;
nev = 0;
song.sel = 3; /* another track: the old one let go */
check("another track: the wheels go to the new one", nev == 1u && ev[0].ch == 3u && ev[0].st == 0xE0u);
fm1_in.wheel[0] = 535;
block();
check("SUSTAIN: CC64 127 pressed (either polarity, from its rest); another track: T2 let go, T4 gets them",
ok3 && nev >= 4u && ev[0].ch == 1u && ev[0].st == 0xB0u && ev[1].ch == 1u && ev[1].d1 == 64u && ev[1].d2 == 0u &&
ev[nev - 1u].ch == 3u && ev[nev - 1u].d1 == 64u && ev[nev - 1u].d2 == 127u);
}
/* ---- the pads ---- */
check("the pads' rule: the MENU / a dialog OFF; the FM-1's keys the UI's (layer, NAME, DRUM grid, STEP FX) WHITE; "
"SEQ STEPS; else TRACKS",
smk_pads_rule(1, 1, 1) == SMK_PM_OFF && smk_pads_rule(0, 1, 1) == SMK_PM_WHITE &&
smk_pads_rule(0, 1, 0) == SMK_PM_WHITE && smk_pads_rule(0, 0, 1) == SMK_PM_STEPS &&
smk_pads_rule(0, 0, 0) == SMK_PM_TRACKS);
check("pad n = hardware pad n - 1 (1..8 the top row, 9..16 the bottom); 7 UNDO, 8 TAP, 9..16 pages",
smk_pad_num(0) == 1u && smk_pad_num(7) == 8u && smk_pad_num(8) == 9u && smk_pad_num(15) == 16u &&
SMK_PAD_UNDO == 7u && SMK_PAD_TAP == 8u && SMK_PAD_PAGE0 == 9u && !strcmp(SMK_PAGES[0].nm, "MIXER") &&
!strcmp(SMK_PAGES[7].nm, "GENERATOR 1"));
{
static const uint8_t WHITE[16] = {0, 2, 4, 6, 7, 9, 11, 12, 14, 16, 18, 19, 21, 23, 24, 26};
uint32_t seen = 0;
smk_pads_t p = {SMK_PADS_PLAY, 0};
uint32_t seen = 0, m;
int32_t e;
for (i = 0; i < SMK_NPAD; i++) {
uint32_t w;
for (w = 0; w < 16u && WHITE[w] != SMK_PK_GRID[i]; w++) {}
if (w < 16u && w == i) seen |= 1u << w;
}
check("WHITE: pad n is the FM-1's n-th white key (F3 G3 .. G5: steps 1..16, the layers' keys)",
seen == 0xFFFFu && smk_pad_key == SMK_PK_NONE);
fm1_in.notes = fm1_in.pnotes = 0;
for (i = 0; i < SMK_NPAD; i++)
if (SMK_PK_GRID[i] == WHITE[i]) seen |= 1u << i;
check("pad n = hardware pad n - 1 (1..8 the top row, mux A; 9..16 the bottom); PLAY: pad n the FM-1's n-th white "
"key (F3 .. G5)", seen == 0xFFFFu && smk_pad_num(0) == 1u && smk_pad_num(15) == 16u);
hal_reset();
smk_pad_key = SMK_PK_GRID;
smk__padq(0, 100);
smk__padq(15, 77);
ok = fm1_in.notes == (1u << 0 | 1u << 26) && fm1_in.pad_vel[0] == 100u && fm1_in.pad_vel[26] == 77u;
ok = fm1_in.notes == (1u << 0 | 1u << 26) && fm1_in.note_vel[0] == 100u && fm1_in.note_vel[26] == 77u;
smk__key_event(5, 50); /* the keybed's F3 too: one note, two sources */
smk__padq(0, 0);
ok &= fm1_in.notes == (1u << 0 | 1u << 26);
smk__key_event(5, 0);
smk__padq(15, 0);
ok &= fm1_in.notes == 0u && smk_pad_take() < 0;
smk_pad_key = SMK_PK_NONE;
smk__padq(3, 64);
e = smk_pad_take();
smk__padq(3, 0);
check("... a hit presses its white key at its velocity (pad 1 F3, pad 16 G5); STEPS / TRACKS: the UI's queue",
check("... a hit presses its white key at its velocity (a key of the keybed alongside); STEPS: the UI's queue",
ok && e == (3 << 8 | 64) && smk_pad_take() == (3 << 8) && fm1_in.notes == 0u);
ok = smk_pads_white(&p);
smk_pads_toggle(&p); /* KNOB BANK with a pad down: waits */
ok &= !smk_pads_white(&p) && !smk_pads_settle(&p, 1) && p.mode == SMK_PADS_PLAY && p.gate;
ok &= smk_pads_settle(&p, 0) && p.mode == SMK_PADS_STEPS && !p.gate && !smk_pads_white(&p);
smk_pads_toggle(&p);
ok &= smk_pads_settle(&p, 0) && p.mode == SMK_PADS_PLAY && smk_pads_white(&p);
smk_pads_toggle(&p);
smk_pads_toggle(&p); /* (pressed again while waiting: undone) */
m = !smk_pads_settle(&p, 0) && p.mode == SMK_PADS_PLAY;
check("KNOB BANK: PLAY <-> STEPS; asked with a pad down, the change waits for the release (pads idle meanwhile)",
ok && m);
}
/* ---- the banks ---- */
ok = 1;
for (i = 0; i < 6u; i++)
ok &= SMK_MACRO[i].trk == i && SMK_MACRO[i].what == SMK_TG_CUT;
check("KNOB BANK: K1..K6 the cutoff of T1..T6, K7 the delay's MIX, K8 the reverb's SIZE",
ok && SMK_MACRO[6].trk == SMK_T_G && SMK_MACRO[6].what == SMK_TG_DMIX && SMK_MACRO[7].what == SMK_TG_RSIZE);
ok = 1;
for (i = 0; i < 4u; i++)
ok &= SMK_FADER[0][i].trk == i && SMK_FADER[0][i].what == SMK_TG_LEVEL;
check("FADER BANK A: the levels of T1..T4; B: T5, T6, the selected track's delay and reverb sends",
ok && SMK_FADER[1][0].trk == 4u && SMK_FADER[1][1].trk == 5u && SMK_FADER[1][1].what == SMK_TG_LEVEL &&
SMK_FADER[1][2].trk == SMK_T_SEL && SMK_FADER[1][2].what == SMK_TG_DSEND && SMK_FADER[1][3].what == SMK_TG_RSEND);
/* ---- the faders ---- */
{
uint32_t b = SMK_FB_LEVEL, cyc = 1, win = 1;
for (i = 0; i < 4u; i++) {
b = smk_fb_next(b);
cyc &= b == (i + 1u) % 4u;
}
for (k = 0; k < 6u; k++)
for (i = 0; i < 4u; i++)
win &= smk_fader_track(i, k) == (k < 4u ? (int)i : i < 2u ? (int)(4u + i) : -1);
check("FADER BANK: LEVEL -> PAN -> REVERB -> DELAY -> LEVEL; F1..F4 T1..T4, T5 / T6 selected: F1 F2 T5 T6, F3 F4 none",
cyc && win && SMK_FB_LEVEL == 0 && SMK_FB_PAN == 1 && SMK_FB_REVERB == 2 && SMK_FB_DELAY == 3);
check("... the pick-up's context changes with the bank and the window (re-armed), not within a window",
smk_fader_ctx(0, 0) == smk_fader_ctx(0, 3) && smk_fader_ctx(0, 3) != smk_fader_ctx(0, 4) &&
smk_fader_ctx(0, 4) == smk_fader_ctx(0, 5) && smk_fader_ctx(1, 0) != smk_fader_ctx(0, 0) &&
smk_fader_ctx(3, 5) == 7u);
}
{
smk_pick_t p;
uint32_t a, b, c, d, e2, f;
@@ -293,12 +438,12 @@ int main(void)
b = !smk_pickup(&p, 60, 100); /* still below */
c = smk_pickup(&p, 101, 100); /* crossed it */
d = smk_pickup(&p, 90, 101); /* picked: follows */
e2 = !smk_pickup(&p, 92, 40); /* the value moved elsewhere (a knob): lost */
e2 = !smk_pickup(&p, 92, 40); /* the value moved elsewhere (a knob, a load): lost */
f = smk_pickup(&p, 41, 40); /* met again */
check("pick-up: a fader moves its value only once it has met it (or crossed it); lost when the value moves elsewhere",
a && b && c && d && e2 && f);
smk_pick_reset(&p);
check("... a first reading right at the value takes it, one far from it does not",
check("... a first reading right at the value takes it, one far from it does not (a bank / window change resets)",
smk_pickup(&p, 64, 65) && (smk_pick_reset(&p), !smk_pickup(&p, 0, 127)));
}
printf("%s\n", bad ? "SMK MAP TEST FAILED" : "smk map test passed");
+2149 -2151
View File
File diff suppressed because it is too large. Load diff