MuseScore  3.4
Music composition and notation
select.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2002-2011 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 __SELECT_H__
14 #define __SELECT_H__
15 
16 #include "pitchspelling.h"
17 #include "mscore.h"
18 #include "durationtype.h"
19 
20 namespace Ms {
21 
22 class Score;
23 class Page;
24 class System;
25 class ChordRest;
26 class Element;
27 class Segment;
28 class Note;
29 class Measure;
30 class Chord;
31 
32 //---------------------------------------------------------
33 // ElementPattern
34 //---------------------------------------------------------
35 
37  QList<Element*> el;
38  int type;
39  int subtype;
41  int staffEnd; // exclusive
42  int voice;
43  const System* system;
46  };
47 
48 //---------------------------------------------------------
49 // NotePattern
50 //---------------------------------------------------------
51 
52 struct NotePattern {
53  QList<Note*> el;
54  int pitch = -1;
55  int string = STRING_NONE;
58  TDuration durationType = TDuration();
62  int staffEnd; // exclusive
63  int voice;
64  const System* system;
65  };
66 
67 //---------------------------------------------------------
68 // SelState
69 //---------------------------------------------------------
70 
71 enum class SelState : char {
72  NONE, // nothing is selected
73  LIST, // disjoint selection
74  RANGE, // adjacent selection, a range in one or more staves
75  // is selected
76  };
77 
78 //---------------------------------------------------------
79 // SelectionFilterType
80 // see also `static const char* labels[]` in mscore/selectionwindow.cpp
81 // need to keep those in sync!
82 //---------------------------------------------------------
83 
84 enum class SelectionFilterType {
85  NONE = 0,
86  FIRST_VOICE = 1 << 0,
87  SECOND_VOICE = 1 << 1,
88  THIRD_VOICE = 1 << 2,
89  FOURTH_VOICE = 1 << 3,
90  DYNAMIC = 1 << 4,
91  FINGERING = 1 << 5,
92  LYRICS = 1 << 6,
93  CHORD_SYMBOL = 1 << 7,
94  OTHER_TEXT = 1 << 8,
95  ARTICULATION = 1 << 9,
96  SLUR = 1 << 10,
97  FIGURED_BASS = 1 << 11,
98  OTTAVA = 1 << 12,
99  PEDAL_LINE = 1 << 13,
100  OTHER_LINE = 1 << 14,
101  ARPEGGIO = 1 << 15,
102  GLISSANDO = 1 << 16,
103  FRET_DIAGRAM = 1 << 17,
104  BREATH = 1 << 18,
105  TREMOLO = 1 << 19,
106  GRACE_NOTE = 1 << 20,
107  ALL = -1
108  };
109 
110 
111 //---------------------------------------------------------
112 // SelectionFilter
113 //---------------------------------------------------------
114 
118 
119 public:
120  SelectionFilter() { _score = 0; _filtered = (int)SelectionFilterType::ALL;}
121  SelectionFilter(SelectionFilterType f) : _score(nullptr), _filtered(int(f)) {}
122  SelectionFilter(Score* score) { _score = score; _filtered = (int)SelectionFilterType::ALL;}
123  int& filtered() { return _filtered; }
124  void setFiltered(SelectionFilterType type, bool set);
125  bool isFiltered(SelectionFilterType type) const { return _filtered & (int)type; }
126  bool canSelect(const Element*) const;
127  bool canSelectVoice(int track) const;
128  };
129 
130 //-------------------------------------------------------------------
131 // Selection
132 // For SelState::LIST state only visible elements can be selected
133 // (no Chord element etc.).
134 //-------------------------------------------------------------------
135 
136 class Selection {
139  QList<Element*> _el; // valid in mode SelState::LIST
140 
141  int _staffStart; // valid if selState is SelState::RANGE
144  Segment* _endSegment; // next segment after selection
145 
146  Fraction _plannedTick1 { -1, 1 }; // Will be actually selected on updateSelectedElements() call.
147  Fraction _plannedTick2 { -1, 1 }; // Used by setRangeTicks() to restore proper selection after
148  // command end in case some changes are expected to segments'
149  // structure (e.g. MMRests reconstruction).
150 
153 
154  Fraction _currentTick; // tracks the most recent selection
156 
157  QByteArray staffMimeData() const;
158  QByteArray symbolListMimeData() const;
159  SelectionFilter selectionFilter() const;
160  bool canSelect(Element* e) const { return selectionFilter().canSelect(e); }
161  bool canSelectVoice(int track) const { return selectionFilter().canSelectVoice(track); }
162  void appendFiltered(Element* e);
163  void appendChord(Chord* chord);
164 
165  public:
166  Selection() { _score = 0; _state = SelState::NONE; }
167  Selection(Score*);
168  Score* score() const { return _score; }
169  SelState state() const { return _state; }
170  bool isNone() const { return _state == SelState::NONE; }
171  bool isRange() const { return _state == SelState::RANGE; }
172  bool isList() const { return _state == SelState::LIST; }
173  void setState(SelState s);
174 
175  const QList<Element*>& elements() const { return _el; }
176  std::vector<Note*> noteList(int track = -1) const;
177 
178  const QList<Element*> uniqueElements() const;
179  QList<Note*> uniqueNotes(int track = -1) const;
180 
181  bool isSingle() const { return (_state == SelState::LIST) && (_el.size() == 1); }
182 
183  void add(Element*);
184  void deselectAll();
185  void remove(Element*);
186  void clear();
187  Element* element() const;
188  ChordRest* cr() const;
189  Segment* firstChordRestSegment() const;
190  ChordRest* firstChordRest(int track = -1) const;
191  ChordRest* lastChordRest(int track = -1) const;
192  Measure* findMeasure() const;
193  void update();
194  void updateState();
195  void dump();
196  QString mimeType() const;
197  QByteArray mimeData() const;
198 
199  Segment* startSegment() const { return _startSegment; }
200  Segment* endSegment() const { return _endSegment; }
201  void setStartSegment(Segment* s) { _startSegment = s; }
202  void setEndSegment(Segment* s) { _endSegment = s; }
203  void setRange(Segment* startSegment, Segment* endSegment, int staffStart, int staffEnd);
204  void setRangeTicks(const Fraction& tick1, const Fraction& tick2, int staffStart, int staffEnd);
205  Segment* activeSegment() const { return _activeSegment; }
206  void setActiveSegment(Segment* s) { _activeSegment = s; }
207  ChordRest* activeCR() const;
208  bool isStartActive() const;
209  bool isEndActive() const;
210  ChordRest* currentCR() const;
211  Fraction tickStart() const;
212  Fraction tickEnd() const;
213  int staffStart() const { return _staffStart; }
214  int staffEnd() const { return _staffEnd; }
215  int activeTrack() const { return _activeTrack; }
216  void setStaffStart(int v) { _staffStart = v; }
217  void setStaffEnd(int v) { _staffEnd = v; }
218  void setActiveTrack(int v) { _activeTrack = v; }
219  bool canCopy() const;
220  void updateSelectedElements();
221  bool measureRange(Measure** m1, Measure** m2) const;
222  void extendRangeSelection(ChordRest* cr);
223  void extendRangeSelection(Segment* seg, Segment* segAfter, int staffIdx, const Fraction& tick, const Fraction& etick);
224  };
225 
226 
227 } // namespace Ms
228 #endif
229 
int staffEnd
Definition: select.h:41
Definition: select.h:136
bool isSingle() const
Definition: select.h:181
Definition: durationtype.h:28
SelState
Definition: select.h:71
const System * system
Definition: select.h:64
bool canSelectVoice(int track) const
Definition: select.h:161
bool isList() const
Definition: select.h:172
Score * _score
Definition: select.h:116
bool subtypeValid
Definition: select.h:44
Definition: select.h:36
int activeTrack() const
Definition: select.h:215
one measure in a system
Definition: measure.h:65
bool isNone() const
Definition: select.h:170
SelState _state
Definition: select.h:138
int staffEnd
Definition: select.h:62
const QList< Element * > & elements() const
Definition: select.h:175
Base class of score layout elements.
Definition: element.h:158
Score * _score
Definition: select.h:137
bool isFiltered(SelectionFilterType type) const
Definition: select.h:125
void setStaffEnd(int v)
Definition: select.h:217
int _activeTrack
Definition: select.h:152
void setStaffStart(int v)
Definition: select.h:216
Segment * _activeSegment
Definition: select.h:151
QList< Element * > _el
Definition: select.h:139
SelectionFilter(Score *score)
Definition: select.h:122
int _staffStart
Definition: select.h:141
Definition: score.h:391
void setActiveSegment(Segment *s)
Definition: select.h:206
Definition: select.h:52
bool isRange() const
Definition: select.h:171
Segment * _startSegment
Definition: select.h:143
SelectionFilter()
Definition: select.h:120
int _staffEnd
Definition: select.h:142
int staffEnd() const
Definition: select.h:214
Score * score() const
Definition: select.h:168
int _filtered
Definition: select.h:117
Definition: select.h:115
int & filtered()
Definition: select.h:123
void setActiveTrack(int v)
Definition: select.h:218
SelectionFilter(SelectionFilterType f)
Definition: select.h:121
Definition: segment.h:50
int staffStart
Definition: select.h:61
Definition: aeolus.cpp:26
Segment * activeSegment() const
Definition: select.h:205
Definition: pitchspelling.h:41
Fraction durationTicks
Definition: select.h:59
NoteType
Definition: types.h:255
void setStartSegment(Segment *s)
Definition: select.h:201
int _currentTrack
Definition: select.h:155
int staffStart() const
Definition: select.h:213
int voice
Definition: select.h:42
QList< Note * > el
Definition: select.h:53
Segment * startSegment() const
Definition: select.h:199
Graphic representation of a chord.
Definition: chord.h:55
int voice
Definition: select.h:63
Fraction durationTicks
Definition: select.h:45
Definition: chordrest.h:48
bool canSelect(Element *e) const
Definition: select.h:160
int staffStart
Definition: select.h:40
Selection()
Definition: select.h:166
void setEndSegment(Segment *s)
Definition: select.h:202
Group
Definition: note.h:56
int tpc(int idx, int pitch, int opt)
Definition: pitchspelling.cpp:539
QList< Element * > el
Definition: select.h:37
One row of measures for all instruments; a complete piece of the timeline.
Definition: system.h:79
Definition: fraction.h:46
SelState state() const
Definition: select.h:169
int type
Definition: select.h:38
const System * system
Definition: select.h:43
SelectionFilterType
Definition: select.h:84
Segment * _endSegment
Definition: select.h:144
int subtype
Definition: select.h:39
QList< int > noteList
Definition: bagpembell.h:20
Segment * endSegment() const
Definition: select.h:200
Fraction _currentTick
Definition: select.h:154