Skip to content

Commit

Permalink
Merge pull request #6205 from dmitrio95/306551-plugin-api-symbols
Browse files Browse the repository at this point in the history
fix #306551: make symbols accessible to plugins
  • Loading branch information
anatoly-os committed Jun 22, 2020
2 parents b3741fc + 8f70650 commit 9a668ca
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 98 deletions.
1 change: 1 addition & 0 deletions Doxyfile.plugins
Expand Up @@ -799,6 +799,7 @@ INPUT = doc/plugins.md \
mscore/plugin/api \
libmscore/types.h \
libmscore/style.h \
libmscore/sym.h \
libmscore/note.h \
libmscore/mscore.h \
libmscore/lyrics.h \
Expand Down
2 changes: 1 addition & 1 deletion libmscore/accidental.h
Expand Up @@ -24,11 +24,11 @@

#include "config.h"
#include "element.h"
#include "sym.h"

namespace Ms {

class Note;
enum class SymId;
enum class AccidentalVal : signed char;

//---------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions libmscore/articulation.h
Expand Up @@ -15,6 +15,7 @@

#include "element.h"
#include "mscore.h"
#include "sym.h"

namespace Ms {

Expand All @@ -24,8 +25,6 @@ class Measure;
class System;
class Page;

enum class SymId;

//---------------------------------------------------------
// ArticulationInfo
// gives infos about note attributes
Expand Down
3 changes: 1 addition & 2 deletions libmscore/breath.h
Expand Up @@ -14,11 +14,10 @@
#define __BREATH_H__

#include "element.h"
#include "sym.h"

namespace Ms {

enum class SymId;

//---------------------------------------------------------
// BreathType
//---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion libmscore/element.h
Expand Up @@ -19,6 +19,7 @@
#include "scoreElement.h"
#include "shape.h"
#include "sig.h"
#include "sym.h"

namespace Ms {

Expand All @@ -34,7 +35,6 @@ namespace Ms {

class XmlReader;
class XmlWriter;
enum class SymId;
enum class Pid;
class StaffType;

Expand Down
3 changes: 1 addition & 2 deletions libmscore/fermata.h
Expand Up @@ -15,6 +15,7 @@

#include "element.h"
#include "mscore.h"
#include "sym.h"

namespace Ms {

Expand All @@ -24,8 +25,6 @@ class Measure;
class System;
class Page;

enum class SymId;

//---------------------------------------------------------
// Fermata
//---------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions libmscore/key.h
Expand Up @@ -13,6 +13,8 @@
#ifndef __KEY__H__
#define __KEY__H__

#include "sym.h"

namespace Ms {

class XmlWriter;
Expand Down Expand Up @@ -75,8 +77,6 @@ static inline bool operator!= (const Key a, const Key b) { return static_cast<in
static inline Key operator+= (Key& a, const Key& b) { return a = Key(static_cast<int>(a) + static_cast<int>(b)); }
static inline Key operator-= (Key& a, const Key& b) { return a = Key(static_cast<int>(a) - static_cast<int>(b)); }

enum class SymId;

//---------------------------------------------------------
// KeySym
// position of one symbol in KeySig
Expand Down
2 changes: 1 addition & 1 deletion libmscore/note.h
Expand Up @@ -24,6 +24,7 @@
#include "pitchspelling.h"
#include "shape.h"
#include "key.h"
#include "sym.h"

namespace Ms {

Expand All @@ -41,7 +42,6 @@ class NoteDot;
class Spanner;
class StaffType;
class NoteEditData;
enum class SymId;
enum class AccidentalType : char;

static const int MAX_DOTS = 4;
Expand Down
2 changes: 1 addition & 1 deletion libmscore/rest.h
Expand Up @@ -15,11 +15,11 @@

#include "chordrest.h"
#include "notedot.h"
#include "sym.h"

namespace Ms {

class TDuration;
enum class SymId;

//---------------------------------------------------------
// @@ Rest
Expand Down
2 changes: 1 addition & 1 deletion libmscore/score.h
Expand Up @@ -27,6 +27,7 @@
#include "spannermap.h"
#include "layoutbreak.h"
#include "property.h"
#include "sym.h"

namespace Ms {

Expand Down Expand Up @@ -95,7 +96,6 @@ struct LayoutContext;
enum class Tid;
enum class ClefType : signed char;
enum class BeatType : char;
enum class SymId;
enum class Key;
enum class HairpinType : signed char;
enum class SegmentType;
Expand Down
1 change: 1 addition & 0 deletions libmscore/style.h
Expand Up @@ -24,6 +24,7 @@ struct ChordDescription;
class Element;
class Score;

// Needs to be duplicated here and in sym.h since moc doesn't handle macros from #include'd files
#ifdef SCRIPT_INTERFACE
#define BEGIN_QT_REGISTERED_ENUM(Name) \
class MSQE_##Name { \
Expand Down
28 changes: 27 additions & 1 deletion libmscore/sym.h
Expand Up @@ -19,17 +19,33 @@
#include "ft2build.h"
#include FT_FREETYPE_H

// Needs to be duplicated here and in style.h since moc doesn't handle macros from #include'd files
#ifdef SCRIPT_INTERFACE
#define BEGIN_QT_REGISTERED_ENUM(Name) \
class MSQE_##Name { \
Q_GADGET \
public:
#define END_QT_REGISTERED_ENUM(Name) \
Q_ENUM(Name); \
}; \
using Name = MSQE_##Name::Name;
#else
#define BEGIN_QT_REGISTERED_ENUM(Name)
#define END_QT_REGISTERED_ENUM(Name)
#endif

namespace Ms {

//---------------------------------------------------------
// SymId
// must be in sync with symNames
//---------------------------------------------------------

BEGIN_QT_REGISTERED_ENUM(SymId)
enum class SymId {

// SMuFL standard symbol ID's

///.\{
noSym,
fourStringTabClef,
sixStringTabClef,
Expand Down Expand Up @@ -2662,10 +2678,13 @@ enum class SymId {
// END OF TABLE

lastSym
///\}
};
END_QT_REGISTERED_ENUM(SymId)

//---------------------------------------------------------
// Sym
/// \cond PLUGIN_API \private \endcond
//---------------------------------------------------------

class Sym {
Expand Down Expand Up @@ -2734,6 +2753,7 @@ class Sym {

//---------------------------------------------------------
// GlyphKey
/// \cond PLUGIN_API \private \endcond
//---------------------------------------------------------

struct GlyphKey {
Expand All @@ -2750,6 +2770,11 @@ struct GlyphKey {
bool operator==(const GlyphKey&) const;
};

//---------------------------------------------------------
// GlyphPixmap
/// \cond PLUGIN_API \private \endcond
//---------------------------------------------------------

struct GlyphPixmap {
QPixmap pm;
QPointF offset;
Expand All @@ -2762,6 +2787,7 @@ inline uint qHash(const GlyphKey& k)

//---------------------------------------------------------
// ScoreFont
/// \cond PLUGIN_API \private \endcond
//---------------------------------------------------------

class ScoreFont {
Expand Down
2 changes: 1 addition & 1 deletion libmscore/symbol.h
Expand Up @@ -14,12 +14,12 @@
#define __SYMBOL_H__

#include "bsymbol.h"
#include "sym.h"

namespace Ms {

class Segment;
class ScoreFont;
enum class SymId;

//---------------------------------------------------------
// @@ Symbol
Expand Down
2 changes: 1 addition & 1 deletion libmscore/utils.h
Expand Up @@ -15,11 +15,11 @@

#include "mscore.h"
#include "interval.h"
#include "sym.h"

namespace Ms {

enum class Key;
enum class SymId;

//---------------------------------------------------------
// cycles
Expand Down
6 changes: 6 additions & 0 deletions mscore/plugin/api/elements.h
Expand Up @@ -309,6 +309,10 @@ class Element : public Ms::PluginAPI::ScoreElement {
API_PROPERTY( dashLineLen, DASH_LINE_LEN )
API_PROPERTY( dashGapLen, DASH_GAP_LEN )
// API_PROPERTY_READ_ONLY( tick, TICK ) // wasn't available in 2.X, disabled due to fractions transition
/**
* Symbol ID of this element (if approproate),
* one of PluginAPI::PluginAPI::SymId values.
*/
API_PROPERTY( symbol, SYMBOL )
API_PROPERTY( playRepeats, PLAY_REPEATS )
API_PROPERTY( createSystemHeader, CREATE_SYSTEM_HEADER )
Expand Down Expand Up @@ -411,8 +415,10 @@ class Note : public Element {
Q_OBJECT
Q_PROPERTY(Ms::PluginAPI::Element* accidental READ accidental)
Q_PROPERTY(Ms::AccidentalType accidentalType READ accidentalType WRITE setAccidentalType)
/** List of dots attached to this note */
Q_PROPERTY(QQmlListProperty<Ms::PluginAPI::Element> dots READ dots)
// Q_PROPERTY(int dotsCount READ qmlDotsCount)
/** List of other elements attached to this note: fingerings, symbols, bends etc. */
Q_PROPERTY(QQmlListProperty<Ms::PluginAPI::Element> elements READ elements)
/// List of PlayEvents associated with this note.
/// Important: You must call Score.createPlayEvents()
Expand Down
79 changes: 22 additions & 57 deletions mscore/plugin/api/qmlpluginapi.cpp
Expand Up @@ -24,68 +24,34 @@
#include "shortcut.h"
#include "musescore.h"
#include "libmscore/musescoreCore.h"
#include "libmscore/score.h"

#include <QQmlEngine>

namespace Ms {
namespace PluginAPI {

Enum* PluginAPI::elementTypeEnum;
Enum* PluginAPI::accidentalTypeEnum;
Enum* PluginAPI::beamModeEnum;
Enum* PluginAPI::placementEnum;
Enum* PluginAPI::glissandoTypeEnum;
Enum* PluginAPI::layoutBreakTypeEnum;
Enum* PluginAPI::lyricsSyllabicEnum;
Enum* PluginAPI::directionEnum;
Enum* PluginAPI::directionHEnum;
Enum* PluginAPI::ornamentStyleEnum;
Enum* PluginAPI::glissandoStyleEnum;
Enum* PluginAPI::tidEnum;
Enum* PluginAPI::alignEnum;
Enum* PluginAPI::noteTypeEnum;
Enum* PluginAPI::playEventTypeEnum;
Enum* PluginAPI::noteHeadTypeEnum;
Enum* PluginAPI::noteHeadSchemeEnum;
Enum* PluginAPI::noteHeadGroupEnum;
Enum* PluginAPI::noteValueTypeEnum;
Enum* PluginAPI::segmentTypeEnum;
Enum* PluginAPI::spannerAnchorEnum;

//---------------------------------------------------------
// PluginAPI::initEnums
//---------------------------------------------------------

void PluginAPI::initEnums() {
static bool initialized = false;
if (initialized)
return;

PluginAPI::elementTypeEnum = wrapEnum<Ms::ElementType>();
PluginAPI::accidentalTypeEnum = wrapEnum<Ms::AccidentalType>();
PluginAPI::beamModeEnum = wrapEnum<Ms::Beam::Mode>();
PluginAPI::placementEnum = wrapEnum<Ms::Placement>();
PluginAPI::glissandoTypeEnum = wrapEnum<Ms::GlissandoType>();
PluginAPI::layoutBreakTypeEnum = wrapEnum<Ms::LayoutBreak::Type>();
PluginAPI::lyricsSyllabicEnum = wrapEnum<Ms::Lyrics::Syllabic>();
PluginAPI::directionEnum = wrapEnum<Ms::Direction>();
PluginAPI::directionHEnum = wrapEnum<Ms::MScore::DirectionH>();
PluginAPI::ornamentStyleEnum = wrapEnum<Ms::MScore::OrnamentStyle>();
PluginAPI::glissandoStyleEnum = wrapEnum<Ms::GlissandoStyle>();
PluginAPI::tidEnum = wrapEnum<Ms::Tid>();
PluginAPI::alignEnum = wrapEnum<Ms::Align>();
PluginAPI::noteTypeEnum = wrapEnum<Ms::NoteType>();
PluginAPI::playEventTypeEnum = wrapEnum<Ms::PlayEventType>();
PluginAPI::noteHeadTypeEnum = wrapEnum<Ms::NoteHead::Type>();
PluginAPI::noteHeadSchemeEnum = wrapEnum<Ms::NoteHead::Scheme>();
PluginAPI::noteHeadGroupEnum = wrapEnum<Ms::NoteHead::Group>();
PluginAPI::noteValueTypeEnum = wrapEnum<Ms::Note::ValueType>();
PluginAPI::segmentTypeEnum = wrapEnum<Ms::SegmentType>();
PluginAPI::spannerAnchorEnum = wrapEnum<Ms::Spanner::Anchor>();

initialized = true;
}
Enum* PluginAPI::elementTypeEnum = nullptr;
Enum* PluginAPI::accidentalTypeEnum = nullptr;
Enum* PluginAPI::beamModeEnum = nullptr;
Enum* PluginAPI::placementEnum = nullptr;
Enum* PluginAPI::glissandoTypeEnum = nullptr;
Enum* PluginAPI::layoutBreakTypeEnum = nullptr;
Enum* PluginAPI::lyricsSyllabicEnum = nullptr;
Enum* PluginAPI::directionEnum = nullptr;
Enum* PluginAPI::directionHEnum = nullptr;
Enum* PluginAPI::ornamentStyleEnum = nullptr;
Enum* PluginAPI::glissandoStyleEnum = nullptr;
Enum* PluginAPI::tidEnum = nullptr;
Enum* PluginAPI::alignEnum = nullptr;
Enum* PluginAPI::noteTypeEnum = nullptr;
Enum* PluginAPI::playEventTypeEnum = nullptr;
Enum* PluginAPI::noteHeadTypeEnum = nullptr;
Enum* PluginAPI::noteHeadSchemeEnum = nullptr;
Enum* PluginAPI::noteHeadGroupEnum = nullptr;
Enum* PluginAPI::noteValueTypeEnum = nullptr;
Enum* PluginAPI::segmentTypeEnum = nullptr;
Enum* PluginAPI::spannerAnchorEnum = nullptr;
Enum* PluginAPI::symIdEnum = nullptr;

//---------------------------------------------------------
// PluginAPI
Expand All @@ -94,7 +60,6 @@ void PluginAPI::initEnums() {
PluginAPI::PluginAPI(QQuickItem* parent)
: Ms::QmlPlugin(parent)
{
initEnums();
setRequiresScore(true); // by default plugins require a score to work
}

Expand Down

0 comments on commit 9a668ca

Please sign in to comment.