MuseScore Plugins  3.5
Plugins API for MuseScore
fraction.h
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2009 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __PLUGIN_API_FRACTION_H__
14 #define __PLUGIN_API_FRACTION_H__
15 
16 #include "libmscore/fraction.h"
17 
18 namespace Ms {
19 namespace PluginAPI {
20 
21 //---------------------------------------------------------
22 // FractionWrapper
30 //---------------------------------------------------------
31 
32 class FractionWrapper : public QObject {
33  Q_OBJECT
35  Q_PROPERTY(int numerator READ numerator)
37  Q_PROPERTY(int denominator READ denominator)
42  Q_PROPERTY(int ticks READ ticks) // FIXME: fraction transition
44  Q_PROPERTY(QString str READ toString)
45 
46  Ms::Fraction f;
47 
49  public slots:
50  void setFraction(Fraction _f) { f = _f; }
51 
52  public:
53  FractionWrapper() = default;
54  FractionWrapper(const Ms::Fraction& _f) : f(_f) {}
55 
56  Ms::Fraction fraction() const { return f; }
57  int numerator() const { return f.numerator(); }
58  int denominator() const { return f.denominator(); }
59  int ticks() const { return f.ticks(); }
60  QString toString() const { return f.toString(); }
62  };
63 
64 //---------------------------------------------------------
65 // wrap
68 //---------------------------------------------------------
69 
70 inline FractionWrapper* wrap(Ms::Fraction f)
71  {
72  FractionWrapper* w = new FractionWrapper(f);
73  // All wrapper objects should belong to JavaScript code.
74  QQmlEngine::setObjectOwnership(w, QQmlEngine::JavaScriptOwnership);
75  return w;
76  }
77 
78 } // namespace PluginAPI
79 } // namespace Ms
80 
81 #endif
QString str
String representation of this fraction.
Definition: fraction.h:44
int ticks
MIDI ticks number equal to the number of the whole notes represented by this fraction.
Definition: fraction.h:42
Definition: cursor.cpp:30
int numerator
Fraction numerator.
Definition: fraction.h:35
int denominator
Fraction denominator.
Definition: fraction.h:37
Fraction object available to QML plugins.
Definition: fraction.h:32