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 
28 namespace Ms {
29 
30 class Tie;
31 class Chord;
32 class NoteEvent;
33 class Text;
34 class Score;
35 class Sym;
36 class MuseScoreView;
37 class Bend;
38 class AccidentalState;
39 class Accidental;
40 class NoteDot;
41 class Spanner;
42 class StaffType;
43 enum class SymId;
44 enum class AccidentalType : char;
45 
46 static const int MAX_DOTS = 4;
47 
48 //---------------------------------------------------------
49 // @@ NoteHead
50 //---------------------------------------------------------
51 
52 class 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 
163 struct 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 
175 static 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 
211 class 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 };
220  bool _dotsHidden { false };
223  bool _fretConflict { false };
225  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 ppitch() const;
327  int epitch() const;
328  qreal tuning() const { return _tuning; }
329  void setTuning(qreal v) { _tuning = v; }
330  void undoSetTpc(int v);
331  int transposition() const;
332  bool fixed() const { return _fixed; }
333  void setFixed(bool v) { _fixed = v; }
334  int fixedLine() const { return _fixedLine; }
335  void setFixedLine(int v) { _fixedLine = v; }
336 
337  int tpc() const;
338  int tpc1() const { return _tpc[0]; } // non transposed tpc
339  int tpc2() const { return _tpc[1]; } // transposed tpc
340  QString tpcUserName(bool explicitAccidental = false) const;
341 
342  void setTpc(int v);
343  void setTpc1(int v) { _tpc[0] = v; }
344  void setTpc2(int v) { _tpc[1] = v; }
345  void setTpcFromPitch();
346  int tpc1default(int pitch) const;
347  int tpc2default(int pitch) const;
348  int transposeTpc(int tpc);
349 
350  Accidental* accidental() const { return _accidental; }
351  void setAccidental(Accidental* a) { _accidental = a; }
352 
353  AccidentalType accidentalType() const;
354  void setAccidentalType(AccidentalType type);
355 
356  int line() const;
357  void setLine(int n) { _line = n; }
358  int physicalLine() const;
359 
360  int fret() const { return _fret; }
361  void setFret(int val) { _fret = val; }
362  int string() const { return _string; }
363  void setString(int val);
364  bool ghost() const { return _ghost; }
365  void setGhost(bool val) { _ghost = val; }
366  bool fretConflict() const { return _fretConflict; }
367  void setFretConflict(bool val) { _fretConflict = val; }
368 
369  virtual void add(Element*) override;
370  virtual void remove(Element*) override;
371 
372  bool mirror() const { return _mirror; }
373  void setMirror(bool val) { _mirror = val; }
374 
375  bool small() const { return _small; }
376  void setSmall(bool val);
377 
378  bool play() const { return _play; }
379  void setPlay(bool val) { _play = val; }
380 
381  Ms::Tie* tieFor() const { return _tieFor; }
382  Ms::Tie* tieBack() const { return _tieBack; }
383  void setTieFor(Tie* t) { _tieFor = t; }
384  void setTieBack(Tie* t) { _tieBack = t; }
385  Note* firstTiedNote() const;
386  const Note* lastTiedNote() const;
387  void disconnectTiedNotes();
388  void connectTiedNotes();
389 
390  Chord* chord() const { return (Chord*)parent(); }
391  void setChord(Chord* a) { setParent((Element*)a); }
392  virtual void draw(QPainter*) const override;
393 
394  virtual void read(XmlReader&) override;
395  virtual bool readProperties(XmlReader&) override;
396  virtual void readAddConnector(ConnectorInfoReader* info, bool pasteMode) override;
397  virtual void write(XmlWriter&) const override;
398 
399  bool acceptDrop(EditData&) const override;
400  Element* drop(EditData&);
401 
402  bool hidden() const { return _hidden; }
403  void setHidden(bool val) { _hidden = val; }
404  bool dotsHidden() const { return _dotsHidden; }
405  void setDotsHidden(bool val) { _dotsHidden = val; }
406 
407  NoteType noteType() const;
408  QString noteTypeUserName() const;
409 
410  ElementList& el() { return _el; }
411  const ElementList& el() const { return _el; }
412 
413  int subchannel() const { return _subchannel; }
414  void setSubchannel(int val) { _subchannel = val; }
415 
416  MScore::DirectionH userMirror() const { return _userMirror; }
417  void setUserMirror(MScore::DirectionH d) { _userMirror = d; }
418 
419  Direction userDotPosition() const { return _userDotPosition; }
420  void setUserDotPosition(Direction d) { _userDotPosition = d; }
421  bool dotIsUp() const; // actual dot position
422 
423  void reset();
424 
425  ValueType veloType() const { return _veloType; }
426  void setVeloType(ValueType v) { _veloType = v; }
427  int veloOffset() const { return _veloOffset; }
428  void setVeloOffset(int v) { _veloOffset = v; }
429 
430  void setOnTimeOffset(int v);
431  void setOffTimeOffset(int v);
432 
433  int customizeVelocity(int velo) const;
434  NoteDot* dot(int n) { return _dots[n]; }
435  const QVector<NoteDot*>& dots() const { return _dots; }
436  QVector<NoteDot*>& dots() { return _dots; }
437 
438  int qmlDotsCount();
439  void updateAccidental(AccidentalState*);
440  void updateLine();
441  void setNval(const NoteVal&, Fraction = { -1, 1} );
442  NoteEventList& playEvents() { return _playEvents; }
443  const NoteEventList& playEvents() const { return _playEvents; }
444  NoteEvent* noteEvent(int idx) { return &_playEvents[idx]; }
445  void setPlayEvents(const NoteEventList& l) { _playEvents = l; }
446 
447  const QVector<Spanner*>& spannerFor() const { return _spannerFor; }
448  const QVector<Spanner*>& spannerBack() const { return _spannerBack; }
449 
450  void addSpannerBack(Spanner* e) { if (!_spannerBack.contains(e)) _spannerBack.push_back(e); }
451  bool removeSpannerBack(Spanner* e) { return _spannerBack.removeOne(e); }
452  void addSpannerFor(Spanner* e) { if (!_spannerFor.contains(e)) _spannerFor.push_back(e); }
453  bool removeSpannerFor(Spanner* e) { return _spannerFor.removeOne(e); }
454 
455  void transposeDiatonic(int interval, bool keepAlterations, bool useDoubleAccidentals);
456 
457  virtual void localSpatiumChanged(qreal oldValue, qreal newValue) override;
458  virtual QVariant getProperty(Pid propertyId) const override;
459  virtual bool setProperty(Pid propertyId, const QVariant&) override;
460  void undoChangeDotsVisible(bool v);
461  virtual QVariant propertyDefault(Pid) const override;
462  virtual QString propertyUserValue(Pid) const override;
463 
464  bool mark() const { return _mark; }
465  void setMark(bool v) const { _mark = v; }
466  virtual void setScore(Score* s) override;
467  void setDotY(Direction);
468 
469  void addParentheses();
470 
471  static SymId noteHead(int direction, NoteHead::Group, NoteHead::Type, int tpc, Key key, NoteHeadScheme scheme);
472  static SymId noteHead(int direction, NoteHead::Group, NoteHead::Type);
473  NoteVal noteVal() const;
474 
475  Element* nextInEl(Element* e);
476  Element* prevInEl(Element* e);
477  virtual Element* nextElement() override;
478  virtual Element* prevElement() override;
479  virtual Element* lastElementBeforeSegment();
480  virtual Element* nextSegmentElement() override;
481  virtual Element* prevSegmentElement() override;
482 
483  virtual QString accessibleInfo() const override;
484  virtual QString screenReaderInfo() const override;
485  virtual QString accessibleExtraInfo() const override;
486 
487  virtual Shape shape() const override;
488  std::vector<Note*> tiedNotes() const;
489 
490  void setOffTimeType(int v) { _offTimeType = v; }
491  void setOnTimeType(int v) { _onTimeType = v; }
492  int offTimeType() const { return _offTimeType; }
493  int onTimeType() const { return _onTimeType; }
494  };
495 
496 } // namespace Ms
497 #endif
Ms::ElementType::NOTEHEAD
@ NOTEHEAD
Ms::NoteHead
Definition: note.h:52
Ms::Direction::AUTO
@ AUTO
Ms::NoteHead::Type
Type
Definition: note.h:128
Ms::Note::epitch
int epitch() const
effective pitch
Ms::AccidentalType
AccidentalType
Definition: types.h:151
Ms::NoteHead::Group::HEAD_NORMAL
@ HEAD_NORMAL
Ms::ElementType::NOTE
@ NOTE
Ms::NoteHead::Type::HEAD_AUTO
@ HEAD_AUTO
Ms::NoteType
NoteType
Definition: types.h:254
Ms::NoteHead::Group
Group
Definition: note.h:55
Ms::Note
Graphic representation of a note.
Definition: note.h:211
Ms::Note::ppitch
int ppitch() const
playback pitch
Ms::MScore::DirectionH
DirectionH
Definition: mscore.h:297
Ms
Definition: cursor.cpp:29
Ms::Direction
Direction
Definition: types.h:281
Ms::ElementType
ElementType
Definition: types.h:34
Ms::MScore::DirectionH::AUTO
@ AUTO