-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathNote.ts
More file actions
1315 lines (1190 loc) · 43.1 KB
/
Note.ts
File metadata and controls
1315 lines (1190 loc) · 43.1 KB
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
import { AccentuationType } from '@coderline/alphatab/model/AccentuationType';
import type { Beat } from '@coderline/alphatab/model/Beat';
import { BendPoint } from '@coderline/alphatab/model/BendPoint';
import { BendStyle } from '@coderline/alphatab/model/BendStyle';
import { BendType } from '@coderline/alphatab/model/BendType';
import { Duration } from '@coderline/alphatab/model/Duration';
import { DynamicValue } from '@coderline/alphatab/model/DynamicValue';
import { Fingers } from '@coderline/alphatab/model/Fingers';
import { HarmonicType } from '@coderline/alphatab/model/HarmonicType';
import { NoteAccidentalMode } from '@coderline/alphatab/model/NoteAccidentalMode';
import { Ottavia } from '@coderline/alphatab/model/Ottavia';
import { SlideInType } from '@coderline/alphatab/model/SlideInType';
import { SlideOutType } from '@coderline/alphatab/model/SlideOutType';
import type { Staff } from '@coderline/alphatab/model/Staff';
import { VibratoType } from '@coderline/alphatab/model/VibratoType';
import { NotationMode } from '@coderline/alphatab/NotationSettings';
import type { Settings } from '@coderline/alphatab/Settings';
import { Lazy } from '@coderline/alphatab/util/Lazy';
import { Logger } from '@coderline/alphatab/Logger';
import { ModelUtils } from '@coderline/alphatab/model/ModelUtils';
import { PickStroke } from '@coderline/alphatab/model/PickStroke';
import { PercussionMapper } from '@coderline/alphatab/model/PercussionMapper';
import { NoteOrnament } from '@coderline/alphatab/model/NoteOrnament';
import { ElementStyle } from '@coderline/alphatab/model/ElementStyle';
import type { MusicFontSymbol } from '@coderline/alphatab/model/MusicFontSymbol';
/**
* @internal
*/
class NoteIdBag {
public tieDestinationNoteId: number = -1;
public tieOriginNoteId: number = -1;
public slurDestinationNoteId: number = -1;
public slurOriginNoteId: number = -1;
public hammerPullDestinationNoteId: number = -1;
public hammerPullOriginNoteId: number = -1;
public slideTargetNoteId: number = -1;
public slideOriginNoteId: number = -1;
}
/**
* Lists all graphical sub elements within a {@link Note} which can be styled via {@link Note.style}
* @public
*/
export enum NoteSubElement {
/**
* The effects and annotations shown in dedicated effect bands above the staves (e.g. vibrato).
* The style of the first note with the effect wins.
*/
Effects = 0,
/**
* The note head on the standard notation staff.
*/
StandardNotationNoteHead = 1,
/**
* The accidentals on the standard notation staff.
*/
StandardNotationAccidentals = 2,
/**
* The effects and annotations applied to this note on the standard notation staff (e.g. bends).
* If effects on beats result in individual note elements shown, this color will apply.
*/
StandardNotationEffects = 3,
/**
* The fret number on the guitar tab staff.
*/
GuitarTabFretNumber = 4,
/**
* The effects and annotations applied to this note on the guitar tab staff (e.g. bends).
* If effects on beats result in individual note elements shown, this color will apply.
*/
GuitarTabEffects = 5,
/**
* The note head on the slash notation staff.
*/
SlashNoteHead = 6,
/**
* The effects and annotations applied to this note on the slash notation staff (e.g. dots).
* If effects on beats result in individual note elements shown, this color will apply.
*/
SlashEffects = 7,
/**
* The note number on the numbered notation staff.
*/
NumberedNumber = 8,
/**
* The accidentals on the numbered notation staff.
*/
NumberedAccidentals = 9,
/**
* The effects and annotations applied to this note on the number notation staff (e.g. dots).
* If effects on beats result in individual note elements shown, this color will apply.
*/
NumberedEffects = 10
}
/**
* Defines the custom styles for notes.
* @json
* @json_strict
* @public
*/
export class NoteStyle extends ElementStyle<NoteSubElement> {
/**
* The symbol that should be used as note head.
*/
public noteHead?: MusicFontSymbol;
/**
* Whether the note head symbol should be centered on the stem (e.g. for arrow notes)
*/
public noteHeadCenterOnStem?: boolean;
}
/**
* A note is a single played sound on a fretted instrument.
* It consists of a fret offset and a string on which the note is played on.
* It also can be modified by a lot of different effects.
* @cloneable
* @json
* @json_strict
* @public
*/
export class Note {
/**
* @internal
*/
public static globalNoteId: number = 0;
/**
* @internal
*/
public static resetIds() {
Note.globalNoteId = 0;
}
/**
* Gets or sets the unique id of this note.
* @clone_ignore
*/
public id: number = Note.globalNoteId++;
/**
* Gets or sets the zero-based index of this note within the beat.
* @json_ignore
*/
public index: number = 0;
/**
* Gets or sets the accentuation of this note.
*/
public accentuated: AccentuationType = AccentuationType.None;
/**
* Gets or sets the bend type for this note.
*/
public bendType: BendType = BendType.None;
/**
* Gets or sets the bend style for this note.
*/
public bendStyle: BendStyle = BendStyle.Default;
/**
* Gets or sets the note from which this note continues the bend.
* @clone_ignore
* @json_ignore
*/
public bendOrigin: Note | null = null;
/**
* Gets or sets whether this note continues a bend from a previous note.
*/
public isContinuedBend: boolean = false;
/**
* Gets or sets a list of the points defining the bend behavior.
* @clone_add addBendPoint
* @json_add addBendPoint
*/
public bendPoints: BendPoint[] | null = null;
/**
* Gets or sets the bend point with the highest bend value.
* @clone_ignore
* @json_ignore
*/
public maxBendPoint: BendPoint | null = null;
public get hasBend(): boolean {
return this.bendPoints !== null && this.bendType !== BendType.None;
}
public get isStringed(): boolean {
return this.string >= 0;
}
/**
* Gets or sets the fret on which this note is played on the instrument.
* 0 is the nut.
*/
public fret: number = -1;
/**
* Gets or sets the string number where the note is placed.
* 1 is the lowest string on the guitar and the bottom line on the tablature.
* It then increases the the number of strings on available on the track.
*/
public string: number = -1;
/**
* Gets or sets whether the string number for this note should be shown.
*/
public showStringNumber: boolean = false;
public get isPiano(): boolean {
return !this.isStringed && this.octave >= 0 && this.tone >= 0;
}
/**
* Gets or sets the octave on which this note is played.
*/
public octave: number = -1;
/**
* Gets or sets the tone of this note within the octave.
*/
public tone: number = -1;
public get isPercussion(): boolean {
return this.percussionArticulation >= 0;
}
/**
* Gets or sets the percusson element.
* @deprecated
*/
public get element(): number {
return this.isPercussion ? PercussionMapper.getElementAndVariation(this)[0] : -1;
}
/**
* Gets or sets the variation of this note.
* @deprecated
*/
public get variation(): number {
return this.isPercussion ? PercussionMapper.getElementAndVariation(this)[1] : -1;
}
/**
* Gets or sets the index of percussion articulation in the related `track.percussionArticulations`.
* If the articulation is not listed in `track.percussionArticulations` the following list based on GP7 applies:
* - 029 Ride (choke)
* - 030 Cymbal (hit)
* - 031 Snare (side stick)
* - 033 Snare (side stick)
* - 034 Snare (hit)
* - 035 Kick (hit)
* - 036 Kick (hit)
* - 037 Snare (side stick)
* - 038 Snare (hit)
* - 039 Hand Clap (hit)
* - 040 Snare (hit)
* - 041 Low Floor Tom (hit)
* - 042 Hi-Hat (closed)
* - 043 Very Low Tom (hit)
* - 044 Pedal Hi-Hat (hit)
* - 045 Low Tom (hit)
* - 046 Hi-Hat (open)
* - 047 Mid Tom (hit)
* - 048 High Tom (hit)
* - 049 Crash high (hit)
* - 050 High Floor Tom (hit)
* - 051 Ride (middle)
* - 052 China (hit)
* - 053 Ride (bell)
* - 054 Tambourine (hit)
* - 055 Splash (hit)
* - 056 Cowbell medium (hit)
* - 057 Crash medium (hit)
* - 058 Vibraslap (hit)
* - 059 Ride (edge)
* - 060 Hand (hit)
* - 061 Hand (hit)
* - 062 Conga high (mute)
* - 063 Conga high (hit)
* - 064 Conga low (hit)
* - 065 Timbale high (hit)
* - 066 Timbale low (hit)
* - 067 Agogo high (hit)
* - 068 Agogo tow (hit)
* - 069 Cabasa (hit)
* - 070 Left Maraca (hit)
* - 071 Whistle high (hit)
* - 072 Whistle low (hit)
* - 073 Guiro (hit)
* - 074 Guiro (scrap-return)
* - 075 Claves (hit)
* - 076 Woodblock high (hit)
* - 077 Woodblock low (hit)
* - 078 Cuica (mute)
* - 079 Cuica (open)
* - 080 Triangle (rnute)
* - 081 Triangle (hit)
* - 082 Shaker (hit)
* - 083 Tinkle Bell (hat)
* - 083 Jingle Bell (hit)
* - 084 Bell Tree (hit)
* - 085 Castanets (hit)
* - 086 Surdo (hit)
* - 087 Surdo (mute)
* - 091 Snare (rim shot)
* - 092 Hi-Hat (half)
* - 093 Ride (edge)
* - 094 Ride (choke)
* - 095 Splash (choke)
* - 096 China (choke)
* - 097 Crash high (choke)
* - 098 Crash medium (choke)
* - 099 Cowbell low (hit)
* - 100 Cowbell low (tip)
* - 101 Cowbell medium (tip)
* - 102 Cowbell high (hit)
* - 103 Cowbell high (tip)
* - 104 Hand (mute)
* - 105 Hand (slap)
* - 106 Hand (mute)
* - 107 Hand (slap)
* - 108 Conga low (slap)
* - 109 Conga low (mute)
* - 110 Conga high (slap)
* - 111 Tambourine (return)
* - 112 Tambourine (roll)
* - 113 Tambourine (hand)
* - 114 Grancassa (hit)
* - 115 Piatti (hat)
* - 116 Piatti (hand)
* - 117 Cabasa (return)
* - 118 Left Maraca (return)
* - 119 Right Maraca (hit)
* - 120 Right Maraca (return)
* - 122 Shaker (return)
* - 123 Bell Tee (return)
* - 124 Golpe (thumb)
* - 125 Golpe (finger)
* - 126 Ride (middle)
* - 127 Ride (bell)
*/
public percussionArticulation: number = -1;
/**
* Gets or sets whether this note is visible on the music sheet.
*/
public isVisible: boolean = true;
/**
* Gets a value indicating whether the note is left hand tapped.
*/
public isLeftHandTapped: boolean = false;
/**
* Gets or sets whether this note starts a hammeron or pulloff.
*/
public isHammerPullOrigin: boolean = false;
public get isHammerPullDestination(): boolean {
return !!this.hammerPullOrigin;
}
/**
* Gets the origin of the hammeron/pulloff of this note.
* @clone_ignore
* @json_ignore
*/
public hammerPullOrigin: Note | null = null;
/**
* Gets the destination for the hammeron/pullof started by this note.
* @clone_ignore
* @json_ignore
*/
public hammerPullDestination: Note | null = null;
public get isSlurOrigin(): boolean {
return !!this.slurDestination;
}
/**
* Gets or sets whether this note finishes a slur.
*/
public isSlurDestination: boolean = false;
/**
* Gets or sets the note where the slur of this note starts.
* @clone_ignore
* @json_ignore
*/
public slurOrigin: Note | null = null;
/**
* Gets or sets the note where the slur of this note ends.
* @clone_ignore
* @json_ignore
*/
public slurDestination: Note | null = null;
public get isHarmonic(): boolean {
return this.harmonicType !== HarmonicType.None;
}
/**
* Gets or sets the harmonic type applied to this note.
*/
public harmonicType: HarmonicType = HarmonicType.None;
/**
* Gets or sets the value defining the harmonic pitch.
*/
public harmonicValue: number = 0;
/**
* Gets or sets whether the note is a ghost note and shown in parenthesis. Also this will make the note a bit more silent.
*/
public isGhost: boolean = false;
/**
* Gets or sets whether this note has a let-ring effect.
*/
public isLetRing: boolean = false;
/**
* Gets or sets the destination note for the let-ring effect.
* @clone_ignore
* @json_ignore
*/
public letRingDestination: Note | null = null;
/**
* Gets or sets whether this note has a palm-mute effect.
*/
public isPalmMute: boolean = false;
/**
* Gets or sets the destination note for the palm-mute effect.
* @clone_ignore
* @json_ignore
*/
public palmMuteDestination: Note | null = null;
/**
* Gets or sets whether the note is shown and played as dead note.
*/
public isDead: boolean = false;
/**
* Gets or sets whether the note is played as staccato.
*/
public isStaccato: boolean = false;
/**
* Gets or sets the slide-in type this note is played with.
*/
public slideInType: SlideInType = SlideInType.None;
/**
* Gets or sets the slide-out type this note is played with.
*/
public slideOutType: SlideOutType = SlideOutType.None;
/**
* Gets or sets the target note for several slide types.
* @clone_ignore
* @json_ignore
*/
public slideTarget: Note | null = null;
/**
* Gets or sets the source note for several slide types.
* @clone_ignore
* @json_ignore
*/
public slideOrigin: Note | null = null;
/**
* Gets or sets whether a vibrato is played on the note.
*/
public vibrato: VibratoType = VibratoType.None;
/**
* Gets the origin of the tied if this note is tied.
* @clone_ignore
* @json_ignore
*/
public tieOrigin: Note | null = null;
/**
* Gets the desination of the tie.
* @clone_ignore
* @json_ignore
*/
public tieDestination: Note | null = null;
/**
* Gets or sets whether this note is ends a tied note.
*/
public isTieDestination: boolean = false;
public get isTieOrigin(): boolean {
return this.tieDestination !== null;
}
/**
* Gets or sets the fingers used for this note on the left hand.
*/
public leftHandFinger: Fingers = Fingers.Unknown;
/**
* Gets or sets the fingers used for this note on the right hand.
*/
public rightHandFinger: Fingers = Fingers.Unknown;
/**
* Gets or sets whether this note has fingering defined.
*/
public get isFingering(): boolean {
return this.leftHandFinger !== Fingers.Unknown || this.rightHandFinger !== Fingers.Unknown;
}
/**
* Gets or sets the target note value for the trill effect.
*/
public trillValue: number = -1;
public get trillFret(): number {
return this.trillValue - this.stringTuning;
}
public get isTrill(): boolean {
return this.trillValue >= 0;
}
/**
* Gets or sets the speed of the trill effect.
*/
public trillSpeed: Duration = Duration.ThirtySecond;
/**
* Gets or sets the percentual duration of the note relative to the overall beat duration.
*/
public durationPercent: number = 1;
/**
* Gets or sets how accidetnals for this note should be handled.
*/
public accidentalMode: NoteAccidentalMode = NoteAccidentalMode.Default;
/**
* Gets or sets the reference to the parent beat to which this note belongs to.
* @clone_ignore
* @json_ignore
*/
public beat!: Beat;
/**
* Gets or sets the dynamics for this note.
*/
public dynamics: DynamicValue = DynamicValue.F;
/**
* @clone_ignore
* @json_ignore
*/
public isEffectSlurOrigin: boolean = false;
/**
* @clone_ignore
* @json_ignore
*/
public hasEffectSlur: boolean = false;
public get isEffectSlurDestination(): boolean {
return !!this.effectSlurOrigin;
}
/**
* @clone_ignore
* @json_ignore
*/
public effectSlurOrigin: Note | null = null;
/**
* @clone_ignore
* @json_ignore
*/
public effectSlurDestination: Note | null = null;
/**
* The ornament applied on the note.
*/
public ornament: NoteOrnament = NoteOrnament.None;
/**
* The style customizations for this item.
* @clone_ignore
*/
public style?: NoteStyle;
public get stringTuning(): number {
return this.beat.voice.bar.staff.capo + Note.getStringTuning(this.beat.voice.bar.staff, this.string);
}
public static getStringTuning(staff: Staff, noteString: number): number {
if (staff.tuning.length > 0) {
return staff.tuning[staff.tuning.length - (noteString - 1) - 1];
}
return 0;
}
public get realValue(): number {
return this.calculateRealValue(true, true);
}
public get realValueWithoutHarmonic(): number {
return this.calculateRealValue(true, false);
}
/**
* Calculates the real note value of this note as midi key respecting the given options.
* @param applyTranspositionPitch Whether or not to apply the transposition pitch of the current staff.
* @param applyHarmonic Whether or not to apply harmonic pitches to the note.
* @returns The calculated note value as midi key.
*/
public calculateRealValue(applyTranspositionPitch: boolean, applyHarmonic: boolean): number {
const transpositionPitch = applyTranspositionPitch ? this.beat.voice.bar.staff.transpositionPitch : 0;
if (applyHarmonic) {
let realValue = this.calculateRealValue(applyTranspositionPitch, false);
if (this.isStringed) {
if (this.harmonicType === HarmonicType.Natural) {
realValue = this.harmonicPitch + this.stringTuning - transpositionPitch;
} else {
realValue += this.harmonicPitch;
}
}
return realValue;
}
if (this.isPercussion) {
return this.percussionArticulation;
}
if (this.isStringed) {
return this.fret + this.stringTuning - transpositionPitch;
}
if (this.isPiano) {
return this.octave * 12 + this.tone - transpositionPitch;
}
return 0;
}
public get harmonicPitch(): number {
if (this.harmonicType === HarmonicType.None || !this.isStringed) {
return 0;
}
const value: number = this.harmonicValue;
// add semitones to reach corresponding harmonic frets
if (ModelUtils.isAlmostEqualTo(value, 2.4)) {
return 36;
}
if (ModelUtils.isAlmostEqualTo(value, 2.7)) {
// Fret 3 2nd octave + minor seventh
return 34;
}
if (value < 3) {
// no natural harmonics below fret 3
return 0;
}
if (value <= 3.5) {
// Fret 3 2nd octave + fifth
return 31;
}
if (value <= 4) {
return 28;
}
if (value <= 5) {
return 24;
}
if (value <= 6) {
return 34;
}
if (value <= 7) {
return 19;
}
if (value <= 8.5) {
return 36;
}
if (value <= 9) {
return 28;
}
if (value <= 10) {
return 34;
}
if (value <= 11) {
return 0;
}
if (value <= 12) {
return 12;
}
if (value < 14) {
// fret 13,14 stay
return 0;
}
if (value <= 15) {
return 34;
}
if (value <= 16) {
return 28;
}
if (value <= 17) {
return 36;
}
if (value <= 18) {
return 0;
}
if (value <= 19) {
return 19;
}
if (value <= 21) {
// 20,21 stay
return 0;
}
if (value <= 22) {
return 36;
}
if (value <= 24) {
return 24;
}
return 0;
}
public get initialBendValue(): number {
if (this.hasBend) {
return Math.floor(this.bendPoints![0].value / 2);
}
if (this.bendOrigin) {
return Math.floor(this.bendOrigin.bendPoints![this.bendOrigin.bendPoints!.length - 1].value / 2);
}
if (this.isTieDestination && this.tieOrigin!.bendOrigin) {
return Math.floor(
this.tieOrigin!.bendOrigin.bendPoints![this.tieOrigin!.bendOrigin.bendPoints!.length - 1].value / 2
);
}
if (this.beat.hasWhammyBar) {
return Math.floor(this.beat.whammyBarPoints![0].value / 2);
}
if (this.beat.isContinuedWhammy) {
return Math.floor(
this.beat.previousBeat!.whammyBarPoints![this.beat.previousBeat!.whammyBarPoints!.length - 1].value / 2
);
}
return 0;
}
public get displayValue(): number {
return this.displayValueWithoutBend + this.initialBendValue;
}
public get displayValueWithoutBend(): number {
let noteValue: number = this.realValue;
if (this.harmonicType !== HarmonicType.Natural && this.harmonicType !== HarmonicType.None) {
noteValue -= this.harmonicPitch;
}
switch (this.beat.ottava) {
case Ottavia._15ma:
noteValue -= 24;
break;
case Ottavia._8va:
noteValue -= 12;
break;
case Ottavia.Regular:
break;
case Ottavia._8vb:
noteValue += 12;
break;
case Ottavia._15mb:
noteValue += 24;
break;
}
switch (this.beat.voice.bar.clefOttava) {
case Ottavia._15ma:
noteValue -= 24;
break;
case Ottavia._8va:
noteValue -= 12;
break;
case Ottavia.Regular:
break;
case Ottavia._8vb:
noteValue += 12;
break;
case Ottavia._15mb:
noteValue += 24;
break;
}
return noteValue - this.beat.voice.bar.staff.displayTranspositionPitch;
}
public get hasQuarterToneOffset(): boolean {
if (this.hasBend) {
return this.bendPoints![0].value % 2 !== 0;
}
if (this.bendOrigin) {
return this.bendOrigin.bendPoints![this.bendOrigin.bendPoints!.length - 1].value % 2 !== 0;
}
if (this.beat.hasWhammyBar) {
return this.beat.whammyBarPoints![0].value % 2 !== 0;
}
if (this.beat.isContinuedWhammy) {
return (
this.beat.previousBeat!.whammyBarPoints![this.beat.previousBeat!.whammyBarPoints!.length - 1].value %
2 !==
0
);
}
return false;
}
public addBendPoint(point: BendPoint): void {
let points = this.bendPoints;
if (points === null) {
points = [];
this.bendPoints = points;
}
points.push(point);
if (!this.maxBendPoint || point.value > this.maxBendPoint.value) {
this.maxBendPoint = point;
}
if (this.bendType === BendType.None) {
this.bendType = BendType.Custom;
}
}
public finish(settings: Settings, sharedDataBag: Map<string, unknown> | null = null): void {
const nextNoteOnLine: Lazy<Note | null> = new Lazy<Note | null>(() => Note.nextNoteOnSameLine(this));
const isSongBook: boolean = settings && settings.notation.notationMode === NotationMode.SongBook;
// connect ties
if (this.isTieDestination) {
this.chain(sharedDataBag);
// implicit let ring
if (isSongBook && this.tieOrigin && this.tieOrigin.isLetRing) {
this.isLetRing = true;
}
}
// connect letring
if (this.isLetRing) {
if (!nextNoteOnLine.value || !nextNoteOnLine.value.isLetRing) {
this.letRingDestination = this;
} else {
this.letRingDestination = nextNoteOnLine.value;
}
if (isSongBook && this.isTieDestination && !this.tieOrigin!.hasBend) {
this.isVisible = false;
}
}
// connect palmmute
if (this.isPalmMute) {
if (!nextNoteOnLine.value || !nextNoteOnLine.value.isPalmMute) {
this.palmMuteDestination = this;
} else {
this.palmMuteDestination = nextNoteOnLine.value;
}
}
// set hammeron/pulloffs
if (this.isHammerPullOrigin) {
const hammerPullDestination = Note.findHammerPullDestination(this);
if (!hammerPullDestination) {
this.isHammerPullOrigin = false;
} else {
this.hammerPullDestination = hammerPullDestination;
hammerPullDestination.hammerPullOrigin = this;
}
}
// set slides
switch (this.slideOutType) {
case SlideOutType.Shift:
case SlideOutType.Legato:
if (!this.slideTarget) {
this.slideTarget = nextNoteOnLine.value;
}
if (!this.slideTarget) {
this.slideOutType = SlideOutType.None;
} else {
this.slideTarget.slideOrigin = this;
}
break;
}
let effectSlurDestination: Note | null = null;
if (this.isHammerPullOrigin && this.hammerPullDestination) {
effectSlurDestination = this.hammerPullDestination;
} else if (this.slideOutType === SlideOutType.Legato && this.slideTarget) {
effectSlurDestination = this.slideTarget;
}
if (effectSlurDestination) {
this.hasEffectSlur = true;
if (this.effectSlurOrigin && this.beat.pickStroke === PickStroke.None) {
this.effectSlurOrigin.effectSlurDestination = effectSlurDestination;
this.effectSlurOrigin.effectSlurDestination.effectSlurOrigin = this.effectSlurOrigin;
this.effectSlurOrigin = null;
} else {
this.isEffectSlurOrigin = true;
this.effectSlurDestination = effectSlurDestination;
this.effectSlurDestination.effectSlurOrigin = this;
}
}
// try to detect what kind of bend was used and cleans unneeded points if required
// Guitar Pro 6 and above (gpif.xml) uses exactly 4 points to define all bends
const points = this.bendPoints;
const hasBend = points != null && points.length > 0;
if (hasBend) {
const isContinuedBend: boolean = this.isTieDestination && this.tieOrigin!.hasBend;
this.isContinuedBend = isContinuedBend;
} else {
this.bendType = BendType.None;
}
if (hasBend && this.bendType === BendType.Custom) {
if (points!.length === 4) {
const origin: BendPoint = points[0];
const middle1: BendPoint = points[1];
const middle2: BendPoint = points[2];
const destination: BendPoint = points[3];
// the middle points are used for holds, anything else is a new feature we do not support yet
if (middle1.value === middle2.value) {
// bend higher?
if (destination.value > origin.value) {
if (middle1.value > destination.value) {
this.bendType = BendType.BendRelease;
} else if (!this.isContinuedBend && origin.value > 0) {
this.bendType = BendType.PrebendBend;
points.splice(2, 1);
points.splice(1, 1);
} else {
this.bendType = BendType.Bend;
points.splice(2, 1);
points.splice(1, 1);
}
} else if (destination.value < origin.value) {
// origin must be > 0 otherwise it's no release, we cannot bend negative
if (this.isContinuedBend) {
this.bendType = BendType.Release;
points.splice(2, 1);
points.splice(1, 1);
} else {
this.bendType = BendType.PrebendRelease;
points.splice(2, 1);
points.splice(1, 1);
}
} else {
if (middle1.value > origin.value) {
this.bendType = BendType.BendRelease;
} else if (origin.value > 0 && !this.isContinuedBend) {
this.bendType = BendType.Prebend;
points.splice(2, 1);
points.splice(1, 1);
} else {
this.bendType = BendType.Hold;
points.splice(2, 1);
points.splice(1, 1);
}
}
} else {
Logger.warning('Model', 'Unsupported bend type detected, fallback to custom', null);
}
} else if (points!.length === 3) {
const origin: BendPoint = points[0];
const middle: BendPoint = points[1];
const destination: BendPoint = points[2];
// bend higher?
if (destination.value > origin.value) {
if (middle.value > destination.value) {
this.bendType = BendType.BendRelease;
points.splice(1, 0, new BendPoint(middle.offset, middle.value));
} else if (!this.isContinuedBend && origin.value > 0) {
this.bendType = BendType.PrebendBend;
points.splice(1, 1);
} else {
this.bendType = BendType.Bend;
points.splice(1, 1);