Repository navigation
Firmware Add A Page Or Key
This page is the recipe for giving the device a new soft key (F1 to F6) on a page that exists, or a whole new page. It tells you which files to touch, in which order, how to test it, and the traps. The worked example in the code is PERFORM, the page added in firmware 1.7.0.
New to the firmware? Read Firmware Internals first.
| File | For a soft key | For a page |
|---|---|---|
sfx-forge/fw_state.h |
its caption in SOFT (and soft_caption if it changes with the state) |
PG_... in the enum, TAB_OF, a row in SOFT, soft_set
|
sfx-forge/fw_pages.h |
tab_key, set_page, arrow, encoder
|
|
sfx-forge/fw_softkeys.h |
its case in the page's soft_... function |
a new soft_... function |
sfx-forge/fw_events.h |
its line in the page's HELP_... table |
the pad branch and the F1 to F6 branch in on_event, a new HELP_... table |
sfx-forge/fw_draw_pages.h |
a draw_... function |
|
sfx-forge/fw_draw.h |
on_draw, parts 2 to 6 |
|
fw_stage_input.h, fw_stage_draw.h
|
only if the stage should have the button | only if the stage should show it |
tests/, build.sh
|
a scene and a check | a check on tests/host.mjs
|
docs/MANUAL.md, README.md, docs/figures.py
|
section 20, "Playing it", the cheat sheet | the same |
flowchart TB
key["a key is pressed"]
onevent["on_event<br/>fw_events.h"]
tabkey["tab_key, set_page<br/>fw_pages.h"]
soft["soft_seq, soft_song ...<br/>fw_softkeys.h"]
song["SONG, or a sound<br/>fw_state.h"]
caption["SOFT, soft_caption<br/>fw_state.h"]
ondraw["on_draw<br/>fw_draw.h"]
drawpage["draw_...<br/>fw_draw_pages.h"]
help["HELP_... tables<br/>fw_events.h"]
key --> onevent
onevent -->|"K1 to K6"| tabkey
onevent -->|"F1 to F6, by page"| soft
soft --> song
ondraw -->|"part 2: HOME"| help
ondraw -->|"part 5"| drawpage
ondraw -->|"part 6"| caption
drawpage --> song
-
The caption. In
fw_state.h, write it into theSOFTtable. A caption has at most 7 characters. If it changes with the state, handle it insoft_caption. -
The case. In
fw_softkeys.h, add itscaseinsoft_sound,soft_seq,soft_song,soft_auto,soft_mixorsoft_perform.fis 0 for F1. SHIFT is the variableshift. -
What it does. Use the helpers that exist:
The key ... Do this changes the song change SONG. Callundo_mark(fw_edit.h) first if UNDO should take it backchanges a sound keep_undo(slot)before,changed(slot)afterthrows much away ask twice with confirm("...")says something say("...")does what a key of another page does call that key's function, as soft_performdoes -
HOME. In
fw_events.h, add the line to the page'sHELP_...table. A table has at most 11 rows. -
The stage, if it should have the button: the hit test in
stage_eventand the drawing inon_stage. The same numbers stand in both files. -
A test (below), and the documents.
A page hangs on one of the six K keys. There is no seventh key, so a new page is one more press of a key that exists.
-
fw_state.h. AddPG_...to the enum. The order of the list is used: a sound page goes beforePG_SEQand gets a row inPAGE_PARAMS;PG_SEQtoPG_MASTERare the song's pages; a page that is neither goes afterPG_LINK. Add its entry inTAB_OF(a missing one stops the build). Look atmix_page,sound_page,song_keysandpattern_keys: is the new page one of them? -
fw_pages.h.tab_key(which press of which K key opens it),set_page(the K key's label, at most 7 characters),arrow(LEFT / RIGHT) andencoder(what the four encoders turn). -
Soft keys. A row in
SOFT(raise the table's first size), its case insoft_set, a functionsoft_..., and the branch inon_eventunder "F1-F6: by page". Callrelabel()when the captions change. -
Pads. The page's branch in
on_event's pad case. A pad let go must end what it began, whatever the mode is by then. -
Display. A
draw_...function infw_draw_pages.h. Then, inon_draw:- part 2: HOME, with a new
HELP_...table; - part 3:
TITLEandFIRST(a missing entry stops the build), and thepagesline that counts the pages of each key; - part 4: the pads' lights, and the page's number in the lights' cache word
led. Everything that decides a light must be in that word, and it must still fit; - part 5:
vibe_link_page(the page's name for the host) and the page's branch; - part 6: which key is dimmed or lit.
- part 2: HOME, with a new
-
The stage, if the page should have a tab there:
ST_PAGEandST_Ninfw_stage_input.h, the names inon_stage. -
Update the comments that list pages: the header of
sfx-forge.cand of each part you touched.
A check drives the built firmware and reads the song it sends back. For a key with SHIFT, pads or SysEx, use the
small host tests/host.mjs. This complete check presses K5 (the SEQ page) and F3 (FILL) and looks at the song:
// tests/check-mykey.mjs
import { load, SECOND, BUTTON } from './host.mjs';
import { stepList, same } from './song-read.mjs';
const device = load(process.argv[2] || 'build/sfx-forge.wasm');
const d = device(); // the factory state, nothing stored
d.run(SECOND);
d.button(BUTTON.K5); // the SEQ page
d.button(BUTTON.F3); // FILL: the selected sound on every beat
const song = d.song().bytes; // the packed song the device sends back
const good = same(stepList(song, 0, 0), [0, 4, 8, 12]); // pattern A, sound 1
console.log(good ? ' ok F3 fills every beat' : ' FAIL F3 fills every beat');
console.log(good ? 'mykey PASSED' : 'mykey FAILED');
process.exit(good ? 0 : 1);- Run
sh build.sh quickto build the firmware. - Run
node tests/check-mykey.mjs build/sfx-forge.wasm. You see oneokline andmykey PASSED. - Add its line to
build.sh, besidecheck-perform.mjs.tests/check-perform.mjsis the model for a whole page.
A key that needs neither SHIFT nor SysEx can be a scene instead: tests/<name>.json played by the SDK's
wasmtest, and tests/check-<name>.mjs. Copy edit.json with check-edit.mjs. A scene needs three lines in
build.sh: mkdir -p out/<name>, the wasmtest line, and the check.
vibe-check (run by build.sh) also presses the buttons and looks whether the display changes, and whether HOME
shows something.
-
Scripts that count K presses. This is the lesson of PERFORM. A script that pressed K5 three times to come
back from AUTO to SEQ landed on PERFORM, where F3 makes the pads mutes. Nothing stops the build for it: a check fails later with
a wrong song, or a picture shows another page. Run
grep -n K5over these and read every hit:tests/*.json,tests/make-grid-scenes.mjs(it writesgrid.json,regrid.jsonandtake64.json: change the script, not the files),tests/check-atomic.mjs,tests/check-grid-keys.mjs,docs/shots.mjs,docs/video/make_videos.py. In the scene files a button is a number: K5 is 14. The same holds for K1 and K4. -
The binary's order. The order of the parts, and of the definitions in
fw_state.h, is the order of code and data in the built.wasm. Add at the end of a group; do not move things for tidiness. - Reserved keys. Put no job on SHIFT + K1 to K6 or SHIFT + RETURN (on the VIBE those never reach a firmware), nor on SHIFT + DATA turned or ENTER held (the SDK's FOCUS uses them).
- No format changes. A page or a key changes no byte of a patch or a song. If yours needs a new field, that is another recipe: Song Format.
- Firmware Add A Setting: when the key sets something that must be remembered.
- Running The Tests: every suite and what a pass looks like.
- Release Checklist: what to do before the change ships.
- Device Controls And Pages: the pages as a player sees them.
- The maintainer's guide, Add a page or a soft key: every step in full, with what each meant for PERFORM
- The maintainer's guide, 6. Invariants
- fw_state.h, fw_pages.h, fw_softkeys.h, fw_events.h, fw_draw.h, fw_draw_pages.h
- tests/host.mjs, tests/check-perform.mjs, tests/check-edit.mjs, build.sh
SFX FORGE, firmware 1.7.2 · Home · Glossary · What Is Tested · the pages are kept in the repository's wiki/ folder: Editing This Wiki
Start
Device
- Quick Start
- Controls And Pages
- Make A Sound
- The Five Engines
- Make A Beat
- Recording
- Finer Grids
- Time Signatures
- Perform
- Song And Arrangement
- Layers And Intensity
- Automation
- Mixer And Effects
- The Stage
- Saving And Reset
- Cheat Sheet
Unity: first steps
- Install
- Quick Start
- Concepts
- Choosing A Route
- One Shots
- Live Voices
- Held Sounds
- Variations
- Presets And Patches
Unity: music
Unity: link and tools
Unity: in practice
- Recipes
- Recipes: Music
- Recipes: Link
- Showcase Walkthrough
- Copy The Showcase Pattern
- Troubleshooting
- Testing Your Audio
Unity: reference and extending
Internals
- Architecture Overview
- Repository Map
- Sound Engine
- Patch Format
- Song Format
- Link Protocol
- Firmware Internals
- Add A Page Or Key
- Add An Engine
- Add A Setting
- Building From Source
- Running The Tests
- Release Checklist
About this wiki