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 : #ifndef MU_ENGRAVING_TEMPOTEXT_H
24 : #define MU_ENGRAVING_TEMPOTEXT_H
25 :
26 : #include "durationtype.h"
27 : #include "textbase.h"
28 :
29 : namespace mu::engraving {
30 : enum class TempoTextType : signed char
31 : {
32 : NORMAL,
33 : A_TEMPO,
34 : TEMPO_PRIMO,
35 : };
36 :
37 : //-------------------------------------------------------------------
38 : // @@ TempoText
39 : /// Tempo marker which determines the midi tempo.
40 : //
41 : // @P tempo float tempo in quarter notes (crochets) per second
42 : // @P followText bool determine tempo from text
43 : //-------------------------------------------------------------------
44 :
45 : class TempoText final : public TextBase
46 : {
47 2253 : OBJECT_ALLOCATOR(engraving, TempoText)
48 1072 : DECLARE_CLASSOF(ElementType::TEMPO_TEXT)
49 :
50 : public:
51 : TempoText(DummyParentOr<Segment> parent);
52 :
53 302 : TempoText* clone() const override { return new TempoText(*this); }
54 : void setOwnershipParent(DummyParentOr<Segment> parent) { EngravingItem::setOwnershipParent(parent); }
55 :
56 2445 : Segment* segment() const { return toSegment(ownershipParent()); }
57 31 : Measure* measure() const { return toMeasure(ownershipParent()->ownershipParent()); }
58 :
59 565 : TempoTextType tempoTextType() const { return m_tempoTextType; }
60 : void setTempoTextType(TempoTextType);
61 :
62 : BeatsPerSecond tempo() const;
63 : double tempoBpm() const;
64 : void setTempo(BeatsPerSecond v);
65 106 : bool isRelative() const { return m_isRelative; }
66 0 : void setRelative(double v) { m_isRelative = true; m_relative = v; }
67 0 : double relativeValue() const { return m_relative; }
68 :
69 77 : bool isNormal() const { return m_tempoTextType == TempoTextType::NORMAL; }
70 : void setNormal() { setTempoTextType(TempoTextType::NORMAL); }
71 :
72 189 : bool isATempo() const { return m_tempoTextType == TempoTextType::A_TEMPO; }
73 0 : void setATempo() { setTempoTextType(TempoTextType::A_TEMPO); }
74 :
75 177 : bool isTempoPrimo() const { return m_tempoTextType == TempoTextType::TEMPO_PRIMO; }
76 0 : void setTempoPrimo() { setTempoTextType(TempoTextType::TEMPO_PRIMO); }
77 :
78 77 : bool playTempoText() const { return m_playTempoText; }
79 0 : void setPlayTempoText(bool v) { m_playTempoText = v; }
80 :
81 686 : bool followText() const { return m_followText; }
82 270 : void setFollowText(bool v) { m_followText = v; }
83 :
84 : void updateTempo();
85 :
86 : TDuration duration() const;
87 :
88 : static int findTempoDuration(const String& s, int& len, TDuration& dur);
89 : static String duration2tempoTextString(const TDuration dur);
90 : static String duration2userName(const TDuration t);
91 :
92 : PropertyValue getProperty(Pid propertyId) const override;
93 : bool setProperty(Pid propertyId, const PropertyValue&) override;
94 : PropertyValue propertyDefault(Pid id) const override;
95 : String accessibleInfo() const override;
96 :
97 1296 : bool positionRelativeToNoteheadRest() const override { return true; }
98 :
99 : String tempoInfo() const;
100 :
101 : static constexpr double DEFAULT_SYM_SIZE_RATIO = 5.0 / 3.0;
102 :
103 : protected:
104 : void commitText() override;
105 :
106 : void undoChangeProperty(Pid id, const PropertyValue&, PropertyFlags ps) override;
107 :
108 : TempoTextType m_tempoTextType;
109 : BeatsPerSecond m_tempo; // beats per second
110 : bool m_followText = false; // parse text to determine tempo
111 : bool m_playTempoText = true;
112 : double m_relative = 0.0;
113 : bool m_isRelative = false;
114 : bool m_alignRightOfRehearsalMark = true;
115 : };
116 : } // namespace mu::engraving
117 : #endif
|