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       CUT_BACH,          // cut time (Bach)
35       CUT_TRIPLE,        // cut triple time (9/8)
36       };
37 
38 //---------------------------------------------------------------------------------------
39 //   @@ TimeSig
40 ///    This class represents a time signature.
41 //---------------------------------------------------------------------------------------
42 
43 class TimeSig final : public Element {
44       QString _numeratorString;     // calculated from actualSig() if !customText
45       QString _denominatorString;
46 
47       std::vector<SymId> ns;
48       std::vector<SymId> ds;
49 
50       QPointF pz;
51       QPointF pn;
52       QPointF pointLargeLeftParen;
53       QPointF pointLargeRightParen;
54       Fraction _sig;
55       Fraction _stretch;      // localSig / globalSig
56       Groups _groups;
57 
58       QSizeF _scale;
59       TimeSigType _timeSigType;
60       bool _showCourtesySig;
61       bool _largeParentheses;
62 
63    public:
64       TimeSig(Score* = 0);
65 
66       QString ssig() const;
67       void setSSig(const QString&);
68 
clone()69       TimeSig* clone() const override          { return new TimeSig(*this);   }
type()70       ElementType type() const override        { return ElementType::TIMESIG; }
71 
timeSigType()72       TimeSigType timeSigType() const    { return _timeSigType; }
73 
74       bool operator==(const TimeSig&) const;
75       bool operator!=(const TimeSig& ts) const { return !(*this == ts); }
76 
77       qreal mag() const override;
78       void draw(QPainter*) const override;
79       void write(XmlWriter& xml) const override;
80       void read(XmlReader&) override;
81       void layout() override;
82       Shape shape() const override;
83 
sig()84       Fraction sig() const               { return _sig; }
85       void setSig(const Fraction& f, TimeSigType st = TimeSigType::NORMAL);
numerator()86       int numerator() const              { return _sig.numerator(); }
denominator()87       int denominator() const            { return _sig.denominator(); }
88 
stretch()89       Fraction stretch() const           { return _stretch;   }
setStretch(const Fraction & s)90       void setStretch(const Fraction& s) { _stretch = s;      }
numeratorStretch()91       int numeratorStretch() const       { return _stretch.numerator(); }
denominatorStretch()92       int denominatorStretch() const     { return _stretch.denominator(); }
93 
94       bool acceptDrop(EditData&) const override;
95       Element* drop(EditData&) override;
96 
segment()97       Segment* segment() const           { return (Segment*)parent(); }
measure()98       Measure* measure() const           { return (Measure*)parent()->parent(); }
99 
showCourtesySig()100       bool showCourtesySig() const       { return _showCourtesySig; }
setShowCourtesySig(bool v)101       void setShowCourtesySig(bool v)    { _showCourtesySig = v;    }
102 
numeratorString()103       QString numeratorString() const    { return _numeratorString;   }
104       void setNumeratorString(const QString&);
105 
denominatorString()106       QString denominatorString() const  { return _denominatorString; }
107       void setDenominatorString(const QString&);
108 
setLargeParentheses(bool v)109       void setLargeParentheses(bool v)    { _largeParentheses = v;    }
110 
setScale(const QSizeF & s)111       void setScale(const QSizeF& s)      { _scale = s; }
112 
113 
114       void setFrom(const TimeSig*);
115 
116       QVariant getProperty(Pid propertyId) const override;
117       bool setProperty(Pid propertyId, const QVariant&) override;
118       QVariant propertyDefault(Pid id) const override;
119       Pid propertyId(const QStringRef& xmlName) const override;
120 
groups()121       const Groups& groups() const    { return _groups; }
setGroups(const Groups & e)122       void setGroups(const Groups& e) { _groups = e; }
123 
globalSig()124       Fraction globalSig() const           { return (_sig * _stretch).reduced();  }
setGlobalSig(const Fraction & f)125       void setGlobalSig(const Fraction& f) { _stretch = (_sig / f).reduced(); }
126 
isLocal()127       bool isLocal() const                 { return _stretch != Fraction(1,1); }
128 
129       Element* nextSegmentElement() override;
130       Element* prevSegmentElement() override;
131       QString accessibleInfo() const override;
132       };
133 
134 }     // namespace Ms
135 #endif
136 
137