MuseScore Plugins  3.2.3
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 namespace Ms {
17 
18 class Element;
19 class Score;
20 class Chord;
21 class Rest;
22 class Note;
23 class Segment;
24 class RepeatSegment;
25 class ChordRest;
26 class StaffText;
27 class Measure;
28 
29 enum class SegmentType;
30 
31 namespace PluginAPI {
32 
33 class Element;
34 class Measure;
35 class Segment;
36 class Score;
37 
38 //---------------------------------------------------------
39 // @@ Cursor
41 //---------------------------------------------------------
42 
43 class Cursor : public QObject {
44  Q_OBJECT
46  Q_PROPERTY(int track READ track WRITE setTrack)
48  Q_PROPERTY(int staffIdx READ staffIdx WRITE setStaffIdx)
50  Q_PROPERTY(int voice READ voice WRITE setVoice)
59  Q_PROPERTY(int filter READ filter WRITE setFilter)
60 
61 
62  Q_PROPERTY(int tick READ tick) // FIXME: fraction transition
64  Q_PROPERTY(double time READ time)
65 
66 
67  Q_PROPERTY(qreal tempo READ tempo)
68 
69 
70  Q_PROPERTY(int keySignature READ qmlKeySignature)
72  Q_PROPERTY(Ms::PluginAPI::Score* score READ score WRITE setScore)
73 
74 
75  Q_PROPERTY(Ms::PluginAPI::Element* element READ element)
77  Q_PROPERTY(Ms::PluginAPI::Segment* segment READ segment)
79  Q_PROPERTY(Ms::PluginAPI::Measure* measure READ measure)
80 
81  public:
82  enum RewindMode {
85  SELECTION_END = 2
86  };
87  Q_ENUM(RewindMode);
88 
89  private:
90  Ms::Score* _score = nullptr;
91  int _track = 0;
92 // bool _expandRepeats; // used?
93 
94  //state
95  Ms::Segment* _segment = nullptr;
96  SegmentType _filter;
97 
98  // utility methods
99  void nextInTrack();
100  void setScore(Ms::Score* s);
101 
102  public:
104  Cursor(Ms::Score* s = nullptr);
105 // Cursor(Score*, bool); // not implemented? what is bool?
106 
107  Score* score() const;
108  void setScore(Score* s);
109 
110  int track() const { return _track; }
111  void setTrack(int v);
112 
113  int staffIdx() const;
114  void setStaffIdx(int v);
115 
116  int voice() const;
117  void setVoice(int v);
118 
119  int filter() const { return int(_filter); }
120  void setFilter(int f) { _filter = SegmentType(f); }
121 
122  Element* element() const;
123  Segment* segment() const;
124  Measure* measure() const;
125 
126  int tick();
127  double time();
128  qreal tempo();
129 
130  int qmlKeySignature();
132 
133  Q_INVOKABLE void rewind(RewindMode mode);
134 
135  Q_INVOKABLE bool next();
136  Q_INVOKABLE bool nextMeasure();
137  Q_INVOKABLE void add(Ms::PluginAPI::Element*);
138 
139  Q_INVOKABLE void addNote(int pitch);
140 
141  //@ set duration
142  //@ z: numerator
143  //@ n: denominator
144  //@ Quarter, if n == 0
145  Q_INVOKABLE void setDuration(int z, int n);
146  };
147 
148 } // namespace PluginAPI
149 } // namespace Ms
150 #endif
151 
Ms::PluginAPI::Cursor::addNote
Q_INVOKABLE void addNote(int pitch)
Adds a note to the current cursor position.
Definition: cursor.cpp:211
Ms::PluginAPI::Cursor::SCORE_START
@ SCORE_START
Rewind to the start of a score.
Definition: cursor.h:83
Ms::PluginAPI::Cursor::tempo
qreal tempo
Tempo at current tick, read only.
Definition: cursor.h:67
Ms::PluginAPI::Cursor::element
Ms::PluginAPI::Element * element
Current element at track, read only.
Definition: cursor.h:75
Ms::PluginAPI::Element
Definition: elements.h:68
Ms::PluginAPI::Note
Definition: elements.h:344
Ms::PluginAPI::Chord
Definition: elements.h:422
Ms::PluginAPI::Cursor::setDuration
Q_INVOKABLE void setDuration(int z, int n)
Set duration of the notes added by the cursor.
Definition: cursor.cpp:233
Ms::PluginAPI::Cursor::rewind
Q_INVOKABLE void rewind(RewindMode mode)
Rewind cursor to a certain position.
Definition: cursor.cpp:85
Ms::PluginAPI::Cursor::filter
int filter
Segment type filter, a bitmask from PluginAPI::PluginAPI::Segment values.
Definition: cursor.h:59
Ms::PluginAPI::Cursor::SELECTION_END
@ SELECTION_END
Rewind to the end of a selection.
Definition: cursor.h:85
Ms::PluginAPI::Measure
Definition: elements.h:519
Ms::PluginAPI::Cursor::RewindMode
RewindMode
Definition: cursor.h:82
Ms::PluginAPI::Cursor::voice
int voice
Current voice (track % 4)
Definition: cursor.h:50
Ms::PluginAPI::Cursor::measure
Ms::PluginAPI::Measure * measure
Current measure, read only.
Definition: cursor.h:79
Ms::PluginAPI::Cursor::track
int track
Current track.
Definition: cursor.h:46
Ms::PluginAPI::Cursor::add
Q_INVOKABLE void add(Ms::PluginAPI::Element *)
Adds the given element to a score at this cursor's position.
Definition: cursor.cpp:167
Ms::SegmentType
SegmentType
Definition: types.h:332
Ms::PluginAPI::Score
Definition: score.h:32
Ms::PluginAPI::Cursor::score
Ms::PluginAPI::Score * score
Associated score.
Definition: cursor.h:72
Ms::PluginAPI::Cursor::keySignature
int keySignature
Key signature of current staff at tick pos.
Definition: cursor.h:70
Ms::PluginAPI::Segment
Definition: elements.h:459
Ms::PluginAPI::Cursor::nextMeasure
Q_INVOKABLE bool nextMeasure()
Move the cursor to the first segment of the next measure.
Definition: cursor.cpp:147
Ms::PluginAPI::Cursor::next
Q_INVOKABLE bool next()
Move the cursor to the next segment.
Definition: cursor.cpp:128
Ms::PluginAPI::PluginAPI
Main class of the plugins framework. Named as MuseScore in QML.
Definition: qmlpluginapi.h:55
Ms::PluginAPI::Cursor::segment
Ms::PluginAPI::Segment * segment
Current segment, read only.
Definition: cursor.h:77
Ms::PluginAPI::Cursor
Cursor can be used by plugins to manipulate the score.
Definition: cursor.h:43
Ms::PluginAPI::Cursor::SELECTION_START
@ SELECTION_START
Rewind to the start of a selection.
Definition: cursor.h:84
Ms
Definition: cursor.cpp:29
Ms::PluginAPI::Cursor::staffIdx
int staffIdx
Current staff (track / 4)
Definition: cursor.h:48
Ms::PluginAPI::Cursor::time
double time
Time at tick position, read only.
Definition: cursor.h:64
Ms::PluginAPI::Cursor::tick
int tick
MIDI tick position, read only.
Definition: cursor.h:62