@@ -111,6 +111,9 @@ export class SongStatsGenerator {
111111 const note = layer . notes [ tickStr ] ;
112112 const tick = parseInt ( tickStr ) ;
113113
114+ // Skip if note is undefined
115+ if ( ! note ) continue ;
116+
114117 if ( tick > tickCount ) {
115118 tickCount = tick ;
116119 }
@@ -120,7 +123,6 @@ export class SongStatsGenerator {
120123 layerCount = layerId ;
121124 }
122125
123- // @ts -ignore //TODO: fix this
124126 const effectivePitch = note . key + note . pitch / 100 ;
125127
126128 // Differences between Note Block Studio and this implementation:
@@ -148,8 +150,9 @@ export class SongStatsGenerator {
148150 // the default Minecraft sounds are enough to play the song (i.e. you can play it using only
149151 // a custom sounds.json in a resource pack).
150152
151- // @ts -ignore //TODO: fix this
152- const instrumentKey = this . song . instruments . loaded [ note . instrument ] . key ; // F#4 = 45
153+ const instrument = this . song . instruments . loaded [ note . instrument ] ! ;
154+ if ( ! instrument ) continue ;
155+ const instrumentKey = instrument . key ; // F#4 = 45
153156 const minRange = 45 - ( instrumentKey - 45 ) - 12 ; // F#3 = 33
154157 const maxRange = 45 - ( instrumentKey - 45 ) + 12 ; // F#5 = 57
155158
@@ -158,15 +161,13 @@ export class SongStatsGenerator {
158161
159162 // Don't consider tempo changers as detuned notes or custom instruments
160163 const isTempoChanger = tempoChangerInstruments . includes (
161- // @ts -ignore //TODO: fix this
162164 note . instrument ,
163165 ) ;
164166
165- // @ts -ignore //TODO: fix this
166167 const hasDetune = note . pitch % 100 !== 0 ;
167168
168169 const usesCustomInstrument =
169- note . instrument >= this . song . instruments . firstCustomIndex ; // @ts -ignore //TODO: fix this
170+ note . instrument >= this . song . instruments . firstCustomIndex ;
170171
171172 if ( ! isTempoChanger ) {
172173 if ( isOutOfRange ) outOfRangeNoteCount ++ ;
@@ -176,7 +177,6 @@ export class SongStatsGenerator {
176177 incompatibleNoteCount ++ ;
177178 }
178179
179- // @ts -ignore //TODO: fix this
180180 instrumentNoteCounts [ note . instrument ] ++ ;
181181 noteCount ++ ;
182182 }
@@ -227,15 +227,17 @@ export class SongStatsGenerator {
227227 const note = layer . notes [ tickStr ] ;
228228 const tick = parseInt ( tickStr ) ;
229229
230- // @ts -ignore //TODO: fix this // Not a tempo changer
230+ // Skip if note is undefined
231+ if ( ! note ) continue ;
232+
233+ // Not a tempo changer
231234 if ( ! tempoChangerInstruments . includes ( note . instrument ) ) continue ;
232235
233236 // The tempo change isn't effective if there's another tempo changer in the same tick,
234237 // so we iterate layers bottom to top and skip the block if a tempo changer has already
235238 // been found in this tick
236239 if ( tick in tempoSegments ) continue ;
237240
238- // @ts -ignore //TODO: fix this
239241 const tempo = Math . abs ( note . pitch ) / 15 ; // note pitch = BPM = (t/s) * 15
240242 tempoSegments [ tick ] = tempo ;
241243 }
@@ -273,10 +275,11 @@ export class SongStatsGenerator {
273275 const currTick = tempoChangeTicks [ i ] ;
274276 const nextTick = tempoChangeTicks [ i + 1 ] ;
275277
276- // @ts -ignore //TODO: fix this
278+ if ( currTick === undefined || nextTick === undefined ) continue ;
279+
277280 const currTempo = tempoSegments [ currTick ] ;
281+ if ( currTempo === undefined ) continue ;
278282
279- // @ts -ignore //TODO: fix this
280283 const segmentDurationTicks = nextTick - currTick ;
281284 const timePerTick = 1 / currTempo ;
282285
0 commit comments