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