Repository navigation
Description
Add screenmap v2 schema parser alongside the existing ScreenMap::ParseJson
I maintain ledmapper (ledmapper.com), the FastLED Video Mapper. We just finished a long design pass on a new screenmap JSON format — call it v2 — that solves several pain points the current FastLED ScreenMap shape can't cleanly express. Full design and rationale lives in zackees/ledmapper#92. Filing here to propose FastLED-side support so v2 files can be parsed directly by the firmware (or by fl::ScreenMap) without a transcoding step.
What v1 (today's ScreenMap) cannot express
The current parser in src/fl/math/screenmap.cpp.hpp reads:
{
"map": {
"strip1": { "x": [...], "y": [...], "diameter": 0.25 }
}
}This is great for "named flat strips of LEDs at known positions." But it can't natively express:
- Forks — one signal range driving multiple physical chains (Y-splitter wiring).
- Logical UI grouping — the artist's mental model of "panel 3, quad 0" vs the per-pin wiring strip.
- 3D installations — there's no
zaxis. - Branch points — a fork branching off the middle of a parent chain (not just the tip).
- Self-documentation — every position is just an
(x[i], y[i])pair with no semantic relationship between segments.
Proposed v2 shape
{
"version": 2,
"groups": {
"trunk": { "color": "#ffffff" },
"branch": { "color": "#ff0000" }
},
"segments": [
{ "id": "a", "pin": 1, "group": "trunk",
"x": [0, 1, 2, 3, 4],
"y": [0, 0, 0, 0, 0] },
{ "id": "b", "pin": 2, "group": "branch", "parent": "a", "offset": 2,
"x": [2, 2, 2, 2],
"y": [0, 1, 2, 3] }
]
}Full rule reference in zackees/ledmapper#92. Key points relevant to FastLED:
segmentsis an ordered array. Each segment owns its own parallelx[]/y[](and optionalz[]) float arrays — same layout your parser already handles, just scoped per segment.pinis per-segment. Lets a single document describe LEDs driven by multiple controller outputs without one-map-entry-per-pin gymnastics.parent+offsetdescribe forks: same signal range, two physical placements branching from a specific LED of the parent.offset: null(or omitted) = branch from the tip; integer = forward index; negative-N= N back from the tip.groupsare UI-only metadata (display color, future per-group attributes). Firmware can safely ignore them.version: 2is optional and explicit; absent + presence ofsegments/groupsat root = auto-detect v2; absent + presence ofmap= auto-detect v1.
Proposal A — minimal: flatten v2 onto the existing flat_map<string, ScreenMap> API
The cheapest FastLED-side change: detect v2, flatten each segment into a ScreenMap entry keyed by the segment's id. Fork twins each get their own entry (e.g. a_fork0, a_fork1). z, groups, parent, offset are ignored. The firmware sees the same flat {name → ScreenMap} it sees today.
In src/fl/math/screenmap.h / screenmap.cpp.hpp:
static bool ParseJson(const char *jsonStrScreenMap,
fl::flat_map<string, ScreenMap> *segmentMaps,
string *err = nullptr) FL_NOEXCEPT;Add a dispatcher inside this method:
- If parsed root has
"version": 2→ parse v2 → flatten into*segmentMaps. - If parsed root has
"version": 1OR has"map"→ existing v1 path. - If parsed root has
"segments"(array) → auto-detect v2. - Otherwise return false (error).
This keeps the public API identical; existing user code continues to work.
Proposal B — first-class: new ScreenMapV2 type that preserves structure
For tools that do care about forks and groups (the editor, video samplers, future 3D-aware renderers), expose a richer type alongside the flat one:
struct ScreenMapV2 {
struct Segment {
string id;
int pin;
string group;
vector<float> x, y, z; // z empty when 2D
string parent; // empty when root
int offset; // INT_MIN when null/omitted (= tip)
};
fl::flat_map<string, string /*color*/> groups;
vector<Segment> segments;
};
static bool ParseJson(const char *jsonStr, ScreenMapV2 *out, string *err = nullptr) FL_NOEXCEPT;Independent of the proposal-A flattening path — both can ship.
Backward compatibility
Existing v1 files are not modified. The current ParseJson overload that takes a flat_map<string, ScreenMap> keeps working exactly as it does today; v2 detection is purely additive. The existing test file tests/fl/math/screenmap.cpp is the contract — v2 support should leave it untouched and pass green.
What I'd like to know
- Is the maintainer team open to merging proposal A (minimal flatten)? It's the lowest-risk addition and unblocks ledmapper-side v2 adoption immediately.
- Should proposal B (structured
ScreenMapV2type) be a separate follow-up issue, or rolled in? - Naming preferences? I called it
ScreenMapV2here but happy to follow whatever convention the project uses (e.g.fl::ScreenMapV2,fl::ScreenMap2, etc.). - Open to a PR for proposal A from my side once direction is agreed.
Cross-ref: zackees/ledmapper#92 (concrete schema spec + ledmapper-side parser implementation plan).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
feat(screenmap): add v2 schema parser alongside v1, auto-detect by sh…