MuseScore  3.4
Music composition and notation
tuplet.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 __TUPLET_H__
14 #define __TUPLET_H__
15 
16 #include "duration.h"
17 #include "property.h"
18 
19 namespace Ms {
20 
21 class Text;
22 class Spanner;
23 enum class TupletNumberType : char;
24 enum class TupletBracketType : char;
25 
26 //------------------------------------------------------------------------
27 // @@ Tuplet
35 //------------------------------------------------------------------------
36 
37 class Tuplet final : public DurationElement {
38  std::vector<DurationElement*> _elements;
43 
46  TDuration _baseLen; // 1/8 for a triplet of 1/8
47 
48  bool _isUp;
49 
51 
52  QPointF p1, p2;
53  QPointF _p1, _p2; // user offset
54  mutable int _id; // used during read/write
55 
57  QPointF bracketL[4];
58  QPointF bracketR[3];
59 
60  Fraction addMissingElement(const Fraction& startTick, const Fraction& endTick);
61 
62  public:
63  Tuplet(Score*);
64  Tuplet(const Tuplet&);
65  ~Tuplet();
66  virtual Tuplet* clone() const override { return new Tuplet(*this); }
67  virtual ElementType type() const override { return ElementType::TUPLET; }
68  virtual void setTrack(int val) override;
69 
70  virtual void add(Element*) override;
71  virtual void remove(Element*) override;
72 
73  Text* number() const { return _number; }
74  void setNumber(Text* t) { _number = t; }
75  void resetNumberProperty();
76 
77  virtual bool isEditable() const override;
78  void startEditDrag(EditData&) override;
79  virtual void editDrag(EditData&) override;
80 
81  virtual void setSelected(bool f) override;
82 
83  virtual Measure* measure() const override { return toMeasure(parent()); }
84 
85  TupletNumberType numberType() const { return _numberType; }
86  TupletBracketType bracketType() const { return _bracketType; }
87  void setNumberType(TupletNumberType val) { _numberType = val; }
88  void setBracketType(TupletBracketType val) { _bracketType = val; }
89  bool hasBracket() const { return _hasBracket; }
90  void setHasBracket(bool b) { _hasBracket = b; }
91  Spatium bracketWidth() const { return _bracketWidth; }
92  void setBracketWidth(Spatium s) { _bracketWidth = s; }
93 
94  Fraction ratio() const { return _ratio; }
95  void setRatio(const Fraction& r) { _ratio = r; }
96 
97  const std::vector<DurationElement*>& elements() const { return _elements; }
98  void clear() { _elements.clear(); }
99  bool contains(const DurationElement* el) const { return std::find(_elements.begin(), _elements.end(), el) != _elements.end(); }
100 
101  virtual void layout() override;
102  virtual void scanElements(void* data, void (*func)(void*, Element*), bool all=true) override;
103 
104  virtual void read(XmlReader&) override;
105  virtual void write(XmlWriter&) const override;
106  virtual bool readProperties(XmlReader&) override;
107 
108  virtual void reset() override;
109 
110  virtual void draw(QPainter*) const override;
111  int id() const { return _id; }
112  void setId(int i) const { _id = i; }
113 
114  TDuration baseLen() const { return _baseLen; }
115  void setBaseLen(const TDuration& d) { _baseLen = d; }
116 
117  virtual void dump() const override;
118 
119  void setDirection(Direction d) { _direction = d; }
120  Direction direction() const { return _direction; }
121  bool isUp() const { return _isUp; }
122  virtual Fraction tick() const override { return _tick; }
123  virtual Fraction rtick() const override;
124  void setTick(const Fraction& v) { _tick = v; }
125  Fraction elementsDuration();
126  void sortElements();
127  bool cross() const;
128 
129  virtual void setVisible(bool f) override;
130 
131  virtual QVariant getProperty(Pid propertyId) const override;
132  virtual bool setProperty(Pid propertyId, const QVariant& v) override;
133  virtual QVariant propertyDefault(Pid id) const override;
134 
135  virtual Shape shape() const override;
136 
138  int gripsCount() const override { return 2; }
139  Grip initialEditModeGrip() const override { return Grip::END; }
140  Grip defaultGrip() const override { return Grip::START; }
141  std::vector<QPointF> gripsPositions(const EditData&) const override;
142 
143  void sanitizeTuplet();
144  void addMissingElements();
145  };
146 
147 
148 } // namespace Ms
149 #endif
150 
void clear()
Definition: tuplet.h:98
Definition: durationtype.h:28
void setNumberType(TupletNumberType val)
Definition: tuplet.h:87
bool hasBracket() const
Definition: tuplet.h:89
Pid
Definition: property.h:62
void setBracketWidth(Spatium s)
Definition: tuplet.h:92
Definition: xml.h:67
Direction _direction
Definition: tuplet.h:39
Fraction _tick
Definition: tuplet.h:50
void setBracketType(TupletBracketType val)
Definition: tuplet.h:88
bool isUp() const
Definition: tuplet.h:121
one measure in a system
Definition: measure.h:65
TupletBracketType _bracketType
Definition: tuplet.h:41
virtual Tuplet * clone() const override
Definition: tuplet.h:66
TupletNumberType
Definition: types.h:500
Base class of score layout elements.
Definition: element.h:158
Direction direction() const
Definition: tuplet.h:120
int id() const
Definition: tuplet.h:111
void setNumber(Text *t)
Definition: tuplet.h:74
Spatium _bracketWidth
Definition: tuplet.h:42
void setTick(const Fraction &v)
Definition: tuplet.h:124
Spatium bracketWidth() const
Definition: tuplet.h:91
TupletNumberType numberType() const
Definition: tuplet.h:85
TupletBracketType
Definition: types.h:501
Definition: score.h:391
void setHasBracket(bool b)
Definition: tuplet.h:90
Example of 1/8 triplet: _baseLen = 1/8 _actualNotes = 3 _normalNotes = 2 (3 notes played in the time ...
Definition: tuplet.h:37
void setId(int i) const
Definition: tuplet.h:112
QPointF p2
Definition: tuplet.h:52
int gripsCount() const override
Definition: tuplet.h:138
Text * number() const
Definition: tuplet.h:73
Grip defaultGrip() const override
Definition: tuplet.h:140
Grip
Definition: element.h:43
int _id
Definition: tuplet.h:54
const std::vector< DurationElement * > & elements() const
Definition: tuplet.h:97
TupletNumberType _numberType
Definition: tuplet.h:40
TDuration _baseLen
Definition: tuplet.h:46
Element::EditBehavior normalModeEditBehavior() const override
Definition: tuplet.h:137
Definition: aeolus.cpp:26
Definition: spatium.h:25
void setRatio(const Fraction &r)
Definition: tuplet.h:95
void setDirection(Direction d)
Definition: tuplet.h:119
TupletBracketType bracketType() const
Definition: tuplet.h:86
QPointF _p2
Definition: tuplet.h:53
Definition: xml.h:218
std::vector< DurationElement * > _elements
Definition: tuplet.h:38
Virtual base class for Chord, Rest and Tuplet.
Definition: duration.h:34
TDuration baseLen() const
Definition: tuplet.h:114
Grip initialEditModeGrip() const override
Definition: tuplet.h:139
bool contains(const DurationElement *el) const
Definition: tuplet.h:99
Fraction _ratio
Definition: tuplet.h:45
void setBaseLen(const TDuration &d)
Definition: tuplet.h:115
Direction
Definition: types.h:282
virtual Fraction tick() const override
Definition: tuplet.h:122
Definition: element.h:111
virtual ElementType type() const override
Definition: tuplet.h:67
virtual Measure * measure() const override
Definition: tuplet.h:83
Text * _number
Definition: tuplet.h:56
Definition: shape.h:42
Definition: fraction.h:46
ElementType
Definition: types.h:34
Fraction ratio() const
Definition: tuplet.h:94
bool _isUp
Definition: tuplet.h:48
Definition: text.h:24
Pid propertyId(const QStringRef &s)
Definition: property.cpp:347
EditBehavior
Definition: element.h:173
bool _hasBracket
Definition: tuplet.h:44