-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNote.java~
99 lines (87 loc) · 2.3 KB
/
Note.java~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import java.util.*;
/**
*
* @author mwillson
*/
public class Note {
private int pitch, freq = 440;
private int durnumerator, durdenominator;
public Note (String p, int durnum, int durden){
switch(p) {
case "A": pitch = 0;
break;
case "B": pitch = 2;
break;
case "C": pitch = 3;
break;
case "D": pitch = 5;
break;
case "E": pitch = 7;
break;
case "F": pitch = 8;
break;
case "G": pitch = 10;
break;
case "A#": pitch = 1;
break;
case "Bb": pitch = 1;
break;
case "C#": pitch = 4;
break;
case "Db": pitch = 4;
break;
case "D#": pitch = 6;
break;
case "Eb": pitch = 6;
break;
case "F#": pitch = 9;
break;
case "Gb": pitch = 9;
break;
case "G#": pitch = 11;
break;
case "Ab": pitch = 11;
break;
}
durnumerator = durnum;
durdenominator = durden;
}
public int getPitch(){
return pitch;
}
public double getDurationNumerator(){
return durnumerator;
}
public int getDurationDenominator(){
return durdenominator;
}
/*
* return a usable matrix representation of the pitch of the note
*/
public char[] pitchMatrix () {
char[] m = new char[12];
for(int i = 0; i < 12; i++){
if(i == pitch){
m[i] = '1';
}else {
m[i] = '0';
}
}
return m;
}
/*
* return a usable matrix representation of the duration of the note
*/
public char[] durationMatrix () {
char[] m = new char[24];
for(int i = 0; i < 12; i++) {
if((i+1) == durnumerator) m[i] = '1';
else m[i] = '0';
}
for(int i = 12; i < 24; i++) {
if((i-11) == durdenominator) m[i] = '1';
else m[i] = '0';
}
return m;
}
}