MuseScore Plugins  3.5
Plugins API for MuseScore
cursor.h
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2012 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 __CURSOR_H__
14 #define __CURSOR_H__
15 
16 #include "fraction.h"
17 
18 namespace Ms {
19 
20 class Element;
21 class InputState;
22 class Score;
23 class Chord;
24 class Rest;
25 class Note;
26 class Segment;
27 class ChordRest;
28 class StaffText;
29 class Measure;
30 
31 enum class SegmentType;
32 
33 namespace PluginAPI {
34 
35 class Element;
36 class Measure;
37 class Segment;
38 class Score;
39 
40 //---------------------------------------------------------
41 // @@ Cursor
51 //---------------------------------------------------------
52 
53 class Cursor : public QObject {
54  Q_OBJECT
56  Q_PROPERTY(int track READ track WRITE setTrack)
58  Q_PROPERTY(int staffIdx READ staffIdx WRITE setStaffIdx)
60  Q_PROPERTY(int voice READ voice WRITE setVoice)
69  Q_PROPERTY(int filter READ filter WRITE setFilter)
70 
72  Q_PROPERTY(int tick READ tick) // FIXME: fraction transition
74  Q_PROPERTY(double time READ time)
75 
77  Q_PROPERTY(qreal tempo READ tempo)
78 
80  Q_PROPERTY(int keySignature READ qmlKeySignature)
82  Q_PROPERTY(Ms::PluginAPI::Score* score READ score WRITE setScore)
83 
85  Q_PROPERTY(Ms::PluginAPI::Element* element READ element)
87  Q_PROPERTY(Ms::PluginAPI::Segment* segment READ qmlSegment)
89  Q_PROPERTY(Ms::PluginAPI::Measure* measure READ measure)
96  Q_PROPERTY(int stringNumber READ inputStateString WRITE setInputStateString)
97 
98  public:
99  enum RewindMode {
103  };
104  Q_ENUM(RewindMode);
105 
110  };
111  Q_ENUM(InputStateMode);
112 
113  private:
120  Q_PROPERTY(InputStateMode inputStateMode READ inputStateMode WRITE setInputStateMode)
121 
122  Ms::Score* _score = nullptr;
123 // bool _expandRepeats; // used?
124  SegmentType _filter;
125  std::unique_ptr<InputState> is;
126  InputStateMode _inputStateMode = INPUT_STATE_INDEPENDENT;
127 
128  // utility methods
129  void prevInTrack();
130  void nextInTrack();
131  void setScore(Ms::Score* s);
132  Ms::Element* currentElement() const;
133 
134  InputState& inputState();
135  const InputState& inputState() const { return const_cast<Cursor*>(this)->inputState(); }
136 
137  Ms::Segment* segment() const;
138  void setSegment(Ms::Segment* seg);
139 
140  int inputStateString() const;
141  void setInputStateString(int);
142 
143  public:
145  Cursor(Ms::Score* s = nullptr);
146 // Cursor(Score*, bool); // not implemented? what is bool?
147 
148  Score* score() const;
149  void setScore(Score* s);
150 
151  int track() const;
152  void setTrack(int v);
153 
154  int staffIdx() const;
155  void setStaffIdx(int v);
156 
157  int voice() const;
158  void setVoice(int v);
159 
160  int filter() const { return int(_filter); }
161  void setFilter(int f) { _filter = SegmentType(f); }
162 
163  InputStateMode inputStateMode() const { return _inputStateMode; }
164  void setInputStateMode(InputStateMode val);
165 
166  Element* element() const;
167  Segment* qmlSegment() const;
168  Measure* measure() const;
169 
170  int tick();
171  double time();
172  qreal tempo();
173 
174  int qmlKeySignature();
176 
177  Q_INVOKABLE void rewind(RewindMode mode);
178  Q_INVOKABLE void rewindToTick(int tick);
179 
180  Q_INVOKABLE bool next();
181  Q_INVOKABLE bool nextMeasure();
182  Q_INVOKABLE bool prev();
183  Q_INVOKABLE void add(Ms::PluginAPI::Element*);
184 
185  Q_INVOKABLE void addNote(int pitch, bool addToChord = false);
186  Q_INVOKABLE void addRest();
187  Q_INVOKABLE void addTuplet(Ms::PluginAPI::FractionWrapper* ratio, Ms::PluginAPI::FractionWrapper* duration);
188 
189  //@ set duration
190  //@ z: numerator
191  //@ n: denominator
192  //@ Quarter, if n == 0
193  Q_INVOKABLE void setDuration(int z, int n);
194  };
195 
196 } // namespace PluginAPI
197 } // namespace Ms
198 #endif
199 
Definition: elements.h:775
Q_INVOKABLE bool next()
Move the cursor to the next segment.
Definition: cursor.cpp:199
double time
Time at tick position, read only.
Definition: cursor.h:74
int stringNumber
A physical string number where this cursor currently at.
Definition: cursor.h:96
Definition: elements.h:709
Q_INVOKABLE void rewind(RewindMode mode)
Rewind cursor to a certain position.
Definition: cursor.cpp:116
Q_INVOKABLE void setDuration(int z, int n)
Set duration of the notes added by the cursor.
Definition: cursor.cpp:507
Input state of cursor is synchronized with score input state.
Definition: cursor.h:109
Ms::PluginAPI::Element element
Current element at track, read only.
Definition: cursor.h:85
Definition: elements.h:85
int track
Current track.
Definition: cursor.h:56
Ms::PluginAPI::Segment segment
Current segment, read only.
Definition: cursor.h:87
Input state of cursor is independent of score input state (default)
Definition: cursor.h:108
Cursor can be used by plugins to manipulate the score.
Definition: cursor.h:53
Definition: score.h:41
Q_INVOKABLE void addRest()
Adds a rest to the current cursor position.
Definition: cursor.cpp:400
RewindMode
Definition: cursor.h:99
Definition: cursor.cpp:30
int keySignature
Key signature of current staff at tick pos.
Definition: cursor.h:80
int voice
Current voice (track % 4)
Definition: cursor.h:60
Ms::PluginAPI::Measure measure
Current measure, read only.
Definition: cursor.h:89
Rewind to the end of a selection.
Definition: cursor.h:102
SegmentType
Definition: types.h:424
Rewind to the start of a selection.
Definition: cursor.h:101
Q_INVOKABLE void add(Ms::PluginAPI::Element *)
Adds the given element to a score at this cursor&#39;s position.
Definition: cursor.cpp:236
int filter
Segment type filter, a bitmask from PluginAPI::PluginAPI::Segment values.
Definition: cursor.h:69
Q_INVOKABLE void addTuplet(Ms::PluginAPI::FractionWrapper *ratio, Ms::PluginAPI::FractionWrapper *duration)
Adds a tuplet to the current cursor position.
Definition: cursor.cpp:445
int tick
MIDI tick position, read only.
Definition: cursor.h:72
Rewind to the start of a score.
Definition: cursor.h:100
Q_INVOKABLE bool nextMeasure()
Move the cursor to the first segment of the next measure.
Definition: cursor.cpp:216
Main class of the plugins framework. Named as MuseScore in QML.
Definition: qmlpluginapi.h:62
Ms::PluginAPI::Score score
Associated score.
Definition: cursor.h:82
Q_INVOKABLE void addNote(int pitch, bool addToChord=false)
Adds a note to the current cursor position.
Definition: cursor.cpp:376
InputStateMode inputStateMode
Behavior of input state (position, notes duration etc.) of this cursor with respect to input state of...
Definition: cursor.h:111
int staffIdx
Current staff (track / 4)
Definition: cursor.h:58
Q_INVOKABLE void rewindToTick(int tick)
Rewind cursor to a position defined by tick.
Definition: cursor.cpp:161
qreal tempo
Tempo at current tick, read only.
Definition: cursor.h:77
InputStateMode
Definition: cursor.h:107
Fraction object available to QML plugins.
Definition: fraction.h:32
Q_INVOKABLE bool prev()
Move the cursor to the previous segment.
Definition: cursor.cpp:184