MuseScore Plugins 3.2.3
Plugins API for MuseScore
note.h
Go to the documentation of this file.
1//=============================================================================
2// MuseScore
3// Music Composition & Notation
4//
5// Copyright (C) 2002-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 __NOTE_H__
14#define __NOTE_H__
15
21#include "element.h"
22#include "symbol.h"
23#include "noteevent.h"
24#include "pitchspelling.h"
25#include "shape.h"
26#include "key.h"
27
28namespace Ms {
29
30class Tie;
31class Chord;
32class NoteEvent;
33class Text;
34class Score;
35class Sym;
36class MuseScoreView;
37class Bend;
38class AccidentalState;
39class Accidental;
40class NoteDot;
41class Spanner;
42class StaffType;
43enum class SymId;
44enum class AccidentalType : char;
45
46static const int MAX_DOTS = 4;
47
48//---------------------------------------------------------
49// @@ NoteHead
50//---------------------------------------------------------
51
52class NoteHead final : public Symbol {
53 Q_GADGET
54 public:
55 enum class Group : signed char {
57 HEAD_NORMAL = 0,
58 HEAD_CROSS,
59 HEAD_PLUS,
60 HEAD_XCIRCLE,
61 HEAD_WITHX,
62 HEAD_TRIANGLE_UP,
63 HEAD_TRIANGLE_DOWN,
64 HEAD_SLASHED1,
65 HEAD_SLASHED2,
66 HEAD_DIAMOND,
67 HEAD_DIAMOND_OLD,
68 HEAD_CIRCLED,
69 HEAD_CIRCLED_LARGE,
70 HEAD_LARGE_ARROW,
71 HEAD_BREVIS_ALT,
72
73 HEAD_SLASH,
74
75 HEAD_SOL,
76 HEAD_LA,
77 HEAD_FA,
78 HEAD_MI,
79 HEAD_DO,
80 HEAD_RE,
81 HEAD_TI,
82 // not exposed from here
83 HEAD_DO_WALKER,
84 HEAD_RE_WALKER,
85 HEAD_TI_WALKER,
86 HEAD_DO_FUNK,
87 HEAD_RE_FUNK,
88 HEAD_TI_FUNK,
89
90 HEAD_DO_NAME,
91 HEAD_RE_NAME,
92 HEAD_MI_NAME,
93 HEAD_FA_NAME,
94 HEAD_SOL_NAME,
95 HEAD_LA_NAME,
96 HEAD_TI_NAME,
97 HEAD_SI_NAME,
98
99 HEAD_A_SHARP,
100 HEAD_A,
101 HEAD_A_FLAT,
102 HEAD_B_SHARP,
103 HEAD_B,
104 HEAD_B_FLAT,
105 HEAD_C_SHARP,
106 HEAD_C,
107 HEAD_C_FLAT,
108 HEAD_D_SHARP,
109 HEAD_D,
110 HEAD_D_FLAT,
111 HEAD_E_SHARP,
112 HEAD_E,
113 HEAD_E_FLAT,
114 HEAD_F_SHARP,
115 HEAD_F,
116 HEAD_F_FLAT,
117 HEAD_G_SHARP,
118 HEAD_G,
119 HEAD_G_FLAT,
120 HEAD_H,
121 HEAD_H_SHARP,
122
123 HEAD_CUSTOM,
124 HEAD_GROUPS,
125 HEAD_INVALID = -1
127 };
128 enum class Type : signed char {
130 HEAD_AUTO = -1,
131 HEAD_WHOLE = 0,
132 HEAD_HALF = 1,
133 HEAD_QUARTER = 2,
134 HEAD_BREVIS = 3,
135 HEAD_TYPES
137 };
138
139 Q_ENUM(Group)
140 Q_ENUM(Type)
141
142 NoteHead(Score* s = 0) : Symbol(s) {}
143 NoteHead &operator=(const NoteHead&) = delete;
144 virtual NoteHead* clone() const override { return new NoteHead(*this); }
145 virtual ElementType type() const override { return ElementType::NOTEHEAD; }
146
147 Group headGroup() const;
148
149 static QString group2userName(Group group);
150 static QString type2userName(Type type);
151 static QString group2name(Group group);
152 static QString type2name(Type type);
153 static Group name2group(QString s);
154 static Type name2type(QString s);
155 };
156
157//---------------------------------------------------------
158// NoteVal
161//---------------------------------------------------------
162
163struct NoteVal {
164 int pitch { -1 };
165 int tpc1 { Tpc::TPC_INVALID };
166 int tpc2 { Tpc::TPC_INVALID };
167 int fret { FRET_NONE };
168 int string { STRING_NONE };
170
171 NoteVal() {}
172 NoteVal(int p) : pitch(p) {}
173 };
174
175static const int INVALID_LINE = -10000;
176
177//---------------------------------------------------------------------------------------
178// @@ Note
180//
181// @P accidental Accidental note accidental (null if none)
182// @P accidentalType int note accidental type
183// @P dots array[NoteDot] list of note dots (some can be null, read only)
184// @P dotsCount int number of note dots (read only)
185// @P elements array[Element] list of elements attached to notehead
186// @P fret int fret number in tablature
187// @P ghost bool ghost note (guitar: death note)
188// @P headGroup enum (NoteHead.HEAD_NORMAL, .HEAD_BREVIS_ALT, .HEAD_CROSS, .HEAD_DIAMOND, .HEAD_DO, .HEAD_FA, .HEAD_LA, .HEAD_MI, .HEAD_RE, .HEAD_SLASH, .HEAD_SOL, .HEAD_TI, .HEAD_XCIRCLE, .HEAD_TRIANGLE)
189// @P headType enum (NoteHead.HEAD_AUTO, .HEAD_BREVIS, .HEAD_HALF, .HEAD_QUARTER, .HEAD_WHOLE)
190// @P hidden bool hidden, not played note (read only)
191// @P line int notehead position (read only)
192// @P mirror bool mirror notehead on x axis (read only)
193// @P pitch int midi pitch
194// @P play bool play note
195// @P ppitch int actual played midi pitch (honoring ottavas) (read only)
196// @P small bool small notehead
197// @P string int string number in tablature
198// @P subchannel int midi subchannel (for midi articulation) (read only)
199// @P tieBack Tie note backward tie (null if none, read only)
200// @P tieFor Tie note forward tie (null if none, read only)
201// @P tpc int tonal pitch class, as per concert pitch setting
202// @P tpc1 int tonal pitch class, non transposed
203// @P tpc2 int tonal pitch class, transposed
204// @P tuning float tuning offset in cent
205// @P userDotPosition enum (Direction.AUTO, Direction.DOWN, Direction.UP)
206// @P userMirror enum (DirectionH.AUTO, DirectionH.LEFT, DirectionH.RIGHT)
207// @P veloOffset int
208// @P veloType enum (Note.OFFSET_VAL, Note.USER_VAL)
209//---------------------------------------------------------------------------------------
210
211class Note final : public Element {
212 Q_GADGET
213 public:
214 enum class ValueType : char { OFFSET_VAL, USER_VAL };
215 Q_ENUM(ValueType)
216
217 private:
218 bool _ghost { false };
219 bool _hidden { false };
222 bool _dotsHidden { false };
224 bool _fretConflict { false };
226 bool dragMode { false };
227 bool _mirror { false };
228 bool _small { false };
229 bool _play { true }; // note is not played if false
230 mutable bool _mark { false }; // for use in sequencer
231 bool _fixed { false }; // for slash notation
232
234 Direction _userDotPosition { Direction::AUTO };
235
238
239 ValueType _veloType { ValueType::OFFSET_VAL };
240
241 char _offTimeType { 0 }; // compatibility only 1 - user(absolute), 2 - offset (%)
242 char _onTimeType { 0 }; // compatibility only 1 - user, 2 - offset
243
244 int _subchannel { 0 };
245 int _line { INVALID_LINE };
246 int _fret { -1 };
247 int _string { -1 };
248 mutable int _tpc[2] { Tpc::TPC_INVALID, Tpc::TPC_INVALID };
249 mutable int _pitch { 0 };
250
251 int _veloOffset { 0 };
252 int _fixedLine { 0 }; // fixed line number if _fixed == true
253 qreal _tuning { 0.0 };
254
255 Accidental* _accidental { 0 };
256
257 Tie* _tieFor { 0 };
258 Tie* _tieBack { 0 };
259
260 ElementList _el;
261 QVector<NoteDot*> _dots;
262 NoteEventList _playEvents;
263 QVector<Spanner*> _spannerFor;
264 QVector<Spanner*> _spannerBack;
265
266 SymId _cachedNoteheadSym; // use in draw to avoid recomputing at every update
267 SymId _cachedSymNull; // additional symbol for some transparent notehead
268
269 QString _fretString;
270
271 virtual void startDrag(EditData&) override;
272 virtual QRectF drag(EditData&) override;
273 virtual void endDrag(EditData&) override;
274 virtual void editDrag(EditData&) override;
275 void addSpanner(Spanner*);
276 void removeSpanner(Spanner*);
277 int concertPitchIdx() const;
278 void updateRelLine(int relLine, bool undoable);
279 bool isNoteName() const;
280 SymId noteHead() const;
281
282 public:
283 Note(Score* s = 0);
284 Note(const Note&, bool link = false);
285 ~Note();
286
287 Note& operator=(const Note&) = delete;
288 virtual Note* clone() const override { return new Note(*this, false); }
289 ElementType type() const override { return ElementType::NOTE; }
290
291 virtual void undoUnlink() override;
292
293 virtual qreal mag() const override;
294
295 void layout();
296 void layout2();
297 //setter is used only in drumset tools to setup the notehead preview in the drumset editor and the palette
298 void setCachedNoteheadSym(SymId i) { _cachedNoteheadSym = i; };
299 void scanElements(void* data, void (*func)(void*, Element*), bool all=true);
300 void setTrack(int val);
301
302 int playTicks() const;
303
304 qreal headWidth() const;
305 qreal headHeight() const;
306 qreal tabHeadWidth(const StaffType* tab = 0) const;
307 qreal tabHeadHeight(const StaffType* tab = 0) const;
308 QPointF stemDownNW() const;
309 QPointF stemUpSE() const;
310 qreal bboxXShift() const;
311 qreal noteheadCenterX() const;
312 qreal bboxRightPos() const;
313 qreal headBodyWidth() const;
314
315 NoteHead::Group headGroup() const { return _headGroup; }
316 NoteHead::Type headType() const { return _headType; }
317 void setHeadGroup(NoteHead::Group val);
318 void setHeadType(NoteHead::Type t);
319
320 virtual int subtype() const override { return (int) _headGroup; }
321 virtual QString subtypeName() const override;
322
323 void setPitch(int val);
324 void setPitch(int pitch, int tpc1, int tpc2);
325 int pitch() const { return _pitch; }
326 int ottaveCapoFret() const;
327 int ppitch() const;
328 int epitch() const;
329 qreal tuning() const { return _tuning; }
330 void setTuning(qreal v) { _tuning = v; }
331 void undoSetTpc(int v);
332 int transposition() const;
333 bool fixed() const { return _fixed; }
334 void setFixed(bool v) { _fixed = v; }
335 int fixedLine() const { return _fixedLine; }
336 void setFixedLine(int v) { _fixedLine = v; }
337
338 int tpc() const;
339 int tpc1() const { return _tpc[0]; } // non transposed tpc
340 int tpc2() const { return _tpc[1]; } // transposed tpc
341 QString tpcUserName(bool explicitAccidental = false) const;
342
343 void setTpc(int v);
344 void setTpc1(int v) { _tpc[0] = v; }
345 void setTpc2(int v) { _tpc[1] = v; }
346 void setTpcFromPitch();
347 int tpc1default(int pitch) const;
348 int tpc2default(int pitch) const;
349 int transposeTpc(int tpc);
350
351 Accidental* accidental() const { return _accidental; }
352 void setAccidental(Accidental* a) { _accidental = a; }
353
354 AccidentalType accidentalType() const;
355 void setAccidentalType(AccidentalType type);
356
357 int line() const;
358 void setLine(int n) { _line = n; }
359 int physicalLine() const;
360
361 int fret() const { return _fret; }
362 void setFret(int val) { _fret = val; }
363 int string() const { return _string; }
364 void setString(int val);
365 bool ghost() const { return _ghost; }
366 void setGhost(bool val) { _ghost = val; }
367 bool fretConflict() const { return _fretConflict; }
368 void setFretConflict(bool val) { _fretConflict = val; }
369
370 virtual void add(Element*) override;
371 virtual void remove(Element*) override;
372
373 bool mirror() const { return _mirror; }
374 void setMirror(bool val) { _mirror = val; }
375
376 bool small() const { return _small; }
377 void setSmall(bool val);
378
379 bool play() const { return _play; }
380 void setPlay(bool val) { _play = val; }
381
382 Ms::Tie* tieFor() const { return _tieFor; }
383 Ms::Tie* tieBack() const { return _tieBack; }
384 void setTieFor(Tie* t) { _tieFor = t; }
385 void setTieBack(Tie* t) { _tieBack = t; }
386 Note* firstTiedNote() const;
387 const Note* lastTiedNote() const;
388 void disconnectTiedNotes();
389 void connectTiedNotes();
390
391 Chord* chord() const { return (Chord*)parent(); }
392 void setChord(Chord* a) { setParent((Element*)a); }
393 virtual void draw(QPainter*) const override;
394
395 virtual void read(XmlReader&) override;
396 virtual bool readProperties(XmlReader&) override;
397 virtual void readAddConnector(ConnectorInfoReader* info, bool pasteMode) override;
398 virtual void write(XmlWriter&) const override;
399
400 bool acceptDrop(EditData&) const override;
401 Element* drop(EditData&);
402
403 bool hidden() const { return _hidden; }
404 void setHidden(bool val) { _hidden = val; }
405 bool dotsHidden() const { return _dotsHidden; }
406 void setDotsHidden(bool val) { _dotsHidden = val; }
407
408 NoteType noteType() const;
409 QString noteTypeUserName() const;
410
411 ElementList& el() { return _el; }
412 const ElementList& el() const { return _el; }
413
414 int subchannel() const { return _subchannel; }
415 void setSubchannel(int val) { _subchannel = val; }
416
417 MScore::DirectionH userMirror() const { return _userMirror; }
418 void setUserMirror(MScore::DirectionH d) { _userMirror = d; }
419
420 Direction userDotPosition() const { return _userDotPosition; }
421 void setUserDotPosition(Direction d) { _userDotPosition = d; }
422 bool dotIsUp() const; // actual dot position
423
424 void reset();
425
426 ValueType veloType() const { return _veloType; }
427 void setVeloType(ValueType v) { _veloType = v; }
428 int veloOffset() const { return _veloOffset; }
429 void setVeloOffset(int v) { _veloOffset = v; }
430
431 void setOnTimeOffset(int v);
432 void setOffTimeOffset(int v);
433
434 int customizeVelocity(int velo) const;
435 NoteDot* dot(int n) { return _dots[n]; }
436 const QVector<NoteDot*>& dots() const { return _dots; }
437 QVector<NoteDot*>& dots() { return _dots; }
438
439 int qmlDotsCount();
440 void updateAccidental(AccidentalState*);
441 void updateLine();
442 void setNval(const NoteVal&, Fraction = { -1, 1} );
443 NoteEventList& playEvents() { return _playEvents; }
444 const NoteEventList& playEvents() const { return _playEvents; }
445 NoteEvent* noteEvent(int idx) { return &_playEvents[idx]; }
446 void setPlayEvents(const NoteEventList& l) { _playEvents = l; }
447
448 const QVector<Spanner*>& spannerFor() const { return _spannerFor; }
449 const QVector<Spanner*>& spannerBack() const { return _spannerBack; }
450
451 void addSpannerBack(Spanner* e) { if (!_spannerBack.contains(e)) _spannerBack.push_back(e); }
452 bool removeSpannerBack(Spanner* e) { return _spannerBack.removeOne(e); }
453 void addSpannerFor(Spanner* e) { if (!_spannerFor.contains(e)) _spannerFor.push_back(e); }
454 bool removeSpannerFor(Spanner* e) { return _spannerFor.removeOne(e); }
455
456 void transposeDiatonic(int interval, bool keepAlterations, bool useDoubleAccidentals);
457
458 virtual void localSpatiumChanged(qreal oldValue, qreal newValue) override;
459 virtual QVariant getProperty(Pid propertyId) const override;
460 virtual bool setProperty(Pid propertyId, const QVariant&) override;
461 void undoChangeDotsVisible(bool v);
462 virtual QVariant propertyDefault(Pid) const override;
463 virtual QString propertyUserValue(Pid) const override;
464
465 bool mark() const { return _mark; }
466 void setMark(bool v) const { _mark = v; }
467 virtual void setScore(Score* s) override;
468 void setDotY(Direction);
469
470 void addParentheses();
471
472 static SymId noteHead(int direction, NoteHead::Group, NoteHead::Type, int tpc, Key key, NoteHeadScheme scheme);
473 static SymId noteHead(int direction, NoteHead::Group, NoteHead::Type);
474 NoteVal noteVal() const;
475
476 Element* nextInEl(Element* e);
477 Element* prevInEl(Element* e);
478 virtual Element* nextElement() override;
479 virtual Element* prevElement() override;
480 virtual Element* lastElementBeforeSegment();
481 virtual Element* nextSegmentElement() override;
482 virtual Element* prevSegmentElement() override;
483
484 virtual QString accessibleInfo() const override;
485 virtual QString screenReaderInfo() const override;
486 virtual QString accessibleExtraInfo() const override;
487
488 virtual Shape shape() const override;
489 std::vector<Note*> tiedNotes() const;
490
491 void setOffTimeType(int v) { _offTimeType = v; }
492 void setOnTimeType(int v) { _onTimeType = v; }
493 int offTimeType() const { return _offTimeType; }
494 int onTimeType() const { return _onTimeType; }
495 };
496
497} // namespace Ms
498#endif
DirectionH
Definition: mscore.h:297
Definition: note.h:52
Group
Definition: note.h:55
Type
Definition: note.h:128
Graphic representation of a note.
Definition: note.h:211
int epitch() const
effective pitch
int ppitch() const
playback pitch
Definition: cursor.cpp:29
NoteType
Definition: types.h:254
ElementType
Definition: types.h:34
Direction
Definition: types.h:281
AccidentalType
Definition: types.h:151