Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #pragma once
24 :
25 : #include "engravingitem.h"
26 :
27 : #include "groups.h"
28 :
29 : namespace mu::engraving {
30 : class Segment;
31 : class Transaction;
32 :
33 : //---------------------------------------------------------
34 : // TimeSigType
35 : //---------------------------------------------------------
36 :
37 : enum class TimeSigType : unsigned char {
38 : NORMAL, // use sz/sn text
39 : FOUR_FOUR, // common time (4/4)
40 : ALLA_BREVE, // cut time (2/2)
41 : CUT_BACH, // cut time (Bach)
42 : CUT_TRIPLE, // cut triple time (9/8)
43 : };
44 :
45 : //---------------------------------------------------------------------------------------
46 : // @@ TimeSig
47 : /// This class represents a time signature.
48 : //---------------------------------------------------------------------------------------
49 :
50 : class TimeSig final : public EngravingItem
51 : {
52 7348 : OBJECT_ALLOCATOR(engraving, TimeSig)
53 138 : DECLARE_CLASSOF(ElementType::TIMESIG)
54 :
55 1175 : M_PROPERTY2(bool, isCourtesy, setIsCourtesy, false)
56 :
57 : public:
58 :
59 : void setOwnershipParent(DummyParentOr<Segment> parent);
60 :
61 : String ssig() const;
62 : void setSSig(const String&);
63 :
64 190 : TimeSig* clone() const override { return new TimeSig(*this); }
65 :
66 8178 : TimeSigType timeSigType() const { return m_timeSigType; }
67 :
68 : int subtype() const override;
69 : TranslatableString subtypeUserName() const override;
70 :
71 : bool operator==(const TimeSig&) const;
72 7 : bool operator!=(const TimeSig& ts) const { return !(*this == ts); }
73 :
74 : double mag() const override;
75 :
76 259110 : Fraction sig() const { return m_sig; }
77 : void setSig(const Fraction& f, TimeSigType st = TimeSigType::NORMAL);
78 2044 : int numerator() const { return m_sig.numerator(); }
79 179454 : int denominator() const { return m_sig.denominator(); }
80 :
81 1774217 : Fraction stretch() const { return m_stretch; }
82 1774 : void setStretch(const Fraction& s) { m_stretch = s; }
83 : int numeratorStretch() const { return m_stretch.numerator(); }
84 : int denominatorStretch() const { return m_stretch.denominator(); }
85 :
86 : bool acceptDrop(EditData&) const override;
87 : EngravingItem* drop(Transaction& tx, EditData&) override;
88 :
89 49010 : Segment* segment() const { return (Segment*)ownershipParent(); }
90 2 : Measure* measure() const { return (Measure*)ownershipParent()->ownershipParent(); }
91 :
92 48026 : bool showCourtesySig() const { return m_showCourtesySig; }
93 62 : void setShowCourtesySig(bool v) { m_showCourtesySig = v; }
94 :
95 15020 : const String& numeratorString() const { return m_numeratorString; }
96 : void setNumeratorString(const String&);
97 :
98 8733 : const String& denominatorString() const { return m_denominatorString; }
99 : void setDenominatorString(const String&);
100 :
101 6297 : bool largeParentheses() const { return m_largeParentheses; }
102 14 : void setLargeParentheses(bool v) { m_largeParentheses = v; }
103 :
104 : void setFrom(const TimeSig*);
105 :
106 : PropertyValue getProperty(Pid propertyId) const override;
107 : bool setProperty(Pid propertyId, const PropertyValue&) override;
108 : PropertyValue propertyDefault(Pid id) const override;
109 :
110 154592 : const Groups& groups() const { return m_groups; }
111 2 : void setGroups(const Groups& e) { m_groups = e; }
112 :
113 233 : bool isLocal() const { return m_stretch != Fraction(1, 1); }
114 :
115 : PointF staffOffset() const override;
116 :
117 : EngravingItem* nextSegmentElement() override;
118 : EngravingItem* prevSegmentElement() override;
119 : String accessibleInfo() const override;
120 :
121 : void initElementStyle(const ElementStyle*) override;
122 : void styleChanged() override;
123 : Sid getPropertyStyle(Pid id) const override;
124 :
125 : bool showOnThisStaff() const;
126 : bool isAboveStaves() const;
127 : bool isAcrossStaves() const;
128 : TimeSigPlacement timeSigPlacement() const;
129 : TimeSigStyle timeSigStyle() const;
130 : double numDist() const;
131 : double yPos() const;
132 6439 : const ScaleF& scale() const { return m_scale; }
133 487 : void setScale(const ScaleF& s) { m_scale = s; } // TODO: think about what to do with this
134 :
135 : struct LayoutData : public EngravingItem::LayoutData {
136 : SymIdList ns;
137 : SymIdList ds;
138 : PointF pz;
139 : PointF pn;
140 : PointF pointLargeLeftParen;
141 : PointF pointLargeRightParen;
142 : };
143 10287 : DECLARE_LAYOUTDATA_METHODS(TimeSig)
144 :
145 : protected:
146 : void added() override;
147 : void removed() override;
148 :
149 : private:
150 :
151 : friend class Factory;
152 : TimeSig(DummyParentOr<Segment> parent);
153 :
154 : String m_numeratorString; // calculated from actualSig() if !customText
155 : String m_denominatorString;
156 :
157 : Fraction m_sig;
158 : Fraction m_stretch; // localSig / globalSig
159 : Groups m_groups;
160 :
161 : ScaleF m_scale = ScaleF(1.0, 1.0);
162 : TimeSigType m_timeSigType = TimeSigType::NORMAL;
163 : bool m_showCourtesySig = false;
164 : bool m_largeParentheses = false;
165 : };
166 : } // namespace mu::engraving
|