23 #include "noteevent.h"
24 #include "pitchspelling.h"
38 class AccidentalState;
46 static const int MAX_DOTS = 4;
55 enum class Group : signed char {
128 enum class Type : signed char {
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; }
147 Group headGroup()
const;
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);
165 int tpc1 { Tpc::TPC_INVALID };
166 int tpc2 { Tpc::TPC_INVALID };
167 int fret { FRET_NONE };
168 int string { STRING_NONE };
172 NoteVal(
int p) : pitch(p) {}
175 static const int INVALID_LINE = -10000;
211 class Note final :
public Element {
214 enum class ValueType : char { OFFSET_VAL, USER_VAL };
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 };
230 mutable bool _mark {
false };
231 bool _fixed {
false };
239 ValueType _veloType { ValueType::OFFSET_VAL };
241 char _offTimeType { 0 };
242 char _onTimeType { 0 };
244 int _subchannel { 0 };
245 int _line { INVALID_LINE };
248 mutable int _tpc[2] { Tpc::TPC_INVALID, Tpc::TPC_INVALID };
249 mutable int _pitch { 0 };
251 int _veloOffset { 0 };
252 int _fixedLine { 0 };
253 qreal _tuning { 0.0 };
255 Accidental* _accidental { 0 };
261 QVector<NoteDot*> _dots;
262 NoteEventList _playEvents;
263 QVector<Spanner*> _spannerFor;
264 QVector<Spanner*> _spannerBack;
266 SymId _cachedNoteheadSym;
267 SymId _cachedSymNull;
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;
284 Note(
const Note&,
bool link =
false);
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; }
291 virtual void undoUnlink()
override;
293 virtual qreal mag()
const override;
298 void setCachedNoteheadSym(SymId i) { _cachedNoteheadSym = i; };
299 void scanElements(
void* data,
void (*func)(
void*, Element*),
bool all=
true);
300 void setTrack(
int val);
302 int playTicks()
const;
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;
320 virtual int subtype()
const override {
return (
int) _headGroup; }
321 virtual QString subtypeName()
const override;
323 void setPitch(
int val);
324 void setPitch(
int pitch,
int tpc1,
int tpc2);
325 int pitch()
const {
return _pitch; }
326 int ottaveCapoFret()
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; }
339 int tpc1()
const {
return _tpc[0]; }
340 int tpc2()
const {
return _tpc[1]; }
341 QString tpcUserName(
bool explicitAccidental =
false)
const;
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);
351 Accidental* accidental()
const {
return _accidental; }
352 void setAccidental(Accidental* a) { _accidental = a; }
358 void setLine(
int n) { _line = n; }
359 int physicalLine()
const;
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; }
370 virtual void add(Element*)
override;
371 virtual void remove(Element*)
override;
373 bool mirror()
const {
return _mirror; }
374 void setMirror(
bool val) { _mirror = val; }
376 bool small()
const {
return _small; }
377 void setSmall(
bool val);
379 bool play()
const {
return _play; }
380 void setPlay(
bool val) { _play = val; }
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();
391 Chord* chord()
const {
return (Chord*)parent(); }
392 void setChord(Chord* a) { setParent((Element*)a); }
393 virtual void draw(QPainter*)
const override;
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;
400 bool acceptDrop(EditData&)
const override;
401 Element* drop(EditData&);
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; }
409 QString noteTypeUserName()
const;
411 ElementList& el() {
return _el; }
412 const ElementList& el()
const {
return _el; }
414 int subchannel()
const {
return _subchannel; }
415 void setSubchannel(
int val) { _subchannel = val; }
420 Direction userDotPosition()
const {
return _userDotPosition; }
421 void setUserDotPosition(
Direction d) { _userDotPosition = d; }
422 bool dotIsUp()
const;
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; }
431 void setOnTimeOffset(
int v);
432 void setOffTimeOffset(
int v);
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; }
440 void updateAccidental(AccidentalState*);
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; }
448 const QVector<Spanner*>& spannerFor()
const {
return _spannerFor; }
449 const QVector<Spanner*>& spannerBack()
const {
return _spannerBack; }
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); }
456 void transposeDiatonic(
int interval,
bool keepAlterations,
bool useDoubleAccidentals);
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;
465 bool mark()
const {
return _mark; }
466 void setMark(
bool v)
const { _mark = v; }
467 virtual void setScore(Score* s)
override;
470 void addParentheses();
474 NoteVal noteVal()
const;
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;
484 virtual QString accessibleInfo()
const override;
485 virtual QString screenReaderInfo()
const override;
486 virtual QString accessibleExtraInfo()
const override;
488 virtual Shape shape()
const override;
489 std::vector<Note*> tiedNotes()
const;
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; }