Tweaks to KeyboardView note drawing

Fixed a bug that was letting some white show. Also changed color of
black keys to gray, as it fit the design better.
master
Raph Levien 11 years ago
parent c7c16b022f
commit f9907cce2f
  1. 81
      android/src/com/levien/synthesizer/android/widgets/keyboard/KeyboardSpec.java
  2. 6
      android/src/com/levien/synthesizer/android/widgets/keyboard/KeyboardView.java

@ -40,63 +40,57 @@ public class KeyboardSpec {
public static KeyboardSpec make2Row() {
KeyboardSpec ks = new KeyboardSpec(12, 84, 24);
final int w = Color.WHITE;
final int b = Color.BLACK;
ks.addKey(0, 12, 12, 12, w); // C
ks.addKey(6, 0, 12, 12, b); // C#
ks.addKey(12, 12, 12, 12, w); // D
ks.addKey(18, 0, 12, 12, b); // D#
ks.addKey(24, 12, 12, 12, w); // E
ks.addKey(36, 12, 12, 12, w); // F
ks.addKey(42, 0, 12, 12, b); // F#
ks.addKey(48, 12, 12, 12, w); // G
ks.addKey(54, 0, 12, 12, b); // G#
ks.addKey(60, 12, 12, 12, w); // A
ks.addKey(66, 0, 12, 12, b); // A#
ks.addKey(72, 12, 12, 12, w); // B
ks.addKey(0, 12, 12, 12, W); // C
ks.addKey(6, 0, 12, 12, B); // C#
ks.addKey(12, 12, 12, 12, W); // D
ks.addKey(18, 0, 12, 12, B); // D#
ks.addKey(24, 12, 12, 12, W); // E
ks.addKey(36, 12, 12, 12, W); // F
ks.addKey(42, 0, 12, 12, B); // F#
ks.addKey(48, 12, 12, 12, W); // G
ks.addKey(54, 0, 12, 12, B); // G#
ks.addKey(60, 12, 12, 12, W); // A
ks.addKey(66, 0, 12, 12, B); // A#
ks.addKey(72, 12, 12, 12, W); // B
return ks;
}
public static KeyboardSpec make3Row() {
KeyboardSpec ks = new KeyboardSpec(24, 84, 32);
final int w = Color.WHITE;
final int b = Color.BLACK;
for (int oct = 0; oct < 2; oct++) {
float x0 = 42 * oct;
float y1 = 20 - 12 * oct;
float y2 = 28 - y1;
ks.addKey(x0 + 0, y1, 12, 12, w); // C
ks.addKey(x0 + 4, 0, 8, 8, b); // C#
ks.addKey(x0 + 6, y2, 12, 12, w); // D
ks.addKey(x0 + 12, 0, 8, 8, b); // D#
ks.addKey(x0 + 12, y1, 12, 12, w); // E
ks.addKey(x0 + 18, y2, 12, 12, w); // F
ks.addKey(x0 + 21, 0, 8, 8, b); // F#
ks.addKey(x0 + 24, y1, 12, 12, w); // G
ks.addKey(x0 + 29, 0, 8, 8, b); // G#
ks.addKey(x0 + 30, y2, 12, 12, w); // A
ks.addKey(x0 + 37, 0, 8, 8, b); // A#
ks.addKey(x0 + 36, y1, 12, 12, w); // B
ks.addKey(x0 + 0, y1, 12, 12, W); // C
ks.addKey(x0 + 4, 0, 8, 8, B); // C#
ks.addKey(x0 + 6, y2, 12, 12, W); // D
ks.addKey(x0 + 12, 0, 8, 8, B); // D#
ks.addKey(x0 + 12, y1, 12, 12, W); // E
ks.addKey(x0 + 18, y2, 12, 12, W); // F
ks.addKey(x0 + 21, 0, 8, 8, B); // F#
ks.addKey(x0 + 24, y1, 12, 12, W); // G
ks.addKey(x0 + 29, 0, 8, 8, B); // G#
ks.addKey(x0 + 30, y2, 12, 12, W); // A
ks.addKey(x0 + 37, 0, 8, 8, B); // A#
ks.addKey(x0 + 36, y1, 12, 12, W); // B
}
return ks;
}
public static KeyboardSpec make3RowChromatic() {
KeyboardSpec ks = new KeyboardSpec(12, 12, 9);
final int w = Color.WHITE;
final int b = Color.BLACK;
ks.addKey(0, 6, 3, 3, w); // C
ks.addKey(1, 3, 3, 3, b); // C#
ks.addKey(2, 0, 3, 3, w); // D
ks.addKey(3, 6, 3, 3, b); // D#
ks.addKey(4, 3, 3, 3, w); // E
ks.addKey(5, 0, 3, 3, w); // F
ks.addKey(6, 6, 3, 3, b); // F#
ks.addKey(7, 3, 3, 3, w); // G
ks.addKey(8, 0, 3, 3, b); // G#
ks.addKey(9, 6, 3, 3, w); // A
ks.addKey(10, 3, 3, 3, b); // A#
ks.addKey(11, 0, 3, 3, w); // B
ks.addKey(0, 6, 3, 3, W); // C
ks.addKey(1, 3, 3, 3, B); // C#
ks.addKey(2, 0, 3, 3, W); // D
ks.addKey(3, 6, 3, 3, B); // D#
ks.addKey(4, 3, 3, 3, W); // E
ks.addKey(5, 0, 3, 3, W); // F
ks.addKey(6, 6, 3, 3, B); // F#
ks.addKey(7, 3, 3, 3, W); // G
ks.addKey(8, 0, 3, 3, B); // G#
ks.addKey(9, 6, 3, 3, W); // A
ks.addKey(10, 3, 3, 3, B); // A#
ks.addKey(11, 0, 3, 3, W); // B
return ks;
}
@ -117,4 +111,7 @@ public class KeyboardSpec {
public float height;
public float maxX;
private int ix_;
private static final int B = Color.GRAY;
private static final int W = Color.WHITE;
}

@ -102,8 +102,8 @@ public class KeyboardView extends View {
float x = x0 + ((i / keyboardSpec_.keys.length) * keyboardSpec_.repeatWidth +
ks.rect.left) * xscale;
float y = y0 + ks.rect.top * yscale;
float width = ks.rect.width() * xscale - strokeWidth_;
float height = ks.rect.height() * yscale - strokeWidth_;
float width = ks.rect.width() * xscale;
float height = ks.rect.height() * yscale;
int note = i + firstKey_;
int vel = noteStatus_[note];
if (vel == 0) {
@ -123,7 +123,7 @@ public class KeyboardView extends View {
if (ks.color != Color.BLACK) {
paint_.setColor(Color.BLACK);
paint_.setStyle(Style.STROKE);
canvas.drawRect(x, y, x + width + strokeWidth_, y + height + strokeWidth_, paint_);
canvas.drawRect(x, y, x + width, y + height, paint_);
} else {
paint_.setColor(Color.WHITE);
}

Loading…
Cancel
Save