/Users/lyon/j4p/src/sound/KeyMap.java
|
1 /**
2 * Role of the Key map is to
3 * map a QWERTY keyboard into a musical
4 * keyboard.
5 * Input is a KeyChar
6 * output is a NoteNumber
7 * User: dlyon
8 * Date: Oct 6, 2003
9 * Time: 5:33:00 PM
10 * To change this template use Options | File Templates.
11 */
12 package sound;
13
14 public class KeyMap {
15 String keyString[] =
16 {"`1234567890-",
17 "qwertyuiop[]",
18 "asdfghjkl;'",
19 "zxcvbnm,./"
20 };
21 int scale[] = Scales.getScale(
22 Scales.WHOLE_NOTES, 0, 8);
23 int keyChars[] = new int[255];
24
25 public KeyMap() {
26 for (int i = 0; i < keyString.length; i++) {
27 assignScale(keyString[i].toCharArray(), i);
28 }
29 System.out.println("Scale is:");
30 println(scale);
31 }
32
33 public int getNoteNumber(int keyCharacter) {
34 System.out.println(keyChars[keyCharacter]);
35 return keyChars[keyCharacter];
36 }
37
38 public void assignScale(char row[], int rowNumber) {
39 for (int i = 0; i < row.length; i++) {
40 int nn = ((2 + rowNumber) * 12) + scale[i % scale.length];
41 System.out.println("assign key:"
42 + (row[i]) + "=" + nn);
43 keyChars[row[i]] = nn;
44 }
45 }
46
47 public void println(int a[]) {
48 for (int i = 0; i < a.length; i++) {
49 System.out.println(a[i]);
50 }
51 }
52
53 public void println(String s) {
54 System.out.println(s);
55 }
56
57 public static void main(String args[]) {
58 new KeyMap();
59 }
60
61 }
62