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 "part.h"
24 :
25 : #include "engraving/dom/harppedaldiagram.h"
26 :
27 : // api
28 : #include "apistructs.h"
29 : #include "elements.h"
30 : #include "instrument.h"
31 :
32 : using namespace mu::engraving::apiv1;
33 :
34 0 : InstrumentListProperty::InstrumentListProperty(Part* p)
35 0 : : QQmlListProperty<Instrument>(p, p, &count, &at) {}
36 :
37 : //---------------------------------------------------------
38 : // InstrumentListProperty::count
39 : //---------------------------------------------------------
40 :
41 0 : qsizetype InstrumentListProperty::count(QQmlListProperty<Instrument>* l)
42 : {
43 0 : return static_cast<qsizetype>(static_cast<Part*>(l->data)->part()->instruments().size());
44 : }
45 :
46 : //---------------------------------------------------------
47 : // InstrumentListProperty::at
48 : //---------------------------------------------------------
49 :
50 0 : Instrument* InstrumentListProperty::at(QQmlListProperty<Instrument>* l, qsizetype i)
51 : {
52 0 : Part* part = static_cast<Part*>(l->data);
53 0 : const mu::engraving::InstrumentList& il = part->part()->instruments();
54 :
55 0 : if (i < 0 || i >= int(il.size())) {
56 0 : return nullptr;
57 : }
58 :
59 0 : mu::engraving::Instrument* instr = std::next(il.begin(), i)->second;
60 :
61 0 : return customWrap<Instrument>(instr, part->part());
62 : }
63 :
64 : //---------------------------------------------------------
65 : // Part::instruments
66 : //---------------------------------------------------------
67 :
68 0 : InstrumentListProperty Part::instruments()
69 : {
70 0 : return InstrumentListProperty(this);
71 : }
72 :
73 : //---------------------------------------------------------
74 : // Part::instrumentAtTick
75 : //---------------------------------------------------------
76 :
77 0 : Instrument* Part::instrumentAtTick(int tick)
78 : {
79 0 : return customWrap<Instrument>(part()->instrument(mu::engraving::Fraction::fromTicks(tick)), part());
80 : }
81 :
82 0 : Instrument* Part::instrumentAtTick(Fraction* tick)
83 : {
84 0 : return customWrap<Instrument>(part()->instrument(tick->fraction()), part());
85 : }
86 :
87 0 : QQmlListProperty<Staff> Part::staves()
88 : {
89 0 : return wrapContainerProperty<Staff>(this, part()->staves());
90 : }
91 :
92 0 : QString Part::longNameAtTick(Fraction* tick)
93 : {
94 0 : return part()->longName(tick->fraction());
95 : }
96 :
97 0 : QString Part::shortNameAtTick(Fraction* tick)
98 : {
99 0 : return part()->shortName(tick->fraction());
100 : }
101 :
102 0 : QString Part::instrumentNameAtTick(Fraction* tick)
103 : {
104 0 : return part()->instrumentName(tick->fraction());
105 : }
106 :
107 0 : QString Part::instrumentIdAtTick(Fraction* tick)
108 : {
109 0 : return part()->instrumentId(tick->fraction());
110 : }
111 :
112 0 : EngravingItem* Part::currentHarpDiagramAtTick(Fraction* tick)
113 : {
114 0 : return wrap(part()->currentHarpDiagram(tick->fraction()));
115 : }
116 :
117 0 : EngravingItem* Part::nextHarpDiagramFromTick(Fraction* tick)
118 : {
119 0 : return wrap(part()->nextHarpDiagram(tick->fraction()));
120 : }
121 :
122 0 : EngravingItem* Part::prevHarpDiagramFromTick(Fraction* tick)
123 : {
124 0 : return wrap(part()->prevHarpDiagram(tick->fraction()));
125 : }
126 :
127 0 : Fraction* Part::tickOfCurrentHarpDiagram(Fraction* tick)
128 : {
129 0 : return wrap(part()->currentHarpDiagramTick(tick->fraction()));
130 : }
|