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 : #include "breath.h"
24 :
25 : #include "types/symnames.h"
26 :
27 : #include "measure.h"
28 : #include "score.h"
29 : #include "segment.h"
30 : #include "staff.h"
31 : #include "system.h"
32 :
33 : #include "log.h"
34 :
35 : using namespace mu;
36 : using namespace mu::engraving;
37 :
38 : namespace mu::engraving {
39 : const std::vector<BreathType> Breath::BREATH_LIST {
40 : { SymId::breathMarkComma, false, 0.0 },
41 : { SymId::breathMarkTick, false, 0.0 },
42 : { SymId::breathMarkSalzedo, false, 0.0 },
43 : { SymId::breathMarkUpbow, false, 0.0 },
44 : { SymId::caesuraCurved, true, 2.0 },
45 : { SymId::caesura, true, 2.0 },
46 : { SymId::caesuraShort, true, 2.0 },
47 : { SymId::caesuraThick, true, 2.0 },
48 : { SymId::chantCaesura, true, 2.0 },
49 : { SymId::caesuraSingleStroke, true, 2.0 },
50 : };
51 :
52 : //---------------------------------------------------------
53 : // Breath
54 : //---------------------------------------------------------
55 :
56 120 : Breath::Breath(DummyParentOr<Segment> parent)
57 120 : : EngravingItem(ElementType::BREATH, parent, ElementFlag::MOVABLE | ElementFlag::ON_STAFF)
58 : {
59 120 : m_symId = SymId::breathMarkComma;
60 120 : m_pause = 0.0;
61 120 : }
62 :
63 : //---------------------------------------------------------
64 : // isCaesura
65 : //---------------------------------------------------------
66 :
67 215 : bool Breath::isCaesura() const
68 : {
69 660 : for (const BreathType& bt : BREATH_LIST) {
70 660 : if (bt.id == m_symId) {
71 215 : return bt.isCaesura;
72 : }
73 : }
74 0 : return false;
75 : }
76 :
77 : //---------------------------------------------------------
78 : // mag
79 : //---------------------------------------------------------
80 :
81 7832 : double Breath::mag() const
82 : {
83 7832 : return staff() ? staff()->staffMag(tick()) : 1.0;
84 : }
85 :
86 : //---------------------------------------------------------
87 : // getProperty
88 : //---------------------------------------------------------
89 :
90 704 : PropertyValue Breath::getProperty(Pid propertyId) const
91 : {
92 704 : switch (propertyId) {
93 64 : case Pid::SYMBOL:
94 64 : return PropertyValue::fromValue(m_symId);
95 64 : case Pid::PAUSE:
96 64 : return m_pause;
97 576 : default:
98 576 : return EngravingItem::getProperty(propertyId);
99 : }
100 : }
101 :
102 : //---------------------------------------------------------
103 : // setProperty
104 : //---------------------------------------------------------
105 :
106 16 : bool Breath::setProperty(Pid propertyId, const PropertyValue& v)
107 : {
108 16 : switch (propertyId) {
109 0 : case Pid::SYMBOL:
110 0 : setSymId(v.value<SymId>());
111 0 : break;
112 0 : case Pid::PAUSE:
113 0 : setPause(v.toDouble());
114 0 : break;
115 16 : default:
116 16 : if (!EngravingItem::setProperty(propertyId, v)) {
117 0 : return false;
118 : }
119 16 : break;
120 : }
121 16 : triggerLayout();
122 16 : setGenerated(false);
123 16 : return true;
124 : }
125 :
126 : //---------------------------------------------------------
127 : // propertyDefault
128 : //---------------------------------------------------------
129 :
130 706 : PropertyValue Breath::propertyDefault(Pid id) const
131 : {
132 706 : switch (id) {
133 64 : case Pid::PAUSE:
134 64 : return 0.0;
135 66 : case Pid::PLACEMENT:
136 66 : return track() & 1 ? PlacementV::BELOW : PlacementV::ABOVE;
137 576 : default:
138 576 : return EngravingItem::propertyDefault(id);
139 : }
140 : }
141 :
142 : //---------------------------------------------------------
143 : // nextSegmentElement
144 : //---------------------------------------------------------
145 :
146 0 : EngravingItem* Breath::nextSegmentElement()
147 : {
148 0 : return segment()->firstInNextSegments(staffIdx());
149 : }
150 :
151 : //---------------------------------------------------------
152 : // prevSegmentElement
153 : //---------------------------------------------------------
154 :
155 0 : EngravingItem* Breath::prevSegmentElement()
156 : {
157 0 : return segment()->lastInPrevSegments(staffIdx());
158 : }
159 :
160 : //---------------------------------------------------------
161 : // accessibleInfo
162 : //---------------------------------------------------------
163 :
164 0 : String Breath::accessibleInfo() const
165 : {
166 0 : return SymNames::translatedUserNameForSymId(m_symId);
167 : }
168 :
169 : //---------------------------------------------------------
170 : // subtypeUserName
171 : //---------------------------------------------------------
172 :
173 0 : muse::TranslatableString Breath::subtypeUserName() const
174 : {
175 0 : return SymNames::userNameForSymId(symId());
176 : }
177 : }
|