Skip to content

Commit da042ca

Browse files
committed
Support for OpenNoteBlockStudio 3.7.0 #37
1 parent f59e9ba commit da042ca

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

src/main/java/com/xxmicloxx/NoteBlockAPI/NBSDecoder.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private static Song parse(InputStream inputStream, File songFile) {
7474
short songHeight = readShort(dataInputStream);
7575
String title = readString(dataInputStream);
7676
String author = readString(dataInputStream);
77-
readString(dataInputStream);
77+
readString(dataInputStream); // original author
7878
String description = readString(dataInputStream);
7979
float speed = readShort(dataInputStream) / 100f;
8080
dataInputStream.readBoolean(); // auto-save
@@ -86,6 +86,11 @@ private static Song parse(InputStream inputStream, File songFile) {
8686
readInt(dataInputStream); // blocks added
8787
readInt(dataInputStream); // blocks removed
8888
readString(dataInputStream); // .mid/.schematic file name
89+
if (nbsversion >= 4) {
90+
dataInputStream.readByte(); // loop on/off
91+
dataInputStream.readByte(); // max loop count
92+
readShort(dataInputStream); // loop start tick
93+
}
8994
short tick = -1;
9095
while (true) {
9196
short jumpTicks = readShort(dataInputStream); // jumps till next tick
@@ -108,8 +113,17 @@ private static Song parse(InputStream inputStream, File songFile) {
108113
if (firstcustominstrumentdiff > 0 && instrument >= firstcustominstrument){
109114
instrument += firstcustominstrumentdiff;
110115
}
116+
117+
byte key = dataInputStream.readByte();
118+
119+
if (nbsversion >= 4) {
120+
dataInputStream.readByte(); // note block velocity
121+
dataInputStream.readByte(); // note block panning
122+
readShort(dataInputStream); // note block pitch
123+
}
124+
111125
setNote(layer, tick, instrument /* instrument */,
112-
dataInputStream.readByte() /* note */, layerHashMap);
126+
key/* note */, layerHashMap);
113127
}
114128
}
115129

@@ -121,9 +135,13 @@ private static Song parse(InputStream inputStream, File songFile) {
121135
Layer layer = layerHashMap.get(i);
122136

123137
String name = readString(dataInputStream);
138+
if (nbsversion >= 4){
139+
dataInputStream.readByte(); // layer lock
140+
}
141+
124142
byte volume = dataInputStream.readByte();
125143
if (nbsversion >= 2){
126-
dataInputStream.readByte();
144+
dataInputStream.readByte(); // layer stereo
127145
}
128146
if (layer != null) {
129147
layer.setName(name);

src/main/java/com/xxmicloxx/NoteBlockAPI/utils/NBSDecoder.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private static Song parse(InputStream inputStream, File songFile) {
7777
short songHeight = readShort(dataInputStream);
7878
String title = readString(dataInputStream);
7979
String author = readString(dataInputStream);
80-
readString(dataInputStream);
80+
readString(dataInputStream); // original author
8181
String description = readString(dataInputStream);
8282
float speed = readShort(dataInputStream) / 100f;
8383
dataInputStream.readBoolean(); // auto-save
@@ -89,6 +89,11 @@ private static Song parse(InputStream inputStream, File songFile) {
8989
readInt(dataInputStream); // blocks added
9090
readInt(dataInputStream); // blocks removed
9191
readString(dataInputStream); // .mid/.schematic file name
92+
if (nbsversion >= 4) {
93+
dataInputStream.readByte(); // loop on/off
94+
dataInputStream.readByte(); // max loop count
95+
readShort(dataInputStream); // loop start tick
96+
}
9297
short tick = -1;
9398
while (true) {
9499
short jumpTicks = readShort(dataInputStream); // jumps till next tick
@@ -111,8 +116,17 @@ private static Song parse(InputStream inputStream, File songFile) {
111116
if (firstcustominstrumentdiff > 0 && instrument >= firstcustominstrument){
112117
instrument += firstcustominstrumentdiff;
113118
}
119+
120+
byte key = dataInputStream.readByte();
121+
122+
if (nbsversion >= 4) {
123+
dataInputStream.readByte(); // note block velocity
124+
dataInputStream.readByte(); // note block panning
125+
readShort(dataInputStream); // note block pitch
126+
}
127+
114128
setNote(layer, tick, instrument /* instrument */,
115-
dataInputStream.readByte() /* note */, layerHashMap);
129+
key/* note */, layerHashMap);
116130
}
117131
}
118132

@@ -124,9 +138,13 @@ private static Song parse(InputStream inputStream, File songFile) {
124138
Layer layer = layerHashMap.get(i);
125139

126140
String name = readString(dataInputStream);
141+
if (nbsversion >= 4){
142+
dataInputStream.readByte(); // layer lock
143+
}
144+
127145
byte volume = dataInputStream.readByte();
128-
if (nbsversion >= 2){//layerstereo
129-
dataInputStream.readByte();
146+
if (nbsversion >= 2){
147+
dataInputStream.readByte(); // layer stereo
130148
}
131149
if (layer != null) {
132150
layer.setName(name);

0 commit comments

Comments
 (0)