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 : #pragma once
23 :
24 : #include "accidental.h"
25 : #include "engravingitem.h"
26 :
27 : #include "pitchspelling.h"
28 :
29 : #include "../types/types.h"
30 :
31 : namespace mu::engraving {
32 : class Factory;
33 :
34 : //---------------------------------------------------------
35 : // @@ Ambitus
36 : //---------------------------------------------------------
37 :
38 : class Ambitus final : public EngravingItem
39 : {
40 4 : OBJECT_ALLOCATOR(engraving, Ambitus)
41 2376 : DECLARE_CLASSOF(ElementType::AMBITUS)
42 :
43 : public:
44 : ~Ambitus();
45 :
46 : static constexpr NoteHeadGroup NOTEHEADGROUP_DEFAULT = NoteHeadGroup::HEAD_NORMAL;
47 : static constexpr NoteHeadType NOTEHEADTYPE_DEFAULT = NoteHeadType::HEAD_AUTO;
48 : static constexpr DirectionH DIRECTION_DEFAULT = DirectionH::AUTO;
49 : static constexpr bool HASLINE_DEFAULT = true;
50 : static constexpr Spatium LINEWIDTH_DEFAULT = 0.12_sp;
51 : static constexpr Spatium LINEOFFSET_DEFAULT = 0.8_sp; // the distance between notehead and line
52 :
53 0 : Ambitus* clone() const override { return new Ambitus(*this); }
54 :
55 : double mag() const override;
56 :
57 : void initFrom(Ambitus* a);
58 :
59 : // getters and setters
60 2 : NoteHeadGroup noteHeadGroup() const { return m_noteHeadGroup; }
61 2 : NoteHeadType noteHeadType() const { return m_noteHeadType; }
62 6 : DirectionH direction() const { return m_direction; }
63 2 : bool hasLine() const { return m_hasLine; }
64 2 : Spatium lineWidth() const { return m_lineWidth; }
65 0 : int topOctave() const { return (m_topPitch / PITCH_DELTA_OCTAVE) - 1; }
66 0 : int bottomOctave() const { return (m_bottomPitch / PITCH_DELTA_OCTAVE) - 1; }
67 6 : int topPitch() const { return m_topPitch; }
68 6 : int bottomPitch() const { return m_bottomPitch; }
69 8 : int topTpc() const { return m_topTpc; }
70 8 : int bottomTpc() const { return m_bottomTpc; }
71 :
72 8 : Accidental* topAccidental() const { return m_topAccidental; }
73 10 : Accidental* bottomAccidental() const { return m_bottomAccidental; }
74 :
75 1 : void setNoteHeadGroup(NoteHeadGroup val) { m_noteHeadGroup = val; }
76 1 : void setNoteHeadType(NoteHeadType val) { m_noteHeadType = val; }
77 1 : void setDirection(DirectionH val) { m_direction = val; }
78 0 : void setHasLine(bool val) { m_hasLine = val; }
79 0 : void setLineWidth(Spatium val) { m_lineWidth = val; }
80 : void setTopPitch(int val, bool applyLogic = true);
81 : void setBottomPitch(int val, bool applyLogic = true);
82 : void setTopTpc(int val, bool applyLogic = true);
83 : void setBottomTpc(int val, bool applyLogic = true);
84 :
85 : // some utility functions
86 2 : Segment* segment() const { return (Segment*)ownershipParent(); }
87 : SymId noteHead() const;
88 : double headWidth() const;
89 :
90 : // re-implemented virtual functions
91 : void scanElements(std::function<void(EngravingItem*)> func) override;
92 : void setTrack(track_idx_t val) override;
93 :
94 : String accessibleInfo() const override;
95 :
96 : void remove(EngravingItem*) override;
97 :
98 : // properties
99 : PropertyValue getProperty(Pid) const override;
100 : bool setProperty(Pid propertyId, const PropertyValue&) override;
101 : PropertyValue propertyDefault(Pid id) const override;
102 :
103 : EngravingItem* nextSegmentElement() override;
104 : EngravingItem* prevSegmentElement() override;
105 :
106 : static AccidentalType accidentalType(int tpc, Key key);
107 : static int staffLine(int tpc, int pitch, ClefType clf);
108 :
109 : struct LayoutData : public EngravingItem::LayoutData {
110 : PointF topPos; // position of top note symbol
111 : PointF bottomPos; // position of bottom note symbol
112 : LineF line; // the drawn line
113 : };
114 4 : DECLARE_LAYOUTDATA_METHODS(Ambitus)
115 :
116 : private:
117 :
118 : friend class Factory;
119 : Ambitus(DummyParentOr<Segment> parent);
120 : Ambitus(const Ambitus& a);
121 :
122 : void normalize();
123 :
124 : struct Ranges {
125 : int topTpc = Tpc::TPC_INVALID;
126 : int bottomTpc = Tpc::TPC_INVALID;
127 : int topPitch = INVALID_PITCH;
128 : int bottomPitch = MAX_PITCH + 1;
129 : };
130 :
131 : Ranges estimateRanges() const; // scan staff up to next section break and update range pitches
132 :
133 : NoteHeadGroup m_noteHeadGroup = NOTEHEADGROUP_DEFAULT;
134 : NoteHeadType m_noteHeadType = NOTEHEADTYPE_DEFAULT;
135 : DirectionH m_direction = DIRECTION_DEFAULT;
136 : bool m_hasLine = HASLINE_DEFAULT;
137 : Spatium m_lineWidth;
138 : Accidental* m_topAccidental = nullptr;
139 : Accidental* m_bottomAccidental = nullptr;
140 : int m_topPitch = INVALID_PITCH, m_bottomPitch = INVALID_PITCH;
141 : int m_topTpc = Tpc::TPC_INVALID, m_bottomTpc = Tpc::TPC_INVALID;
142 : };
143 : }
|