From a8b47c39d97c01fb446b911ed2b9d2b1f194d2a3 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Wed, 19 Apr 2023 13:20:41 +0700 Subject: [PATCH] add a working (or not?) stereo to music --- .../chomens_bot/plugins/MusicPlayerPlugin.java | 11 ++++++++++- .../chayapak/chomens_bot/song/MidiConverter.java | 4 ++-- .../chayapak/chomens_bot/song/NBSConverter.java | 6 +++--- .../land/chipmunk/chayapak/chomens_bot/song/Note.java | 2 ++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java index 070f6a9..90a331f 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java @@ -266,12 +266,21 @@ public class MusicPlayerPlugin extends SessionAdapter { final double floatingPitch = 0.5 * (Math.pow(2, ((key + (pitch / 10)) / 12))); + // totallynotskidded from opennbs + int blockPosition = 0; + + if (currentSong.nbs) { + final int s = (note.stereo + note.panning) / 2; // Stereo values to X coordinates, calc'd from the average of both note and layer pan. + if (s > 100) blockPosition = (s - 100) / -100; + if (s < 100) blockPosition = ((s - 100) * -1) / 100; + } + bot.core().run( "minecraft:execute as " + SELECTOR + " at @s run playsound " + note.instrument.sound + - " record @s ~ ~ ~ " + + " record @s ^" + blockPosition + " ^ ^ " + note.volume + " " + NumberUtilities.clamp(floatingPitch, 0, 2) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/MidiConverter.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/MidiConverter.java index 54409fb..3da7700 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/MidiConverter.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/MidiConverter.java @@ -140,7 +140,7 @@ public class MidiConverter { float volume = (float) velocity / 127.0f; long time = microTime / 1000L; - return new Note(instrument, pitch, volume, time); + return new Note(instrument, pitch, volume, time, -1, 100); } private static Note getMidiPercussionNote (int midiPitch, int velocity, long microTime) { @@ -151,7 +151,7 @@ public class MidiConverter { Instrument instrument = Instrument.fromId(noteId / 25); long time = microTime / 1000L; - return new Note(instrument, pitch, volume, time); + return new Note(instrument, pitch, volume, time, -1, 100); } return null; } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/NBSConverter.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/NBSConverter.java index 8b4982c..38721f3 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/NBSConverter.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/NBSConverter.java @@ -27,7 +27,7 @@ public class NBSConverter { Instrument.PLING, }; - private static class NBSNote { + public static class NBSNote { public int tick; public short layer; public byte instrument; @@ -37,7 +37,7 @@ public class NBSConverter { public short pitch = 0; } - private static class NBSLayer { + public static class NBSLayer { public String name; public byte lock = 0; public byte volume; @@ -176,7 +176,7 @@ public class NBSConverter { } int pitch = key-33; - song.add(new Note(instrument, pitch, (float) note.velocity * (float) layerVolume / 10000f, getMilliTime(note.tick, tempo))); + song.add(new Note(instrument, pitch, (float) note.velocity * (float) layerVolume / 10000f, getMilliTime(note.tick, tempo), note.panning, nbsLayers.get(note.layer).stereo)); } song.length = song.get(song.size()-1).time + 50; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/Note.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/Note.java index fb3557b..4aebc4f 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/Note.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/Note.java @@ -8,6 +8,8 @@ public class Note implements Comparable { public int pitch; public float volume; public long time; + public int panning; + public int stereo; @Override public int compareTo(Note other) {