Skip to content

Commit bf1831a

Browse files
Dheeraj ChandDheeraj Chand
authored andcommitted
Expose FretDiagram setDot/setMarker/setBarre to plugin API
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 #32798
1 parent 5ab5e82 commit bf1831a

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

src/engraving/api/v1/elements.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ EngravingItem* mu::engraving::apiv1::wrap(mu::engraving::EngravingItem* e, Owner
687687
API_WRAP(DurationElement)
688688
API_WRAP(Beam)
689689
API_WRAP(Lyrics)
690+
API_WRAP(FretDiagram)
690691
API_WRAP(Segment)
691692
API_WRAP(Measure)
692693
API_WRAP(MeasureBase)

src/engraving/api/v1/elements.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "engraving/dom/engravingitem.h"
2929
#include "engraving/dom/arpeggio.h"
30+
#include "engraving/dom/fret.h"
3031
#include "engraving/dom/barline.h"
3132
#include "engraving/dom/beam.h"
3233
#include "engraving/dom/bracketItem.h"
@@ -2665,6 +2666,76 @@ class Lyrics : public EngravingItem
26652666
apiv1::EngravingItem* separator() const { return wrap(lyrics()->separator()); }
26662667
};
26672668

2669+
//---------------------------------------------------------
2670+
// FretDiagram
2671+
/// Exposes FretDiagram dot, marker, and barre manipulation
2672+
/// to the QML plugin API.
2673+
/// \since MuseScore 4.7
2674+
//---------------------------------------------------------
2675+
2676+
class FretDiagram : public EngravingItem
2677+
{
2678+
Q_OBJECT
2679+
2680+
/// Number of strings in the diagram.
2681+
Q_PROPERTY(int strings READ strings WRITE setStrings)
2682+
/// Number of frets shown in the diagram.
2683+
Q_PROPERTY(int frets READ frets WRITE setFrets)
2684+
/// Fret offset (0-based: value N means the top of the diagram is at fret N+1).
2685+
Q_PROPERTY(int fretOffset READ fretOffset WRITE setFretOffset)
2686+
/// Whether to show the nut (thick line at top of diagram).
2687+
Q_PROPERTY(bool showNut READ showNut WRITE setShowNut)
2688+
2689+
public:
2690+
/// \cond MS_INTERNAL
2691+
FretDiagram(mu::engraving::FretDiagram* fd = nullptr, Ownership own = Ownership::PLUGIN)
2692+
: EngravingItem(fd, own) {}
2693+
2694+
mu::engraving::FretDiagram* fretDiagram() { return toFretDiagram(e); }
2695+
const mu::engraving::FretDiagram* fretDiagram() const { return toFretDiagram(e); }
2696+
/// \endcond
2697+
2698+
int strings() const { return fretDiagram()->strings(); }
2699+
void setStrings(int n) { fretDiagram()->setStrings(n); }
2700+
int frets() const { return fretDiagram()->frets(); }
2701+
void setFrets(int n) { fretDiagram()->setFrets(n); }
2702+
int fretOffset() const { return fretDiagram()->fretOffset(); }
2703+
void setFretOffset(int val) { fretDiagram()->setFretOffset(val); }
2704+
bool showNut() const { return fretDiagram()->showNut(); }
2705+
void setShowNut(bool val) { fretDiagram()->setShowNut(val); }
2706+
2707+
/// Set a dot on the specified string at the specified fret.
2708+
/// \param string 0-based string index (0 = highest pitched string)
2709+
/// \param fret fret number (1-based, 0 removes the dot)
2710+
/// \param add if true, add a second dot without removing existing ones
2711+
/// \param dotType dot type: 0=normal, 1=cross, 2=square, 3=triangle
2712+
Q_INVOKABLE void setDot(int string, int fret, bool add = false, int dotType = 0) {
2713+
fretDiagram()->setDot(string, fret, add,
2714+
static_cast<mu::engraving::FretDotType>(dotType));
2715+
}
2716+
2717+
/// Set a marker on the specified string.
2718+
/// \param string 0-based string index (0 = highest pitched string)
2719+
/// \param markerType marker type: 0=none, 1=circle (open), 2=cross (muted)
2720+
Q_INVOKABLE void setMarker(int string, int markerType) {
2721+
fretDiagram()->setMarker(string,
2722+
static_cast<mu::engraving::FretMarkerType>(markerType));
2723+
}
2724+
2725+
/// Set a barre across strings at the specified fret.
2726+
/// \param startString 0-based start string index
2727+
/// \param endString 0-based end string index
2728+
/// \param fret fret number (1-based)
2729+
Q_INVOKABLE void setBarre(int startString, int endString, int fret) {
2730+
fretDiagram()->setBarre(startString, endString, fret);
2731+
}
2732+
2733+
/// Remove all dots, markers, and barres from the diagram.
2734+
Q_INVOKABLE void clear() {
2735+
fretDiagram()->clear();
2736+
}
2737+
};
2738+
26682739
#undef API_PROPERTY
26692740
#undef API_PROPERTY_T
26702741
#undef API_PROPERTY_READ_ONLY

0 commit comments

Comments
 (0)