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 <array>
25 : #include <vector>
26 :
27 : #include "io/path.h"
28 :
29 : #include "clef.h"
30 : #include "instrument.h"
31 : #include "mscore.h"
32 : #include "stringdata.h"
33 :
34 : namespace mu::engraving {
35 : class XmlWriter;
36 : class XmlReader;
37 : class Part;
38 : class Staff;
39 : class StaffType;
40 : struct ScoreOrder;
41 :
42 : //---------------------------------------------------------
43 : // InstrumentGenre
44 : //---------------------------------------------------------
45 :
46 : class InstrumentGenre
47 : {
48 : public:
49 : String id;
50 : String name;
51 :
52 176 : InstrumentGenre() {}
53 : void write(XmlWriter& xml) const;
54 : void read(XmlReader&);
55 : };
56 :
57 : //---------------------------------------------------------
58 : // InstrumentFamily
59 : //---------------------------------------------------------
60 :
61 : class InstrumentFamily
62 : {
63 : public:
64 : String id;
65 : String name;
66 :
67 1920 : InstrumentFamily() {}
68 : void write(XmlWriter& xml) const;
69 : void read(XmlReader&);
70 : };
71 :
72 : //---------------------------------------------------------
73 : // InstrumentTemplate
74 : //---------------------------------------------------------
75 :
76 : class InstrumentTemplate
77 : {
78 : public:
79 : InstrumentTemplate();
80 : InstrumentTemplate(const InstrumentTemplate&);
81 : ~InstrumentTemplate();
82 : InstrumentTemplate& operator=(const InstrumentTemplate&);
83 :
84 : String id;
85 : String soundId;
86 : String trackName;
87 : InstrumentLabel instrumentName;
88 : String musicXmlId; ///< used in MusicXML 3.0
89 : String description; ///< a longer description of the instrument
90 :
91 : size_t staffCount = 0;
92 : int sequenceOrder = 0;
93 :
94 : Trait trait;
95 :
96 : int minPitchA = 0; // pitch range playable by an amateur
97 : int maxPitchA = 0;
98 : int minPitchP = 0; // pitch range playable by professional
99 : int maxPitchP = 0;
100 :
101 : Interval transpose; // for transposing instruments
102 :
103 : StaffGroup staffGroup;
104 : const StaffType* staffTypePreset = nullptr;
105 : bool useDrumset = false;
106 : Drumset* drumset = nullptr;
107 :
108 : StringData stringData;
109 :
110 : std::vector<NamedEventList> midiActions;
111 : std::vector<MidiArticulation> midiArticulations;
112 : std::vector<InstrChannel> channel;
113 : std::vector<const InstrumentGenre*> genres; //; list of genres this instrument belongs to
114 : const InstrumentFamily* family = nullptr; //; family the instrument belongs to
115 :
116 : ClefTypeList clefTypes[MAX_STAVES];
117 : int staffLines[MAX_STAVES];
118 : BracketType bracket[MAX_STAVES]; // bracket type (NO_BRACKET)
119 : int bracketSpan[MAX_STAVES];
120 : std::array<bool, MAX_STAVES> barlineSpan{};
121 : bool smallStaff[MAX_STAVES];
122 :
123 : bool extended = false; // belongs to extended instrument set if true
124 : bool singleNoteDynamics = false;
125 :
126 : String groupId;
127 :
128 : GlissandoStyle glissandoStyle = GlissandoStyle::CHROMATIC;
129 :
130 : bool isValid() const;
131 :
132 : void write(XmlWriter& xml) const;
133 : void read(XmlReader&);
134 : ClefTypeList clefType(staff_idx_t staffIdx) const;
135 : String familyId() const;
136 : bool containsGenre(const String& genreId) const;
137 :
138 : private:
139 : void init(const InstrumentTemplate&);
140 : void setPitchRange(const String& s, int& a, int& b) const;
141 : void linkGenre(const String&);
142 : };
143 :
144 : //---------------------------------------------------------
145 : // InstrumentGroup
146 : //---------------------------------------------------------
147 :
148 : struct InstrumentGroup {
149 : String id;
150 : String name;
151 : bool extended; // belongs to extended instruments set if true
152 : std::vector<const InstrumentTemplate*> instrumentTemplates;
153 : void read(XmlReader&);
154 : void clear();
155 :
156 192 : InstrumentGroup() { extended = false; }
157 : };
158 :
159 : //---------------------------------------------------------
160 : // InstrumentIndex
161 : //---------------------------------------------------------
162 :
163 : struct InstrumentIndex {
164 : int groupIndex = 0;
165 : int instrIndex = 0;
166 : size_t templateCount = 0;
167 : const InstrumentTemplate* instrTemplate = nullptr;
168 :
169 : InstrumentIndex(int g, int i, const InstrumentTemplate* it);
170 : };
171 :
172 : extern std::vector<const InstrumentGenre*> instrumentGenres;
173 : extern std::vector<const InstrumentFamily*> instrumentFamilies;
174 : extern std::vector<const InstrumentGroup*> instrumentGroups;
175 : extern std::vector<MidiArticulation> midiArticulations;
176 : extern std::vector<ScoreOrder> instrumentOrders;
177 : extern void clearInstrumentTemplates();
178 : extern bool loadInstrumentTemplates(const muse::io::path_t& instrTemplatesPath);
179 : extern const InstrumentTemplate* combinedTemplateSearch(const Instrument& instrument);
180 : extern InstrumentIndex searchTemplateIndexForTrackName(const String& trackName);
181 : extern InstrumentIndex searchTemplateIndexForId(const String& id);
182 : extern const InstrumentTemplate* searchTemplate(const String& name);
183 : extern const InstrumentTemplate* searchTemplateForMusicXmlId(const String& mxmlId);
184 : extern const InstrumentTemplate* searchTemplateForInstrNameList(const std::vector<String>& nameList, bool useDrumset = false,
185 : bool caseSensitive = true);
186 : extern const InstrumentTemplate* searchTemplateForMidiProgram(int bank, int program, bool useDrumset = false);
187 : extern const InstrumentGenre* searchInstrumentGenre(const String& id);
188 :
189 : extern void addTemplateToGroup(const InstrumentTemplate* templ, const String& groupId);
190 :
191 : extern ClefType defaultClef(int patch);
192 : } // namespace mu::engraving
|