Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ private Song parse(InputStream inputStream) throws Exception {
DataInputStream dataInputStream = new DataInputStream(inputStream);
short length = readShort(dataInputStream);
int nbsversion = 0;
int vanillaInstrumentCount = 10; // The original format has 10 vanilla instruments.
if (length == 0) {
nbsversion = dataInputStream.readByte();
dataInputStream.readByte(); // first custom instrument
nbsversion = dataInputStream.readUnsignedByte();
vanillaInstrumentCount = dataInputStream.readUnsignedByte();
if (nbsversion >= 3) {
length = readShort(dataInputStream);
}
Expand Down Expand Up @@ -91,7 +92,7 @@ private Song parse(InputStream inputStream) throws Exception {
if (jumpLayers == 0) {
break;
}
byte instrument = dataInputStream.readByte();
int instrument = dataInputStream.readUnsignedByte();

byte key = dataInputStream.readByte();
if (nbsversion >= 4) {
Expand All @@ -100,9 +101,12 @@ private Song parse(InputStream inputStream) throws Exception {
readShort(dataInputStream); // note block pitch
}

// Custom instruments start at the count stored in the file, not necessarily 16.
if (instrument >= vanillaInstrumentCount) continue;

NoteBlockInstrument inst = fromNBSInstrument(instrument);

// Probably a custom instrument. Ignore this note
// Unsupported vanilla instrument. Ignore this note
if (inst == null) continue;

Note note = new Note(inst /* instrument */, key - NOTE_OFFSET /* note */);
Expand Down
Loading