@@ -25,7 +25,6 @@ import { Logger } from '@src/alphatab';
25
25
import { Fermata , FermataType } from '@src/model/Fermata' ;
26
26
import { DynamicValue } from '@src/model/DynamicValue' ;
27
27
import { Ottavia } from '@src/model/Ottavia' ;
28
- import { MidiUtils } from '@src/midi/MidiUtils' ;
29
28
import { KeySignature } from '@src/model/KeySignature' ;
30
29
31
30
class DrawObject {
@@ -54,9 +53,9 @@ class GuitarDrawObject extends DrawObject {
54
53
public chord : Chord = new Chord ( ) ;
55
54
}
56
55
57
- class SlurDrawObject extends DrawObject { }
56
+ class SlurDrawObject extends DrawObject { }
58
57
59
- class WavyLineDrawObject extends DrawObject { }
58
+ class WavyLineDrawObject extends DrawObject { }
60
59
61
60
class TupletBracketDrawObject extends DrawObject {
62
61
public number : number = 0 ;
@@ -76,7 +75,7 @@ class OctaveClefDrawObject extends DrawObject {
76
75
public octave : number = 1 ;
77
76
}
78
77
79
- class TrillDrawObject extends DrawObject { }
78
+ class TrillDrawObject extends DrawObject { }
80
79
81
80
class StaffLayout {
82
81
public defaultClef : Clef = Clef . G2 ;
@@ -670,7 +669,7 @@ export class CapellaParser {
670
669
break ;
671
670
case 'repEnd' :
672
671
this . _currentVoiceState . repeatEnd = this . _currentBar . masterBar ;
673
- if ( this . _currentBar . masterBar . repeatCount < this . _currentVoiceState . repeatCount ) {
672
+ if ( this . _currentBar . masterBar . repeatCount < this . _currentVoiceState . repeatCount ) {
674
673
this . _currentBar . masterBar . repeatCount = this . _currentVoiceState . repeatCount ;
675
674
}
676
675
this . parseBarDrawObject ( c ) ;
@@ -687,7 +686,7 @@ export class CapellaParser {
687
686
break ;
688
687
case 'repEndBegin' :
689
688
this . _currentVoiceState . repeatEnd = this . _currentBar . masterBar ;
690
- if ( this . _currentBar . masterBar . repeatCount < this . _currentVoiceState . repeatCount ) {
689
+ if ( this . _currentBar . masterBar . repeatCount < this . _currentVoiceState . repeatCount ) {
691
690
this . _currentBar . masterBar . repeatCount = this . _currentVoiceState . repeatCount ;
692
691
}
693
692
this . parseBarDrawObject ( c ) ;
@@ -728,11 +727,11 @@ export class CapellaParser {
728
727
}
729
728
break ;
730
729
case 'rest' :
731
- const restBeats = this . parseRestDurations (
730
+ const restBeat = this . parseRestDurations (
732
731
this . _currentBar ,
733
732
c . findChildElement ( 'duration' ) !
734
733
) ;
735
- for ( const restBeat of restBeats ) {
734
+ if ( restBeat ) {
736
735
this . initFromPreviousBeat ( restBeat , this . _currentVoice ) ;
737
736
restBeat . updateDurations ( ) ;
738
737
this . _currentVoiceState . currentPosition += restBeat . playbackDuration ;
@@ -980,7 +979,7 @@ export class CapellaParser {
980
979
private applyVolta ( obj : VoltaDrawObject ) {
981
980
if ( obj . lastNumber > 0 ) {
982
981
this . _currentVoiceState . repeatCount = obj . lastNumber ;
983
- if ( this . _currentVoiceState . repeatEnd &&
982
+ if ( this . _currentVoiceState . repeatEnd &&
984
983
this . _currentVoiceState . repeatEnd . repeatCount < this . _currentVoiceState . repeatCount ) {
985
984
this . _currentVoiceState . repeatEnd . repeatCount = this . _currentVoiceState . repeatCount ;
986
985
}
@@ -1000,7 +999,7 @@ export class CapellaParser {
1000
999
this . _currentBar . masterBar . alternateEndings = alternateEndings ;
1001
1000
} else if ( obj . lastNumber > 0 ) {
1002
1001
this . _currentBar . masterBar . alternateEndings = 0x01 << ( obj . lastNumber - 1 ) ;
1003
- } else if ( obj . firstNumber > 0 ) {
1002
+ } else if ( obj . firstNumber > 0 ) {
1004
1003
this . _currentBar . masterBar . alternateEndings = 0x01 << ( obj . firstNumber - 1 ) ;
1005
1004
}
1006
1005
}
@@ -1024,50 +1023,26 @@ export class CapellaParser {
1024
1023
}
1025
1024
}
1026
1025
1027
- private parseRestDurations ( bar : Bar , element : XmlNode ) : Beat [ ] {
1026
+ private parseRestDurations ( bar : Bar , element : XmlNode ) : Beat | null {
1028
1027
const durationBase = element . getAttribute ( 'base' ) ;
1029
1028
if ( durationBase . indexOf ( '/' ) !== - 1 ) {
1030
1029
let restBeat = new Beat ( ) ;
1031
1030
restBeat . beamingMode = this . _beamingMode ;
1032
1031
this . parseDuration ( bar , restBeat , element ) ;
1033
- return [ restBeat ] ;
1032
+ return restBeat ;
1034
1033
}
1035
1034
1036
1035
// for
1037
1036
const fullBars = parseInt ( durationBase ) ;
1038
1037
if ( fullBars === 1 ) {
1039
- let restBeats : Beat [ ] = [ ] ;
1040
- let remainingTicks = bar . masterBar . calculateDuration ( false ) * fullBars ;
1041
- let currentRestDuration = Duration . Whole ;
1042
- let currentRestDurationTicks = MidiUtils . toTicks ( currentRestDuration ) ;
1043
- while ( remainingTicks > 0 ) {
1044
- // reduce to the duration that fits into the remaining time
1045
- while (
1046
- currentRestDurationTicks > remainingTicks &&
1047
- currentRestDuration < Duration . TwoHundredFiftySixth
1048
- ) {
1049
- currentRestDuration = ( ( currentRestDuration as number ) * 2 ) as Duration ;
1050
- currentRestDurationTicks = MidiUtils . toTicks ( currentRestDuration ) ;
1051
- }
1052
-
1053
- // no duration will fit anymore
1054
- if ( currentRestDurationTicks > remainingTicks ) {
1055
- break ;
1056
- }
1057
-
1058
- let restBeat = new Beat ( ) ;
1059
- restBeat . beamingMode = this . _beamingMode ;
1060
- restBeat . duration = currentRestDuration ;
1061
- restBeats . push ( restBeat ) ;
1062
-
1063
- remainingTicks -= currentRestDurationTicks ;
1064
- }
1065
-
1066
- return restBeats ;
1038
+ let restBeat = new Beat ( ) ;
1039
+ restBeat . beamingMode = this . _beamingMode ;
1040
+ restBeat . duration = Duration . Whole ;
1041
+ return restBeat ;
1067
1042
} else {
1068
1043
// TODO: multibar rests
1069
1044
Logger . warning ( 'Importer' , `Multi-Bar rests are not supported` ) ;
1070
- return [ ] ;
1045
+ return null ;
1071
1046
}
1072
1047
}
1073
1048
0 commit comments