forked from CoderLine/alphaTab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeat.ts
More file actions
1279 lines (1126 loc) · 41.8 KB
/
Beat.ts
File metadata and controls
1279 lines (1126 loc) · 41.8 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 { MidiUtils } from '@coderline/alphatab/midi/MidiUtils';
import { Automation, AutomationType } from '@coderline/alphatab/model/Automation';
import { BendPoint } from '@coderline/alphatab/model/BendPoint';
import { BendStyle } from '@coderline/alphatab/model/BendStyle';
import { BendType } from '@coderline/alphatab/model/BendType';
import { BrushType } from '@coderline/alphatab/model/BrushType';
import type { Chord } from '@coderline/alphatab/model/Chord';
import { CrescendoType } from '@coderline/alphatab/model/CrescendoType';
import { Duration } from '@coderline/alphatab/model/Duration';
import { DynamicValue } from '@coderline/alphatab/model/DynamicValue';
import type { Fermata } from '@coderline/alphatab/model/Fermata';
import { GraceType } from '@coderline/alphatab/model/GraceType';
import { Note } from '@coderline/alphatab/model/Note';
import { Ottavia } from '@coderline/alphatab/model/Ottavia';
import { PickStroke } from '@coderline/alphatab/model/PickStroke';
import { TupletGroup } from '@coderline/alphatab/model/TupletGroup';
import { VibratoType } from '@coderline/alphatab/model/VibratoType';
import type { Voice } from '@coderline/alphatab/model/Voice';
import { WhammyType } from '@coderline/alphatab/model/WhammyType';
import { NotationMode } from '@coderline/alphatab/NotationSettings';
import type { Settings } from '@coderline/alphatab/Settings';
import type { BeamDirection } from '@coderline/alphatab/rendering/utils/BeamDirection';
import { BeatCloner } from '@coderline/alphatab/generated/model/BeatCloner';
import { GraceGroup } from '@coderline/alphatab/model/GraceGroup';
import { GolpeType } from '@coderline/alphatab/model/GolpeType';
import { FadeType } from '@coderline/alphatab/model/FadeType';
import { WahPedal } from '@coderline/alphatab/model/WahPedal';
import { BarreShape } from '@coderline/alphatab/model/BarreShape';
import { Rasgueado } from '@coderline/alphatab/model/Rasgueado';
import { ElementStyle } from '@coderline/alphatab/model/ElementStyle';
import { TremoloPickingEffect } from '@coderline/alphatab/model/TremoloPickingEffect';
/**
* Lists the different modes on how beaming for a beat should be done.
* @public
*/
export enum BeatBeamingMode {
/**
* Automatic beaming based on the timing rules.
*/
Auto = 0,
/**
* Force a split to the next beat.
*/
ForceSplitToNext = 1,
/**
* Force a merge with the next beat.
*/
ForceMergeWithNext = 2,
/**
* Force a split to the next beat on the secondary beam.
*/
ForceSplitOnSecondaryToNext = 3
}
/**
* Lists all graphical sub elements within a {@link Beat} which can be styled via {@link Beat.style}
* @public
*/
export enum BeatSubElement {
/**
* The effects and annotations shown in dedicated effect bands above the staves (e.g. fermata).
* Only applies to items which are on beat level but not any individual note level effects.
*/
Effects = 0,
/**
* The stems drawn for note heads in this beat on the standard notation staff.
*/
StandardNotationStem = 1,
/**
* The flags drawn for note heads in this beat on the standard notation staff.
*/
StandardNotationFlags = 2,
/**
* The beams drawn between this and the next beat on the standard notation staff.
*/
StandardNotationBeams = 3,
/**
* The tuplet drawn on the standard notation staff (the first beat affects the whole tuplet if grouped).
*/
StandardNotationTuplet = 4,
/**
* The effects and annotations applied to this beat on the standard notation staff (e.g. brushes).
* Only applies to items which are on beat level but not any individual note level effects.
*/
StandardNotationEffects = 5,
/**
* The rest symbol on the standard notation staff.
*/
StandardNotationRests = 6,
/**
* The stems drawn for note heads in this beat on the guitar tab staff.
*/
GuitarTabStem = 7,
/**
* The flags drawn for note heads in this beat on the guitar tab staff.
*/
GuitarTabFlags = 8,
/**
* The beams drawn between this and the next beat on the guitar tab staff.
*/
GuitarTabBeams = 9,
/**
* The tuplet drawn on the guitar tab staff (the first beat affects the whole tuplet if grouped).
*/
GuitarTabTuplet = 10,
/**
* The effects and annotations applied to this beat on the guitar tab staff (e.g. brushes).
* Only applies to items which are on beat level but not any individual note level effects.
*/
GuitarTabEffects = 11,
/**
* The rest symbol on the guitar tab staff.
*/
GuitarTabRests = 12,
/**
* The stems drawn for note heads in this beat on the slash staff.
*/
SlashStem = 13,
/**
* The flags drawn for note heads in this beat on the slash staff.
*/
SlashFlags = 14,
/**
* The beams drawn between this and the next beat on the slash staff.
*/
SlashBeams = 15,
/**
* The tuplet drawn on the slash staff (the first beat affects the whole tuplet if grouped).
*/
SlashTuplet = 16,
/**
* The rest symbol on the slash staff.
*/
SlashRests = 17,
/**
* The effects and annotations applied to this beat on the slash staff (e.g. brushes).
* Only applies to items which are on beat level but not any individual note level effects.
*/
SlashEffects = 18,
/**
* The duration lines drawn for this beat on the numbered notation staff.
*/
NumberedDuration = 19,
/**
* The effects and annotations applied to this beat on the numbered notation staff (e.g. brushes).
* Only applies to items which are on beat level but not any individual note level effects.
*/
NumberedEffects = 20,
/**
* The rest (0) on the numbered notation staff.
*/
NumberedRests = 21,
/**
* The tuplet drawn on the numbered notation staff (the first beat affects the whole tuplet if grouped).
*/
NumberedTuplet = 22
}
/**
* Lists the different modes for rendering a tuplet number.
* @public
*/
export enum TupletShowNumber {
/**
* Show the actual note count only.
* The renderer may still decide whether the denominator is implied by the meter.
*/
Actual = 0,
/**
* Show both numerator and denominator.
*/
Both = 1,
/**
* Do not show any tuplet number.
*/
None = 2
}
/**
* Defines the custom styles for beats.
* @json
* @json_strict
* @public
*/
export class BeatStyle extends ElementStyle<BeatSubElement> {}
/**
* A beat is a single block within a bar. A beat is a combination
* of several notes played at the same time.
* @json
* @json_strict
* @cloneable
* @public
*/
export class Beat {
private static _globalBeatId: number = 0;
/**
* @internal
*/
public static resetIds() {
Beat._globalBeatId = 0;
}
/**
* Gets or sets the unique id of this beat.
* @clone_ignore
*/
public id: number = Beat._globalBeatId++;
/**
* Gets or sets the zero-based index of this beat within the voice.
* @json_ignore
*/
public index: number = 0;
/**
* Gets or sets the previous beat within the whole song.
* @json_ignore
* @clone_ignore
*/
public previousBeat: Beat | null = null;
/**
* Gets or sets the next beat within the whole song.
* @json_ignore
* @clone_ignore
*/
public nextBeat: Beat | null = null;
public get isLastOfVoice(): boolean {
return this.index === this.voice.beats.length - 1;
}
/**
* Gets or sets the reference to the parent voice this beat belongs to.
* @json_ignore
* @clone_ignore
*/
public voice!: Voice;
/**
* Gets or sets the list of notes contained in this beat.
* @json_add addNote
* @clone_add addNote
*/
public notes: Note[] = [];
/**
* Gets the lookup where the notes per string are registered.
* If this staff contains string based notes this lookup allows fast access.
* @json_ignore
*/
public readonly noteStringLookup: Map<number, Note> = new Map();
/**
* Gets the lookup where the notes per value are registered.
* If this staff contains string based notes this lookup allows fast access.
* @json_ignore
*/
public readonly noteValueLookup: Map<number, Note> = new Map();
/**
* Gets or sets a value indicating whether this beat is considered empty.
*/
public isEmpty: boolean = false;
/**
* Gets or sets which whammy bar style should be used for this bar.
*/
public whammyStyle: BendStyle = BendStyle.Default;
/**
* Gets or sets the ottava applied to this beat.
*/
public ottava: Ottavia = Ottavia.Regular;
/**
* Gets or sets the fermata applied to this beat.
* @clone_ignore
* @json_ignore
*/
public fermata: Fermata | null = null;
/**
* Gets a value indicating whether this beat starts a legato slur.
*/
public isLegatoOrigin: boolean = false;
public get isLegatoDestination(): boolean {
return !!this.previousBeat && this.previousBeat.isLegatoOrigin;
}
/**
* Gets or sets the note with the lowest pitch in this beat. Only visible notes are considered.
* @json_ignore
* @clone_ignore
*/
public minNote: Note | null = null;
/**
* Gets or sets the note with the highest pitch in this beat. Only visible notes are considered.
* @json_ignore
* @clone_ignore
*/
public maxNote: Note | null = null;
/**
* Gets or sets the note with the highest string number in this beat. Only visible notes are considered.
* @json_ignore
* @clone_ignore
*/
public maxStringNote: Note | null = null;
/**
* Gets or sets the note with the lowest string number in this beat. Only visible notes are considered.
* @json_ignore
* @clone_ignore
*/
public minStringNote: Note | null = null;
/**
* Gets or sets the duration of this beat.
*/
public duration: Duration = Duration.Quarter;
public get isRest(): boolean {
return this.isEmpty || (!this.deadSlapped && this.notes.length === 0);
}
/**
* Gets a value indicating whether this beat is a full bar rest.
*/
public get isFullBarRest(): boolean {
return this.isRest && this.voice.beats.length === 1 && this.duration === Duration.Whole;
}
/**
* Gets or sets whether any note in this beat has a let-ring applied.
* @json_ignore
*/
public isLetRing: boolean = false;
/**
* Gets or sets whether any note in this beat has a palm-mute applied.
* @json_ignore
*/
public isPalmMute: boolean = false;
/**
* Gets or sets a list of all automations on this beat.
*/
public automations: Automation[] = [];
/**
* Gets or sets the number of dots applied to the duration of this beat.
*/
public dots: number = 0;
/**
* Gets a value indicating whether this beat is fade-in.
* @deprecated Use `fade`
*/
public get fadeIn(): boolean {
return this.fade === FadeType.FadeIn;
}
/**
* Sets a value indicating whether this beat is fade-in.
* @deprecated Use `fade`
*/
public set fadeIn(value: boolean) {
this.fade = value ? FadeType.FadeIn : FadeType.None;
}
/**
* Gets or sets a value indicating whether this beat is fade-in.
*/
public fade: FadeType = FadeType.None;
/**
* Gets or sets the lyrics shown on this beat.
*/
public lyrics: string[] | null = null;
/**
* Gets or sets a value indicating whether the beat is played in rasgueado style.
*/
public get hasRasgueado(): boolean {
return this.rasgueado !== Rasgueado.None;
}
/**
* Gets or sets a value indicating whether the notes on this beat are played with a pop-style (bass).
*/
public pop: boolean = false;
/**
* Gets or sets a value indicating whether the notes on this beat are played with a slap-style (bass).
*/
public slap: boolean = false;
/**
* Gets or sets a value indicating whether the notes on this beat are played with a tap-style (bass).
*/
public tap: boolean = false;
/**
* Gets or sets the text annotation shown on this beat.
*/
public text: string | null = null;
/**
* Gets or sets whether this beat should be rendered as slashed note.
*/
public slashed: boolean = false;
/**
* Whether this beat should rendered and played as "dead slapped".
*/
public deadSlapped: boolean = false;
/**
* Gets or sets the brush type applied to the notes of this beat.
*/
public brushType: BrushType = BrushType.None;
/**
* Gets or sets the duration of the brush between the notes in midi ticks.
*/
public brushDuration: number = 0;
/**
* Gets or sets the tuplet denominator.
*/
public tupletDenominator: number = -1;
/**
* Gets or sets the tuplet numerator.
*/
public tupletNumerator: number = -1;
/**
* Gets or sets the tuplet number visibility.
*/
public showTupletNumber: TupletShowNumber = TupletShowNumber.Actual;
/**
* Gets or sets the tuplet bracket visibility.
*/
public showTupletBracket: boolean = true;
public get hasTuplet(): boolean {
return (
!(this.tupletDenominator === -1 && this.tupletNumerator === -1) &&
!(this.tupletDenominator === 1 && this.tupletNumerator === 1)
);
}
/**
* @clone_ignore
* @json_ignore
*/
public tupletGroup: TupletGroup | null = null;
/**
* Gets or sets whether this beat continues a whammy effect.
*/
public isContinuedWhammy: boolean = false;
/**
* Gets or sets the whammy bar style of this beat.
*/
public whammyBarType: WhammyType = WhammyType.None;
/**
* Gets or sets the points defining the whammy bar usage.
* @json_add addWhammyBarPoint
* @clone_add addWhammyBarPoint
*/
public whammyBarPoints: BendPoint[] | null = null;
/**
* Gets or sets the highest point with for the highest whammy bar value.
* @json_ignore
* @clone_ignore
*/
public maxWhammyPoint: BendPoint | null = null;
/**
* Gets or sets the highest point with for the lowest whammy bar value.
* @json_ignore
* @clone_ignore
*/
public minWhammyPoint: BendPoint | null = null;
public get hasWhammyBar(): boolean {
return this.whammyBarPoints !== null && this.whammyBarType !== WhammyType.None;
}
/**
* Gets or sets the vibrato effect used on this beat.
*/
public vibrato: VibratoType = VibratoType.None;
/**
* Gets or sets the ID of the chord used on this beat.
*/
public chordId: string | null = null;
public get hasChord(): boolean {
return !!this.chordId;
}
public get chord(): Chord | null {
return this.chordId ? this.voice.bar.staff.getChord(this.chordId)! : null;
}
/**
* Gets or sets the grace style of this beat.
*/
public graceType: GraceType = GraceType.None;
/**
* Gets or sets the grace group this beat belongs to.
* If this beat is not a grace note, it holds the group which belongs to this beat.
* @json_ignore
* @clone_ignore
*/
public graceGroup: GraceGroup | null = null;
/**
* Gets or sets the index of this beat within the grace group if
* this is a grace beat.
* @json_ignore
* @clone_ignore
*/
public graceIndex: number = -1;
/**
* Gets or sets the pickstroke applied on this beat.
*/
public pickStroke: PickStroke = PickStroke.None;
/**
* Whether this beat has a tremolo picking effect.
*/
public get isTremolo(): boolean {
return this.tremoloPicking !== undefined;
}
/**
* The tremolo picking effect.
*/
public tremoloPicking?: TremoloPickingEffect;
/**
* The speed of the tremolo.
* @deprecated Set {@link tremoloPicking} instead.
*/
public get tremoloSpeed(): Duration | null {
const tremolo = this.tremoloPicking;
if (tremolo) {
return tremolo.getDuration(this.duration);
}
return null;
}
/**
* The speed of the tremolo.
* @deprecated Set {@link tremoloPicking} instead.
*/
public set tremoloSpeed(value: Duration | null) {
if (value === null) {
this.tremoloPicking = undefined;
return;
}
let effect = this.tremoloPicking;
if (effect === undefined) {
effect = new TremoloPickingEffect();
this.tremoloPicking = effect;
}
switch (value) {
case Duration.Eighth:
effect.marks = 1;
break;
case Duration.Sixteenth:
effect.marks = 2;
break;
case Duration.ThirtySecond:
effect.marks = 3;
break;
case Duration.SixtyFourth:
effect.marks = 4;
break;
case Duration.OneHundredTwentyEighth:
effect.marks = 5;
break;
}
}
/**
* Gets or sets whether a crescendo/decrescendo is applied on this beat.
*/
public crescendo: CrescendoType = CrescendoType.None;
/**
* The timeline position of the voice within the current bar as it is displayed. (unit: midi ticks)
* This might differ from the actual playback time due to special grace types.
*/
public displayStart: number = 0;
/**
* The calculated visual end position of this beat in midi ticks.
*/
public get displayEnd(): number {
return this.displayStart + this.displayDuration;
}
/**
* The timeline position of the voice within the current bar as it is played. (unit: midi ticks)
* This might differ from the actual playback time due to special grace types.
*/
public playbackStart: number = 0;
/**
* Gets or sets the duration that is used for the display of this beat. It defines the size/width of the beat in
* the music sheet. (unit: midi ticks).
*/
public displayDuration: number = 0;
/**
* Gets or sets the duration that the note is played during the audio generation.
*/
public playbackDuration: number = 0;
/**
* The duration in midi ticks to use for this beat on the {@link displayDuration}
* controlling the visual display of the beat.
* @remarks
* This is used in scenarios where the bar might not have 100% exactly
* a linear structure between the beats. e.g. in MusicXML when using `<forward />`.
*/
public overrideDisplayDuration?: number;
/**
* The type of golpe to play.
*/
public golpe: GolpeType = GolpeType.None;
public get absoluteDisplayStart(): number {
return this.voice.bar.masterBar.start + this.displayStart;
}
public get absolutePlaybackStart(): number {
return this.voice.bar.masterBar.start + this.playbackStart;
}
/**
* Gets or sets the dynamics applied to this beat.
*/
public dynamics: DynamicValue = DynamicValue.F;
/**
* Gets or sets a value indicating whether the beam direction should be inverted.
*/
public invertBeamDirection: boolean = false;
/**
* Gets or sets the preferred beam direction as specified in the input source.
*/
public preferredBeamDirection: BeamDirection | null = null;
/**
* @json_ignore
*/
public isEffectSlurOrigin: boolean = false;
public get isEffectSlurDestination(): boolean {
return !!this.effectSlurOrigin;
}
/**
* @clone_ignore
* @json_ignore
*/
public effectSlurOrigin: Beat | null = null;
/**
* @clone_ignore
* @json_ignore
*/
public effectSlurDestination: Beat | null = null;
/**
* Gets or sets how the beaming should be done for this beat.
*/
public beamingMode: BeatBeamingMode = BeatBeamingMode.Auto;
/**
* Whether the wah pedal should be used when playing the beat.
*/
public wahPedal: WahPedal = WahPedal.None;
/**
* The fret of a barré being played on this beat.
*/
public barreFret: number = -1;
/**
* The shape how the barre should be played on this beat.
*/
public barreShape: BarreShape = BarreShape.None;
/**
* Gets a value indicating whether the beat should be played as Barré
*/
public get isBarre() {
return this.barreShape !== BarreShape.None && this.barreFret >= 0;
}
/**
* The Rasgueado pattern to play with this beat.
*/
public rasgueado: Rasgueado = Rasgueado.None;
/**
* Whether to show the time when this beat is played the first time.
* (requires that the midi for the song is generated so that times are calculated).
* If no midi is generated the timer value might be filled from the input file (or manually).
*/
public showTimer: boolean = false;
/**
* The absolute time in milliseconds when this beat will be played the first time.
*/
public timer: number | null = null;
/**
* The style customizations for this item.
* @clone_ignore
*/
public style?: BeatStyle;
public addWhammyBarPoint(point: BendPoint): void {
let points = this.whammyBarPoints;
if (points === null) {
points = [];
this.whammyBarPoints = points;
}
points.push(point);
if (!this.maxWhammyPoint || point.value > this.maxWhammyPoint.value) {
this.maxWhammyPoint = point;
}
if (!this.minWhammyPoint || point.value < this.minWhammyPoint.value) {
this.minWhammyPoint = point;
}
if (this.whammyBarType === WhammyType.None) {
this.whammyBarType = WhammyType.Custom;
}
}
public removeWhammyBarPoint(index: number): void {
// check index
const points = this.whammyBarPoints;
if (points === null || index < 0 || index >= points.length) {
return;
}
// remove point
points.splice(index, 1);
const point: BendPoint = points[index];
// update maxWhammy point if required
if (point === this.maxWhammyPoint) {
this.maxWhammyPoint = null;
for (const currentPoint of points) {
if (!this.maxWhammyPoint || currentPoint.value > this.maxWhammyPoint.value) {
this.maxWhammyPoint = currentPoint;
}
}
}
if (point === this.minWhammyPoint) {
this.minWhammyPoint = null;
for (const currentPoint of points) {
if (!this.minWhammyPoint || currentPoint.value < this.minWhammyPoint.value) {
this.minWhammyPoint = currentPoint;
}
}
}
}
public addNote(note: Note): void {
note.beat = this;
note.index = this.notes.length;
this.notes.push(note);
if (note.isStringed) {
this.noteStringLookup.set(note.string, note);
}
}
public removeNote(note: Note): void {
const index: number = this.notes.indexOf(note);
if (index >= 0) {
this.notes.splice(index, 1);
if (note.isStringed) {
this.noteStringLookup.delete(note.string);
}
}
}
public getAutomation(type: AutomationType): Automation | null {
for (let i: number = 0, j: number = this.automations.length; i < j; i++) {
const automation: Automation = this.automations[i];
if (automation.type === type) {
return automation;
}
}
return null;
}
public getNoteOnString(noteString: number): Note | null {
if (this.noteStringLookup.has(noteString)) {
return this.noteStringLookup.get(noteString)!;
}
return null;
}
private _calculateDuration(): number {
if (this.overrideDisplayDuration !== undefined) {
return this.overrideDisplayDuration!;
}
if (this.isFullBarRest) {
return this.voice.bar.masterBar.calculateDuration();
}
let ticks: number = MidiUtils.toTicks(this.duration);
if (this.dots === 2) {
ticks = MidiUtils.applyDot(ticks, true);
} else if (this.dots === 1) {
ticks = MidiUtils.applyDot(ticks, false);
}
if (this.tupletDenominator > 0 && this.tupletNumerator >= 0) {
ticks = MidiUtils.applyTuplet(ticks, this.tupletNumerator, this.tupletDenominator);
}
return ticks;
}
public updateDurations(): void {
const ticks: number = this._calculateDuration();
this.playbackDuration = ticks;
switch (this.graceType) {
case GraceType.BeforeBeat:
case GraceType.OnBeat:
switch (this.duration) {
case Duration.Sixteenth:
this.playbackDuration = MidiUtils.toTicks(Duration.SixtyFourth);
break;
case Duration.ThirtySecond:
this.playbackDuration = MidiUtils.toTicks(Duration.OneHundredTwentyEighth);
break;
default:
this.playbackDuration = MidiUtils.toTicks(Duration.ThirtySecond);
break;
}
this.displayDuration = 0;
break;
case GraceType.BendGrace:
this.playbackDuration /= 2;
this.displayDuration = 0;
break;
default:
this.displayDuration = ticks;
const previous: Beat | null = this.previousBeat;
if (previous && previous.graceType === GraceType.BendGrace) {
this.playbackDuration = previous.playbackDuration;
}
break;
}
}
public finishTuplet(): void {
const previousBeat: Beat | null = this.previousBeat;
let currentTupletGroup: TupletGroup | null = previousBeat ? previousBeat.tupletGroup : null;
if (this.hasTuplet || (this.graceType !== GraceType.None && currentTupletGroup)) {
if (!previousBeat || !currentTupletGroup || !currentTupletGroup.check(this)) {
currentTupletGroup = new TupletGroup(this.voice);
currentTupletGroup.check(this);
}
this.tupletGroup = currentTupletGroup;
}
const barDuration = this.voice.bar.masterBar.calculateDuration(false);
const validBeatAutomations: Automation[] = [];
for (const automation of this.automations) {
if (automation.ratioPosition === 0) {
automation.ratioPosition = this.playbackStart / barDuration;
}
// we store tempo automations only on masterbar level
if (automation.type !== AutomationType.Tempo) {
validBeatAutomations.push(automation);
}
}
this.automations = validBeatAutomations;
}
public finish(settings: Settings, sharedDataBag: Map<string, unknown> | null = null): void {
if (
this.getAutomation(AutomationType.Instrument) === null &&
this.index === 0 &&
this.voice.index === 0 &&
this.voice.bar.index === 0 &&
this.voice.bar.staff.index === 0
) {
this.automations.push(
Automation.buildInstrumentAutomation(false, 0, this.voice.bar.staff.track.playbackInfo.program)
);
}
switch (this.graceType) {
case GraceType.OnBeat:
case GraceType.BeforeBeat:
const numberOfGraceBeats: number = this.graceGroup!.beats.length;
// set right duration for beaming/display
if (numberOfGraceBeats === 1) {
this.duration = Duration.Eighth;
} else if (numberOfGraceBeats === 2) {
this.duration = Duration.Sixteenth;
} else {
this.duration = Duration.ThirtySecond;
}
break;
}
if (this.brushType === BrushType.None) {
this.brushDuration = 0;
}
const tremolo = this.tremoloPicking;
if (tremolo !== undefined) {
if (tremolo.marks < TremoloPickingEffect.minMarks || tremolo.marks > TremoloPickingEffect.maxMarks) {
this.tremoloPicking = undefined;
}
}
const displayMode: NotationMode = !settings ? NotationMode.GuitarPro : settings.notation.notationMode;
let isGradual: boolean = this.text === 'grad' || this.text === 'grad.';
if (isGradual && displayMode === NotationMode.SongBook) {
this.text = '';
}
let needCopyBeatForBend: boolean = false;
this.minNote = null;
this.maxNote = null;
this.minStringNote = null;
this.maxStringNote = null;
let visibleNotes: number = 0;
let isEffectSlurBeat: boolean = false;
for (let i: number = 0, j: number = this.notes.length; i < j; i++) {
const note: Note = this.notes[i];
note.dynamics = this.dynamics;
note.finish(settings, sharedDataBag);
if (note.isLetRing) {
this.isLetRing = true;
}
if (note.isPalmMute) {
this.isPalmMute = true;
}
if (displayMode === NotationMode.SongBook && note.hasBend && this.graceType !== GraceType.BendGrace) {
if (!note.isTieOrigin) {
switch (note.bendType) {
case BendType.Bend: