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) 2022 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 : #pragma once
24 :
25 : #include "textbase.h"
26 :
27 : using namespace mu;
28 :
29 : namespace mu::engraving {
30 : enum class PedalPosition : unsigned char {
31 : FLAT,
32 : NATURAL,
33 : SHARP,
34 :
35 : UNSET // Only used in setDiagramText to represent the beginning of a score
36 : };
37 :
38 : // Use for indexes of _pedalState
39 : enum HarpStringType : unsigned char {
40 : D, C, B, E, F, G, A
41 : };
42 :
43 : // Number of strings per octave on a harp
44 : static constexpr int HARP_STRING_NO = 7;
45 :
46 : class HarpPedalDiagram final : public TextBase
47 : {
48 36 : OBJECT_ALLOCATOR(engraving, HarpPedalDiagram)
49 1625 : DECLARE_CLASSOF(ElementType::HARP_DIAGRAM)
50 :
51 : public:
52 : HarpPedalDiagram(DummyParentOr<Segment> parent);
53 : HarpPedalDiagram(const HarpPedalDiagram& h);
54 :
55 0 : HarpPedalDiagram* clone() const override { return new HarpPedalDiagram(*this); }
56 0 : bool isEditable() const override { return false; }
57 :
58 85 : Segment* segment() const { return (Segment*)ownershipParent(); }
59 : Measure* measure() const { return (Measure*)ownershipParent()->ownershipParent(); }
60 :
61 : PropertyValue getProperty(Pid propertyId) const override;
62 : bool setProperty(Pid propertyId, const PropertyValue& v) override;
63 : PropertyValue propertyDefault(Pid id) const override;
64 :
65 : String accessibleInfo() const override;
66 : String screenReaderInfo() const override;
67 :
68 : void setIsDiagram(bool diagram);
69 596 : bool isDiagram() const { return m_isDiagram; }
70 :
71 250 : std::array<PedalPosition, HARP_STRING_NO> getPedalState() const { return m_pedalState; }
72 : void setPedalState(std::array<PedalPosition, HARP_STRING_NO> state);
73 :
74 : void setPedal(HarpStringType harpString, PedalPosition pedal);
75 :
76 : void setPlayableTpcs();
77 :
78 : String createDiagramText();
79 : void updateDiagramText();
80 :
81 : void undoChangePedalState(std::array<PedalPosition, HARP_STRING_NO> _pedalState);
82 :
83 : bool isTpcPlayable(int tpc);
84 2 : const std::set<int>& playableTpcs() const { return m_playableTpcs; }
85 :
86 32 : bool positionRelativeToNoteheadRest() const override { return true; }
87 :
88 : private:
89 :
90 : std::array<PedalPosition, HARP_STRING_NO> m_pedalState;
91 :
92 : std::set<int> m_playableTpcs;
93 :
94 : bool m_isDiagram = true;
95 : };
96 : }
|