diff --git a/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java b/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java index 00a8f9f..81f6fe8 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java +++ b/src/main/java/land/chipmunk/chipmunkbot/plugins/SongPlayer.java @@ -164,7 +164,7 @@ public class SongPlayer extends SessionAdapter { final double floatingPitch = Math.pow(2, (note.pitch - 12) / 12.0); - client.core().run("execute as @a at @s run playsound " + note.instrument.sound + " record @s ~ ~ ~ 1 " + floatingPitch); + client.core().run("execute as @a at @s run playsound " + note.instrument.sound + " record @s ~ ~ ~ " + note.volume + " " + floatingPitch); } } } diff --git a/src/main/java/land/chipmunk/chipmunkbot/song/MidiConverter.java b/src/main/java/land/chipmunk/chipmunkbot/song/MidiConverter.java index e2fb072..a40f7e0 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/song/MidiConverter.java +++ b/src/main/java/land/chipmunk/chipmunkbot/song/MidiConverter.java @@ -85,16 +85,17 @@ public class MidiConverter { else if (sm.getCommand() == NOTE_ON) { if (sm.getData2() == 0) continue; int pitch = sm.getData1(); + int velocity = sm.getData2(); long deltaTick = event.getTick() - prevTick; prevTick = event.getTick(); microTime += (mpq/tpq) * deltaTick; Note note; if (sm.getChannel() == 9) { - note = getMidiPercussionNote(pitch, microTime); + note = getMidiPercussionNote(pitch, velocity, microTime); } else { - note = getMidiInstrumentNote(ids[sm.getChannel()], pitch, microTime); + note = getMidiInstrumentNote(ids[sm.getChannel()], pitch, velocity, microTime); } if (note != null) { song.add(note); @@ -123,7 +124,7 @@ public class MidiConverter { return song; } - public static Note getMidiInstrumentNote(int midiInstrument, int midiPitch, long microTime) { + public static Note getMidiInstrumentNote(int midiInstrument, int velocity, int midiPitch, long microTime) { Instrument instrument = null; Instrument[] instrumentList = instrumentMap.get(midiInstrument); if (instrumentList != null) { @@ -140,19 +141,21 @@ public class MidiConverter { } int pitch = midiPitch-instrument.offset; + float volume = (float) velocity / 127.0f; long time = microTime / 1000L; - return new Note(instrument, pitch, time); + return new Note(instrument, pitch, volume, time); } - private static Note getMidiPercussionNote (int midiPitch, long microTime) { + private static Note getMidiPercussionNote (int midiPitch, int velocity, long microTime) { if (percussionMap.containsKey(midiPitch)) { int noteId = percussionMap.get(midiPitch); int pitch = noteId % 25; + float volume = (float) velocity / 127.0f; Instrument instrument = Instrument.fromId(noteId / 25); long time = microTime / 1000L; - return new Note(instrument, pitch, time); + return new Note(instrument, pitch, volume, time); } return null; } diff --git a/src/main/java/land/chipmunk/chipmunkbot/song/NBSConverter.java b/src/main/java/land/chipmunk/chipmunkbot/song/NBSConverter.java index 6c87e31..6cf5f1a 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/song/NBSConverter.java +++ b/src/main/java/land/chipmunk/chipmunkbot/song/NBSConverter.java @@ -177,7 +177,7 @@ public class NBSConverter { } int pitch = key-33; - song.add(new Note(instrument, pitch, getMilliTime(note.tick, tempo))); + song.add(new Note(instrument, pitch, (float) note.velocity * (float) layerVolume / 10000f, getMilliTime(note.tick, tempo))); } song.length = song.get(song.size()-1).time + 50; diff --git a/src/main/java/land/chipmunk/chipmunkbot/song/Note.java b/src/main/java/land/chipmunk/chipmunkbot/song/Note.java index 24e8156..fb4dcf7 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/song/Note.java +++ b/src/main/java/land/chipmunk/chipmunkbot/song/Note.java @@ -6,6 +6,7 @@ import lombok.AllArgsConstructor; public class Note implements Comparable { public Instrument instrument; public int pitch; + public float volume; public long time; @Override