Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
<version>3.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/xxmicloxx/NoteBlockAPI/utils/NoteUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static float getPitchInOctave(Note note) {
public static float getPitchInOctave(byte key, short pitch) {
// Apply pitch to key
key = applyPitchToKey(key, pitch);
pitch %= 100;
pitch = (short) Math.floorMod(pitch, 100);

// -15 base_-2
// 9 base_-1
Expand All @@ -62,7 +62,7 @@ public static float getPitchInOctave(byte key, short pitch) {
}

public static byte applyPitchToKey(byte key, short pitch) {
key += pitch / 100;
key += Math.floorDiv(pitch, 100);
return key;
}

Expand Down
24 changes: 24 additions & 0 deletions src/test/java/com/xxmicloxx/NoteBlockAPI/utils/NoteUtilsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.xxmicloxx.NoteBlockAPI.utils;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class NoteUtilsTest {

@Test
public void negativeFinePitchMovesToPreviousKeyWithoutIndexUnderflow() {
assertEquals(32, NoteUtils.applyPitchToKey((byte) 33, (short) -30));
assertEquals(expectedPitch(2370), NoteUtils.getPitchInOctave((byte) 33, (short) -30), 0.000001f);
}

@Test
public void negativeFinePitchSelectsThePreviousOctaveSample() {
assertEquals("test_-1", InstrumentUtils.warpNameOutOfRange("test", (byte) 33, (short) -30));
assertEquals("test", InstrumentUtils.warpNameOutOfRange("test", (byte) 57, (short) -30));
}

private float expectedPitch(int index) {
return (float) Math.pow(2, (index - 1200d) / 1200d);
}
}