forked from ChomeNS/chomens-bot-java
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,6 +290,7 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handlePlaying () {
|
public void handlePlaying () {
|
||||||
|
try {
|
||||||
currentSong.advanceTime();
|
currentSong.advanceTime();
|
||||||
while (currentSong.reachedNextNote()) {
|
while (currentSong.reachedNextNote()) {
|
||||||
final Note note = currentSong.getNextNote();
|
final Note note = currentSong.getNextNote();
|
||||||
|
@ -296,7 +300,7 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
||||||
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;
|
||||||
|
@ -316,9 +320,35 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
||||||
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(
|
bot.core.run(
|
||||||
"minecraft:execute as " +
|
"minecraft:execute as " +
|
||||||
SELECTOR +
|
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 " +
|
" at @s run playsound " +
|
||||||
(!instrument.equals("off") ? instrument : note.instrument.sound) +
|
(!instrument.equals("off") ? instrument : note.instrument.sound) +
|
||||||
" record @s ^" + blockPosition + " ^ ^ " +
|
" record @s ^" + blockPosition + " ^ ^ " +
|
||||||
|
@ -329,5 +359,8 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
||||||
|
|
||||||
notesPerSecond++;
|
notesPerSecond++;
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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