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_APIV1_PART_H
24 : #define MU_ENGRAVING_APIV1_PART_H
25 :
26 : #include <QQmlListProperty>
27 :
28 : #include "engraving/dom/part.h"
29 :
30 : // api
31 : #include "scoreelement.h"
32 :
33 : namespace mu::engraving::apiv1 {
34 : class EngravingItem;
35 : class Fraction;
36 : class Instrument;
37 : class Part;
38 : class Staff;
39 :
40 : //---------------------------------------------------------
41 : // InstrumentListProperty
42 : /// \cond PLUGIN_API \private \endcond
43 : //---------------------------------------------------------
44 :
45 : class InstrumentListProperty : public QQmlListProperty<Instrument>
46 : {
47 : public:
48 : InstrumentListProperty(Part* p);
49 :
50 : static qsizetype count(QQmlListProperty<Instrument>* l);
51 : static Instrument* at(QQmlListProperty<Instrument>* l, qsizetype i);
52 : };
53 :
54 : //---------------------------------------------------------
55 : // Part
56 : //---------------------------------------------------------
57 :
58 : class Part : public ScoreElement
59 : {
60 : Q_OBJECT
61 : /// The first track in this part.
62 : Q_PROPERTY(int startTrack READ startTrack)
63 : /// The last track of the next part + 1.
64 : Q_PROPERTY(int endTrack READ endTrack)
65 : /// The MuseScore string identifier
66 : /// for the first instrument in this part.
67 : /// \see \ref mu::plugins::api::Instrument::instrumentId "Instrument.instrumentId"
68 : /// \since MuseScore 4.6
69 : Q_PROPERTY(QString instrumentId READ instrumentId)
70 : /// The string identifier
71 : /// ([MusicXML Sound ID](https://www.musicxml.com/for-developers/standard-sounds/))
72 : /// for the first instrument in this part.
73 : /// Was called using \ref instrumentId prior to 4.6
74 : /// \see \ref mu::plugins::api::Instrument::musicXmlId "Instrument.musicXmlId"
75 : /// \since MuseScore 3.2
76 : Q_PROPERTY(QString musicXmlId READ musicXmlId)
77 : /// The number of Chord Symbols. \since MuseScore 3.2.1
78 : Q_PROPERTY(int harmonyCount READ harmonyCount)
79 : /// Whether this part has chord symbols.
80 : /// \since MuseScore 4.6
81 : Q_PROPERTY(bool hasChordSymbol READ hasChordSymbol)
82 : /// Whether it is a percussion staff. \since MuseScore 3.2.1
83 : Q_PROPERTY(bool hasDrumStaff READ hasDrumStaff)
84 : /// Whether it is a 'normal' staff with notes. \since MuseScore 3.2.1
85 : Q_PROPERTY(bool hasPitchedStaff READ hasPitchedStaff)
86 : /// Whether it is a tablature staff. \since MuseScore 3.2.1
87 : Q_PROPERTY(bool hasTabStaff READ hasTabStaff)
88 : /// The number of lyrics syllables. \since MuseScore 3.2.1
89 : Q_PROPERTY(int lyricCount READ lyricCount)
90 : /// One of 16 music channels that can be assigned an instrument. \since MuseScore 3.2.1
91 : Q_PROPERTY(int midiChannel READ midiChannel)
92 : /// One of the 128 different instruments in General MIDI. \since MuseScore 3.2.1
93 : Q_PROPERTY(int midiProgram READ midiProgram)
94 : /// The long name for the current instrument.
95 : /// Note that this property was writeable in MuseScore v2.x
96 : /// \since MuseScore 3.2.1
97 : Q_PROPERTY(QString longName READ longName)
98 : /// The short name for the current instrument.
99 : /// Note that this property was writeable in MuseScore v2.x
100 : /// \since MuseScore 3.2.1
101 : Q_PROPERTY(QString shortName READ shortName)
102 : /// The name of the current part of music.
103 : /// It is shown in Mixer.
104 : ///
105 : /// Note that this property was writeable in MuseScore v2.x
106 : /// \since MuseScore 3.2.1
107 : Q_PROPERTY(QString partName READ partName)
108 : /// Whether part is shown or hidden.
109 : /// This property is writeable since MuseScore 3.6 (and was writable in MuseScore 2.x)
110 : /// \since MuseScore 3.2.1
111 : Q_PROPERTY(bool show READ show WRITE setShow)
112 :
113 : /// List of instruments in this part.
114 : /// \since MuseScore 3.5
115 : Q_PROPERTY(QQmlListProperty<apiv1::Instrument> instruments READ instruments);
116 :
117 : /// List of staves belonging to this part.
118 : /// \since MuseScore 4.6
119 : Q_PROPERTY(QQmlListProperty<apiv1::Staff> staves READ staves);
120 : /// The part object of this part in the main score.
121 : /// \since MuseScore 4.6
122 : Q_PROPERTY(apiv1::Part * masterPart READ masterPart);
123 :
124 : public:
125 : /// \cond MS_INTERNAL
126 11 : Part(mu::engraving::Part* p = nullptr, Ownership o = Ownership::SCORE)
127 11 : : ScoreElement(p, o) {}
128 :
129 10 : mu::engraving::Part* part() { return toPart(e); }
130 0 : const mu::engraving::Part* part() const { return toPart(e); }
131 :
132 0 : int startTrack() const { return static_cast<int>(part()->trackRange().startTrack); }
133 0 : int endTrack() const { return static_cast<int>(part()->trackRange().endTrack); }
134 0 : QString instrumentId() const { return part()->instrument()->id(); }
135 0 : QString musicXmlId() const { return part()->instrument()->musicXmlId(); }
136 0 : int harmonyCount() const { return part()->harmonyCount(); }
137 0 : bool hasChordSymbol() { return part()->hasChordSymbol(); }
138 0 : bool hasPitchedStaff() const { return part()->hasPitchedStaff(); }
139 0 : bool hasTabStaff() const { return part()->hasTabStaff(); }
140 0 : bool hasDrumStaff() const { return part()->hasDrumStaff(); }
141 0 : int lyricCount() const { return part()->lyricCount(); }
142 0 : int midiChannel() const { return part()->midiChannel(); }
143 0 : int midiProgram() const { return part()->midiProgram(); }
144 0 : QString longName() const { return part()->longName(); }
145 0 : QString shortName() const { return part()->shortName(); }
146 0 : QString partName() const { return part()->partName(); }
147 0 : bool show() const { return part()->show(); }
148 0 : void setShow(bool val) { set(engraving::Pid::VISIBLE, val); }
149 0 : apiv1::Part* masterPart() { return wrap<apiv1::Part>(part()->masterPart()); }
150 :
151 : InstrumentListProperty instruments();
152 : QQmlListProperty<apiv1::Staff> staves();
153 : /// \endcond
154 :
155 : /// The instrument of the part at the given tick in the score.
156 : /// \param tick Tick location in the score, as an integer.
157 : /// \since MuseScore 3.5
158 : Q_INVOKABLE apiv1::Instrument* instrumentAtTick(int tick);
159 :
160 : /// The instrument of the part at the given tick in the score.
161 : /// \param tick Tick location in the score, as a fraction.
162 : /// \since MuseScore 4.6
163 : Q_INVOKABLE apiv1::Instrument* instrumentAtTick(apiv1::Fraction* tick);
164 :
165 : /// The long name of the part at a given tick in the score.
166 : /// \param tick Tick location in the score, as a fraction.
167 : /// \since MuseScore 4.6
168 : Q_INVOKABLE QString longNameAtTick(apiv1::Fraction* tick);
169 : /// The short name of the part at a given tick in the score.
170 : /// \param tick Tick location in the score, as a fraction.
171 : /// \since MuseScore 4.6
172 : Q_INVOKABLE QString shortNameAtTick(apiv1::Fraction* tick);
173 : /// The name of the part's instrument at a given tick in the score.
174 : /// \param tick Tick location in the score, as a fraction.
175 : /// \since MuseScore 4.6
176 : Q_INVOKABLE QString instrumentNameAtTick(apiv1::Fraction* tick);
177 : /// The ID of the part's instrument at a given tick in the score.
178 : /// \param tick Tick location in the score, as a fraction.
179 : /// \since MuseScore 4.6
180 : Q_INVOKABLE QString instrumentIdAtTick(apiv1::Fraction* tick);
181 : /// The currently active harp pedal diagram at a given tick in the score.
182 : /// \param tick Tick location in the score, as a fraction.
183 : /// \since MuseScore 4.6
184 : Q_INVOKABLE apiv1::EngravingItem* currentHarpDiagramAtTick(apiv1::Fraction* tick);
185 : /// The next active harp pedal diagram at a given tick in the score.
186 : /// \param tick Tick location in the score, as a fraction.
187 : /// \since MuseScore 4.6
188 : Q_INVOKABLE apiv1::EngravingItem* nextHarpDiagramFromTick(apiv1::Fraction* tick);
189 : /// The previous active harp pedal diagram at a given tick in the score.
190 : /// \param tick Tick location in the score, as a fraction.
191 : /// \since MuseScore 4.6
192 : Q_INVOKABLE apiv1::EngravingItem* prevHarpDiagramFromTick(apiv1::Fraction* tick);
193 : /// The tick of the currently active harp pedal diagram at a given tick in the score.
194 : /// \param tick Tick location in the score, as a fraction.
195 : /// \since MuseScore 4.6
196 : Q_INVOKABLE apiv1::Fraction* tickOfCurrentHarpDiagram(apiv1::Fraction* tick);
197 : };
198 : }
199 :
200 : #endif
|