add a working (or not?) stereo to music

This commit is contained in:
Chayapak 2023-04-19 13:20:41 +07:00
parent 551f48f2dc
commit a8b47c39d9
4 changed files with 17 additions and 6 deletions

View file

@ -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)

View file

@ -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;
}

View file

@ -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;

View file

@ -8,6 +8,8 @@ public class Note implements Comparable<Note> {
public int pitch;
public float volume;
public long time;
public int panning;
public int stereo;
@Override
public int compareTo(Note other) {