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 2133 : 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 :
55 2329 : Segment* segment() const { return toSegment(ownershipParent()); }
56 31 : Measure* measure() const { return toMeasure(ownershipParent()->ownershipParent()); }
57 :
58 565 : TempoTextType tempoTextType() const { return m_tempoTextType; }
59 : void setTempoTextType(TempoTextType);
60 :
61 : BeatsPerSecond tempo() const;
62 : double tempoBpm() const;
63 : void setTempo(BeatsPerSecond v);
64 106 : bool isRelative() const { return m_isRelative; }
65 0 : void setRelative(double v) { m_isRelative = true; m_relative = v; }
66 0 : double relativeValue() const { return m_relative; }
67 :
68 77 : bool isNormal() const { return m_tempoTextType == TempoTextType::NORMAL; }
69 : void setNormal() { setTempoTextType(TempoTextType::NORMAL); }
70 :
71 189 : bool isATempo() const { return m_tempoTextType == TempoTextType::A_TEMPO; }
72 0 : void setATempo() { setTempoTextType(TempoTextType::A_TEMPO); }
73 :
74 177 : bool isTempoPrimo() const { return m_tempoTextType == TempoTextType::TEMPO_PRIMO; }
75 0 : void setTempoPrimo() { setTempoTextType(TempoTextType::TEMPO_PRIMO); }
76 :
77 77 : bool playTempoText() const { return m_playTempoText; }
78 0 : void setPlayTempoText(bool v) { m_playTempoText = v; }
79 :
80 686 : bool followText() const { return m_followText; }
81 270 : void setFollowText(bool v) { m_followText = v; }
82 :
83 : void updateTempo();
84 :
85 : TDuration duration() const;
86 :
87 : static int findTempoDuration(const String& s, int& len, TDuration& dur);
88 : static String duration2tempoTextString(const TDuration dur);
89 : static String duration2userName(const TDuration t);
90 :
91 : PropertyValue getProperty(Pid propertyId) const override;
92 : bool setProperty(Pid propertyId, const PropertyValue&) override;
93 : PropertyValue propertyDefault(Pid id) const override;
94 : String accessibleInfo() const override;
95 :
96 1238 : bool positionRelativeToNoteheadRest() const override { return true; }
97 :
98 : String tempoInfo() const;
99 :
100 : static constexpr double DEFAULT_SYM_SIZE_RATIO = 5.0 / 3.0;
101 :
102 : protected:
103 : void commitText() override;
104 :
105 : void undoChangeProperty(Pid id, const PropertyValue&, PropertyFlags ps) override;
106 :
107 : TempoTextType m_tempoTextType;
108 : BeatsPerSecond m_tempo; // beats per second
109 : bool m_followText = false; // parse text to determine tempo
110 : bool m_playTempoText = true;
111 : double m_relative = 0.0;
112 : bool m_isRelative = false;
113 : bool m_alignRightOfRehearsalMark = true;
114 : };
115 : } // namespace mu::engraving
116 : #endif
|