@@ -111,6 +111,9 @@ export class SongStatsGenerator {
111
111
const note = layer . notes [ tickStr ] ;
112
112
const tick = parseInt ( tickStr ) ;
113
113
114
+ // Skip if note is undefined
115
+ if ( ! note ) continue ;
116
+
114
117
if ( tick > tickCount ) {
115
118
tickCount = tick ;
116
119
}
@@ -120,7 +123,6 @@ export class SongStatsGenerator {
120
123
layerCount = layerId ;
121
124
}
122
125
123
- // @ts -ignore //TODO: fix this
124
126
const effectivePitch = note . key + note . pitch / 100 ;
125
127
126
128
// Differences between Note Block Studio and this implementation:
@@ -148,8 +150,9 @@ export class SongStatsGenerator {
148
150
// the default Minecraft sounds are enough to play the song (i.e. you can play it using only
149
151
// a custom sounds.json in a resource pack).
150
152
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
153
156
const minRange = 45 - ( instrumentKey - 45 ) - 12 ; // F#3 = 33
154
157
const maxRange = 45 - ( instrumentKey - 45 ) + 12 ; // F#5 = 57
155
158
@@ -158,15 +161,13 @@ export class SongStatsGenerator {
158
161
159
162
// Don't consider tempo changers as detuned notes or custom instruments
160
163
const isTempoChanger = tempoChangerInstruments . includes (
161
- // @ts -ignore //TODO: fix this
162
164
note . instrument ,
163
165
) ;
164
166
165
- // @ts -ignore //TODO: fix this
166
167
const hasDetune = note . pitch % 100 !== 0 ;
167
168
168
169
const usesCustomInstrument =
169
- note . instrument >= this . song . instruments . firstCustomIndex ; // @ts -ignore //TODO: fix this
170
+ note . instrument >= this . song . instruments . firstCustomIndex ;
170
171
171
172
if ( ! isTempoChanger ) {
172
173
if ( isOutOfRange ) outOfRangeNoteCount ++ ;
@@ -176,7 +177,6 @@ export class SongStatsGenerator {
176
177
incompatibleNoteCount ++ ;
177
178
}
178
179
179
- // @ts -ignore //TODO: fix this
180
180
instrumentNoteCounts [ note . instrument ] ++ ;
181
181
noteCount ++ ;
182
182
}
@@ -227,15 +227,17 @@ export class SongStatsGenerator {
227
227
const note = layer . notes [ tickStr ] ;
228
228
const tick = parseInt ( tickStr ) ;
229
229
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
231
234
if ( ! tempoChangerInstruments . includes ( note . instrument ) ) continue ;
232
235
233
236
// The tempo change isn't effective if there's another tempo changer in the same tick,
234
237
// so we iterate layers bottom to top and skip the block if a tempo changer has already
235
238
// been found in this tick
236
239
if ( tick in tempoSegments ) continue ;
237
240
238
- // @ts -ignore //TODO: fix this
239
241
const tempo = Math . abs ( note . pitch ) / 15 ; // note pitch = BPM = (t/s) * 15
240
242
tempoSegments [ tick ] = tempo ;
241
243
}
@@ -273,10 +275,11 @@ export class SongStatsGenerator {
273
275
const currTick = tempoChangeTicks [ i ] ;
274
276
const nextTick = tempoChangeTicks [ i + 1 ] ;
275
277
276
- // @ts -ignore //TODO: fix this
278
+ if ( currTick === undefined || nextTick === undefined ) continue ;
279
+
277
280
const currTempo = tempoSegments [ currTick ] ;
281
+ if ( currTempo === undefined ) continue ;
278
282
279
- // @ts -ignore //TODO: fix this
280
283
const segmentDurationTicks = nextTick - currTick ;
281
284
const timePerTick = 1 / currTempo ;
282
285
0 commit comments