MuseScore  3.4
Music composition and notation
timesig.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2002-2017 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 __TIMESIG_H__
14 #define __TIMESIG_H__
15 
16 #include "element.h"
17 #include "sig.h"
18 #include "mscore.h"
19 #include "groups.h"
20 
21 namespace Ms {
22 
23 class MuseScoreView;
24 class Segment;
25 
26 //---------------------------------------------------------
27 // TimeSigType
28 //---------------------------------------------------------
29 
30 enum class TimeSigType : char {
31  NORMAL, // use sz/sn text
32  FOUR_FOUR, // common time (4/4)
33  ALLA_BREVE, // cut time (2/2)
34  };
35 
36 //---------------------------------------------------------------------------------------
37 // @@ TimeSig
39 //---------------------------------------------------------------------------------------
40 
41 class TimeSig final : public Element {
42  QString _numeratorString; // calculated from actualSig() if !customText
44 
45  std::vector<SymId> ns;
46  std::vector<SymId> ds;
47 
48  QPointF pz;
49  QPointF pn;
53  Fraction _stretch; // localSig / globalSig
55 
56  QSizeF _scale;
60 
61  public:
62  TimeSig(Score* = 0);
63 
64  QString ssig() const;
65  void setSSig(const QString&);
66 
67  virtual TimeSig* clone() const override { return new TimeSig(*this); }
68  virtual ElementType type() const override { return ElementType::TIMESIG; }
69 
70  TimeSigType timeSigType() const { return _timeSigType; }
71 
72  bool operator==(const TimeSig&) const;
73  bool operator!=(const TimeSig& ts) const { return !(*this == ts); }
74 
75  virtual qreal mag() const override;
76  virtual void draw(QPainter*) const override;
77  virtual void write(XmlWriter& xml) const override;
78  virtual void read(XmlReader&) override;
79  virtual void layout() override;
80  virtual Shape shape() const override;
81 
82  Fraction sig() const { return _sig; }
83  void setSig(const Fraction& f, TimeSigType st = TimeSigType::NORMAL);
84  int numerator() const { return _sig.numerator(); }
85  int denominator() const { return _sig.denominator(); }
86 
87  Fraction stretch() const { return _stretch; }
88  void setStretch(const Fraction& s) { _stretch = s; }
89  int numeratorStretch() const { return _stretch.numerator(); }
90  int denominatorStretch() const { return _stretch.denominator(); }
91 
92  bool acceptDrop(EditData&) const override;
93  virtual Element* drop(EditData&) override;
94 
95  Segment* segment() const { return (Segment*)parent(); }
96  Measure* measure() const { return (Measure*)parent()->parent(); }
97 
98  bool showCourtesySig() const { return _showCourtesySig; }
99  void setShowCourtesySig(bool v) { _showCourtesySig = v; }
100 
101  QString numeratorString() const { return _numeratorString; }
102  void setNumeratorString(const QString&);
103 
104  QString denominatorString() const { return _denominatorString; }
105  void setDenominatorString(const QString&);
106 
107  void setLargeParentheses(bool v) { _largeParentheses = v; }
108 
109  void setScale(const QSizeF& s) { _scale = s; }
110 
111 
112  void setFrom(const TimeSig*);
113 
114  virtual QVariant getProperty(Pid propertyId) const override;
115  virtual bool setProperty(Pid propertyId, const QVariant&) override;
116  virtual QVariant propertyDefault(Pid id) const override;
117  virtual Pid propertyId(const QStringRef& xmlName) const override;
118 
119  const Groups& groups() const { return _groups; }
120  void setGroups(const Groups& e) { _groups = e; }
121 
122  Fraction globalSig() const { return (_sig * _stretch).reduced(); }
123  void setGlobalSig(const Fraction& f) { _stretch = (_sig / f).reduced(); }
124 
125  bool isLocal() const { return _stretch != Fraction(1,1); }
126 
127  virtual Element* nextSegmentElement();
128  virtual Element* prevSegmentElement();
129  virtual QString accessibleInfo() const override;
130  };
131 
132 } // namespace Ms
133 #endif
134 
int numerator() const
Definition: timesig.h:84
int numerator() const
Definition: fraction.h:62
const Groups & groups() const
Definition: timesig.h:119
Pid
Definition: property.h:62
This class represents a time signature.
Definition: timesig.h:41
void setScale(const QSizeF &s)
Definition: timesig.h:109
Definition: xml.h:67
QSizeF _scale
Definition: timesig.h:56
int denominator() const
Definition: timesig.h:85
Fraction reduced() const
Definition: fraction.h:101
int denominatorStretch() const
Definition: timesig.h:90
int denominator() const
Definition: fraction.h:63
one measure in a system
Definition: measure.h:65
bool isLocal() const
Definition: timesig.h:125
QString _numeratorString
Definition: timesig.h:42
bool _showCourtesySig
Definition: timesig.h:58
std::vector< SymId > ns
Definition: timesig.h:45
Base class of score layout elements.
Definition: element.h:158
void setShowCourtesySig(bool v)
Definition: timesig.h:99
Measure * measure() const
Definition: timesig.h:96
bool _largeParentheses
Definition: timesig.h:59
QString _denominatorString
Definition: timesig.h:43
void setLargeParentheses(bool v)
Definition: timesig.h:107
virtual ElementType type() const override
Definition: timesig.h:68
GroupNodes must be sorted by tick.
Definition: groups.h:48
Element * parent() const
Definition: element.h:192
Fraction globalSig() const
Definition: timesig.h:122
std::vector< SymId > ds
Definition: timesig.h:46
Definition: score.h:391
Fraction stretch() const
Definition: timesig.h:87
bool showCourtesySig() const
Definition: timesig.h:98
QPointF pointLargeLeftParen
Definition: timesig.h:50
bool operator!=(const TimeSig &ts) const
Definition: timesig.h:73
QString denominatorString() const
Definition: timesig.h:104
Fraction _sig
Definition: timesig.h:52
Definition: segment.h:50
Fraction sig() const
Definition: timesig.h:82
int numeratorStretch() const
Definition: timesig.h:89
Definition: aeolus.cpp:26
TimeSigType
Definition: timesig.h:30
QString numeratorString() const
Definition: timesig.h:101
Definition: xml.h:218
Groups _groups
Definition: timesig.h:54
Fraction _stretch
Definition: timesig.h:53
void setGlobalSig(const Fraction &f)
Definition: timesig.h:123
Segment * segment() const
Definition: timesig.h:95
Definition: element.h:111
QPointF pointLargeRightParen
Definition: timesig.h:51
Definition: shape.h:42
QPointF pn
Definition: timesig.h:49
Definition: fraction.h:46
ElementType
Definition: types.h:34
virtual TimeSig * clone() const override
Definition: timesig.h:67
void setStretch(const Fraction &s)
Definition: timesig.h:88
QPointF pz
Definition: timesig.h:48
Pid propertyId(const QStringRef &s)
Definition: property.cpp:347
TimeSigType timeSigType() const
Definition: timesig.h:70
void setGroups(const Groups &e)
Definition: timesig.h:120
TimeSigType _timeSigType
Definition: timesig.h:57