Skip to content

Add screenmap v2 schema parser alongside ScreenMap::ParseJson (forks, groups, optional z, branch offset) #3050

Closed

Description

@zackees

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 z axis.
  • 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:

  • segments is an ordered array. Each segment owns its own parallel x[] / y[] (and optional z[]) float arrays — same layout your parser already handles, just scoped per segment.
  • pin is per-segment. Lets a single document describe LEDs driven by multiple controller outputs without one-map-entry-per-pin gymnastics.
  • parent + offset describe 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.
  • groups are UI-only metadata (display color, future per-group attributes). Firmware can safely ignore them.
  • version: 2 is optional and explicit; absent + presence of segments/groups at root = auto-detect v2; absent + presence of map = 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:

  1. If parsed root has "version": 2 → parse v2 → flatten into *segmentMaps.
  2. If parsed root has "version": 1 OR has "map" → existing v1 path.
  3. If parsed root has "segments" (array) → auto-detect v2.
  4. 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

  1. Is the maintainer team open to merging proposal A (minimal flatten)? It's the lowest-risk addition and unblocks ledmapper-side v2 adoption immediately.
  2. Should proposal B (structured ScreenMapV2 type) be a separate follow-up issue, or rolled in?
  3. Naming preferences? I called it ScreenMapV2 here but happy to follow whatever convention the project uses (e.g. fl::ScreenMapV2, fl::ScreenMap2, etc.).
  4. 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions