An enum holding tones.
| 12 | * An enum holding tones. |
| 13 | */ |
| 14 | public enum Tone { |
| 15 | F((byte) -0x1, true), |
| 16 | G((byte) 0x1, true), |
| 17 | A((byte) 0x3, true), |
| 18 | B((byte) 0x5, false), |
| 19 | C((byte) 0x6, true), |
| 20 | D((byte) 0x8, true), |
| 21 | E((byte) 0xA, false); |
| 22 | |
| 23 | private final boolean sharpable; |
| 24 | private final byte id; |
| 25 | private static final Map<Byte, Note.Tone> tones = new HashMap<Byte, Note.Tone>(); |
| 26 | /** The number of tones including sharped tones. */ |
| 27 | public static final byte TONES_COUNT; |
| 28 | |
| 29 | private Tone(byte id, boolean sharpable) { |
| 30 | this.id = id; |
| 31 | this.sharpable = sharpable; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Returns the not sharped id of this tone. |
| 36 | * |
| 37 | * @return the not sharped id of this tone. |
| 38 | */ |
| 39 | public byte getId() { |
| 40 | return getId(false); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Returns the id of this tone. These method allows to return the |
| 45 | * sharped id of the tone. If the tone couldn't be sharped it always |
| 46 | * return the not sharped id of this tone. |
| 47 | * |
| 48 | * @param sharped |
| 49 | * Set to true to return the sharped id. |
| 50 | * @return the id of this tone. |
| 51 | */ |
| 52 | public byte getId(boolean sharped) { |
| 53 | byte tempId = (byte) (sharped && sharpable ? id + 1 : id); |
| 54 | |
| 55 | while (tempId < 0) { |
| 56 | tempId += TONES_COUNT; |
| 57 | } |
| 58 | return (byte) (tempId % TONES_COUNT); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Returns if this tone could be sharped. |
| 63 | * |
| 64 | * @return if this tone could be sharped. |
| 65 | */ |
| 66 | public boolean isSharpable() { |
| 67 | return sharpable; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Returns if this tone id is the sharped id of the tone. |
nothing calls this directly
no test coverage detected