Skip to content

Commit 2742020

Browse files
committed
Added trumpet instruments, added NBS v6 support
1 parent 6191d79 commit 2742020

8 files changed

Lines changed: 76 additions & 48 deletions

File tree

-446 KB
Binary file not shown.

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ For a reference implementation of NoteBlockLib, check out [NoteBlockTool](https:
66

77
## Features
88
- Supports reading .nbs, .mid, .txt, .mcsp, .mcsp2 and .notebot files
9-
- Supports writing .nbs, .txt and .mcsp2 files
10-
- Can convert all formats to .nbs
9+
- Supports writing (and converting to) .nbs, .txt and .mcsp2 files
1110
- Offers an easy way to play note block songs in your application
1211
- Good MIDI importer
1312
- Supports most MIDI files
1413
- Supports velocity and panning
1514
- Can handle Black MIDI files
1615
- Supports all NBS versions
17-
- Version 0 - 5
16+
- Version 0 - 6
1817
- Supports Tempo Changers
1918
- Many tools for manipulating songs
2019
- Optimize songs for use in Minecraft (Transposing, Resampling)

src/main/java/net/raphimc/noteblocklib/format/midi/mapping/MidiMappings.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import net.raphimc.noteblocklib.format.minecraft.MinecraftInstrument;
2222

2323
// Thanks u3002 for the mappings (https://gist.github.com/u3002/cf4daa83bc82b5917fc86fb23815578a)
24+
// Also credit to OpenNoteBlockStudio (https://github.com/OpenNBS/NoteBlockStudio/blob/development/scripts/midi_instruments/midi_instruments.gml)
2425
public class MidiMappings {
2526

2627
public static final InstrumentMapping[] INSTRUMENT_MAPPINGS = new InstrumentMapping[MidiDefinitions.KEY_COUNT];
@@ -49,7 +50,7 @@ public class MidiMappings {
4950
INSTRUMENT_MAPPINGS[19] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);
5051
INSTRUMENT_MAPPINGS[20] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);
5152
INSTRUMENT_MAPPINGS[21] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);
52-
INSTRUMENT_MAPPINGS[22] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);
53+
INSTRUMENT_MAPPINGS[22] = new InstrumentMapping(MinecraftInstrument.TRUMPET, 0);
5354
INSTRUMENT_MAPPINGS[23] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);
5455
INSTRUMENT_MAPPINGS[24] = new InstrumentMapping(MinecraftInstrument.GUITAR, 1);
5556
INSTRUMENT_MAPPINGS[25] = new InstrumentMapping(MinecraftInstrument.GUITAR, 1);
@@ -83,18 +84,18 @@ public class MidiMappings {
8384
INSTRUMENT_MAPPINGS[53] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);
8485
INSTRUMENT_MAPPINGS[54] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);
8586
INSTRUMENT_MAPPINGS[55] = new InstrumentMapping(MinecraftInstrument.SNARE, 0);
86-
INSTRUMENT_MAPPINGS[56] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);
87-
INSTRUMENT_MAPPINGS[57] = new InstrumentMapping(MinecraftInstrument.DIDGERIDOO, 2);
88-
INSTRUMENT_MAPPINGS[58] = new InstrumentMapping(MinecraftInstrument.DIDGERIDOO, 2);
89-
INSTRUMENT_MAPPINGS[59] = new InstrumentMapping(MinecraftInstrument.DIDGERIDOO, 2);
90-
INSTRUMENT_MAPPINGS[60] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);
91-
INSTRUMENT_MAPPINGS[61] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);
92-
INSTRUMENT_MAPPINGS[62] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);
93-
INSTRUMENT_MAPPINGS[63] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);
87+
INSTRUMENT_MAPPINGS[56] = new InstrumentMapping(MinecraftInstrument.TRUMPET, 0);
88+
INSTRUMENT_MAPPINGS[57] = new InstrumentMapping(MinecraftInstrument.TRUMPET_EXPOSED, 0);
89+
INSTRUMENT_MAPPINGS[58] = new InstrumentMapping(MinecraftInstrument.TRUMPET_WEATHERED, 2);
90+
INSTRUMENT_MAPPINGS[59] = new InstrumentMapping(MinecraftInstrument.TRUMPET_OXIDIZED, 1);
91+
INSTRUMENT_MAPPINGS[60] = new InstrumentMapping(MinecraftInstrument.TRUMPET_EXPOSED, 0);
92+
INSTRUMENT_MAPPINGS[61] = new InstrumentMapping(MinecraftInstrument.TRUMPET_EXPOSED, 0);
93+
INSTRUMENT_MAPPINGS[62] = new InstrumentMapping(MinecraftInstrument.TRUMPET_EXPOSED, 0);
94+
INSTRUMENT_MAPPINGS[63] = new InstrumentMapping(MinecraftInstrument.TRUMPET, 0);
9495
INSTRUMENT_MAPPINGS[64] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);
95-
INSTRUMENT_MAPPINGS[65] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);
96-
INSTRUMENT_MAPPINGS[66] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);
97-
INSTRUMENT_MAPPINGS[67] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);
96+
INSTRUMENT_MAPPINGS[65] = new InstrumentMapping(MinecraftInstrument.TRUMPET, 0);
97+
INSTRUMENT_MAPPINGS[66] = new InstrumentMapping(MinecraftInstrument.TRUMPET, 0);
98+
INSTRUMENT_MAPPINGS[67] = new InstrumentMapping(MinecraftInstrument.TRUMPET_EXPOSED, 0);
9899
INSTRUMENT_MAPPINGS[68] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);
99100
INSTRUMENT_MAPPINGS[69] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);
100101
INSTRUMENT_MAPPINGS[70] = new InstrumentMapping(MinecraftInstrument.FLUTE, -1);

src/main/java/net/raphimc/noteblocklib/format/minecraft/MinecraftDefinitions.java

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,47 @@ public class MinecraftDefinitions {
3838
// Instrument -> [lower shifts, upper shifts]
3939
private static final Map<MinecraftInstrument, MinecraftInstrument[][]> INSTRUMENT_SHIFTS = new EnumMap<>(MinecraftInstrument.class);
4040

41+
// | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
42+
// | | | HARP | | |
43+
// | (BASS_DRUM) | | | | |
44+
// | | | (SNARE) | | |
45+
// | | | | | (HAT) |
46+
// | BASS | | FLUTE | |
47+
// | | | | | BELL |
48+
// | | GUITAR | | | |
49+
// | | | | | CHIME |
50+
// | | | | | XYLOPHONE |
51+
// | | | IRON_XYLOPHONE | | |
52+
// | | | | COW_BELL | |
53+
// | DIDGERIDOO | | | | |
54+
// | | | BIT | | |
55+
// | | | BANJO | | |
56+
// | | | PLING | | |
57+
// | | | TRUMPET | | |
58+
// | | | TRUMPET_EXPOSED | | |
59+
// | | TRUMPET_OXIDIZED | | | |
60+
// | | TRUMPET_WEATHERED | | | |
4161
static {
4262
INSTRUMENT_SHIFTS.put(HARP, new MinecraftInstrument[][]{new MinecraftInstrument[]{BASS}, new MinecraftInstrument[]{BELL}});
43-
INSTRUMENT_SHIFTS.put(BASS, new MinecraftInstrument[][]{new MinecraftInstrument[0], new MinecraftInstrument[]{HARP, BELL}});
4463
INSTRUMENT_SHIFTS.put(BASS_DRUM, new MinecraftInstrument[][]{new MinecraftInstrument[0], new MinecraftInstrument[]{SNARE}});
4564
INSTRUMENT_SHIFTS.put(SNARE, new MinecraftInstrument[][]{new MinecraftInstrument[]{BASS_DRUM}, new MinecraftInstrument[]{HAT}});
46-
INSTRUMENT_SHIFTS.put(HAT, new MinecraftInstrument[][]{new MinecraftInstrument[]{BASS_DRUM}, new MinecraftInstrument[]{CHIME}});
47-
INSTRUMENT_SHIFTS.put(GUITAR, new MinecraftInstrument[][]{new MinecraftInstrument[]{BASS}, new MinecraftInstrument[]{COW_BELL, XYLOPHONE}});
48-
INSTRUMENT_SHIFTS.put(FLUTE, new MinecraftInstrument[][]{new MinecraftInstrument[]{DIDGERIDOO}, new MinecraftInstrument[]{BELL, CHIME}});
49-
INSTRUMENT_SHIFTS.put(BELL, new MinecraftInstrument[][]{new MinecraftInstrument[]{HARP}, new MinecraftInstrument[0]});
50-
INSTRUMENT_SHIFTS.put(CHIME, new MinecraftInstrument[][]{new MinecraftInstrument[]{BELL}, new MinecraftInstrument[0]});
51-
INSTRUMENT_SHIFTS.put(XYLOPHONE, new MinecraftInstrument[][]{new MinecraftInstrument[]{COW_BELL}, new MinecraftInstrument[]{CHIME}});
52-
INSTRUMENT_SHIFTS.put(IRON_XYLOPHONE, new MinecraftInstrument[][]{new MinecraftInstrument[]{BASS}, new MinecraftInstrument[]{BELL}});
65+
INSTRUMENT_SHIFTS.put(HAT, new MinecraftInstrument[][]{new MinecraftInstrument[]{SNARE}, new MinecraftInstrument[0]});
66+
INSTRUMENT_SHIFTS.put(BASS, new MinecraftInstrument[][]{new MinecraftInstrument[0], new MinecraftInstrument[]{HARP, BELL}});
67+
INSTRUMENT_SHIFTS.put(FLUTE, new MinecraftInstrument[][]{new MinecraftInstrument[]{GUITAR}, new MinecraftInstrument[0]});
68+
INSTRUMENT_SHIFTS.put(BELL, new MinecraftInstrument[][]{new MinecraftInstrument[]{HARP, BASS}, new MinecraftInstrument[0]});
69+
INSTRUMENT_SHIFTS.put(GUITAR, new MinecraftInstrument[][]{new MinecraftInstrument[0], new MinecraftInstrument[]{FLUTE}});
70+
INSTRUMENT_SHIFTS.put(CHIME, new MinecraftInstrument[][]{new MinecraftInstrument[]{HARP, DIDGERIDOO}, new MinecraftInstrument[0]});
71+
INSTRUMENT_SHIFTS.put(XYLOPHONE, new MinecraftInstrument[][]{new MinecraftInstrument[]{IRON_XYLOPHONE, BASS}, new MinecraftInstrument[0]});
72+
INSTRUMENT_SHIFTS.put(IRON_XYLOPHONE, new MinecraftInstrument[][]{new MinecraftInstrument[]{BASS}, new MinecraftInstrument[]{XYLOPHONE}});
5373
INSTRUMENT_SHIFTS.put(COW_BELL, new MinecraftInstrument[][]{new MinecraftInstrument[]{GUITAR}, new MinecraftInstrument[]{XYLOPHONE}});
54-
INSTRUMENT_SHIFTS.put(DIDGERIDOO, new MinecraftInstrument[][]{new MinecraftInstrument[]{BASS}, new MinecraftInstrument[]{FLUTE, BELL}});
74+
INSTRUMENT_SHIFTS.put(DIDGERIDOO, new MinecraftInstrument[][]{new MinecraftInstrument[0], new MinecraftInstrument[]{BANJO, BELL}});
5575
INSTRUMENT_SHIFTS.put(BIT, new MinecraftInstrument[][]{new MinecraftInstrument[]{DIDGERIDOO}, new MinecraftInstrument[]{BELL}});
5676
INSTRUMENT_SHIFTS.put(BANJO, new MinecraftInstrument[][]{new MinecraftInstrument[]{DIDGERIDOO}, new MinecraftInstrument[]{BELL}});
5777
INSTRUMENT_SHIFTS.put(PLING, new MinecraftInstrument[][]{new MinecraftInstrument[]{BASS}, new MinecraftInstrument[]{BELL}});
78+
INSTRUMENT_SHIFTS.put(TRUMPET, new MinecraftInstrument[][]{new MinecraftInstrument[]{DIDGERIDOO}, new MinecraftInstrument[]{CHIME}});
79+
INSTRUMENT_SHIFTS.put(TRUMPET_EXPOSED, new MinecraftInstrument[][]{new MinecraftInstrument[]{DIDGERIDOO}, new MinecraftInstrument[]{CHIME}});
80+
INSTRUMENT_SHIFTS.put(TRUMPET_OXIDIZED, new MinecraftInstrument[][]{new MinecraftInstrument[0], new MinecraftInstrument[]{FLUTE}});
81+
INSTRUMENT_SHIFTS.put(TRUMPET_WEATHERED, new MinecraftInstrument[][]{new MinecraftInstrument[0], new MinecraftInstrument[]{FLUTE}});
5882
}
5983

6084
/**

src/main/java/net/raphimc/noteblocklib/format/minecraft/MinecraftInstrument.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,48 @@
2222
public enum MinecraftInstrument implements Instrument {
2323

2424
HARP(0, 0, "block.note_block.harp"),
25-
BASS(1, 4, "block.note_block.bass"),
26-
BASS_DRUM(2, 1, "block.note_block.basedrum"),
27-
SNARE(3, 2, "block.note_block.snare"),
28-
HAT(4, 3, "block.note_block.hat"),
29-
GUITAR(5, 7, "block.note_block.guitar"),
30-
FLUTE(6, 5, "block.note_block.flute"),
31-
BELL(7, 6, "block.note_block.bell"),
25+
BASS_DRUM(1, 2, "block.note_block.basedrum"),
26+
SNARE(2, 3, "block.note_block.snare"),
27+
HAT(3, 4, "block.note_block.hat"),
28+
BASS(4, 1, "block.note_block.bass"),
29+
FLUTE(5, 6, "block.note_block.flute"),
30+
BELL(6, 7, "block.note_block.bell"),
31+
GUITAR(7, 5, "block.note_block.guitar"),
3232
CHIME(8, 8, "block.note_block.chime"),
3333
XYLOPHONE(9, 9, "block.note_block.xylophone"),
3434
IRON_XYLOPHONE(10, 10, "block.note_block.iron_xylophone"),
3535
COW_BELL(11, 11, "block.note_block.cow_bell"),
3636
DIDGERIDOO(12, 12, "block.note_block.didgeridoo"),
3737
BIT(13, 13, "block.note_block.bit"),
3838
BANJO(14, 14, "block.note_block.banjo"),
39-
PLING(15, 15, "block.note_block.pling");
39+
PLING(15, 15, "block.note_block.pling"),
40+
TRUMPET(16, 16, "block.note_block.trumpet"),
41+
TRUMPET_EXPOSED(17, 17, "block.note_block.trumpet_exposed"),
42+
TRUMPET_OXIDIZED(18, 18, "block.note_block.trumpet_oxidized"),
43+
TRUMPET_WEATHERED(19, 19, "block.note_block.trumpet_weathered");
4044

41-
private final int nbsId;
4245
private final int mcId;
46+
private final int nbsId;
4347
private final String mcSoundName;
4448

45-
MinecraftInstrument(final int nbsId, final int mcId, final String mcSoundName) {
46-
this.nbsId = nbsId;
49+
MinecraftInstrument(final int mcId, final int nbsId, final String mcSoundName) {
4750
this.mcId = mcId;
51+
this.nbsId = nbsId;
4852
this.mcSoundName = mcSoundName;
4953
}
5054

51-
public static MinecraftInstrument fromNbsId(final int nbsId) {
55+
public static MinecraftInstrument fromMcId(final int mcId) {
5256
for (final MinecraftInstrument instrument : MinecraftInstrument.values()) {
53-
if (instrument.nbsId == nbsId) {
57+
if (instrument.mcId == mcId) {
5458
return instrument;
5559
}
5660
}
5761
return null;
5862
}
5963

60-
public static MinecraftInstrument fromMcId(final int mcId) {
64+
public static MinecraftInstrument fromNbsId(final int nbsId) {
6165
for (final MinecraftInstrument instrument : MinecraftInstrument.values()) {
62-
if (instrument.mcId == mcId) {
66+
if (instrument.nbsId == nbsId) {
6367
return instrument;
6468
}
6569
}
@@ -75,14 +79,14 @@ public static MinecraftInstrument fromMcSoundName(final String mcSoundName) {
7579
return null;
7680
}
7781

78-
public int nbsId() {
79-
return this.nbsId;
80-
}
81-
8282
public int mcId() {
8383
return this.mcId;
8484
}
8585

86+
public int nbsId() {
87+
return this.nbsId;
88+
}
89+
8690
public String mcSoundName() {
8791
return this.mcSoundName;
8892
}

src/main/java/net/raphimc/noteblocklib/format/nbs/NbsIo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static NbsSong readSong(final InputStream is, final String fileName) thro
6363
song.setVanillaInstrumentCount(10);
6464
}
6565

66-
if (song.getVersion() < 0 || song.getVersion() > 5) {
66+
if (song.getVersion() < 0 || song.getVersion() > 6) {
6767
throw new IllegalStateException("Unsupported NBS version: " + song.getVersion());
6868
}
6969

@@ -234,7 +234,7 @@ public static NbsSong readSong(final InputStream is, final String fileName) thro
234234
}
235235

236236
public static void writeSong(final NbsSong song, final OutputStream os) throws IOException {
237-
if (song.getVersion() < 0 || song.getVersion() > 5) {
237+
if (song.getVersion() < 0 || song.getVersion() > 6) {
238238
throw new IllegalArgumentException("Unsupported NBS version: " + song.getVersion());
239239
}
240240
if (song.getLayerCount() > song.getLayers().size()) {

src/main/java/net/raphimc/noteblocklib/format/nbs/model/NbsSong.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public NbsSong() {
129129

130130
public NbsSong(final String fileName) {
131131
super(SongFormat.NBS, fileName);
132-
this.version = 5;
132+
this.version = 6;
133133
this.vanillaInstrumentCount = (byte) MinecraftInstrument.values().length;
134134
}
135135

src/main/java/net/raphimc/noteblocklib/model/note/Note.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public Note() {
3939
}
4040

4141
/**
42-
* @return The group ID of the note. Groups are used in events to determine which notes are affected by the event. -1 means that the note is not in any group.
42+
* @return The group ID of the note. Groups are used in events to determine which notes are affected by an event. -1 means that the note is not in any group.
4343
*/
4444
public int getGroupId() {
4545
return this.groupId;
4646
}
4747

4848
/**
49-
* @param groupId The group ID of the note. Groups are used in events to determine which notes are affected by the event. -1 means that the note is not in any group.
49+
* @param groupId The group ID of the note. Groups are used in events to determine which notes are affected by an event. -1 means that the note is not in any group.
5050
* @return this
5151
*/
5252
public Note setGroupId(final int groupId) {

0 commit comments

Comments
 (0)