Skip to content

Expose FretDiagram setDot/setMarker/setBarre to plugin API#32848

Open
dheerajchand wants to merge 1 commit intomusescore:masterfrom
dheerajchand:feature/fretdiagram-plugin-api
Open

Expose FretDiagram setDot/setMarker/setBarre to plugin API#32848
dheerajchand wants to merge 1 commit intomusescore:masterfrom
dheerajchand:feature/fretdiagram-plugin-api

Conversation

@dheerajchand
Copy link
Copy Markdown

@dheerajchand dheerajchand commented Mar 29, 2026

Summary

Add a FretDiagram wrapper class to the QML plugin API that exposes the methods needed to programmatically set dots, markers, and barres on fretboard diagrams from plugins.

Currently, plugins can create a FretDiagram element and set its grid properties (fretStrings, fretFrets, fretOffset), but cannot set individual dot positions, open/muted markers, or barres. This makes it impossible to insert complete fretboard diagrams from a plugin — only empty grids.

Changes

src/engraving/api/v1/elements.h:

  • Add #include "engraving/dom/fret.h"
  • Add FretDiagram wrapper class inheriting from EngravingItem
  • Expose Q_INVOKABLE methods: setDot(), setMarker(), setBarre(), clear()
  • Expose Q_PROPERTY accessors: strings, frets, fretOffset, showNut

src/engraving/api/v1/elements.cpp:

  • Add API_WRAP(FretDiagram) to the wrap() function

Plugin usage after this change

var fd = newElement(Element.FRET_DIAGRAM)
fd.strings = 6
fd.frets = 4
fd.fretOffset = 7  // fret 8

// Set dots (0-based string index, 0 = highest string)
fd.setDot(5, 1)    // root on low E
fd.setDot(3, 1)    // b7 on D
fd.setDot(2, 2)    // 3 on G

// Set markers
fd.setMarker(4, 2) // mute A string (2 = cross)
fd.setMarker(1, 2) // mute B string
fd.setMarker(0, 2) // mute high e

cursor.add(fd)

Context

This resolves #32798. The FretDiagram dom class already has full setDot(), setMarker(), and setBarre() implementations — they just aren't exposed to the QML plugin API. This PR follows the exact same wrapper pattern used by Note, Chord, Lyrics, and other existing API wrapper classes.

The Chord Library plugin is a concrete use case — it provides a searchable jazz guitar voicing library but currently can only insert empty grids because of this limitation.

Add a FretDiagram wrapper class to the QML plugin API that exposes
the methods needed to programmatically set dots, markers (open/muted),
and barres on fretboard diagrams from plugins.

New Q_INVOKABLE methods:
- setDot(string, fret, add, dotType) — place a dot on a string/fret
- setMarker(string, markerType) — set open (O) or muted (X) marker
- setBarre(startString, endString, fret) — create a barre
- clear() — remove all dots/markers/barres

New Q_PROPERTY accessors:
- strings (read/write) — number of strings
- frets (read/write) — number of visible frets
- fretOffset (read/write) — starting fret position
- showNut (read/write) — toggle nut display

This follows the same wrapper pattern used by Note, Chord, Lyrics,
and other existing API wrapper classes. The wrapper delegates to the
existing FretDiagram dom class methods which already handle all the
internal logic.

Fixes musescore#32798
@dheerajchand dheerajchand force-pushed the feature/fretdiagram-plugin-api branch from 92e81f7 to bf1831a Compare March 29, 2026 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plugin API: Expose FretDiagram setDot/setMarker/setBarre to QML

1 participant