MuseScore  3.4
Music composition and notation
importgtp.h
Go to the documentation of this file.
1 //=============================================================================
2 // MusE Score
3 // Linux Music Score Editor
4 //
5 // Copyright (C) 2010 Werner Schweer and others
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19 
20 #ifndef __IMPORTGTP_H__
21 #define __IMPORTGTP_H__
22 
23 #include <libmscore/score.h>
24 #include <libmscore/mscore.h>
25 #include <libmscore/fraction.h>
26 #include <libmscore/fret.h>
27 #include <libmscore/chordrest.h>
28 #include <libmscore/slur.h>
29 #include <libmscore/clef.h>
30 #include <libmscore/keysig.h>
31 #include <libmscore/chordrest.h>
32 #include <libmscore/clef.h>
33 #include <libmscore/keysig.h>
34 #include <libmscore/hairpin.h>
35 #include <libmscore/ottava.h>
36 #include <libmscore/vibrato.h>
37 #include <libmscore/drumset.h>
38 
39 namespace Ms {
40 
41 class Score;
42 class Chord;
43 class Note;
44 class Segment;
45 class Measure;
46 class Tuplet;
47 class Volta;
48 class LetRing;
49 class PalmMute;
50 class Vibrato;
51 
52 static const int GP_MAX_LYRIC_LINES = 5;
53 static const int GP_MAX_TRACK_NUMBER = 32;
54 static const int GP_MAX_STRING_NUMBER = 7;
55 static const int GP_DEFAULT_PERCUSSION_CHANNEL = 9;
56 static const int GP_INVALID_KEYSIG = 127;
57 static const int GP_VOLTA_BINARY = 1;
58 static const int GP_VOLTA_FLAGS = 2;
59 
60 Score::FileError importGTP(Score* score, const QString& filename, const char* data, unsigned int data_len);
61 
62 enum class Repeat : char;
63 
64 struct GpTrack {
65  int patch;
66  uchar volume, pan, chorus, reverb, phase, tremolo;
67  };
68 
69 struct GPVolta {
70  int voltaType;
71  QList<int> voltaInfo;
72 };
73 
74 /* How the fermatas are represented in Guitar Pro is two integers, the
75  * first is an index value and the second is the time division that
76  * index value refers to, and they are givin with respect to a
77  * measure. Time division 0 means a minim, 1 is a crotchet, 2 is a
78  * quaver and so on, with the index (counting from 0) referring to how
79  * many time divisions occur before the fermata. These numbers are
80  * separated in GP6 with a '/' character. For example, a note
81  * occurring on the third beat of a measure in a 4/4 bar would be
82  * represented as 2/1.
83  */
84 
85 struct GPFermata {
86  int index;
88  QString type;
89  };
90 
91 struct GPLyrics {
92  QStringList lyrics;
93  std::vector<Segment*> segments;
94  int fromBeat;
97  };
98 
99 struct GpBar {
101  bool freeTime;
102  int keysig;
103  QString marker;
106  int repeats;
108  QString direction;
109  QString directionStyle;
110 
111  QString section[2];
112 
113  std::vector<QString> directions;
114 
115  GpBar();
116  };
117 
118 //---------------------------------------------------------
119 // GuitarPro
120 //---------------------------------------------------------
121 
122 class GuitarPro {
123  protected:
124  std::list<Note*> slideList; //list of start slide notes
125 
126  // note effect bit masks
127  static const uchar EFFECT_BEND = 0x1;
128  static const uchar EFFECT_STACATTO = 0x1;
129  static const uchar EFFECT_HAMMER = 0x2;
130  static const uchar EFFECT_PALM_MUTE = 0x2;
131  static const uchar EFFECT_TREMOLO = 0x4;
132  static const uchar EFFECT_LET_RING = 0x8;
133  static const uchar EFFECT_SLIDE_OLD = 0x4;
134  static const uchar EFFECT_SLIDE = 0x8;
135  static const uchar EFFECT_GRACE = 0x10;
136  static const uchar EFFECT_ARTIFICIAL_HARMONIC = 0x10;
137  static const uchar EFFECT_TRILL = 0x20;
138  static const uchar EFFECT_GHOST = 0x01;
139 
140  // arpeggio direction masks
141  static const uchar ARPEGGIO_UP = 0xa;
142  static const uchar ARPEGGIO_DOWN = 0x2;
143 
144  // note bit masks
145  static const uchar NOTE_GHOST = 0x04; // 2
146  static const uchar NOTE_DEAD = 0x20; //5
147  static const uchar NOTE_DYNAMIC = 0x10; // 4
148  static const uchar NOTE_FRET = 0x20; //5
149  static const uchar NOTE_FINGERING = 0x80; //7
150  static const uchar NOTE_MARCATO = 0x02; //1
151  static const uchar NOTE_SFORZATO = 0x40; //6
152  static const uchar NOTE_SLUR = 0x8;//3
153  static const uchar NOTE_APPOGIATURA = 0x02;//1
154 
155  // beat bit masks
156  static const uchar BEAT_VIBRATO_TREMOLO = 0x02;
157  static const uchar BEAT_FADE = 0x10;
158  static const uchar BEAT_EFFECT = 0x20;
159  static const uchar BEAT_TREMOLO = 0x04;
160  static const uchar BEAT_ARPEGGIO = 0x40;
161  static const uchar BEAT_STROKE_DIR = 0x02;
162  static const uchar BEAT_DOTTED = 0x01;
163  static const uchar BEAT_PAUSE = 0x40;
164  static const uchar BEAT_TUPLET = 0x20;
165  static const uchar BEAT_LYRICS = 0x4;
166  static const uchar BEAT_EFFECTS = 0x8;
167  static const uchar BEAT_MIX_CHANGE = 0x10;
168  static const uchar BEAT_CHORD = 0x2;
169 
170  // score bit masks
171  static const uchar SCORE_TIMESIG_NUMERATOR = 0x1;
172  static const uchar SCORE_TIMESIG_DENOMINATOR = 0x2;
173  static const uchar SCORE_REPEAT_START = 0x4;
174  static const uchar SCORE_REPEAT_END = 0x8;
175  static const uchar SCORE_MARKER = 0x20;
176  static const uchar SCORE_VOLTA = 0x10;
177  static const uchar SCORE_KEYSIG = 0x40;
178  static const uchar SCORE_DOUBLE_BAR = 0x80;
179 
180  // slide kinds
181  static const int SHIFT_SLIDE = 1;
182  static const int LEGATO_SLIDE = 2;
183  static const int SLIDE_OUT_DOWN = 4;
184  static const int SLIDE_OUT_UP = 8;
185  static const int SLIDE_IN_ABOVE = 16;
186  static const int SLIDE_IN_BELOW = 32;
187 
188  static const int MAX_PITCH = 127;
189  static const char* const errmsg[];
190  int version;
191  int key { 0 };
192 
193  Segment* last_segment { nullptr };
194  Measure* last_measure { nullptr };
195  int last_tempo { -1 };
196 
197  QMap<int, QList<GPFermata>*> fermatas;
198  std::vector<Ottava*> ottava;
201  QFile* f;
202  int curPos;
205  std::vector<int> ottavaFound;
206  std::vector<QString> ottavaValue;
207  std::map<int, std::pair<int, bool>> tempoMap;
208  int tempo;
209  QMap<int,int> slides;
210 
212  int slide;
214  QTextCodec* _codec { 0 };
215  Slur** slurs { nullptr };
216 
217  void skip(qint64 len);
218  void read(void* p, qint64 len);
219  int readUChar();
220  int readChar();
221  QString readPascalString(int);
222  QString readWordPascalString();
223  QString readBytePascalString();
224  int readInt();
225  QString readDelphiString();
226  void readVolta(GPVolta*, Measure*);
227  virtual void readBend(Note*);
228  virtual bool readMixChange(Measure* measure);
229  virtual int readBeatEffects(int track, Segment*) = 0;
230  void readLyrics();
231  void readChannels();
232  void setTuplet(Tuplet* tuplet, int tuple);
233  void setupTupletStyle(Tuplet* tuplet);
234  Fraction len2fraction(int len);
235  void addDynamic(Note*, int d);
236  void createMeasures();
237  void applyBeatEffects(Chord*, int beatEffects);
238  void readTremoloBar(int track, Segment*);
239  void readChord(Segment* seg, int track, int numStrings, QString name, bool gpHeader);
240  void restsForEmptyBeats(Segment* seg, Measure* measure, ChordRest* cr, Fraction& l, int track, const Fraction& tick);
241  void createSlur(bool hasSlur, int staffIdx, ChordRest* cr);
242  void createOttava(bool hasOttava, int track, ChordRest* cr, QString value);
243  void createSlide(int slide, ChordRest* cr, int staffIdx, Note* note = nullptr);
244  void createCrecDim(int staffIdx, int track, const Fraction& tick, bool crec);
245  Text* addTextToNote(QString, Align, Note*);
246  void addPalmMute(Note*);
247  void addLetRing(Note*);
248  void addVibrato(Note*, Vibrato::Type type = Vibrato::Type::GUITAR_VIBRATO);
249  void addTap(Note*);
250  void addSlap(Note*);
251  void addPop(Note*);
252  void createTuningString(int strings, int tuning[]);
253 
254  std::vector<PalmMute*> _palmMutes;
255  std::vector<LetRing*> _letRings;
256  std::vector<Vibrato*> _vibratos;
257 
258  public:
259  std::vector<std::string> tunings;
260 
261  void setTempo(int n, Measure* measure);
262  void initGuitarProDrumset();
263  QString title, subtitle, artist, album, composer;
264  QString transcriber, instructions;
265  QStringList comments;
266  GpTrack channelDefaults[GP_MAX_TRACK_NUMBER * 2];
267  int staves;
268  int measures;
269  QList<GpBar> bars;
270 
271  enum class GuitarProError : char { GP_NO_ERROR, GP_UNKNOWN_FORMAT,
272  GP_EOF, GP_BAD_NUMBER_OF_STRINGS
273  };
274 
275  GuitarPro(MasterScore*, int v);
276  virtual ~GuitarPro();
277  virtual bool read(QFile*) = 0;
278  QString error(GuitarProError n) const { return QString(errmsg[int(n)]); }
279  };
280 
281 //---------------------------------------------------------
282 // GuitarPro1
283 //---------------------------------------------------------
284 
285 class GuitarPro1 : public GuitarPro {
286 
287  protected:
288  bool readNote(int string, Note* note);
289  virtual int readBeatEffects(int track, Segment*);
290 
291  public:
292  GuitarPro1(MasterScore* s, int v) : GuitarPro(s, v) {}
293  virtual bool read(QFile*);
294  };
295 
296 //---------------------------------------------------------
297 // GuitarPro2
298 //---------------------------------------------------------
299 
300 class GuitarPro2 : public GuitarPro1 {
301 
302  public:
303  GuitarPro2(MasterScore* s, int v) : GuitarPro1(s, v) {}
304  virtual bool read(QFile*);
305  };
306 
307 //---------------------------------------------------------
308 // GuitarPro3
309 //---------------------------------------------------------
310 
311 class GuitarPro3 : public GuitarPro1 {
312  virtual int readBeatEffects(int track, Segment* segment);
313 
314  public:
315  GuitarPro3(MasterScore* s, int v) : GuitarPro1(s, v) {}
316  virtual bool read(QFile*);
317  };
318 
319 //---------------------------------------------------------
320 // GuitarPro4
321 //---------------------------------------------------------
322 
323 class GuitarPro4 : public GuitarPro {
324  std::vector<int> curDynam;
325  std::vector<int> tupleKind;
326  void readInfo();
327  bool readNote(int string, int staffIdx, Note* note);
328  virtual int readBeatEffects(int track, Segment* segment);
329  virtual bool readMixChange(Measure* measure);
330  int convertGP4SlideNum(int slide);
331 
332  public:
333  GuitarPro4(MasterScore* s, int v) : GuitarPro(s, v) {}
334  virtual bool read(QFile*);
335  };
336 
337 //---------------------------------------------------------
338 // GuitarPro5
339 //---------------------------------------------------------
340 
341 class GuitarPro5 : public GuitarPro {
342  std::map<std::pair<int, int>, bool> dead_end;
343  int _beat_counter{ 0 };
344  void readInfo();
345  void readPageSetup();
346  virtual int readBeatEffects(int track, Segment* segment);
347  bool readNote(int string, Note* note);
348  virtual bool readMixChange(Measure* measure);
349  void readMeasure(Measure* measure, int staffIdx, Tuplet*[], bool mixChange);
350  int readArtificialHarmonic();
351  bool readTracks();
352  void readMeasures(int startingTempo);
353  Fraction readBeat(const Fraction& tick, int voice, Measure* measure, int staffIdx, Tuplet** tuplets, bool mixChange);
354  bool readNoteEffects(Note*);
355 
356  public:
357  GuitarPro5(MasterScore* s, int v) : GuitarPro(s, v) {}
358  virtual bool read(QFile*);
359  };
360 
361 //---------------------------------------------------------
362 // GuitarPro6
363 //---------------------------------------------------------
364 
365 class GuitarPro6 : public GuitarPro {
366 
368  Volta* _lastVolta{ nullptr };
369  // an integer stored in the header indicating that the file is not compressed (BCFS).
370  const int GPX_HEADER_UNCOMPRESSED = 1397113666;
371  // an integer stored in the header indicating that the file is not compressed (BCFZ).
372  const int GPX_HEADER_COMPRESSED = 1514554178;
373  int position = 0;
374  QMap<int, int>* slides;
375  // a constant storing the amount of bits per byte
376  const int BITS_IN_BYTE = 8;
377  // contains all the information about notes that will go in the parts
378  struct GPPartInfo {
379  QDomNode masterBars;
380  QDomNode bars;
381  QDomNode voices;
382  QDomNode beats;
383  QDomNode notes;
384  QDomNode rhythms;
385  };
387  // a mapping from identifiers to fret diagrams
388  QMap<int, FretDiagram*> fretDiagrams;
389  void parseFile(char* filename, QByteArray* data);
390  int readBit(QByteArray* buffer);
391  QByteArray getBytes(QByteArray* buffer, int offset, int length);
392  void readGPX(QByteArray* buffer);
393  int readInteger(QByteArray* buffer, int offset);
394  QByteArray readString(QByteArray* buffer, int offset, int length);
395  int readBits(QByteArray* buffer, int bitsToRead);
396  int readBitsReversed(QByteArray* buffer, int bitsToRead);
397  void readGpif(QByteArray* data);
398  void readScore(QDomNode* metadata);
399  void readChord(QDomNode* diagram, int track);
400  int findNumMeasures(GPPartInfo* partInfo);
401  void readMasterTracks(QDomNode* masterTrack);
402  void readDrumNote(Note* note, int element, int variation);
403  Fraction readBeats(QString beats, GPPartInfo* partInfo, Measure* measure, const Fraction& startTick, int staffIdx, int voiceNum, Tuplet* tuplets[], int measureCounter);
404  void readBars(QDomNode* barList, Measure* measure, ClefType oldClefId[], GPPartInfo* partInfo, int measureCounter);
405  void readTracks(QDomNode* tracks);
406  void readMasterBars(GPPartInfo* partInfo);
407  Fraction rhythmToDuration(QString value);
408  Fraction fermataToFraction(int numerator, int denominator);
409  QDomNode getNode(const QString& id, QDomNode currentDomNode);
410  void unhandledNode(QString nodeName);
411  void makeTie(Note* note);
413  void addTremoloBar(Segment* segment, int track, int whammyOrigin, int whammyMiddle, int whammyEnd);
414 
415  std::map<std::pair<int, int>, Note*> slideMap;
416 
417  protected:
418  void readNote(int string, Note* note);
419  virtual int readBeatEffects(int track, Segment*);
420 
421  public:
423  virtual bool read(QFile*);
424  };
425 
426 } // namespace Ms
427 #endif
Fraction _lastTick
Definition: importgtp.h:367
QMap< int, QList< GPFermata > * > fermatas
Definition: importgtp.h:197
int * previousDynamic
Definition: importgtp.h:412
Definition: importgtp.h:99
Definition: importgtp.h:64
Definition: importgtp.h:69
QList< GpBar > bars
Definition: importgtp.h:269
int version
Definition: importgtp.h:190
Type
Definition: vibrato.h:59
int repeats
Definition: importgtp.h:106
GuitarPro2(MasterScore *s, int v)
Definition: importgtp.h:303
int curPos
Definition: importgtp.h:202
GuitarPro5(MasterScore *s, int v)
Definition: importgtp.h:357
QString direction
Definition: importgtp.h:108
QDomNode rhythms
Definition: importgtp.h:384
int staves
Definition: importgtp.h:267
std::vector< Vibrato * > _vibratos
Definition: importgtp.h:256
std::map< std::pair< int, int >, Note * > slideMap
Definition: importgtp.h:415
Definition: volta.h:48
Definition: importgtp.h:365
Definition of Score class.
one measure in a system
Definition: measure.h:65
GuitarPro3(MasterScore *s, int v)
Definition: importgtp.h:315
std::vector< int > ottavaFound
Definition: importgtp.h:205
Definition: score.h:1227
Definition: slur.h:55
QString title
Definition: importgtp.h:263
std::vector< QString > directions
Definition: importgtp.h:113
QDomNode beats
Definition: importgtp.h:382
BarLineType barLine
Definition: importgtp.h:104
int previousTempo
Definition: importgtp.h:203
int keysig
Definition: importgtp.h:102
QMap< int, FretDiagram * > fretDiagrams
Definition: importgtp.h:388
QDomNode bars
Definition: importgtp.h:380
QString error(GuitarProError n) const
Definition: importgtp.h:278
GuitarProError
Definition: importgtp.h:271
int index
Definition: importgtp.h:86
int beatCounter
Definition: importgtp.h:95
GuitarPro6(MasterScore *s)
Definition: importgtp.h:422
std::vector< Segment * > segments
Definition: importgtp.h:93
Definition of classes Clef.
Definition: hairpin.h:84
QDomNode notes
Definition: importgtp.h:383
QMap< int, int > * slides
Definition: importgtp.h:374
Definition: importgtp.h:285
std::vector< std::string > tunings
Definition: importgtp.h:259
std::list< Note * > slideList
Definition: importgtp.h:124
Example of 1/8 triplet: _baseLen = 1/8 _actualNotes = 3 _normalNotes = 2 (3 notes played in the time ...
Definition: tuplet.h:37
QStringList comments
Definition: importgtp.h:265
void createMeasures(const ReducedFraction &firstTick, ReducedFraction &lastTick, Score *score)
Definition: importmidi.cpp:819
uchar volume
Definition: importgtp.h:66
Score::FileError importGTP(MasterScore *score, const QString &name)
Definition: importgtp.cpp:2708
Definition: importgtp.h:91
GuitarPro1(MasterScore *s, int v)
Definition: importgtp.h:292
Definition: importgtp.h:311
Definition: importgtp.h:378
int slide
Definition: importgtp.h:212
std::map< std::pair< int, int >, bool > dead_end
Definition: importgtp.h:342
QDomNode voices
Definition: importgtp.h:381
QFile * f
Definition: importgtp.h:201
Hairpin ** hairpins
Definition: importgtp.h:199
FileError
Definition: score.h:395
int voltaType
Definition: importgtp.h:70
Definition: segment.h:50
Definition: importgtp.h:300
Definition: aeolus.cpp:26
std::vector< int > curDynam
Definition: importgtp.h:324
std::map< int, std::pair< int, bool > > tempoMap
Definition: importgtp.h:207
std::vector< Ottava * > ottava
Definition: importgtp.h:198
int previousDynamic
Definition: importgtp.h:204
int tempo
Definition: importgtp.h:208
std::vector< QString > ottavaValue
Definition: importgtp.h:206
int voltaSequence
Definition: importgtp.h:213
QMap< int, int > slides
Definition: importgtp.h:209
Slur ** legatos
Definition: importgtp.h:386
Graphic representation of a chord.
Definition: chord.h:55
Fraction timesig
Definition: importgtp.h:100
int timeDivision
Definition: importgtp.h:87
MasterScore * score
Definition: importgtp.h:200
Definition: importgtp.h:323
Repeat repeatFlags
Definition: importgtp.h:105
Definition: chordrest.h:48
QDomNode masterBars
Definition: importgtp.h:379
QString type
Definition: importgtp.h:88
std::vector< LetRing * > _letRings
Definition: importgtp.h:255
QStringList lyrics
Definition: importgtp.h:92
Definition: importgtp.h:122
Score::FileError readScore(MasterScore *score, QString name, bool ignoreVersionError)
Import file name.
Definition: file.cpp:2257
Repeat
Definition: measurebase.h:34
std::vector< PalmMute * > _palmMutes
Definition: importgtp.h:254
Definition: importgtp.h:85
int measures
Definition: importgtp.h:268
QList< int > voltaInfo
Definition: importgtp.h:71
Graphic representation of a note.
Definition: note.h:212
ClefType
Definition: clef.h:37
Definition: fraction.h:46
QString directionStyle
Definition: importgtp.h:109
bool freeTime
Definition: importgtp.h:101
GPLyrics gpLyrics
Definition: importgtp.h:211
Align
Definition: types.h:439
Definition: text.h:24
int fromBeat
Definition: importgtp.h:94
Definition: importgtp.h:341
GuitarPro4(MasterScore *s, int v)
Definition: importgtp.h:333
QString marker
Definition: importgtp.h:103
int patch
Definition: importgtp.h:65
QString transcriber
Definition: importgtp.h:264
BarLineType
Definition: mscore.h:199
GPVolta volta
Definition: importgtp.h:107
std::vector< int > tupleKind
Definition: importgtp.h:325
int lyricTrack
Definition: importgtp.h:96