Java Enumeration of Musical Notes
Posted
by
Crupler
on Stack Overflow
See other posts from Stack Overflow
or by Crupler
Published on 2012-11-03T04:25:38Z
Indexed on
2012/11/03
5:01 UTC
Read the original article
Hit count: 223
How would you create an enumeration of the musical notes in Java, with each notes having an octave and then a keyed variable? This is what I have so far...
public enum Notes
{
c,
cS,
d,
dS,
e,
f,
fS,
g,
gS,
a,
aS,
b;
int octave;
boolean isPlaying;
}
So when I access the enums in my code I write something like this...
Notes.c.octave = 4;
Notes.c.isPlaying = true;
Now here is my question: How can I have an isPlaying boolean for each note in each octave?
Like so:
Notes.c.octave.isPlaying = true;
Or would I have to go like:
public enum Notes
{
c1,
cS1,
d1,
dS1,
e1,
f1,
fS1,
g1,
gS1,
a1,
aS1,
b1
c2,
cS2,
d2,
dS2,
e2,
f2,
fS2,
g2,
gS2,
a2,
aS2,
b2;
etc...
boolean isPlaying;
}
Thank you in advance for taking your time to answer this question!
© Stack Overflow or respective owner