@@ -230,33 +230,46 @@ private void drawPiano(final Matrix4fStack positionMatrix) {
230
230
final float blackKeyWidth = whiteKeyWidth * BLACK_KEY_WIDTH_RATIO ;
231
231
232
232
Renderer2D .INSTANCE .beginGlobalBuffering ();
233
- Renderer2D .INSTANCE .filledRect (positionMatrix , 0 , 0 , width , height , Color .BLACK );
234
233
235
234
final float keyLineOffset = height / KEY_LINE_OFFSET_RATIO ;
236
235
for (int nbsKey = 0 ; nbsKey < this .pianoKeyPositions .length ; nbsKey ++) {
237
236
final float x = this .pianoKeyPositions [nbsKey ];
238
237
final float progress = this .pianoKeyLastColors [nbsKey ] != null ? MathUtils .clamp ((System .nanoTime () - this .pianoKeyLastPlayed [nbsKey ]) / (float ) KEY_ANIMATION_DURATION , 0F , 1F ) : 1F ;
239
238
final float colorProgress = progress < 0.5F ? 0 : (progress - 0.5F ) * 2 ;
240
239
final float pressOffset = height / KEY_PRESS_DEPTH_RATIO - height / KEY_PRESS_DEPTH_RATIO * (progress < 0.5F ? 1F - progress : progress );
240
+ final String noteName = this .getNoteName (nbsKey );
241
241
if (!this .isBlackKey (nbsKey )) {
242
+ Renderer2D .INSTANCE .filledRect (positionMatrix , x , pressOffset , x + 1 , height , Color .BLACK );
243
+ Renderer2D .INSTANCE .filledRect (positionMatrix , x + whiteKeyWidth - 1 , pressOffset , x + whiteKeyWidth , height , Color .BLACK );
242
244
Renderer2D .INSTANCE .filledRect (positionMatrix , x + 1 , pressOffset , x + whiteKeyWidth - 1 , height , Color .WHITE );
243
245
if (this .pianoKeyLastColors [nbsKey ] != null ) {
244
246
Renderer2D .INSTANCE .filledRect (positionMatrix , x + 1 , pressOffset , x + whiteKeyWidth - 1 , height , this .pianoKeyLastColors [nbsKey ].withAlpha (Math .round (PRESSED_KEY_COLOR_ALPHA * (1 - colorProgress ))));
245
247
}
246
248
Renderer2D .INSTANCE .filledRect (positionMatrix , x , height - keyLineOffset + pressOffset , x + whiteKeyWidth , height - keyLineOffset - KEY_LINE_HEIGHT + pressOffset , Color .GRAY );
249
+
250
+ this .textRenderer .setGlobalScale (ThinGL .getWindowFramebufferWidth () / 2745F ); // 0,7
251
+ final float nameWidth = this .textRenderer .calculateWidth (noteName );
252
+ this .textRenderer .renderString (positionMatrix , GlobalObjects .GLOBAL_BATCH , this .getNoteName (nbsKey ), x + whiteKeyWidth / 2 - nameWidth / 2 , height - keyLineOffset - KEY_LINE_HEIGHT + pressOffset - this .textRenderer .getPaddedHeight (), 0 , Color .BLACK );
253
+ this .textRenderer .setGlobalScale (1F );
247
254
} else {
248
255
positionMatrix .pushMatrix ();
249
256
positionMatrix .translate (0 , 0 , 1 );
250
- Renderer2D .INSTANCE .filledRect (positionMatrix , x , pressOffset , x + blackKeyWidth , height * BLACK_KEY_HEIGHT_RATIO , Color .BLACK );
257
+
258
+ Renderer2D .INSTANCE .filledRect (positionMatrix , x , pressOffset - height / KEY_PRESS_DEPTH_RATIO / 2 , x + blackKeyWidth , height * BLACK_KEY_HEIGHT_RATIO , Color .BLACK );
251
259
if (this .pianoKeyLastColors [nbsKey ] != null ) {
252
- Renderer2D .INSTANCE .filledRect (positionMatrix , x , pressOffset , x + blackKeyWidth , height * BLACK_KEY_HEIGHT_RATIO , this .pianoKeyLastColors [nbsKey ].withAlpha (Math .round (PRESSED_KEY_COLOR_ALPHA * (1 - colorProgress ))));
260
+ Renderer2D .INSTANCE .filledRect (positionMatrix , x , pressOffset - height / KEY_PRESS_DEPTH_RATIO / 2 , x + blackKeyWidth , height * BLACK_KEY_HEIGHT_RATIO , this .pianoKeyLastColors [nbsKey ].withAlpha (Math .round (PRESSED_KEY_COLOR_ALPHA * (1 - colorProgress ))));
253
261
}
254
262
Renderer2D .INSTANCE .filledRect (positionMatrix , x , height * BLACK_KEY_HEIGHT_RATIO - keyLineOffset + pressOffset , x + blackKeyWidth , height * BLACK_KEY_HEIGHT_RATIO - keyLineOffset - KEY_LINE_HEIGHT + pressOffset , Color .GRAY );
263
+
264
+ this .textRenderer .setGlobalScale (ThinGL .getWindowFramebufferWidth () / 4000F ); // 0,48
265
+ final float nameWidth = this .textRenderer .calculateWidth (noteName );
266
+ this .textRenderer .renderString (positionMatrix , GlobalObjects .GLOBAL_BATCH , this .getNoteName (nbsKey ), x + blackKeyWidth / 2 - nameWidth / 2 , height * BLACK_KEY_HEIGHT_RATIO - keyLineOffset - KEY_LINE_HEIGHT + pressOffset - this .textRenderer .getPaddedHeight (), 0 , Color .WHITE );
267
+ this .textRenderer .setGlobalScale (1F );
268
+
255
269
positionMatrix .popMatrix ();
256
270
}
257
271
}
258
272
259
- Renderer2D .INSTANCE .filledRect (positionMatrix , 0 , -1 , width , 1 , Color .RED );
260
273
Renderer2D .INSTANCE .endBuffering ();
261
274
}
262
275
@@ -298,6 +311,27 @@ private boolean isBlackKey(final int nbsKey) {
298
311
return noteInOctave == 1 || noteInOctave == 3 || noteInOctave == 6 || noteInOctave == 8 || noteInOctave == 10 ;
299
312
}
300
313
314
+ private String getNoteName (final int nbsKey ) {
315
+ final int noteInOctave = nbsKey % 12 ;
316
+ String noteName = switch (noteInOctave ) {
317
+ case 0 -> "A" ;
318
+ case 1 -> "A#" ;
319
+ case 2 -> "B" ;
320
+ case 3 -> "C" ;
321
+ case 4 -> "C#" ;
322
+ case 5 -> "D" ;
323
+ case 6 -> "D#" ;
324
+ case 7 -> "E" ;
325
+ case 8 -> "F" ;
326
+ case 9 -> "F#" ;
327
+ case 10 -> "G" ;
328
+ case 11 -> "G#" ;
329
+ default -> throw new IllegalStateException ("Unexpected value: " + noteInOctave );
330
+ };
331
+ noteName += (nbsKey + NbsDefinitions .NBS_LOWEST_MIDI_KEY ) / 12 - 1 ;
332
+ return noteName ;
333
+ }
334
+
301
335
private void updatePianoKeyPositions () {
302
336
Arrays .fill (this .pianoKeyPositions , 0F );
303
337
final int width = ThinGL .getWindowFramebufferWidth ();
0 commit comments