/
importgtp.cpp
2458 lines (2219 loc) · 99 KB
/
importgtp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2011 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#include "importgtp.h"
#include "globals.h"
#include "libmscore/score.h"
#include "libmscore/measurebase.h"
#include "libmscore/text.h"
#include "libmscore/box.h"
#include "libmscore/staff.h"
#include "libmscore/part.h"
#include "libmscore/measure.h"
#include "libmscore/timesig.h"
#include "libmscore/tremolo.h"
#include "libmscore/rest.h"
#include "libmscore/chord.h"
#include "libmscore/note.h"
#include "libmscore/stringdata.h"
#include "libmscore/clef.h"
#include "libmscore/lyrics.h"
#include "libmscore/tempotext.h"
#include "libmscore/slur.h"
#include "libmscore/tie.h"
#include "libmscore/tuplet.h"
#include "libmscore/barline.h"
#include "libmscore/excerpt.h"
#include "libmscore/stafftype.h"
#include "libmscore/bracket.h"
#include "libmscore/articulation.h"
#include "libmscore/keysig.h"
#include "libmscore/harmony.h"
#include "libmscore/bend.h"
#include "libmscore/tremolobar.h"
#include "libmscore/segment.h"
#include "libmscore/rehearsalmark.h"
#include "libmscore/dynamic.h"
#include "libmscore/arpeggio.h"
#include "libmscore/volta.h"
#include "libmscore/fret.h"
#include "libmscore/instrtemplate.h"
#include "libmscore/glissando.h"
#include "libmscore/chordline.h"
#include "libmscore/instrtemplate.h"
#include "libmscore/hairpin.h"
#include "libmscore/ottava.h"
#include "libmscore/notedot.h"
#include "libmscore/stafftext.h"
#include "preferences.h"
namespace Ms {
//---------------------------------------------------------
// errmsg
//---------------------------------------------------------
const char* GuitarPro::errmsg[] = {
"no error",
"unknown file format",
"unexpected end of file",
"bad number of strings",
};
//---------------------------------------------------------
// GpBar
//---------------------------------------------------------
GpBar::GpBar()
{
barLine = BarLineType::NORMAL;
keysig = GP_INVALID_KEYSIG;
timesig = Fraction(4,4);
repeatFlags = Repeat::NONE;
repeats = 2;
}
//---------------------------------------------------------
// GuitarPro
//---------------------------------------------------------
GuitarPro::GuitarPro(Score* s, int v)
{
score = s;
version = v;
_codec = QTextCodec::codecForName(preferences.importCharsetGP.toLatin1());
voltaSequence = 1;
}
GuitarPro::~GuitarPro()
{
}
//---------------------------------------------------------
// skip
//---------------------------------------------------------
void GuitarPro::skip(qint64 len)
{
char c;
while (len--)
read(&c, 1);
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
void GuitarPro::read(void* p, qint64 len)
{
if (len == 0)
return;
qint64 rv = f->read((char*)p, len);
#ifdef QT_NO_DEBUG
Q_UNUSED(rv); // avoid warning about unused variable in RELEASE mode
#endif
Q_ASSERT(rv == len);
curPos += len;
}
//---------------------------------------------------------
// readChar
//---------------------------------------------------------
int GuitarPro::readChar()
{
char c;
read(&c, 1);
return c;
}
//---------------------------------------------------------
// readUChar
//---------------------------------------------------------
int GuitarPro::readUChar()
{
uchar c;
read(&c, 1);
return c;
}
//---------------------------------------------------------
// readPascalString
//---------------------------------------------------------
QString GuitarPro::readPascalString(int n)
{
uchar l = readUChar();
char s[l + 1];
read(s, l);
s[l] = 0;
skip(n - l);
if(_codec)
return _codec->toUnicode(s);
else
return QString(s);
}
//---------------------------------------------------------
// readWordPascalString
//---------------------------------------------------------
QString GuitarPro::readWordPascalString()
{
int l = readInt();
char c[l+1];
read(c, l);
c[l] = 0;
if(_codec)
return _codec->toUnicode(c);
else
return QString::fromLocal8Bit(c);
}
//---------------------------------------------------------
// readBytePascalString
//---------------------------------------------------------
QString GuitarPro::readBytePascalString()
{
int l = readUChar();
char c[l+1];
read(c, l);
c[l] = 0;
if(_codec)
return _codec->toUnicode(c);
else
return QString::fromLocal8Bit(c);
}
//---------------------------------------------------------
// readDelphiString
//---------------------------------------------------------
QString GuitarPro::readDelphiString()
{
int maxl = readInt();
uchar l = readUChar();
if (maxl != l + 1)
qFatal("readDelphiString: first word doesn't match second byte");
char c[l + 1];
read(c, l);
c[l] = 0;
if(_codec)
return _codec->toUnicode(c);
else
return QString::fromLatin1(c);
}
//---------------------------------------------------------
// readInt
//---------------------------------------------------------
int GuitarPro::readInt()
{
uchar x;
read(&x, 1);
int r = x;
read(&x, 1);
r += x << 8;
read(&x, 1);
r += x << 16;
read(&x, 1);
r += x << 24;
return r;
}
//---------------------------------------------------------
// initGuitarProDrumset
//---------------------------------------------------------
void GuitarPro::initGuitarProDrumset()
{
gpDrumset = new Drumset;
for (int i = 0; i < 128; ++i) {
gpDrumset->drum(i).notehead = NoteHead::Group::HEAD_INVALID;
gpDrumset->drum(i).line = 0;
gpDrumset->drum(i).shortcut = 0;
gpDrumset->drum(i).voice = 0;
gpDrumset->drum(i).stemDirection = MScore::Direction::UP;
}
// new drumset determined via guitar pro (third argument specifies position on staff, 10 = C3, 9 = D3, 8 = E3,...)
gpDrumset->drum(27) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "High Q"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(28) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Slap"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(29) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Scratch Push"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(30) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Scratch Pull"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(31) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Sticks"), NoteHead::Group::HEAD_CROSS, 3, MScore::Direction::UP);
gpDrumset->drum(32) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Square Click"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(33) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Metronome Click"), NoteHead::Group::HEAD_CROSS, 3, MScore::Direction::UP);
gpDrumset->drum(34) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Metronome Bell"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(35) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Acoustic Bass Drum"), NoteHead::Group::HEAD_NORMAL, 7, MScore::Direction::UP);
gpDrumset->drum(36) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Bass Drum 1"), NoteHead::Group::HEAD_NORMAL, 7, MScore::Direction::UP);
gpDrumset->drum(37) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Side Stick"), NoteHead::Group::HEAD_CROSS, 3, MScore::Direction::UP);
gpDrumset->drum(38) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Acoustic Snare"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(39) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Hand Clap"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(40) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Electric Snare"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(41) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Low Floor Tom"), NoteHead::Group::HEAD_NORMAL, 6, MScore::Direction::UP);
gpDrumset->drum(42) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Closed Hi-Hat"), NoteHead::Group::HEAD_CROSS, -1, MScore::Direction::UP);
gpDrumset->drum(43) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "High Floor Tom"), NoteHead::Group::HEAD_NORMAL, 5, MScore::Direction::UP);
gpDrumset->drum(44) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Pedal Hi-Hat"), NoteHead::Group::HEAD_CROSS, 7, MScore::Direction::UP);
gpDrumset->drum(45) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Low Tom"), NoteHead::Group::HEAD_NORMAL, 4, MScore::Direction::UP);
gpDrumset->drum(46) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Open Hi-Hat"), NoteHead::Group::HEAD_CROSS, -1, MScore::Direction::UP);
gpDrumset->drum(47) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Low-Mid Tom"), NoteHead::Group::HEAD_NORMAL, 2, MScore::Direction::UP);
gpDrumset->drum(48) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Hi-Mid Tom"), NoteHead::Group::HEAD_NORMAL, 1, MScore::Direction::UP);
gpDrumset->drum(49) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Crash Cymbal 1"), NoteHead::Group::HEAD_DIAMOND, -1, MScore::Direction::UP);
gpDrumset->drum(50) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "High Tom"), NoteHead::Group::HEAD_NORMAL, 0, MScore::Direction::UP);
gpDrumset->drum(51) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Ride Cymbal 1"), NoteHead::Group::HEAD_DIAMOND, -1, MScore::Direction::UP);
gpDrumset->drum(52) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Chinese Cymbal"), NoteHead::Group::HEAD_CROSS, -1, MScore::Direction::UP);
gpDrumset->drum(53) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Ride Bell"), NoteHead::Group::HEAD_DIAMOND, -1, MScore::Direction::UP);
gpDrumset->drum(54) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Tambourine"), NoteHead::Group::HEAD_CROSS, 2, MScore::Direction::UP);
gpDrumset->drum(55) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Splash Cymbal"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(56) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Cowbell"), NoteHead::Group::HEAD_NORMAL, 1, MScore::Direction::UP);
gpDrumset->drum(57) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Crash Cymbal 2"), NoteHead::Group::HEAD_DIAMOND, -1, MScore::Direction::UP);
gpDrumset->drum(58) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Vibraslap"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(59) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Ride Cymbal 2"), NoteHead::Group::HEAD_DIAMOND, -1, MScore::Direction::UP);
gpDrumset->drum(60) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Hi Bongo"), NoteHead::Group::HEAD_NORMAL, 8, MScore::Direction::UP);
gpDrumset->drum(61) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Low Bongo"), NoteHead::Group::HEAD_NORMAL, 9, MScore::Direction::UP);
gpDrumset->drum(62) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Mute Hi Conga"), NoteHead::Group::HEAD_CROSS, 5, MScore::Direction::UP);
gpDrumset->drum(63) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Open Hi Conga"), NoteHead::Group::HEAD_CROSS, 4, MScore::Direction::UP);
gpDrumset->drum(64) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Low Conga"), NoteHead::Group::HEAD_CROSS, 6, MScore::Direction::UP);
gpDrumset->drum(65) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "High Timbale"), NoteHead::Group::HEAD_CROSS, 8, MScore::Direction::UP);
gpDrumset->drum(66) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Low Timbale"), NoteHead::Group::HEAD_CROSS, 9, MScore::Direction::UP);
gpDrumset->drum(67) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "High Agogo"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(68) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Low Agogo"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(69) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Cabasa"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(70) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Maracas"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(71) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Short Whistle"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(72) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Long Whistle"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(73) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Short Guiro"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(74) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Long Guiro"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(75) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Claves"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(76) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Hi Wood Block"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(77) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Low Wood Block"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(78) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Mute Cuica"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(79) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Open Cuica"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(80) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Mute Triangle"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(81) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Open Triangle"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(82) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Shaker"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(83) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Sleigh Bell"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(84) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Bell Tree"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(85) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Castanets"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(86) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Mute Surdo"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
gpDrumset->drum(87) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Open Surdo"), NoteHead::Group::HEAD_NORMAL, 3, MScore::Direction::UP);
}
//---------------------------------------------------------
// addPalmMate
//---------------------------------------------------------
void GuitarPro::addPalmMute(Note* note)
{
QString palmMute = "P.M.";
TextStyle textStyle;
textStyle.setAlign(AlignmentFlags::CENTER);
addTextToNote(palmMute, textStyle, note);
}
//---------------------------------------------------------
// addLetRing
//---------------------------------------------------------
void GuitarPro::addLetRing(Note* note)
{
QString letRing = "let ring";
TextStyle textStyle;
textStyle.setItalic(true);
textStyle.setAlign(AlignmentFlags::CENTER);
addTextToNote(letRing, textStyle, note);
}
//---------------------------------------------------------
// addTap
//---------------------------------------------------------
void GuitarPro::addTap(Note* note)
{
QString tap = "T";
TextStyle textStyle;
textStyle.setAlign(AlignmentFlags::CENTER);
addTextToNote(tap, textStyle, note);
}
//---------------------------------------------------------
// addSlap
//---------------------------------------------------------
void GuitarPro::addSlap(Note* note)
{
QString slap = "S";
TextStyle textStyle;
textStyle.setAlign(AlignmentFlags::CENTER);
addTextToNote(slap, textStyle, note);
}
//---------------------------------------------------------
// addPop
//---------------------------------------------------------
void GuitarPro::addPop(Note* note)
{
QString pop = "P";
TextStyle textStyle;
textStyle.setAlign(AlignmentFlags::CENTER);
addTextToNote(pop, textStyle, note);
}
//---------------------------------------------------------
// addTextToNote
//---------------------------------------------------------
void GuitarPro::addTextToNote(QString string, TextStyle textStyle, Note* note)
{
Text* text = new Text(score);
text->setTextStyle(textStyle);
text->setPlainText(string);
text->setAbove(true);
note->add(text);
}
//---------------------------------------------------------
// setTuplet
//---------------------------------------------------------
void GuitarPro::setTuplet(Tuplet* tuplet, int tuple)
{
switch(tuple) {
case 3:
tuplet->setRatio(Fraction(3,2));
break;
case 5:
tuplet->setRatio(Fraction(5,4));
break;
case 6:
tuplet->setRatio(Fraction(6,4));
break;
case 7:
tuplet->setRatio(Fraction(7,4));
break;
case 9:
tuplet->setRatio(Fraction(9,8));
break;
case 10:
tuplet->setRatio(Fraction(10,8));
break;
case 11:
tuplet->setRatio(Fraction(11,8));
break;
case 12:
tuplet->setRatio(Fraction(12,8));
break;
case 13:
tuplet->setRatio(Fraction(13,8));
break;
default:
qFatal("unsupported tuplet %d\n", tuple);
}
}
//---------------------------------------------------------
// addDynamic
//---------------------------------------------------------
void GuitarPro::addDynamic(Note* note, int d)
{
if (!note->chord()){
qDebug() << "addDynamics: No chord associated with this note";
return;
}
Dynamic* dyn = new Dynamic(score);
// guitar pro only allows their users to go from ppp to fff
QString map_dyn[] = {"f","ppp","pp","p","mp","mf","f","ff","fff"};
dyn->setDynamicType(map_dyn[d]);
dyn->setTrack(note->track());
if (note->chord()->isGrace()) {
Chord* parent = static_cast<Chord*>(note->chord()->parent());
parent->segment()->add(dyn);
}
else
note->chord()->segment()->add(dyn);
}
void GuitarPro::readVolta(GPVolta* gpVolta, Measure* m)
{
/* Volta information is at most eight bits
* signifying which numbers should appear in the
* volta. A single bit 1 represents we should show
* 1, 100 represents 3, 10000 represents 6, 10101
* represents 1,3,5 etc. */
if (gpVolta->voltaInfo.length() != 0) {
// we have volta information - set up a volta
Ms::Volta* volta = new Ms::Volta(score);
volta->endings().clear();
QString voltaTextString = "";
// initialise count to 1 as the first bit processed with represesnt first time volta
int count = 0;
int binaryNumber = 0;
// iterate through the volta information and determine the decimal numbers for voltas
auto iter = gpVolta->voltaInfo.begin();
while (iter != gpVolta->voltaInfo.end()) {
switch (gpVolta->voltaType) {
case GP_VOLTA_FLAGS:
count++;
if (*iter == 1) { // we want this number to be displayed in the volta
if (voltaTextString == "")
voltaTextString += QString::number(count);
else
voltaTextString += "," + QString::number(count);
// add the decimal number to the endings field of voltas as well as the text
volta->endings().append(count);
}
++iter;
break;
case GP_VOLTA_BINARY:
// find the binary number in decimal
if (*iter == 1) {
binaryNumber += pow(2,count);
}
++iter;
if (iter == gpVolta->voltaInfo.end()) {
// display all numbers in the volta from voltaSequence to the decimal
while (voltaSequence <= binaryNumber) {
if (voltaTextString == "")
voltaTextString = QString::number(voltaSequence);
else
voltaTextString += "," + QString::number(voltaSequence);
volta->endings().append(voltaSequence);
voltaSequence++;
}
}
count++;
break;
}
}
volta->setText(Xml::xmlString(voltaTextString));
volta->setTick(m->tick());
volta->setTick2(m->tick() + m->ticks());
score->addElement(volta);
}
}
//---------------------------------------------------------
// readBend
// bend graph
//---------------------------------------------------------
void GuitarPro::readBend(Note* note)
{
readUChar(); // icon
readInt(); // shown aplitude
int numPoints = readInt(); // the number of points in the bend
// there are no notes in the bend, exit the function
if (numPoints == 0)
return;
Bend* bend = new Bend(note->score());
for (int i = 0; i < numPoints; ++i) {
int bendTime = readInt();
int bendPitch = readInt();
int bendVibrato = readUChar();
bend->points().append(PitchValue(bendTime, bendPitch, bendVibrato));
}
bend->setTrack(note->track());
note->add(bend);
}
//---------------------------------------------------------
// readLyrics
//---------------------------------------------------------
void GuitarPro::readLyrics()
{
gpLyrics.lyricTrack = readInt(); // lyric track
gpLyrics.fromBeat = readInt();
gpLyrics.beatCounter = 0;
QString lyrics = readWordPascalString();
lyrics.replace(QRegExp("\n"), " ");
lyrics.replace(QRegExp("\r"), " ");
gpLyrics.lyrics = lyrics.split(" ", QString::KeepEmptyParts);
for (int i = 0; i < 4; ++i) {
readInt();
readWordPascalString();
}
}
//---------------------------------------------------------
// createSlide
//---------------------------------------------------------
void GuitarPro::createSlide(int slide, ChordRest* cr, int staffIdx)
{
// shift / legato slide
if (slide == SHIFT_SLIDE || slide == LEGATO_SLIDE) {
Glissando* s = new Glissando(score);
/* s->setXmlText("");
s->setGlissandoType(Glissando::Type::STRAIGHT);
cr->add(s); */
s->setAnchor(Spanner::Anchor::NOTE);
Segment* prevSeg = cr->segment()->prev1(Segment::Type::ChordRest);
Element* prevElem = prevSeg->element(staffIdx);
if (prevElem) {
if (prevElem->type() == Element::Type::CHORD) {
Chord* prevChord = static_cast<Chord*>(prevElem);
/** TODO we should not just take the top note here
* but the /correct/ note need to check whether GP
* supports multi-note gliss. I think it can in modern
* versions */
s->setStartElement(prevChord->upNote());
s->setTick(prevSeg->tick());
s->setTrack(staffIdx);
s->setParent(prevChord->upNote());
s->setText("");
s->setGlissandoType(Glissando::Type::STRAIGHT);
if (slide == LEGATO_SLIDE)
createSlur(true, staffIdx, prevChord);
}
}
Chord* chord = (Chord*) cr;
/* TODO again here, we should not just set the up note but the
* /correct/ note need to check whether GP supports
* multi-note gliss. I think it can in modern versions */
s->setEndElement(chord->upNote());
s->setTick2(chord->segment()->tick());
s->setTrack2(staffIdx);
score->addElement(s);
if (slide == LEGATO_SLIDE)
createSlur(false, staffIdx, cr);
}
// slide out downwards (fall)
else if (slide == SLIDE_OUT_DOWN) {
ChordLine* cl = new ChordLine(score);
cl->setChordLineType(ChordLineType::FALL);
cl->setStraight(true);
cr->add(cl);
}
// slide out upwards (doit)
else if (slide == SLIDE_OUT_UP) {
ChordLine* cl = new ChordLine(score);
cl->setChordLineType(ChordLineType::DOIT);
cl->setStraight(true);
cr->add(cl);
}
// slide in from below (plop)
else if (slide == SLIDE_IN_BELOW) {
ChordLine* cl = new ChordLine(score);
cl->setChordLineType(ChordLineType::PLOP);
cl->setStraight(true);
cr->add(cl);
}
// slide in from above (scoop)
else if (slide == SLIDE_IN_ABOVE) {
ChordLine* cl = new ChordLine(score);
cl->setChordLineType(ChordLineType::SCOOP);
cl->setStraight(true);
cr->add(cl);
}
}
//---------------------------------------------------------
// readChannels
//---------------------------------------------------------
void GuitarPro::readChannels()
{
for (int i = 0; i < GP_MAX_TRACK_NUMBER * 2; ++i) {
channelDefaults[i].patch = readInt();
channelDefaults[i].volume = readUChar() * 8 - 1;
channelDefaults[i].pan = readUChar() * 8 - 1;
channelDefaults[i].chorus = readUChar() * 8 - 1;
channelDefaults[i].reverb = readUChar() * 8 - 1;
channelDefaults[i].phase = readUChar() * 8 - 1;
channelDefaults[i].tremolo = readUChar() * 8 - 1;
// defaults of 255, or any value above 127, are set to 0 (Musescore range is 0-127)
if (channelDefaults[i].patch > 127) { channelDefaults[i].patch = 0; }
if (channelDefaults[i].volume > 127) { channelDefaults[i].volume = 0; }
if (channelDefaults[i].pan > 127) { channelDefaults[i].pan = 0; }
if (channelDefaults[i].chorus > 127) { channelDefaults[i].chorus = 0; }
if (channelDefaults[i].reverb > 127) { channelDefaults[i].reverb = 0; }
if (channelDefaults[i].phase > 127) { channelDefaults[i].phase = 0; }
if (channelDefaults[i].tremolo > 127) { channelDefaults[i].tremolo = 0; }
// skip over blank information included for backwards compatibility with 3.0
skip(2);
}
}
//---------------------------------------------------------
// len2fraction
//---------------------------------------------------------
Fraction GuitarPro::len2fraction(int len)
{
Fraction l;
switch(len) {
case -2: l.set(1, 1); break;
case -1: l.set(1, 2); break;
case 0: l.set(1, 4); break;
case 1: l.set(1, 8); break;
case 2: l.set(1, 16); break;
case 3: l.set(1, 32); break;
case 4: l.set(1, 64); break;
case 5: l.set(1, 128); break;
// set to len - in some cases we get whacky numbers for this (40, 28...)
default:
l.set(1,len);
}
return l;
}
//---------------------------------------------------------
// readMixChange
//---------------------------------------------------------
bool GuitarPro::readMixChange(Measure* measure)
{
/*char patch =*/ readChar();
signed char volume = readChar();
signed char pan = readChar();
signed char chorus = readChar();
signed char reverb = readChar();
signed char phase = readChar();
signed char tremolo = readChar();
int tempo = readInt();
if (volume >= 0)
readChar();
if (pan >= 0)
readChar();
if (chorus >= 0)
readChar();
if (reverb >= 0)
readChar();
if (phase >= 0)
readChar();
if (tremolo >= 0)
readChar();
if (tempo >= 0) {
if (tempo != previousTempo) {
previousTempo = tempo;
setTempo(tempo, measure);
}
readChar();
}
return true;
}
//---------------------------------------------------------
// createMeasures
//---------------------------------------------------------
void GuitarPro::createMeasures()
{
int tick = 0;
Fraction ts;
// for (int i = 0; i < measures; ++i) {
for (int i = 0; i < bars.size(); ++i) { // ?? (ws)
Fraction nts = bars[i].timesig;
Measure* m = new Measure(score);
m->setTick(tick);
m->setTimesig(nts);
m->setLen(nts);
if (i == 0 || ts != nts) {
for (int staffIdx = 0; staffIdx < staves; ++staffIdx) {
Staff* staff = score->staff(staffIdx);
StaffType* staffType = staff->staffType();
if (staffType->genTimesig()) {
TimeSig* t = new TimeSig(score);
t->setTrack(staffIdx * VOICES);
t->setSig(nts);
Segment* s = m->getSegment(Segment::Type::TimeSig, tick);
s->add(t);
}
}
}
if (i == 0 || (bars[i].keysig != GP_INVALID_KEYSIG)) {
for (int staffIdx = 0; staffIdx < staves; ++staffIdx) {
int keysig = bars[i].keysig != GP_INVALID_KEYSIG ? bars[i].keysig : key;
if (tick == 0 || score->staff(staffIdx)->key(tick) != Key(keysig)) {
KeySig* t = new KeySig(score);
t->setKey(Key(keysig));
t->setTrack(staffIdx * VOICES);
Segment* s = m->getSegment(Segment::Type::KeySig, tick);
s->add(t);
}
}
}
readVolta(&bars[i].volta, m);
m->setRepeatFlags(bars[i].repeatFlags);
m->setRepeatCount(bars[i].repeats); // supported in gp5
// reset the volta sequence if we have an opening repeat
if (bars[i].repeatFlags == Repeat::START)
voltaSequence = 1;
// otherwise, if we see an end repeat symbol, only reset if the bar after it does not contain a volta
else if (bars[i].repeatFlags == Repeat::END && i < bars.length() - 1) {
if (bars[i+1].volta.voltaInfo.length() == 0) {
voltaSequence = 1; // reset the volta count
}
}
score->measures()->add(m);
tick += nts.ticks();
ts = nts;
}
}
//---------------------------------------------------------
// applyBeatEffects
//---------------------------------------------------------
void GuitarPro::applyBeatEffects(Chord* chord, int beatEffect)
{
/* tap/slap/pop implemented as text until SMuFL has
* specifications and we can add them to fonts. Note that
* tap/slap/pop are just added to the top note in the chord,
* technically these can be applied to individual notes on the
* UI, but Guitar Pro has no way to express that on the
* score. To get the same result, we should just add the marking
* to above the top note.
*/
if (beatEffect == 1)
addTap(chord->upNote());
else if (beatEffect == 2)
addSlap(chord->upNote());
else if (beatEffect == 3)
addPop(chord->upNote());
else if (beatEffect == 4) {
Articulation* a = new Articulation(chord->score());
a->setArticulationType(ArticulationType::FadeIn);
a->setAnchor(ArticulationAnchor::TOP_STAFF);
chord->add(a);
}
else if (beatEffect == 5) {
Articulation* a = new Articulation(chord->score());
a->setArticulationType(ArticulationType::Upbow);
chord->add(a);
}
else if (beatEffect == 6) {
Articulation* art = new Articulation(chord->score());
art->setArticulationType(ArticulationType::Downbow);
chord->add(art);
}
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
void GuitarPro1::read(QFile* fp)
{
f = fp;
curPos = 30;
title = readDelphiString();
artist = readDelphiString();
readDelphiString();
int tempo = readInt();
/*uchar num =*/ readUChar(); // Shuffle rhythm feel
// int octave = 0;
key = 0;
if (version > 102)
key = readInt(); // key
staves = version > 102 ? 8 : 1;
//int tnumerator = 4;
//int tdenominator = 4;
//
// create a part for every staff
//
for (int staffIdx = 0; staffIdx < staves; ++staffIdx) {
Part* part = new Part(score);
Staff* s = new Staff(score);
s->setPart(part);
part->insertStaff(s, 0);
score->staves().push_back(s);
score->appendPart(part);
}
int tick = 0;
Fraction ts;
for (int i = 0; i < staves; ++i) {
int tuning[GP_MAX_STRING_NUMBER];
int strings = version > 101 ? readInt() : 6;
for (int j = 0; j < strings; ++j)
tuning[j] = readInt();
int tuning2[strings];
for (int k = 0; k < strings; ++k)
tuning2[strings-k-1] = tuning[k];
int frets = 32; // TODO
StringData stringData(frets, strings, tuning2);
Part* part = score->staff(i)->part();
Instrument* instr = part->instrument();
instr->setStringData(stringData);
}
measures = readInt();
for (int i = 0; i < measures; ++i) {
Fraction nts = bars[i].timesig;
Measure* m = new Measure(score);
m->setTick(tick);
m->setTimesig(nts);
m->setLen(nts);
if (i == 0 || ts != nts) {
for (int staffIdx = 0; staffIdx < staves; ++staffIdx) {
TimeSig* t = new TimeSig(score);
t->setTrack(staffIdx * VOICES);
t->setSig(nts);
Segment* s = m->getSegment(Segment::Type::TimeSig, tick);
s->add(t);
}
}
score->measures()->add(m);
tick += nts.ticks();
ts = nts;
}
previousTempo = tempo;
Measure* measure = score->firstMeasure();
bool mixChange = false;
for (int bar = 0; bar < measures; ++bar, measure = measure->nextMeasure()) {
const GpBar& gpbar = bars[bar];
if (!gpbar.marker.isEmpty()) {
Text* s = new RehearsalMark(score);
s->setPlainText(gpbar.marker.trimmed());
s->setTrack(0);
Segment* segment = measure->getSegment(Segment::Type::ChordRest, measure->tick());
segment->add(s);
}
Tuplet* tuplets[staves];
for (int staffIdx = 0; staffIdx < staves; ++staffIdx)
tuplets[staffIdx] = 0;
for (int staffIdx = 0; staffIdx < staves; ++staffIdx) {
Fraction measureLen = 0;
int track = staffIdx * VOICES;
int tick = measure->tick();
int beats = readInt();
for (int beat = 0; beat < beats; ++beat) {
// int pause = 0;
uchar beatBits = readUChar();
bool dotted = beatBits & BEAT_DOTTED;
if (beatBits & BEAT_PAUSE)
/*pause =*/ readUChar();
int len = readChar();
int tuple = 0;
if (beatBits & BEAT_TUPLET)
tuple = readInt();
Segment* segment = measure->getSegment(Segment::Type::ChordRest, tick);
if (beatBits & BEAT_CHORD) {
int numStrings = score->staff(staffIdx)->part()->instrument()->stringData()->strings();
int header = readUChar();
QString name;
if ((header & 1) == 0) {
name = readDelphiString();
readChord(segment, track, numStrings, name, false);
}
else {
skip(25);
name = readPascalString(34);
readChord(segment, track, numStrings, name, true);
skip(36);
}
}
Lyrics* lyrics = 0;
if (beatBits & BEAT_LYRICS) {
lyrics = new Lyrics(score);
lyrics->setPlainText(readDelphiString());
}
if (beatBits & BEAT_EFFECTS)
readBeatEffects(track, segment);
if (beatBits & BEAT_MIX_CHANGE) {
readMixChange(measure);
mixChange = true;
}
int strings = readUChar(); // used strings mask
Fraction l = len2fraction(len);
ChordRest* cr;
if (strings)
cr = new Chord(score);
else
cr = new Rest(score);
cr->setTrack(track);
if (lyrics)
cr->add(lyrics);
TDuration d(l);
d.setDots(dotted ? 1 : 0);
if (dotted)
l = l + (l/2);
if (tuple) {
Tuplet* tuplet = tuplets[staffIdx];
if ((tuplet == 0) || (tuplet->elementsDuration() == tuplet->baseLen().fraction() * tuplet->ratio().numerator())) {
tuplet = new Tuplet(score);
tuplet->setTrack(cr->track());
tuplets[staffIdx] = tuplet;
setTuplet(tuplet, tuple);
tuplet->setParent(measure);
}
tuplet->setTrack(track);
tuplet->setBaseLen(l);
tuplet->setDuration(l * tuplet->ratio().denominator());
cr->setTuplet(tuplet);
tuplet->add(cr); //TODOxxx
}
cr->setDuration(l);
cr->setDurationType(d);
segment->add(cr);
Staff* staff = cr->staff();