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 : #ifndef MU_IMPORTEXPORT_IMPORTPTB_H
23 : #define MU_IMPORTEXPORT_IMPORTPTB_H
24 :
25 : #include "io/file.h"
26 :
27 : #include "engraving/types/fraction.h"
28 : #include "engraving/dom/score.h"
29 : #include "engraving/dom/mscore.h"
30 : #include "engraving/dom/fret.h"
31 : #include "engraving/dom/chordrest.h"
32 : #include "engraving/dom/slur.h"
33 : #include "engraving/dom/clef.h"
34 : #include "engraving/dom/keysig.h"
35 : #include "engraving/dom/chordrest.h"
36 : #include "engraving/dom/clef.h"
37 : #include "engraving/dom/keysig.h"
38 : #include "engraving/dom/hairpin.h"
39 : #include "engraving/dom/ottava.h"
40 : #include "engraving/dom/drumset.h"
41 :
42 : #include "engraving/engravingerrors.h"
43 :
44 : namespace mu::engraving {
45 : class PalmMute;
46 : } // namespace mu::engraving
47 :
48 : namespace mu::iex::guitarpro {
49 : class PowerTab
50 : {
51 : muse::io::IODevice* _file = nullptr;
52 : mu::engraving::MasterScore* score = nullptr;
53 :
54 : bool readBoolean();
55 : unsigned char readUInt8();
56 : char readChar();
57 : unsigned short readShort();
58 : int readInt();
59 : void skip(int len = 1);
60 : std::string readString(int length = -1);
61 :
62 : struct ptSongInfo {
63 : int classification{ 0 };
64 : int releaseType{ 0 };
65 : int albumType{ 0 };
66 : int day{ 0 };
67 : int month{ 0 };
68 : int year{ 0 };
69 : int style{ 0 };
70 : int level{ 0 };
71 : bool liverecording{ 0 };
72 : std::string name;
73 : std::string interpret;
74 : std::string album;
75 : std::string author;
76 : std::string lyricist;
77 : std::string arranger;
78 : std::string guitarTranscriber;
79 : std::string bassTranscriber;
80 : std::string lyrics;
81 : std::string guitarInstructions;
82 : std::string bassInstructions;
83 : std::string instructions;
84 : std::string copyright;
85 : };
86 :
87 : struct ptComponent {
88 : enum Type {
89 : Empty,
90 : GuitarIn,
91 : Tempo,
92 : Symbol,
93 : Bar,
94 : Note,
95 : Beat,
96 : TDirection
97 : };
98 0 : virtual Type type()
99 : {
100 0 : return Empty;
101 : }
102 :
103 54 : virtual ~ptComponent() {}
104 : };
105 :
106 : struct stRhytmSlash final : public ptComponent {
107 : int position { 0 };
108 : int duration { 0 };
109 : bool triplet{ false };
110 : bool tripletend{ false };
111 : bool dotted{ false };
112 : bool doubleDotted{ false };
113 : bool is_rest{ false };
114 : };
115 :
116 : struct ptGuitarIn final : public ptComponent {
117 : int rhythmSlash{ true };
118 : int staff{ 0 };
119 : int trackinfo{ 0 };
120 : int section{ 0 };
121 : int position{ 0 };
122 0 : Type type() override
123 : {
124 0 : return GuitarIn;
125 : }
126 : };
127 :
128 : struct ptSymbol final : public ptComponent {
129 : int value{ 0 };
130 0 : ptSymbol(int val)
131 0 : : value(val) {}
132 0 : Type type() override
133 : {
134 0 : return Symbol;
135 : }
136 : };
137 :
138 : struct ptBar final : public ptComponent {
139 : int measureNo{ 0 };
140 : int repeatClose{ 0 };
141 : bool repeatStart{ false };
142 :
143 : int numerator{ 0 };
144 : int denominator{ 0 };
145 0 : Type type() override
146 : {
147 0 : return Bar;
148 : }
149 : };
150 : std::vector<ptBar*> bars;
151 :
152 : struct ptNote final : public ptComponent {
153 : int value{ 0 };
154 : int str{ 0 };
155 : int bend{ 0 };
156 : bool tied{ false };
157 : bool dead{ false };
158 : bool hammer{ false };
159 : int slide{ 0 };
160 0 : Type type() override
161 : {
162 0 : return Note;
163 : }
164 : };
165 :
166 : struct ptChord final : public ptComponent {
167 : int key;
168 : int formula;
169 : int modification;
170 : int extra;
171 : int top_fret;
172 : std::vector<int> frets;
173 : };
174 :
175 : struct ptChordText final : public ptComponent {
176 : int position;
177 : int key;
178 : int formula;
179 : int formula_mod;
180 : int extra;
181 : };
182 :
183 : struct ptBeat final : public ptComponent {
184 : int position{ 0 };
185 : int staff{ 0 };
186 : int voice{ 0 };
187 : int mmrest{ 0 };
188 : bool isRest{ false };
189 : int duration{ 0 };
190 : int enters{ 0 };
191 : int times{ 0 };
192 : bool dotted{ false };
193 : bool tuplet{ false };
194 : bool doubleDotted{ false };
195 : bool vibrato{ false };
196 : bool grace{ false };
197 : bool arpeggioUp{ false };
198 : bool arpeggioDown{ false };
199 : bool palmMute{ false };
200 : bool accent{ false };
201 : bool staccato{ false };
202 : std::vector<ptNote> notes;
203 :
204 6 : ptBeat(int _staff, int _voice)
205 6 : : staff(_staff), voice(_voice) {}
206 : ptBeat() = default;
207 0 : Type type() override
208 : {
209 0 : return Beat;
210 : }
211 : };
212 :
213 : struct ptDirection final : public ptComponent {
214 : enum Direction {
215 : DIRECTION_CODA = 0,
216 : DIRECTION_DOUBLE_CODA = 1,
217 : DIRECTION_SEGNO = 2,
218 : DIRECTION_SEGNO_SEGNO = 3,
219 : DIRECTION_FINE = 4,
220 : DIRECTION_DA_CAPO = 5,
221 : DIRECTION_DAL_SEGNO = 6,
222 : DIRECTION_DAL_SEGNO_SEGNO = 7,
223 : DIRECTION_TO_CODA = 8,
224 : DIRECTION_TO_DOUBLE_CODA = 9,
225 : DIRECTION_DA_CAPO_AL_CODA = 10,
226 : DIRECTION_DA_CAPO_AL_DOUBLE_CODA = 11,
227 : DIRECTION_DAL_SEGNO_AL_CODA = 12,
228 : DIRECTION_DAL_SEGNO_AL_DOUBLE_CODA = 13,
229 : DIRECTION_DAL_SEGNO_SEGNO_AL_CODA = 14,
230 : DIRECTION_DAL_SEGNO_SEGNO_AL_DOUBLE_CODA = 15,
231 : DIRECTION_DA_CAPO_AL_FINE = 16,
232 : DIRECTION_DAL_SEGNO_AL_FINE = 17,
233 : DIRECTION_DAL_SEGNO_SEGNO_AL_FINE = 18
234 : };
235 :
236 : enum ActiveSym {
237 : ACTIVE_SYMBOL_NONE = 0,
238 : ACTIVE_SYMBOL_DC = 1,
239 : ACTIVE_SYMBOL_DS = 2,
240 : ACTIVE_SYMBOL_DSS = 3
241 : };
242 :
243 : Direction direction{ DIRECTION_CODA };
244 : ActiveSym activeSymbol{ ACTIVE_SYMBOL_NONE };
245 : int repeat{ 0 };
246 :
247 0 : ptDirection(int dir, int sym, int rep)
248 0 : : direction((Direction)dir),
249 0 : activeSymbol((ActiveSym)sym), repeat(rep) {}
250 0 : Type type() override
251 : {
252 0 : return TDirection;
253 : }
254 : };
255 :
256 : struct ptPosition {
257 : int position{ 0 };
258 : std::vector<std::shared_ptr<ptComponent> > components;
259 : void addComponent(ptComponent* c);
260 : };
261 :
262 : struct TrackInfo {
263 : int number{ 0 };
264 : std::string name;
265 : int instrument{ 0 };
266 : int volume{ 0 };
267 : int balance{ 0 };
268 : int reverb{ 0 };
269 : int chorus{ 0 };
270 : int tremolo{ 0 };
271 : int phaser{ 0 };
272 : int capo{ 0 };
273 : std::string tuningName;
274 : int offset{ 0 };
275 : std::vector<int> strings;
276 : int notes_count{ 0 };
277 : };
278 :
279 : typedef std::list<ptBeat> tBeatList;
280 :
281 : struct ptTrack;
282 : struct ptSection {
283 : int number { 0 };
284 : int staves { 0 };
285 : std::string partName;
286 : char partMarker { 0 };
287 :
288 : std::vector<ptPosition> positions;
289 :
290 : std::vector<int> staffMap;
291 :
292 : int tempo { 0 };
293 :
294 : std::list<stRhytmSlash> rhythm;
295 :
296 : std::map<int, ptChordText> chordTextMap;
297 : std::vector<tBeatList> beats;
298 : std::list<std::shared_ptr<ptBar> > bars;
299 : bool readed { false };
300 :
301 : void copyTracks(ptTrack*);
302 :
303 : ptSection(int num);
304 : ptPosition& getPosition(int pos);
305 : int getNextPositionNumber();
306 : };
307 :
308 : struct chordData {
309 : int a[3];
310 : bool operator >(const chordData& other) const
311 : {
312 : if (a[0] == other.a[0]) {
313 : if (a[1] == other.a[1]) {
314 : return a[2] > other.a[2];
315 : }
316 : return a[1] > other.a[1];
317 : }
318 : return a[0] > other.a[0];
319 : }
320 :
321 0 : bool operator <(const chordData& other) const
322 : {
323 0 : if (a[0] == other.a[0]) {
324 0 : if (a[1] == other.a[1]) {
325 0 : return a[2] < other.a[2];
326 : }
327 0 : return a[1] < other.a[1];
328 : }
329 0 : return a[0] < other.a[0];
330 : }
331 :
332 : bool operator ==(const chordData& other) const
333 : {
334 : return memcmp(a, other.a, 3 * sizeof(int)) == 0;
335 : }
336 : };
337 :
338 : struct ptTrack {
339 : std::vector<TrackInfo> infos;
340 : std::vector<ptSection> sections;
341 : ptSection& getSection(int ind);
342 : std::map < chordData, ptChord > diagramMap;
343 :
344 : std::list<ptGuitarIn> guitar_ins;
345 : };
346 :
347 : struct ptSong {
348 : ptSongInfo info;
349 : ptTrack track1;
350 : ptTrack track2;
351 : };
352 :
353 : void readSongInfo(ptSongInfo& info);
354 : void readDataInstruments(ptTrack& info);
355 : void readTrackInfo(ptTrack& info);
356 : void readGuitarIn(ptTrack& info);
357 : void readTempoMarker(ptTrack& info);
358 : void readSectionSymbol(ptTrack& info);
359 : void readSection(ptSection& sec);
360 : void readBarLine(ptSection& sec);
361 : void readDirection(ptSection& sec);
362 : void readTimeSignature(ptBar* bar);
363 : void readStaff(int staff, ptSection& sec);
364 : void readPosition(int staff, int voice, ptSection& sec);
365 : void readNote(ptBeat* beat);
366 : void readRehearsalSign(ptSection& sec);
367 : void readChordText(ptSection& sec);
368 : void readChord(ptTrack& si);
369 : void readRhytmSlash(ptSection& sec);
370 :
371 : void readFloatingText();
372 : void readFontSettings();
373 : void readDynamic();
374 : void readKeySignature();
375 :
376 : bool readVersion();
377 : int readHeaderItems();
378 :
379 : std::vector<int> lastStaffMap;
380 : std::vector<int> getStaffMap(ptSection& sec);
381 : int repeatCount{ 0 };
382 : void addToScore(ptSection& sec);
383 :
384 : mu::engraving::Measure* createMeasure(ptBar* bar, const mu::engraving::Fraction& tick);
385 : void fillMeasure(tBeatList& elist, mu::engraving::Measure* measure, int staff, std::vector<mu::engraving::Note*>&);
386 :
387 : int staves{ 0 };
388 :
389 : ptTrack* curTrack;
390 : int staffInc{ 0 };
391 : char lastPart{ 0 };
392 :
393 : ptSection* cur_section;
394 :
395 : std::vector<mu::engraving::PalmMute*> _palmMutes;
396 : void addPalmMute(mu::engraving::Chord*);
397 :
398 : public:
399 3 : PowerTab(muse::io::IODevice* f, mu::engraving::MasterScore* s)
400 3 : : _file(f), score(s) {}
401 : mu::engraving::Err read();
402 : };
403 : } // namespace mu::iex::guitarpro
404 :
405 : #endif // MU_IMPORTEXPORT_IMPORTPTB_H
|