@@ -147,19 +147,17 @@ public void delete() {
147
147
148
148
public void render (final Matrix4fStack positionMatrix ) {
149
149
final int height = ThinGL .getWindowFramebufferHeight ();
150
-
151
150
this .renderedNotes = 0 ;
152
151
this .updatePianoKeyPositions ();
153
152
154
153
this .drawNotes (positionMatrix );
154
+ GlobalObjects .GLOBAL_BATCH .draw ();
155
155
156
156
positionMatrix .pushMatrix ();
157
157
positionMatrix .translate (0 , height - (int ) (height / PIANO_HEIGHT_DIVIDER ), 0 );
158
158
this .drawPiano (positionMatrix );
159
159
positionMatrix .popMatrix ();
160
-
161
160
this .drawDebugText (positionMatrix );
162
-
163
161
GlobalObjects .GLOBAL_BATCH .draw ();
164
162
}
165
163
@@ -169,11 +167,10 @@ private void drawNotes(final Matrix4fStack positionMatrix) {
169
167
final float whiteKeyWidth = (float ) width / WHITE_PIANO_KEY_COUNT ;
170
168
final float blackKeyWidth = whiteKeyWidth * BLACK_KEY_WIDTH_RATIO ;
171
169
final float noteSize = 16 * Math .max (1 , width / 960 );
172
- final float noteSquishFactor = 1F ;
173
170
174
171
final Song song = this .songPlayer .getSong ();
175
- final int tickWindow = MathUtils .ceilInt (height / ( noteSize / noteSquishFactor ) );
176
- final int currentTick = this .songPlayer .getTick ();
172
+ final int tickWindow = MathUtils .ceilInt (height / noteSize );
173
+ final int currentTick = this .songPlayer .getTick () - 1 ; // SongPlayer advances the tick immediately after playing the previous one
177
174
final int endTick = currentTick + tickWindow ;
178
175
final float ticksPerSecond = this .songPlayer .getCurrentTicksPerSecond ();
179
176
final long lastTickTime = this .songPlayer .getLastTickTime ();
@@ -182,7 +179,8 @@ private void drawNotes(final Matrix4fStack positionMatrix) {
182
179
final float tickProgress = !paused ? MathUtils .clamp (timeSinceLastTick / (1_000_000_000F / ticksPerSecond ), 0F , 1F ) : 0F ;
183
180
184
181
Renderer2D .INSTANCE .beginGlobalBuffering ();
185
- for (int tick = endTick ; tick >= currentTick ; tick --) {
182
+ for (int tick = endTick ; tick >= currentTick - 1 ; tick --) {
183
+ final float y = height - (tick - currentTick + 1 - tickProgress ) * noteSize ;
186
184
for (Note note : song .getNotes ().getOrEmpty (tick )) {
187
185
final int nbsKey = note .getNbsKey ();
188
186
if (nbsKey < 0 || nbsKey >= this .pianoKeyPositions .length ) {
@@ -195,7 +193,6 @@ private void drawNotes(final Matrix4fStack positionMatrix) {
195
193
x += blackKeyWidth / 2F ;
196
194
}
197
195
x -= noteSize / 2F ;
198
- final float y = height - (tick - currentTick + 1 - tickProgress ) * noteSize / noteSquishFactor ;
199
196
200
197
final float alpha = MathUtils .clamp (note .getVolume (), 0.25F , 1F );
201
198
if (note .getInstrument () instanceof MinecraftInstrument instrument ) {
@@ -221,6 +218,18 @@ private void drawNotes(final Matrix4fStack positionMatrix) {
221
218
}
222
219
this .renderedNotes ++;
223
220
}
221
+ if (song .getTempoEvents ().get (tick ) != 0 ) {
222
+ final float bottomY = y + noteSize ;
223
+ final float tps = song .getTempoEvents ().get (tick );
224
+ final String tempoString = "Tempo: " + String .format ("%.2f" , tps ) + " t/s" ;
225
+
226
+ this .textRenderer .setGlobalScale (ThinGL .getWindowFramebufferWidth () / 2000F );
227
+ final float textHeight = this .textRenderer .calculateHeight (tempoString );
228
+ this .textRenderer .renderString (positionMatrix , GlobalObjects .GLOBAL_BATCH , tempoString , 10 , bottomY - textHeight - 2 , 0 , Color .WHITE );
229
+ this .textRenderer .setGlobalScale (1F );
230
+
231
+ Renderer2D .INSTANCE .filledRectangle (positionMatrix , 0 , bottomY , width , bottomY + 1 , Color .WHITE .withAlpha (100 ));
232
+ }
224
233
}
225
234
Renderer2D .INSTANCE .endBuffering ();
226
235
}
@@ -296,6 +305,9 @@ private void drawDebugText(final Matrix4fStack positionMatrix) {
296
305
this .textRenderer .renderString (positionMatrix , GlobalObjects .GLOBAL_BATCH , "Position: " + currentPosition + " / " + this .songPlayer .getSong ().getHumanReadableLength (), 5 , textY , 0 , Color .WHITE );
297
306
textY += this .textRenderer .getPaddedHeight ();
298
307
308
+ this .textRenderer .renderString (positionMatrix , GlobalObjects .GLOBAL_BATCH , "Tempo: " + String .format ("%.2f" , this .songPlayer .getCurrentTicksPerSecond ())+ " t/s" , 5 , textY , 0 , Color .WHITE );
309
+ textY += this .textRenderer .getPaddedHeight ();
310
+
299
311
if (this .songPlayer .getSoundSystem () != null ) {
300
312
this .textRenderer .renderString (positionMatrix , GlobalObjects .GLOBAL_BATCH , this .songPlayer .getSoundSystem ().getStatusLine (), 5 , textY , 0 , Color .WHITE );
301
313
textY += this .textRenderer .getPaddedHeight ();
0 commit comments