Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. public class Note {
  2.  
  3. public enum Lengths {
  4. DOUBLE_WHOLE_NOTE(0.5f),
  5. ...
  6. SIXTYFOURTH_NOTE(64);
  7.  
  8. private float length;
  9.  
  10. Lengths(float length) {
  11.  
  12. this.length = length;
  13. }
  14.  
  15. public float getLength() {
  16.  
  17. return length;
  18. }
  19.  
  20. private static final Map<Float, Lengths> lookup = new HashMap<Float, Lengths>();
  21. static {
  22. for (Lengths length : Lengths.values())
  23. lookup.put(length.getLength(), length);
  24. }
  25.  
  26. public static Lengths get(float length) {
  27.  
  28. return lookup.get(length);
  29. }
  30.  
  31. }
  32.  
  33. public enum Names {
  34. C(0),
  35. ...
  36. REST(-1);
  37.  
  38. private final int number;
  39.  
  40. Names(int number) {
  41.  
  42. this.number = number;
  43. }
  44.  
  45. public int getValue() {
  46.  
  47. return number;
  48. }
  49.  
  50. private static final Map<Integer, Names> lookup = new HashMap<Integer, Names>();
  51. static {
  52. for (Names name : Names.values())
  53. lookup.put(name.getValue(), name);
  54. }
  55.  
  56. public static Names get(Integer value) {
  57.  
  58. return lookup.get(value);
  59. }
  60.  
  61. }
  62.  
  63. private int pitch;
  64. private float length;
  65.  
  66. public int getPitch() {
  67.  
  68. return pitch;
  69. }
  70.  
  71. public void setPitch(int pitch) {
  72.  
  73. this.pitch = pitch;
  74. }
  75.  
  76. public float getLength() {
  77.  
  78. return length;
  79. }
  80.  
  81. public void setLength(float length) {
  82.  
  83. this.length = length;
  84. }
  85.  
  86. private Note(int pitch, float length) {
  87.  
  88. this.length = length;
  89. this.pitch = pitch;
  90. }
  91.  
  92. public int getOctave() {
  93.  
  94. return (pitch / 12) - 5;
  95. }
  96.  
  97. public Note.Names getNameOfNote() {
  98.  
  99. return Names.get(this.getPitch() % 12);
  100. }
  101.  
  102. public Note.Lengths getLengthOfNote() {
  103.  
  104. return Lengths.get(this.getLength());
  105. }
  106.  
  107. }
  108.  
  109. Cars audi = new Cars();
  110.  
  111. Car bmw = new Car();
  112.  
  113. public float getLength() {
  114.  
  115. return length;
  116. }
  117.  
  118. public float getDuration() {
  119.  
  120. return duration;
  121. }
  122.  
  123. public Note.Names getNameOfNote() {
  124.  
  125. return Names.get(this.getPitch() % 12);
  126. }
  127.  
  128. public int getPitchClass() {
  129.  
  130. return (this.getPitch() % 12 + 12) % 12;
  131. }
  132.  
  133. public Note.Names getScientificPitchClassName() {
  134.  
  135. return Names.get(this.getPitchClass());
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement