Skip to content

Commit 34c90bb

Browse files
committed
Octave range transpose and backward compatibility fix
1 parent 6702a4a commit 34c90bb

File tree

4 files changed

+86
-16
lines changed

4 files changed

+86
-16
lines changed

src/main/java/com/xxmicloxx/NoteBlockAPI/model/playmode/MonoMode.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ public void play(Player player, Location location, Song song, Layer layer, Note
1717
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
1818
CustomInstrument instrument = song.getCustomInstruments()[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
1919

20-
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, 0);
20+
if (instrument.getSound() != null) {
21+
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, 0);
22+
} else {
23+
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, 0);
24+
}
2125
} else {
22-
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, 0);
26+
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, 0);
2327
}
2428
}
2529

@@ -33,9 +37,23 @@ public void play(Player player, Location location, Song song, Layer layer, Note
3337
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
3438
CustomInstrument instrument = song.getCustomInstruments()[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
3539

36-
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, 0);
40+
if (!doTranspose){
41+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, 0);
42+
} else {
43+
if (instrument.getSound() != null) {
44+
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, 0);
45+
} else {
46+
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, 0);
47+
}
48+
}
49+
3750
} else {
38-
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, 0);
51+
if (NoteUtils.isOutOfRange(note.getKey(), note.getPitch()) && !doTranspose) {
52+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, 0);
53+
}
54+
else {
55+
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, 0);
56+
}
3957
}
4058
}
4159
}

src/main/java/com/xxmicloxx/NoteBlockAPI/model/playmode/MonoStereoMode.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ public void play(Player player, Location location, Song song, Layer layer, Note
1919
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
2020
CustomInstrument instrument = song.getCustomInstruments()[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
2121

22-
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
23-
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, -distance);
22+
if (instrument.getSound() != null) {
23+
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, distance);
24+
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, -distance);
25+
} else {
26+
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, distance);
27+
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, -distance);
28+
}
2429
} else {
25-
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
26-
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, -distance);
30+
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, distance);
31+
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, -distance);
2732
}
2833
}
2934

@@ -38,11 +43,26 @@ public void play(Player player, Location location, Song song, Layer layer, Note
3843
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
3944
CustomInstrument instrument = song.getCustomInstruments()[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
4045

41-
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
42-
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, -distance);
46+
if (!doTranspose){
47+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
48+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, -distance);
49+
} else {
50+
if (instrument.getSound() != null) {
51+
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, distance);
52+
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, -distance);
53+
} else {
54+
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, distance);
55+
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, -distance);
56+
}
57+
}
4358
} else {
44-
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
45-
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, -distance);
59+
if (NoteUtils.isOutOfRange(note.getKey(), note.getPitch()) && !doTranspose) {
60+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
61+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, -distance);
62+
} else {
63+
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, distance);
64+
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, -distance);
65+
}
4666
}
4767
}
4868

src/main/java/com/xxmicloxx/NoteBlockAPI/model/playmode/StereoMode.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ public void play(Player player, Location location, Song song, Layer layer, Note
3131
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
3232
CustomInstrument instrument = song.getCustomInstruments()[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
3333

34-
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
34+
if (instrument.getSound() != null) {
35+
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, distance);
36+
} else {
37+
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, distance);
38+
}
3539
} else {
36-
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
40+
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, distance);
3741
}
3842
}
3943

@@ -59,9 +63,21 @@ public void play(Player player, Location location, Song song, Layer layer, Note
5963
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
6064
CustomInstrument instrument = song.getCustomInstruments()[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
6165

62-
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
66+
if (!doTranspose){
67+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
68+
} else {
69+
if (instrument.getSound() != null) {
70+
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, distance);
71+
} else {
72+
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, distance);
73+
}
74+
}
6375
} else {
64-
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
76+
if (NoteUtils.isOutOfRange(note.getKey(), note.getPitch()) && !doTranspose) {
77+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
78+
} else {
79+
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, distance);
80+
}
6581
}
6682
}
6783

src/main/java/com/xxmicloxx/NoteBlockAPI/utils/NoteUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,23 @@ public static float getPitchTransposed(byte key, short pitch) {
9191
while (key < 33) key += 12;
9292
while (key > 57) key -= 12;
9393

94+
key -= 33;
95+
9496
return pitches[key * 100 + pitch];
9597
}
9698

99+
/**
100+
* Returns true if combination of specified key and pitch is outside Minecraft octave range
101+
* @param key
102+
* @param pitch
103+
* @return
104+
*/
105+
public static boolean isOutOfRange(byte key, short pitch){
106+
key = applyPitchToKey(key, pitch);
107+
108+
if(key < 33) return true;
109+
else if(key < 57) return false;
110+
else return true;
111+
}
112+
97113
}

0 commit comments

Comments
 (0)