MuseScore  3.4
Music composition and notation
cursor.h
Go to the documentation of this file.
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 
62  Q_PROPERTY(int tick READ tick) // FIXME: fraction transition
64  Q_PROPERTY(double time READ time)
65 
67  Q_PROPERTY(qreal tempo READ tempo)
68 
70  Q_PROPERTY(int keySignature READ qmlKeySignature)
72  Q_PROPERTY(Ms::PluginAPI::Score* score READ score WRITE setScore)
73 
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 {
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;
97 
98  // utility methods
99  void prevInTrack();
100  void nextInTrack();
101  void setScore(Ms::Score* s);
102  Ms::Element* currentElement() const;
103 
104  public:
106  Cursor(Ms::Score* s = nullptr);
107 // Cursor(Score*, bool); // not implemented? what is bool?
108 
109  Score* score() const;
110  void setScore(Score* s);
111 
112  int track() const { return _track; }
113  void setTrack(int v);
114 
115  int staffIdx() const;
116  void setStaffIdx(int v);
117 
118  int voice() const;
119  void setVoice(int v);
120 
121  int filter() const { return int(_filter); }
122  void setFilter(int f) { _filter = SegmentType(f); }
123 
124  Element* element() const;
125  Segment* segment() const;
126  Measure* measure() const;
127 
128  int tick();
129  double time();
130  qreal tempo();
131 
132  int qmlKeySignature();
134 
135  Q_INVOKABLE void rewind(RewindMode mode);
136 
137  Q_INVOKABLE bool next();
138  Q_INVOKABLE bool nextMeasure();
139  Q_INVOKABLE bool prev();
140  Q_INVOKABLE void add(Ms::PluginAPI::Element*);
141 
142  Q_INVOKABLE void addNote(int pitch, bool addToChord = false);
143 
144  //@ set duration
145  //@ z: numerator
146  //@ n: denominator
147  //@ Quarter, if n == 0
148  Q_INVOKABLE void setDuration(int z, int n);
149  };
150 
151 } // namespace PluginAPI
152 } // namespace Ms
153 #endif
154 
Definition: elements.h:631
Cursor(Ms::Score *s=nullptr)
Definition: cursor.cpp:36
int keySignature
Key signature of current staff at tick pos.
Definition: cursor.h:70
Definition: elements.h:565
Score * score() const
int qmlKeySignature()
Definition: cursor.cpp:511
SegmentType _filter
Definition: cursor.h:96
Rewind to the end of a selection.
Definition: cursor.h:85
void setScore(Ms::Score *s)
Definition: cursor.cpp:55
Base class of score layout elements.
Definition: element.h:158
Definition: elements.h:75
Q_INVOKABLE void rewind(RewindMode mode)
Rewind cursor to a certain position.
Definition: cursor.cpp:85
Rewind to the start of a selection.
Definition: cursor.h:84
void prevInTrack()
Definition: cursor.cpp:486
Definition: score.h:391
int _track
Definition: cursor.h:91
Q_INVOKABLE void addNote(int pitch, bool addToChord=false)
Adds a note to the current cursor position.
Definition: cursor.cpp:322
void setVoice(int v)
Definition: cursor.cpp:452
Measure * measure() const
Cursor can be used by plugins to manipulate the score.
Definition: cursor.h:43
void setTrack(int v)
Definition: cursor.cpp:422
Definition: score.h:36
SegmentType
Definition: types.h:333
int track() const
Definition: cursor.h:112
RewindMode
Definition: cursor.h:82
int filter() const
Definition: cursor.h:121
Definition: segment.h:50
void setStaffIdx(int v)
Definition: cursor.cpp:437
Definition: aeolus.cpp:26
Q_INVOKABLE bool prev()
Move the cursor to the previous segment.
Definition: cursor.cpp:129
Element * element() const
void setFilter(int f)
Definition: cursor.h:122
Rewind to the start of a score.
Definition: cursor.h:83
void nextInTrack()
Definition: cursor.cpp:499
Q_INVOKABLE void add(Ms::PluginAPI::Element *)
Adds the given element to a score at this cursor's position.
Definition: cursor.cpp:185
Ms::Segment * _segment
Definition: cursor.h:95
Main class of the plugins framework. Named as MuseScore in QML.
Definition: qmlpluginapi.h:54
Ms::Score * _score
Definition: cursor.h:90
Q_INVOKABLE bool nextMeasure()
Move the cursor to the first segment of the next measure.
Definition: cursor.cpp:165
Q_INVOKABLE bool next()
Move the cursor to the next segment.
Definition: cursor.cpp:146
Segment * segment() const
Ms::Element * currentElement() const
Definition: cursor.cpp:383
Q_INVOKABLE void setDuration(int z, int n)
Set duration of the notes added by the cursor.
Definition: cursor.cpp:344