Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Highlight pressed key when using Midi keyboard

  • Loading branch information...
commit bd5d80646e08f11b72a112fde607221a5f01f841 1 parent f0b8fe0
Pal Szasz authored
View
1  src/com/space/piano/App.java
@@ -66,6 +66,7 @@ public App(String[] args) {
public void onKey(int note, boolean on) {
play(note, on);
mGame.onKey(note, on);
+ mWin.getKeyboard().onKey(note, on);
}
public void play(int note, boolean on) {
View
16 src/com/space/piano/Keyboard.java
@@ -109,12 +109,8 @@ protected void processKeyEvent(KeyEvent e) {
if (key != null) {
if (e.getID() == KeyEvent.KEY_PRESSED && !key.isPressed()) {
mApp.onKey(key.getNote(), true);
- key.setPressed(true);
- repaint();
} else if (e.getID() == KeyEvent.KEY_RELEASED) {
mApp.onKey(key.getNote(), false);
- key.setPressed(false);
- repaint();
}
}
e.consume();
@@ -137,12 +133,8 @@ protected void processMouseEvent(MouseEvent e) {
if (key != null) {
if (e.getID() == MouseEvent.MOUSE_PRESSED) {
mApp.onKey(key.getNote(), true);
- key.setPressed(true);
- repaint();
} else if (e.getID() == MouseEvent.MOUSE_RELEASED) {
mApp.onKey(key.getNote(), false);
- key.setPressed(false);
- repaint();
}
}
e.consume();
@@ -184,4 +176,12 @@ public boolean isKeyVisible(int midiNote) {
return midiNote >= getFirstNote() && midiNote <= getLastNote();
}
+ public void onKey(int note, boolean on) {
+ Key key = findKeyByNote(note);
+ if (key != null) {
+ key.setPressed(on);
+ repaint();
+ }
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.