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 "laissezvib.h"
24 :
25 : #include "../editing/mscoreview.h"
26 :
27 : #include "chord.h"
28 : #include "measure.h"
29 : #include "note.h"
30 : #include "score.h"
31 : #include "staff.h"
32 :
33 : namespace mu::engraving {
34 : static const ElementStyle laissezVibStyle {
35 : { Sid::minLaissezVibLength, Pid::MIN_LENGTH }
36 : };
37 :
38 21 : LaissezVib::LaissezVib(DummyParentOr<Note> parent)
39 21 : : Tie(ElementType::LAISSEZ_VIB, parent)
40 : {
41 21 : initElementStyle(&laissezVibStyle);
42 21 : }
43 :
44 331 : PropertyValue LaissezVib::getProperty(Pid propertyId) const
45 : {
46 331 : switch (propertyId) {
47 0 : case Pid::MIN_LENGTH:
48 0 : return minLength();
49 331 : default:
50 331 : return Tie::getProperty(propertyId);
51 : }
52 : }
53 :
54 294 : PropertyValue LaissezVib::propertyDefault(Pid propertyId) const
55 : {
56 294 : switch (propertyId) {
57 0 : case Pid::MIN_LENGTH:
58 0 : return 2.0_sp;
59 294 : default:
60 294 : return Tie::propertyDefault(propertyId);
61 : }
62 : }
63 :
64 23 : bool LaissezVib::setProperty(Pid propertyId, const PropertyValue& v)
65 : {
66 23 : switch (propertyId) {
67 21 : case Pid::MIN_LENGTH:
68 21 : setMinLength(v.value<Spatium>());
69 21 : break;
70 2 : default:
71 2 : return Tie::setProperty(propertyId, v);
72 : }
73 21 : triggerLayout();
74 21 : return true;
75 : }
76 :
77 0 : SymId LaissezVib::symId() const
78 : {
79 0 : return up() ? SymId::articLaissezVibrerAbove : SymId::articLaissezVibrerBelow;
80 : }
81 :
82 21 : SlurTieSegment* LaissezVib::newSlurTieSegment()
83 : {
84 21 : LaissezVibSegment* seg = new LaissezVibSegment(this);
85 21 : seg->setTrack(track());
86 21 : return seg;
87 : }
88 :
89 0 : void LaissezVib::setEndNote(Note* note)
90 : {
91 0 : setEndElement(note);
92 0 : }
93 :
94 0 : void LaissezVib::setEndElement(EngravingItem* e)
95 : {
96 : UNUSED(e);
97 0 : ASSERT_X("Laissez vibrer ties do not have an end note");
98 : }
99 :
100 21 : LaissezVibSegment::LaissezVibSegment(LaissezVib* sp)
101 21 : : TieSegment(ElementType::LAISSEZ_VIB_SEGMENT, sp)
102 : {
103 21 : }
104 :
105 0 : LaissezVibSegment::LaissezVibSegment(const LaissezVibSegment& s)
106 0 : : TieSegment(s)
107 : {
108 0 : }
109 :
110 0 : String LaissezVibSegment::formatBarsAndBeats() const
111 : {
112 0 : const Spanner* spanner = this->spanner();
113 0 : const Segment* startSeg = spanner ? spanner->startSegment() : nullptr;
114 :
115 0 : if (!startSeg) {
116 0 : return EngravingItem::formatBarsAndBeats();
117 : }
118 :
119 0 : return startSeg->formatBarsAndBeats();
120 : }
121 : }
|