uh some instrument in uh uh custom pitch yeah changes

This commit is contained in:
Chayapak 2023-10-04 17:11:26 +07:00
parent e1bf49e279
commit bead13d6ec
3 changed files with 43 additions and 18 deletions

View file

@ -316,11 +316,7 @@ public class MusicPlayerPlugin extends Bot.Listener {
if (note.volume == 0 || notesPerSecond > totalCoreBlocks * (50 * 20)) continue;
float key = note.pitch;
// totally didn't look at the minecraft code and found the note block pitch thingy so i totallydidnotskidded it
double floatingPitch = Math.pow(2.0, ((key + (pitch / 10)) - 12) / 12.0);
// final double floatingPitch = 0.5 * (Math.pow(2, ((key + (pitch / 10)) / 12)));
float key = note.shiftedPitch;
float blockPosition = 0;
@ -349,11 +345,13 @@ public class MusicPlayerPlugin extends Bot.Listener {
final boolean isMoreOrLessOctave = key < 33 || key > 57;
if (isMoreOrLessOctave) {
final double notShiftedFloatingPitch = Math.pow(2.0, ((note.pitch + (pitch / 10)) - 12) / 12.0);
bot.core.run(
"minecraft:execute as " +
CUSTOM_PITCH_SELECTOR +
" at @s run playsound " +
(!instrument.equals("off") ? instrument : note.instrument.sound) + ".pitch." + floatingPitch +
(!instrument.equals("off") ? instrument : note.instrument.sound) + ".pitch." + notShiftedFloatingPitch +
" record @s ^" + blockPosition + " ^ ^ " +
note.volume +
" " +
@ -363,19 +361,19 @@ public class MusicPlayerPlugin extends Bot.Listener {
// 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 < 33) key += 12; // 1 octave has 12 notes so we just keep moving octaves here
while (key > 57) key -= 12;
key -= 33;
floatingPitch = Math.pow(2.0, ((key + (pitch / 10)) - 12) / 12.0);
double floatingPitch = Math.pow(2.0, ((key + (pitch / 10)) - 12) / 12.0);
for (int i = 0; i < amplify; i++) {
bot.core.run(
"minecraft:execute as " +
(isMoreOrLessOctave ? SELECTOR : BOTH_SELECTOR) +
" at @s run playsound " +
(!instrument.equals("off") ? instrument : note.instrument.sound) +
(!instrument.equals("off") ? instrument : note.shiftedInstrument.sound) +
" record @s ^" + blockPosition + " ^ ^ " +
note.volume +
" " +

View file

@ -172,18 +172,18 @@ public class MidiConverter implements Converter {
}
public static Note getMidiInstrumentNote(int midiInstrument, int midiPitch, float velocity, long microTime, int panning) {
Instrument instrument = null;
Instrument shiftedInstrument = null;
Instrument[] instrumentList = instrumentMap.get(midiInstrument);
if (instrumentList != null) {
for (Instrument candidateInstrument : instrumentList) {
if (midiPitch >= candidateInstrument.offset && midiPitch <= candidateInstrument.offset+24) {
instrument = candidateInstrument;
shiftedInstrument = candidateInstrument;
break;
}
}
if (instrument == null) {
// instrument = instrumentList[0];
if (shiftedInstrument == null) {
// shiftedInstrument = instrumentList[0];
// we are finding the closest instrument offset here and use that
// closest instrument as the instrument
@ -203,29 +203,30 @@ public class MidiConverter implements Converter {
final int closest = offsets[idx];
instrument = Arrays.stream(instrumentList)
shiftedInstrument = Arrays.stream(instrumentList)
.filter(ins -> ins.offset == closest)
.toArray(Instrument[]::new)[0];
}
}
if (instrument == null) {
if (shiftedInstrument == null) {
return null;
}
int pitch = midiPitch-instrument.offset;
int shiftedInstrumentPitch = midiPitch - shiftedInstrument.offset;
int pitch = midiPitch - instrumentList[0].offset;
float volume = velocity / 127.0f;
long time = microTime / 1000L;
return new Note(instrument, pitch, midiPitch, volume, time, (int) ((panning - 64) / (float) 64) * 100, 100);
return new Note(instrumentList[0], shiftedInstrument, shiftedInstrumentPitch, pitch, midiPitch, volume, time, (int) ((panning - 64) / (float) 64) * 100, 100);
}
private static Note getMidiPercussionNote (int midiPitch, float velocity, long microTime, int panning) {
if (percussionMap.containsKey(midiPitch)) {
int noteId = percussionMap.get(midiPitch);
int pitch = noteId % 25;
float volume = (float) velocity / 127.0f;
float volume = velocity / 127.0f;
Instrument instrument = Instrument.fromId(noteId / 25);
long time = microTime / 1000L;

View file

@ -3,7 +3,9 @@ package land.chipmunk.chayapak.chomens_bot.song;
// Author: hhhzzzsss
public class Note implements Comparable<Note> {
public final Instrument instrument;
public final Instrument shiftedInstrument;
public final int pitch;
public final int shiftedPitch;
public final int originalPitch;
public final float volume;
public final long time;
@ -20,7 +22,31 @@ public class Note implements Comparable<Note> {
int stereo
) {
this.instrument = instrument;
this.shiftedInstrument = this.instrument;
this.pitch = pitch;
this.shiftedPitch = this.pitch;
this.originalPitch = originalPitch;
this.volume = volume;
this.time = time;
this.panning = panning;
this.stereo = stereo;
}
public Note (
Instrument instrument,
Instrument shiftedInstrument,
int pitch,
int shiftedPitch,
int originalPitch,
float volume,
long time,
int panning,
int stereo
) {
this.instrument = instrument;
this.shiftedInstrument = shiftedInstrument;
this.pitch = pitch;
this.shiftedPitch = shiftedPitch;
this.originalPitch = originalPitch;
this.volume = volume;
this.time = time;