Skip to content

Commit

Permalink
custom instruments werent functioning properly
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoGamerGH committed Jan 27, 2023
1 parent 41af62c commit 1cd3989
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/main/java/me/bruno/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,17 @@ public static boolean parse(File f, String fileName) {
Map<Byte, Byte> customInstrumentPitchMap = new HashMap<>();

for (int i = 0; i < customInstruments; i++) {
String instrumentName = FileReader.readString(dis);
String soundFile = FileReader.readString(dis);
byte soundPitch = dis.readByte();
boolean pressKey = MathUtils.bitToBoolean(dis.readByte());
customInstrumentPitchMap.put((byte) (vanillaInstruments + i), soundPitch);
instrumentMap.put((byte) (vanillaInstruments + i), mostRecentInt(instrumentMap));
if (instrumentMap.isEmpty()) {
instrumentMap.put((byte) (vanillaInstruments + i),0);
} else if (!instrumentMap.containsKey((byte) (vanillaInstruments + i))) {
instrumentMap.put((byte) (vanillaInstruments + i), mostRecentInt(instrumentMap) + 1);
}

}


Expand All @@ -189,20 +197,19 @@ public static boolean parse(File f, String fileName) {


List<Track> tracks = new ArrayList<>();

for (int i = 0; i < instrumentMap.size(); i++) {
tracks.add(sequence.createTrack());
}
long tempoToBpm = (long) ((tempo) * 15);
tracks.forEach(track -> track.add(createSetTempoEvent(0, tempoToBpm)));


for (byte values :instrumentMap.keySet()) {
tracks.get(instrumentMap.get(values)).add(makeEvent(SET_INSTRUMENT, instrumentMap.get(values), instrumentMap.get(values), 0, 0));
for (int i = 0; i < instrumentMap.size(); i++) {
tracks.get(i).add(makeEvent(SET_INSTRUMENT, i, i, 0, 0));
}


System.out.println(instrumentMap);
for (int i = 0; i < instrumentLists.size(); i++) {

for (Note note : instrumentLists.get(i)) {
int val = instrumentMap.get(note.getInstrument());
int finalNote = note.getKey()+ 21;
Expand All @@ -212,7 +219,7 @@ public static boolean parse(File f, String fileName) {
case 6, 8 -> finalNote = finalNote + 12;
case 7, 9 -> finalNote = finalNote + 24;
}
if (note.getInstrument() > vanillaInstruments-1) {
if (note.getInstrument() >= vanillaInstruments) {
finalNote = finalNote - (customInstrumentPitchMap.get(note.getInstrument()) - 45);
}

Expand Down

0 comments on commit 1cd3989

Please sign in to comment.