custom pitch thing (my chipmunk mod fork)
this one also took ages to make and its because my very dumb skill :((((((((((((((((((((((((9 well it works at least
This commit is contained in:
parent
426f507a14
commit
979f585601
3 changed files with 69 additions and 47 deletions
|
@ -27,7 +27,10 @@ import java.util.concurrent.TimeUnit;
|
||||||
public class MusicPlayerPlugin extends Bot.Listener {
|
public class MusicPlayerPlugin extends Bot.Listener {
|
||||||
private final Bot bot;
|
private final Bot bot;
|
||||||
|
|
||||||
public static final String SELECTOR = "@a[tag=!nomusic,tag=!chomens_bot_nomusic]";
|
public static final String SELECTOR = "@a[tag=!nomusic,tag=!chomens_bot_nomusic,tag=!custompitch]";
|
||||||
|
public static final String CUSTOM_PITCH_SELECTOR = "@a[tag=!nomusic,tag=!chomens_bot_nomusic,tag=custompitch]";
|
||||||
|
public static final String BOTH_SELECTOR = "@a[tag=!nomusic,tag=!chomens_bot_nomusic]";
|
||||||
|
|
||||||
public static final Path SONG_DIR = Path.of("songs");
|
public static final Path SONG_DIR = Path.of("songs");
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
|
@ -287,47 +290,77 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handlePlaying () {
|
public void handlePlaying () {
|
||||||
currentSong.advanceTime();
|
try {
|
||||||
while (currentSong.reachedNextNote()) {
|
currentSong.advanceTime();
|
||||||
final Note note = currentSong.getNextNote();
|
while (currentSong.reachedNextNote()) {
|
||||||
|
final Note note = currentSong.getNextNote();
|
||||||
|
|
||||||
if (notesPerSecond > 1240) continue;
|
if (notesPerSecond > 1240) continue;
|
||||||
|
|
||||||
float key = note.pitch;
|
float key = note.pitch;
|
||||||
|
|
||||||
// totally didn't look at the minecraft code and found the note block pitch thingy so i totallydidnotskidded™ it
|
// totally didn't look at the minecraft code and found the note block pitch thingy so i totallydidnotskidded™ it
|
||||||
final double floatingPitch = Math.pow(2.0, ((key + (pitch / 10)) - 12) / 12.0);
|
double floatingPitch = Math.pow(2.0, ((key + (pitch / 10)) - 12) / 12.0);
|
||||||
// final double floatingPitch = 0.5 * (Math.pow(2, ((key + (pitch / 10)) / 12)));
|
// final double floatingPitch = 0.5 * (Math.pow(2, ((key + (pitch / 10)) / 12)));
|
||||||
|
|
||||||
float blockPosition = 0;
|
float blockPosition = 0;
|
||||||
|
|
||||||
// totallynotskidded from opennbs
|
// totallynotskidded from opennbs
|
||||||
if (currentSong.nbs) {
|
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.
|
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 = (float) (s - 100) / -100;
|
if (s > 100) blockPosition = (float) (s - 100) / -100;
|
||||||
else if (s < 100) blockPosition = (float) ((s - 100) * -1) / 100;
|
else if (s < 100) blockPosition = (float) ((s - 100) * -1) / 100;
|
||||||
} else {
|
} else {
|
||||||
// i wrote this part
|
// i wrote this part
|
||||||
|
|
||||||
// this uses the average of the pitch and the volume to calculate the stereo
|
// this uses the average of the pitch and the volume to calculate the stereo
|
||||||
final float average = (note.pitch + note.volume) / 2;
|
final float average = (note.pitch + note.volume) / 2;
|
||||||
|
|
||||||
if (average > 5) blockPosition = (average - 5) / -5;
|
if (average > 5) blockPosition = (average - 5) / -5;
|
||||||
else if (average < 5) blockPosition = ((average - 5) * -1) / 5;
|
else if (average < 5) blockPosition = ((average - 5) * -1) / 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
key += 33;
|
||||||
|
|
||||||
|
final boolean isMoreOrLessOctave = key < 33 || key > 57;
|
||||||
|
|
||||||
|
if (isMoreOrLessOctave) {
|
||||||
|
bot.core.run(
|
||||||
|
"minecraft:execute as " +
|
||||||
|
CUSTOM_PITCH_SELECTOR +
|
||||||
|
" at @s run playsound " +
|
||||||
|
(!instrument.equals("off") ? instrument : note.instrument.sound) + ".pitch." + floatingPitch +
|
||||||
|
" record @s ^" + blockPosition + " ^ ^ " +
|
||||||
|
note.volume +
|
||||||
|
" " +
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// these 2 lines are totallynotskidded from https://github.com/OpenNBS/OpenNoteBlockStudio/blob/master/scripts/selection_transpose/selection_transpose.gml
|
||||||
|
// so huge thanks to them uwu
|
||||||
|
while (key < 33) key += 12;
|
||||||
|
while (key > 57) key -= 12;
|
||||||
|
|
||||||
|
key -= 33;
|
||||||
|
|
||||||
|
floatingPitch = Math.pow(2.0, ((key + (pitch / 10)) - 12) / 12.0);
|
||||||
|
|
||||||
|
bot.core.run(
|
||||||
|
"minecraft:execute as " +
|
||||||
|
(isMoreOrLessOctave ? SELECTOR : BOTH_SELECTOR) +
|
||||||
|
" at @s run playsound " +
|
||||||
|
(!instrument.equals("off") ? instrument : note.instrument.sound) +
|
||||||
|
" record @s ^" + blockPosition + " ^ ^ " +
|
||||||
|
note.volume +
|
||||||
|
" " +
|
||||||
|
MathUtilities.clamp(floatingPitch, 0, 2)
|
||||||
|
);
|
||||||
|
|
||||||
|
notesPerSecond++;
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
bot.core.run(
|
e.printStackTrace();
|
||||||
"minecraft:execute as " +
|
|
||||||
SELECTOR +
|
|
||||||
" at @s run playsound " +
|
|
||||||
(!instrument.equals("off") ? instrument : note.instrument.sound) +
|
|
||||||
" record @s ^" + blockPosition + " ^ ^ " +
|
|
||||||
note.volume +
|
|
||||||
" " +
|
|
||||||
MathUtilities.clamp(floatingPitch, 0, 2)
|
|
||||||
);
|
|
||||||
|
|
||||||
notesPerSecond++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,18 +131,12 @@ public class MidiConverter implements Converter {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pitch = (midiPitch-instrument.offset) + /* lazy -> */ 33;
|
int pitch = midiPitch-instrument.offset;
|
||||||
|
|
||||||
// these 2 lines are totallynotskidded from https://github.com/OpenNBS/OpenNoteBlockStudio/blob/master/scripts/selection_transpose/selection_transpose.gml
|
|
||||||
// so huge thanks to them uwu
|
|
||||||
// will this do anything if it's midi?
|
|
||||||
while (pitch < 33) pitch += 12;
|
|
||||||
while (pitch > 57) pitch -= 12;
|
|
||||||
|
|
||||||
float volume = (float) velocity / 127.0f;
|
float volume = (float) velocity / 127.0f;
|
||||||
long time = microTime / 1000L;
|
long time = microTime / 1000L;
|
||||||
|
|
||||||
return new Note(instrument, pitch - 33, volume, time, -1, 100);
|
return new Note(instrument, pitch, volume, time, -1, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Note getMidiPercussionNote (int midiPitch, int velocity, long microTime) {
|
private static Note getMidiPercussionNote (int midiPitch, int velocity, long microTime) {
|
||||||
|
|
|
@ -183,11 +183,6 @@ public class NBSConverter implements Converter {
|
||||||
layerVolume = nbsLayers.get(note.layer).volume;
|
layerVolume = nbsLayers.get(note.layer).volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
// these 2 lines are totallynotskidded from https://github.com/OpenNBS/OpenNoteBlockStudio/blob/master/scripts/selection_transpose/selection_transpose.gml
|
|
||||||
// so huge thanks to them uwu
|
|
||||||
while (key < 33) key += 12;
|
|
||||||
while (key > 57) key -= 12;
|
|
||||||
|
|
||||||
int pitch = key-33;
|
int pitch = key-33;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue