|
21 | 21 | import net.raphimc.noteblocklib.format.midi.mapping.MidiMappings; |
22 | 22 | import net.raphimc.noteblocklib.format.midi.mapping.PercussionMapping; |
23 | 23 | import net.raphimc.noteblocklib.format.midi.model.MidiSong; |
| 24 | +import net.raphimc.noteblocklib.format.nbs.NbsDefinitions; |
24 | 25 | import net.raphimc.noteblocklib.model.Note; |
25 | 26 | import net.raphimc.noteblocklib.util.MathUtil; |
26 | 27 | import net.raphimc.noteblocklib.util.SongResampler; |
|
37 | 38 | public class MidiIo { |
38 | 39 |
|
39 | 40 | public static MidiSong readSong(final InputStream is, final String fileName) throws IOException, InvalidMidiDataException { |
40 | | - return parseSong(MidiSystem.getSequence(is), fileName); |
| 41 | + return readSong(is, fileName, true); |
| 42 | + } |
| 43 | + |
| 44 | + public static MidiSong readSong(final InputStream is, final String fileName, final boolean skipOutOfRangeNotes) throws IOException, InvalidMidiDataException { |
| 45 | + return parseSong(MidiSystem.getSequence(is), fileName, skipOutOfRangeNotes); |
41 | 46 | } |
42 | 47 |
|
43 | 48 | public static MidiSong parseSong(final Sequence sequence, final String fileName) { |
| 49 | + return parseSong(sequence, fileName, true); |
| 50 | + } |
| 51 | + |
| 52 | + public static MidiSong parseSong(final Sequence sequence, final String fileName, final boolean skipOutOfRangeNotes) { |
44 | 53 | final MidiSong song = new MidiSong(fileName); |
45 | 54 |
|
46 | 55 | if (sequence.getTickLength() > Integer.MAX_VALUE) { |
@@ -91,6 +100,10 @@ public static MidiSong parseSong(final Sequence sequence, final String fileName) |
91 | 100 | note.setVolume(((float) velocity / MAX_VELOCITY) * (float) channelVolumes[shortMessage.getChannel()] / MAX_VELOCITY); |
92 | 101 | note.setPanning((float) (pan - CENTER_PAN) / CENTER_PAN); |
93 | 102 |
|
| 103 | + if (skipOutOfRangeNotes && (note.getMidiKey() < NbsDefinitions.LOWEST_MIDI_KEY || note.getMidiKey() > NbsDefinitions.HIGHEST_MIDI_KEY)) { |
| 104 | + continue; |
| 105 | + } |
| 106 | + |
94 | 107 | song.getNotes().add((int) event.getTick(), note); |
95 | 108 | break; |
96 | 109 | case NOTE_OFF: |
|
0 commit comments