Skip to content

Commit e18f6bc

Browse files
committed
ornament intervals
1 parent ad14312 commit e18f6bc

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

src/engraving/api/v1/apitypes.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,58 @@ enum class OrnamentShowAccidental {
10031003
};
10041004
Q_ENUM_NS(OrnamentShowAccidental);
10051005

1006+
//---------------------------------------------------------
1007+
// OrnamentIntervalWrapper
1008+
/// Ornament interval wrapper object available to QML plugins.
1009+
/// Use PluginAPI::PluginAPI::ornamentInterval to create a
1010+
/// fraction for usage within your plugin:
1011+
/// \code
1012+
/// var interval = ornamentInterval(IntervalStep.SECOND, IntervalType.MAJOR);
1013+
/// \endcode
1014+
//---------------------------------------------------------
1015+
1016+
class OrnamentIntervalWrapper : public QObject
1017+
{
1018+
Q_OBJECT
1019+
/// Interval step
1020+
Q_PROPERTY(IntervalStep step READ step)
1021+
/// Interval type
1022+
Q_PROPERTY(IntervalType type READ type)
1023+
/// Whether this interval is perfect
1024+
Q_PROPERTY(bool isPerfect READ isPerfect)
1025+
1026+
mu::engraving::OrnamentInterval o;
1027+
1028+
/// \cond MS_INTERNAL
1029+
public slots:
1030+
void setOrnamentInterval(engraving::OrnamentInterval m_o) { o = m_o; }
1031+
1032+
public:
1033+
OrnamentIntervalWrapper() = default;
1034+
OrnamentIntervalWrapper(const mu::engraving::OrnamentInterval& m_o)
1035+
: o(m_o) {}
1036+
1037+
mu::engraving::OrnamentInterval ornamentInterval() const { return o; }
1038+
IntervalStep step() const { return IntervalStep(o.step); }
1039+
IntervalType type() const { return IntervalType(o.type); }
1040+
bool isPerfect() const { return o.isPerfect(); }
1041+
/// \endcond
1042+
};
1043+
1044+
//---------------------------------------------------------
1045+
// wrap
1046+
/// \cond PLUGIN_API \private \endcond
1047+
/// \relates OrnamentIntervalWrapper
1048+
//---------------------------------------------------------
1049+
1050+
inline OrnamentIntervalWrapper* wrap(mu::engraving::OrnamentInterval o)
1051+
{
1052+
OrnamentIntervalWrapper* w = new OrnamentIntervalWrapper(o);
1053+
// All wrapper objects should belong to JavaScript code.
1054+
QQmlEngine::setObjectOwnership(w, QQmlEngine::JavaScriptOwnership);
1055+
return w;
1056+
}
1057+
10061058
enum class PartialSpannerDirection {
10071059
NONE = int(mu::engraving::PartialSpannerDirection::NONE),
10081060
INCOMING = int(mu::engraving::PartialSpannerDirection::INCOMING),

src/engraving/api/v1/qmlpluginapi.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727

2828
#include "engraving/compat/scoreaccess.h"
2929
#include "engraving/dom/factory.h"
30+
#include "engraving/types/types.h"
3031

3132
// api
33+
#include "apitypes.h"
3234
#include "engravingapiv1.h"
3335
#include "score.h"
3436
#include "instrument.h"
@@ -541,3 +543,20 @@ qreal PluginAPI::mscoreDPI() const
541543
{
542544
return engraving::DPI;
543545
}
546+
547+
OrnamentIntervalWrapper* PluginAPI::defaultOrnamentInterval() const
548+
{
549+
return wrap(mu::engraving::DEFAULT_ORNAMENT_INTERVAL);
550+
}
551+
552+
//---------------------------------------------------------
553+
// PluginAPI::ornamentInterval
554+
/// Creates a new ornament interval with the given step and type
555+
//---------------------------------------------------------
556+
557+
OrnamentIntervalWrapper* PluginAPI::ornamentInterval(apiv1::IntervalStep step, apiv1::IntervalType type) const
558+
{
559+
return wrap(mu::engraving::OrnamentInterval(step, type));
560+
}
561+
562+

src/engraving/api/v1/qmlpluginapi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class EngravingItem;
4848
namespace mu::engraving::apiv1 {
4949
class EngravingItem;
5050
class FractionWrapper;
51+
class OrnamentIntervalWrapper;
5152
class MsProcess;
5253
class Score;
5354

@@ -482,6 +483,8 @@ class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV
482483

483484
Q_INVOKABLE apiv1::FractionWrapper* fraction(int numerator, int denominator) const;
484485

486+
Q_INVOKABLE apiv1::OrnamentIntervalWrapper* ornamentInterval(apiv1::IntervalStep step, apiv1::IntervalType type) const;
487+
485488
Q_INVOKABLE void quit();
486489

487490
QString pluginType() const;
@@ -517,6 +520,7 @@ class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV
517520
int mscoreMinorVersion() const;
518521
int mscoreUpdateVersion() const;
519522
qreal mscoreDPI() const;
523+
OrnamentIntervalWrapper* defaultOrnamentInterval() const;
520524

521525
private:
522526
mu::engraving::Score* currentScore() const;

0 commit comments

Comments
 (0)