1717 */
1818package net .raphimc .noteblocklib .data ;
1919
20+ import net .raphimc .noteblocklib .format .midi .MidiDefinitions ;
2021import net .raphimc .noteblocklib .model .Note ;
2122import net .raphimc .noteblocklib .model .instrument .Instrument ;
23+ import net .raphimc .noteblocklib .util .MathUtil ;
2224
2325import java .util .EnumMap ;
2426import java .util .Map ;
2729
2830public class MinecraftDefinitions {
2931
30- public static final int MC_LOWEST_MIDI_KEY = 54 ;
31- public static final int MC_HIGHEST_MIDI_KEY = 78 ;
32- public static final int MC_LOWEST_KEY = 0 ;
33- public static final int MC_HIGHEST_KEY = 24 ;
34- public static final int MC_KEYS = Constants .KEYS_PER_OCTAVE * 2 ;
32+ public static final int LOWEST_MIDI_KEY = 54 ;
33+ public static final int HIGHEST_MIDI_KEY = 78 ;
34+ public static final int LOWEST_KEY = 0 ;
35+ public static final int HIGHEST_KEY = 24 ;
36+ public static final int KEY_COUNT = MidiDefinitions .KEYS_PER_OCTAVE * 2 ;
3537
3638 // Instrument -> [lower shifts, upper shifts]
3739 private static final Map <MinecraftInstrument , MinecraftInstrument [][]> INSTRUMENT_SHIFTS = new EnumMap <>(MinecraftInstrument .class );
@@ -62,7 +64,7 @@ public class MinecraftDefinitions {
6264 * @param note The note to clamp
6365 */
6466 public static void clampNoteKey (final Note note ) {
65- note .setMidiKey (Math . max ( MC_LOWEST_MIDI_KEY , Math . min ( MC_HIGHEST_MIDI_KEY , note .getMidiKey ()) ));
67+ note .setMidiKey (MathUtil . clamp ( note .getMidiKey (), LOWEST_MIDI_KEY , HIGHEST_MIDI_KEY ));
6668 }
6769
6870 /**
@@ -72,7 +74,7 @@ public static void clampNoteKey(final Note note) {
7274 * @param note The note to transpose
7375 */
7476 public static void transposeNoteKey (final Note note ) {
75- transposeNoteKey (note , Constants .KEYS_PER_OCTAVE );
77+ transposeNoteKey (note , MidiDefinitions .KEYS_PER_OCTAVE );
7678 }
7779
7880 /**
@@ -84,10 +86,10 @@ public static void transposeNoteKey(final Note note) {
8486 */
8587 public static void transposeNoteKey (final Note note , final int transposeAmount ) {
8688 float key = note .getMidiKey ();
87- while (key < MC_LOWEST_MIDI_KEY ) {
89+ while (key < LOWEST_MIDI_KEY ) {
8890 key += transposeAmount ;
8991 }
90- while (key > MC_HIGHEST_MIDI_KEY ) {
92+ while (key > HIGHEST_MIDI_KEY ) {
9193 key -= transposeAmount ;
9294 }
9395 note .setMidiKey (key );
@@ -113,15 +115,15 @@ public static void instrumentShiftNote(final Note note) {
113115
114116 float key = note .getMidiKey ();
115117 int downShifts = 0 ;
116- while (key < MC_LOWEST_MIDI_KEY && downShifts < shifts [0 ].length ) {
118+ while (key < LOWEST_MIDI_KEY && downShifts < shifts [0 ].length ) {
117119 instrument = shifts [0 ][downShifts ++];
118- key += MinecraftDefinitions . MC_KEYS ;
120+ key += KEY_COUNT ;
119121 }
120122
121123 int upShifts = 0 ;
122- while (key > MC_HIGHEST_MIDI_KEY && upShifts < shifts [1 ].length ) {
124+ while (key > HIGHEST_MIDI_KEY && upShifts < shifts [1 ].length ) {
123125 instrument = shifts [1 ][upShifts ++];
124- key -= MinecraftDefinitions . MC_KEYS ;
126+ key -= KEY_COUNT ;
125127 }
126128
127129 note .setInstrument (instrument );
@@ -138,12 +140,12 @@ public static void instrumentShiftNote(final Note note) {
138140 */
139141 public static int applyExtendedNotesResourcePack (final Note note ) {
140142 int octavesDelta = 0 ;
141- while (note .getMidiKey () < MC_LOWEST_MIDI_KEY ) {
142- note .setMidiKey (note .getMidiKey () + MC_KEYS );
143+ while (note .getMidiKey () < LOWEST_MIDI_KEY ) {
144+ note .setMidiKey (note .getMidiKey () + KEY_COUNT );
143145 octavesDelta --;
144146 }
145- while (note .getMidiKey () > MC_HIGHEST_MIDI_KEY ) {
146- note .setMidiKey (note .getMidiKey () - MC_KEYS );
147+ while (note .getMidiKey () > HIGHEST_MIDI_KEY ) {
148+ note .setMidiKey (note .getMidiKey () - KEY_COUNT );
147149 octavesDelta ++;
148150 }
149151 return octavesDelta ;
0 commit comments