Added song items

This commit is contained in:
hhhzzzsss 2023-06-16 00:31:10 -05:00
parent 5c37d7f157
commit 7ce233625f
14 changed files with 932 additions and 383 deletions

View file

@ -1,5 +1,7 @@
package com.github.hhhzzzsss.songplayer;
import com.github.hhhzzzsss.songplayer.item.SongItemCreatorThread;
import com.github.hhhzzzsss.songplayer.item.SongItemUtils;
import com.github.hhhzzzsss.songplayer.playing.SongHandler;
import com.github.hhhzzzsss.songplayer.playing.Stage;
import com.github.hhhzzzsss.songplayer.song.Note;
@ -8,18 +10,22 @@ import com.github.hhhzzzsss.songplayer.song.Song;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.command.CommandSource;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Hand;
import net.minecraft.world.GameMode;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.github.hhhzzzsss.songplayer.SongPlayer.MC;
public class CommandProcessor {
public static ArrayList<Command> commands = new ArrayList<>();
public static HashMap<String, Command> commandMap = new HashMap<>();
@ -43,6 +49,7 @@ public class CommandProcessor {
commands.add(new useVanillaCommandsCommand());
commands.add(new toggleFakePlayerCommand());
commands.add(new setStageTypeCommand());
commands.add(new songItemCommand());
commands.add(new testSongCommand());
for (Command command : commands) {
@ -813,6 +820,80 @@ public class CommandProcessor {
}
}
private static class songItemCommand extends Command {
public String getName() {
return "songItem";
}
public String[] getAliases() {
return new String[]{"item"};
}
public String[] getSyntax() {
return new String[] {
"create <song or url>",
"setSongName <name>",
};
}
public String getDescription() {
return "Assigns/edits song data for the item in your hand";
}
public boolean processCommand(String args) {
if (args.length() == 0) {
return false;
}
if (MC.interactionManager.getCurrentGameMode() != GameMode.CREATIVE) {
SongPlayer.addChatMessage("§cYou must be in creative mode to use this command");
return true;
}
ItemStack stack = MC.player.getMainHandStack().copy();
NbtCompound songPlayerNBT = stack.getSubNbt("SongPlayerData");
String[] split = args.split(" ");
switch (split[0].toLowerCase()) {
case "create":
if (split.length != 2) return false;
try {
(new SongItemCreatorThread(split[1])).start();
} catch (IOException e) {
SongPlayer.addChatMessage("§cError creating song item: §4" + e.getMessage());
}
return true;
case "setsongname":
if (split.length < 2) return false;
if (songPlayerNBT == null) {
SongPlayer.addChatMessage("§cYou must be holding a song item");
return true;
}
String name = String.join(" ", Arrays.copyOfRange(split, 1, split.length));
songPlayerNBT.putString(SongItemUtils.DISPLAY_NAME_KEY, name);
MC.interactionManager.clickCreativeStack(MC.player.getStackInHand(Hand.MAIN_HAND), 36 + MC.player.getInventory().selectedSlot);
SongPlayer.addChatMessage("§6Set song's display name to §3" + name);
return true;
default:
return false;
}
}
public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBuilder suggestionsBuilder) {
String[] split = args.split(" ", -1);
if (split.length <= 1) {
return CommandSource.suggestMatching(new String[] {
"create",
"setSongName",
}, suggestionsBuilder);
}
switch (split[0].toLowerCase()) {
case "create":
if (split.length == 2) {
return Util.giveSongSuggestions(split[1], suggestionsBuilder);
}
case "setsongname":
default:
return null;
}
}
}
private static class testSongCommand extends Command {
public String getName() {
return "testSong";

View file

@ -39,6 +39,10 @@ public class SongPlayer implements ModInitializer {
MC.player.sendMessage(Text.of(message), false);
}
public static void addChatMessage(Text text) {
MC.player.sendMessage(text, false);
}
public static void removeFakePlayer() {
if (fakePlayer != null) {
fakePlayer.remove(Entity.RemovalReason.DISCARDED);

View file

@ -0,0 +1,375 @@
package com.github.hhhzzzsss.songplayer.conversion;
import com.github.hhhzzzsss.songplayer.song.DownloadUtils;
import com.github.hhhzzzsss.songplayer.song.Instrument;
import com.github.hhhzzzsss.songplayer.song.Note;
import com.github.hhhzzzsss.songplayer.song.Song;
import javax.sound.midi.*;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
public class MidiConverter {
public static final int SET_INSTRUMENT = 0xC0;
public static final int SET_TEMPO = 0x51;
public static final int NOTE_ON = 0x90;
public static final int NOTE_OFF = 0x80;
public static Song getSongFromUrl(URL url) throws IOException, InvalidMidiDataException, URISyntaxException, NoSuchAlgorithmException, KeyManagementException {
Sequence sequence = MidiSystem.getSequence(DownloadUtils.DownloadToInputStream(url, 5*1024*1024));
return getSong(sequence, Paths.get(url.toURI().getPath()).getFileName().toString());
}
public static Song getSongFromFile(Path file) throws InvalidMidiDataException, IOException {
Sequence sequence = MidiSystem.getSequence(file.toFile());
return getSong(sequence, file.getFileName().toString());
}
public static Song getSongFromBytes(byte[] bytes, String name) throws InvalidMidiDataException, IOException {
Sequence sequence = MidiSystem.getSequence(new ByteArrayInputStream(bytes));
return getSong(sequence, name);
}
public static Song getSong(Sequence sequence, String name) {
Song song = new Song(name);
long tpq = sequence.getResolution();
ArrayList<MidiEvent> tempoEvents = new ArrayList<>();
for (Track track : sequence.getTracks()) {
for (int i = 0; i < track.size(); i++) {
MidiEvent event = track.get(i);
MidiMessage message = event.getMessage();
if (message instanceof MetaMessage) {
MetaMessage mm = (MetaMessage) message;
if (mm.getType() == SET_TEMPO) {
tempoEvents.add(event);
}
}
}
}
Collections.sort(tempoEvents, (a, b) -> Long.compare(a.getTick(), b.getTick()));
for (Track track : sequence.getTracks()) {
long microTime = 0;
int[] instrumentIds = new int[16];
int mpq = 500000;
int tempoEventIdx = 0;
long prevTick = 0;
for (int i = 0; i < track.size(); i++) {
MidiEvent event = track.get(i);
MidiMessage message = event.getMessage();
while (tempoEventIdx < tempoEvents.size() && event.getTick() > tempoEvents.get(tempoEventIdx).getTick()) {
long deltaTick = tempoEvents.get(tempoEventIdx).getTick() - prevTick;
prevTick = tempoEvents.get(tempoEventIdx).getTick();
microTime += (mpq/tpq) * deltaTick;
MetaMessage mm = (MetaMessage) tempoEvents.get(tempoEventIdx).getMessage();
byte[] data = mm.getData();
int new_mpq = (data[2]&0xFF) | ((data[1]&0xFF)<<8) | ((data[0]&0xFF)<<16);
if (new_mpq != 0) mpq = new_mpq;
tempoEventIdx++;
}
if (message instanceof ShortMessage) {
ShortMessage sm = (ShortMessage) message;
if (sm.getCommand() == SET_INSTRUMENT) {
instrumentIds[sm.getChannel()] = sm.getData1();
}
else if (sm.getCommand() == NOTE_ON) {
if (sm.getData2() == 0) continue;
int pitch = sm.getData1();
long deltaTick = event.getTick() - prevTick;
prevTick = event.getTick();
microTime += (mpq/tpq) * deltaTick;
Note note;
if (sm.getChannel() == 9) {
note = getMidiPercussionNote(pitch, microTime);
}
else {
note = getMidiInstrumentNote(instrumentIds[sm.getChannel()], pitch, microTime);
}
if (note != null) {
song.add(note);
}
long time = microTime / 1000L;
if (time > song.length) {
song.length = time;
}
}
else if (sm.getCommand() == NOTE_OFF) {
long deltaTick = event.getTick() - prevTick;
prevTick = event.getTick();
microTime += (mpq/tpq) * deltaTick;
long time = microTime / 1000L;
if (time > song.length) {
song.length = time;
}
}
}
}
}
song.sort();
return song;
}
public static Note getMidiInstrumentNote(int midiInstrument, int midiPitch, long microTime) {
com.github.hhhzzzsss.songplayer.song.Instrument instrument = null;
com.github.hhhzzzsss.songplayer.song.Instrument[] instrumentList = instrumentMap.get(midiInstrument);
if (instrumentList != null) {
for (com.github.hhhzzzsss.songplayer.song.Instrument candidateInstrument : instrumentList) {
if (midiPitch >= candidateInstrument.offset && midiPitch <= candidateInstrument.offset+24) {
instrument = candidateInstrument;
break;
}
}
}
if (instrument == null) {
return null;
}
int pitch = midiPitch-instrument.offset;
int noteId = pitch + instrument.instrumentId*25;
long time = microTime / 1000L;
return new Note(noteId, time);
}
private static Note getMidiPercussionNote(int midiPitch, long microTime) {
if (percussionMap.containsKey(midiPitch)) {
int noteId = percussionMap.get(midiPitch);
long time = microTime / 1000L;
return new Note(noteId, time);
}
return null;
}
public static HashMap<Integer, com.github.hhhzzzsss.songplayer.song.Instrument[]> instrumentMap = new HashMap<>();
static {
// Piano (HARP BASS BELL)
instrumentMap.put(0, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Acoustic Grand Piano
instrumentMap.put(1, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Bright Acoustic Piano
instrumentMap.put(2, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Electric Grand Piano
instrumentMap.put(3, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Honky-tonk Piano
instrumentMap.put(4, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Electric Piano 1
instrumentMap.put(5, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Electric Piano 2
instrumentMap.put(6, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Harpsichord
instrumentMap.put(7, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Clavinet
// Chromatic Percussion (IRON_XYLOPHONE XYLOPHONE BASS)
instrumentMap.put(8, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Celesta
instrumentMap.put(9, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Glockenspiel
instrumentMap.put(10, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Music Box
instrumentMap.put(11, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Vibraphone
instrumentMap.put(12, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Marimba
instrumentMap.put(13, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Xylophone
instrumentMap.put(14, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Tubular Bells
instrumentMap.put(15, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Dulcimer
// Organ (BIT DIDGERIDOO BELL)
instrumentMap.put(16, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Drawbar Organ
instrumentMap.put(17, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Percussive Organ
instrumentMap.put(18, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Rock Organ
instrumentMap.put(19, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Church Organ
instrumentMap.put(20, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Reed Organ
instrumentMap.put(21, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Accordian
instrumentMap.put(22, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Harmonica
instrumentMap.put(23, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Tango Accordian
// Guitar (BIT DIDGERIDOO BELL)
instrumentMap.put(24, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.GUITAR, com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Acoustic Guitar (nylon)
instrumentMap.put(25, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.GUITAR, com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Acoustic Guitar (steel)
instrumentMap.put(26, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.GUITAR, com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Electric Guitar (jazz)
instrumentMap.put(27, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.GUITAR, com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Electric Guitar (clean)
instrumentMap.put(28, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.GUITAR, com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Electric Guitar (muted)
instrumentMap.put(29, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Overdriven Guitar
instrumentMap.put(30, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Distortion Guitar
instrumentMap.put(31, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.GUITAR, com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Guitar Harmonics
// Bass
instrumentMap.put(32, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Acoustic Bass
instrumentMap.put(33, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Electric Bass (finger)
instrumentMap.put(34, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Electric Bass (pick)
instrumentMap.put(35, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Fretless Bass
instrumentMap.put(36, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Slap Bass 1
instrumentMap.put(37, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Slap Bass 2
instrumentMap.put(38, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Synth Bass 1
instrumentMap.put(39, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE}); // Synth Bass 2
// Strings
instrumentMap.put(40, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.GUITAR, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Violin
instrumentMap.put(41, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.GUITAR, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Viola
instrumentMap.put(42, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.GUITAR, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Cello
instrumentMap.put(43, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.GUITAR, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Contrabass
instrumentMap.put(44, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Tremolo Strings
instrumentMap.put(45, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Pizzicato Strings
instrumentMap.put(46, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.CHIME}); // Orchestral Harp
instrumentMap.put(47, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Timpani
// Ensenble
instrumentMap.put(48, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // String Ensemble 1
instrumentMap.put(49, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // String Ensemble 2
instrumentMap.put(50, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Synth Strings 1
instrumentMap.put(51, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Synth Strings 2
instrumentMap.put(52, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Choir Aahs
instrumentMap.put(53, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Voice Oohs
instrumentMap.put(54, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Synth Choir
instrumentMap.put(55, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL}); // Orchestra Hit
// Brass
instrumentMap.put(56, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(57, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(58, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(59, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(60, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(61, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(62, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(63, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
// Reed
instrumentMap.put(64, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(65, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(66, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(67, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(68, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(69, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(70, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(71, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
// Pipe
instrumentMap.put(72, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(73, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(74, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(75, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(76, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(77, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(78, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(79, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.FLUTE, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
// Synth Lead
instrumentMap.put(80, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(81, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(82, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(83, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(84, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(85, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(86, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(87, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
// Synth Pad
instrumentMap.put(88, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(89, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(90, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(91, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(92, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(93, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(94, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(95, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
// Synth Effects
// instrumentMap.put(96, new Instrument[]{});
// instrumentMap.put(97, new Instrument[]{});
instrumentMap.put(98, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BIT, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(99, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(100, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(101, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(102, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(103, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
// Ethnic
instrumentMap.put(104, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BANJO, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(105, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BANJO, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(106, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BANJO, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(107, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BANJO, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(108, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.BANJO, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(109, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(110, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
instrumentMap.put(111, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.HARP, com.github.hhhzzzsss.songplayer.song.Instrument.DIDGERIDOO, com.github.hhhzzzsss.songplayer.song.Instrument.BELL});
// Percussive
instrumentMap.put(112, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE});
instrumentMap.put(113, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE});
instrumentMap.put(114, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE});
instrumentMap.put(115, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE});
instrumentMap.put(116, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE});
instrumentMap.put(117, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE});
instrumentMap.put(118, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE});
instrumentMap.put(119, new com.github.hhhzzzsss.songplayer.song.Instrument[]{com.github.hhhzzzsss.songplayer.song.Instrument.IRON_XYLOPHONE, com.github.hhhzzzsss.songplayer.song.Instrument.BASS, com.github.hhhzzzsss.songplayer.song.Instrument.XYLOPHONE});
}
public static HashMap<Integer, Integer> percussionMap = new HashMap<>();
static {
percussionMap.put(35, 10 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.BASEDRUM.instrumentId);
percussionMap.put(36, 6 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.BASEDRUM.instrumentId);
percussionMap.put(37, 6 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(38, 8 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.SNARE.instrumentId);
percussionMap.put(39, 6 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(40, 4 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.SNARE.instrumentId);
percussionMap.put(41, 6 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.BASEDRUM.instrumentId);
percussionMap.put(42, 22 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.SNARE.instrumentId);
percussionMap.put(43, 13 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.BASEDRUM.instrumentId);
percussionMap.put(44, 22 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.SNARE.instrumentId);
percussionMap.put(45, 15 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.BASEDRUM.instrumentId);
percussionMap.put(46, 18 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.SNARE.instrumentId);
percussionMap.put(47, 20 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.BASEDRUM.instrumentId);
percussionMap.put(48, 23 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.BASEDRUM.instrumentId);
percussionMap.put(49, 17 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.SNARE.instrumentId);
percussionMap.put(50, 23 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.BASEDRUM.instrumentId);
percussionMap.put(51, 24 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.SNARE.instrumentId);
percussionMap.put(52, 8 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.SNARE.instrumentId);
percussionMap.put(53, 13 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.SNARE.instrumentId);
percussionMap.put(54, 18 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(55, 18 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.SNARE.instrumentId);
percussionMap.put(56, 1 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(57, 13 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.SNARE.instrumentId);
percussionMap.put(58, 2 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(59, 13 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.SNARE.instrumentId);
percussionMap.put(60, 9 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(61, 2 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(62, 8 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(63, 22 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.BASEDRUM.instrumentId);
percussionMap.put(64, 15 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.BASEDRUM.instrumentId);
percussionMap.put(65, 13 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.SNARE.instrumentId);
percussionMap.put(66, 8 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.SNARE.instrumentId);
percussionMap.put(67, 8 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(68, 3 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(69, 20 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(70, 23 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(71, 24 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(72, 24 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(73, 17 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(74, 11 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(75, 18 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(76, 9 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(77, 5 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(78, 22 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(79, 19 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.SNARE.instrumentId);
percussionMap.put(80, 17 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(81, 22 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(82, 22 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.SNARE.instrumentId);
percussionMap.put(83, 24 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.CHIME.instrumentId);
percussionMap.put(84, 24 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.CHIME.instrumentId);
percussionMap.put(85, 21 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.HAT.instrumentId);
percussionMap.put(86, 14 + 25* com.github.hhhzzzsss.songplayer.song.Instrument.BASEDRUM.instrumentId);
percussionMap.put(87, 7 + 25* Instrument.BASEDRUM.instrumentId);
}
}

View file

@ -1,4 +1,8 @@
package com.github.hhhzzzsss.songplayer.song;
package com.github.hhhzzzsss.songplayer.conversion;
import com.github.hhhzzzsss.songplayer.song.Instrument;
import com.github.hhhzzzsss.songplayer.song.Note;
import com.github.hhhzzzsss.songplayer.song.Song;
import java.io.IOException;
import java.nio.ByteBuffer;

View file

@ -0,0 +1,158 @@
package com.github.hhhzzzsss.songplayer.conversion;
import com.github.hhhzzzsss.songplayer.song.Note;
import com.github.hhhzzzsss.songplayer.song.Song;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
public class SPConverter {
public static final byte[] FILE_TYPE_SIGNATURE = {-53, 123, -51, -124, -122, -46, -35, 38};
public static Song getSongFromBytes(byte[] bytes, String fileName) throws IOException {
InputStream is = new GZIPInputStream(new ByteArrayInputStream(bytes));
bytes = is.readAllBytes();
is.close();
ByteBuffer buffer = ByteBuffer.wrap(bytes);
buffer.order(ByteOrder.LITTLE_ENDIAN);
for (byte b : FILE_TYPE_SIGNATURE) {
if (b != buffer.get()) {
throw new IOException("Invalid file type signature");
}
}
byte version = buffer.get();
// Currently on format version 1
if (version != 1) {
throw new IOException("Unsupported format version!");
}
long songLength = buffer.getLong();
String songName = getString(buffer, bytes.length);
int loop = buffer.get() & 0xFF;
int loopCount = buffer.get() & 0xFF;
long loopPosition = buffer.getLong();
Song song = new Song(songName.trim().length() > 0 ? songName : fileName);
song.length = songLength;
song.looping = loop > 0;
song.loopCount = loopCount;
song.loopPosition = loopPosition;
long time = 0;
while (true) {
int noteId = buffer.getShort();
if (noteId >= 0 && noteId < 400) {
time += getVarLong(buffer);
song.add(new Note(noteId, time));
}
else if ((noteId & 0xFFFF) == 0xFFFF) {
break;
}
else {
throw new IOException("Song contains invalid note id of " + noteId);
}
}
return song;
}
public static byte[] getBytesFromSong(Song song) throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
OutputStream os = new GZIPOutputStream(byteArrayOutputStream);
byte version = 1;
os.write(FILE_TYPE_SIGNATURE);
os.write(version);
writeLong(os, song.length);
writeString(os, song.name);
os.write(song.looping ? 1 : 0);
os.write(Math.min(song.loopCount, 0xFF));
writeLong(os, song.loopPosition);
song.sort();
long prevTime = 0;
for (Note note : song.notes) {
writeShort(os, note.noteId);
writeVarLong(os, note.time - prevTime);
prevTime = note.time;
}
writeShort(os, 0xFFFF);
os.close();
return byteArrayOutputStream.toByteArray();
}
private static String getString(ByteBuffer buffer, int maxSize) throws IOException {
int length = buffer.getInt();
if (length > maxSize) {
throw new IOException("String is too large");
}
byte arr[] = new byte[length];
buffer.get(arr, 0, length);
System.out.println(new String(arr, StandardCharsets.UTF_8));
return new String(arr, StandardCharsets.UTF_8);
}
private static void writeString(OutputStream os, String string) throws IOException {
byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
writeInt(os, bytes.length);
os.write(bytes);
System.out.println(string);
}
private static long getVarLong(ByteBuffer buffer) {
long val = 0;
long mult = 1;
int flag = 1;
while (flag != 0) {
int b = buffer.get() & 0xFF;
val += (b & 0x7F) * mult;
mult <<= 7;
flag = b >>> 7;
}
return val;
}
private static void writeVarLong(OutputStream os, long val) throws IOException {
do {
int b = (int) (val & 0x7F);
val >>>= 7;
if (val > 0) {
b |= 0x80;
}
os.write((byte) b);
} while (val > 0);
}
private static void writeShort(OutputStream os, int val) throws IOException {
os.write(val & 0xFF);
os.write((val >>> 8) & 0xFF);
}
private static void writeInt(OutputStream os, int val) throws IOException {
os.write(val & 0xFF);
os.write((val >>> 8) & 0xFF);
os.write((val >>> 16) & 0xFF);
os.write((val >>> 24) & 0xFF);
}
private static void writeLong(OutputStream os, long val) throws IOException {
os.write((int) val & 0xFF);
os.write((int) (val >>> 8) & 0xFF);
os.write((int) (val >>> 16) & 0xFF);
os.write((int) (val >>> 24) & 0xFF);
os.write((int) (val >>> 32) & 0xFF);
os.write((int) (val >>> 40) & 0xFF);
os.write((int) (val >>> 48) & 0xFF);
os.write((int) (val >>> 56) & 0xFF);
}
}

View file

@ -0,0 +1,110 @@
package com.github.hhhzzzsss.songplayer.item;
import com.github.hhhzzzsss.songplayer.SongPlayer;
import com.github.hhhzzzsss.songplayer.playing.SongHandler;
import net.minecraft.client.font.MultilineText;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class SongItemConfirmationScreen extends Screen {
private ItemStack stack;
private SongItemLoaderThread loaderThread;
private MultilineText unloadedText;
private MultilineText loadedText;
private boolean loaded = false;
private static final Text CONFIRM = Text.literal("Play");
private static final Text CANCEL = Text.literal("Cancel");
public SongItemConfirmationScreen(ItemStack stack) throws IOException {
super(Text.literal("Use song item"));
this.stack = stack;
this.loaderThread = new SongItemLoaderThread(stack);
this.loaderThread.start();
}
@Override
protected void init() {
super.init();
String unloadedMessage = "§7Loading song...";
this.unloadedText = MultilineText.create(this.textRenderer, Text.literal(unloadedMessage));
}
private void addButtons(int y) {
int centerX = this.width / 2;
this.addDrawableChild(ButtonWidget.builder(CONFIRM, button -> {
SongHandler.getInstance().loadSong(loaderThread);
this.client.setScreen(null);
}).dimensions(centerX - 105, y, 100, 20).build());
this.addDrawableChild(ButtonWidget.builder(CANCEL, button -> {
this.client.setScreen(null);
}).dimensions(centerX + 5, y, 100, 20).build());
}
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
this.renderBackground(matrices);
drawCenteredTextWithShadow(matrices, this.textRenderer, this.title, this.width / 2, 40, 0xFFFFFF);
if (!loaderThread.isAlive()) {
if (loaderThread.exception != null) {
SongPlayer.addChatMessage("§cError loading song item: §4" + loaderThread.exception.getMessage());
this.client.setScreen(null);
return;
}
else if (loadedText == null) {
String[] loadedMessages = {
"§3" + loaderThread.song.name,
String.format("§7Max notes per second: %s%d", getNumberColor(loaderThread.maxNotesPerSecond), loaderThread.maxNotesPerSecond),
String.format("§7Avg notes per second: %s%.2f", getNumberColor(loaderThread.avgNotesPerSecond), loaderThread.avgNotesPerSecond),
};
List<Text> messageList = Arrays.stream(loadedMessages).map(Text::literal).collect(Collectors.toList());;
this.loadedText = MultilineText.createFromTexts(this.textRenderer, messageList);
int loadedTextHeight = this.loadedText.count() * this.textRenderer.fontHeight;
addButtons(60 + loadedTextHeight + 12);
loaded = true;
}
}
if (loaded) {
loadedText.drawCenterWithShadow(matrices, this.width / 2, 60);
}
else {
unloadedText.drawCenterWithShadow(matrices, this.width / 2, 60);
}
super.render(matrices, mouseX, mouseY, delta);
}
public String getNumberColor(double number) {
if (number < 50) {
return "§a";
}
else if (number < 100) {
return "§e";
}
else if (number < 300) {
return "§6";
}
else if (number < 600) {
return "§c";
}
else {
return "§4";
}
}
}

View file

@ -0,0 +1,52 @@
package com.github.hhhzzzsss.songplayer.item;
import com.github.hhhzzzsss.songplayer.SongPlayer;
import com.github.hhhzzzsss.songplayer.conversion.SPConverter;
import com.github.hhhzzzsss.songplayer.song.SongLoaderThread;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import java.io.IOException;
public class SongItemCreatorThread extends SongLoaderThread {
public final int slotId;
public final ItemStack stack;
public SongItemCreatorThread(String location) throws IOException {
super(location);
this.slotId = SongPlayer.MC.player.getInventory().selectedSlot;
this.stack = SongPlayer.MC.player.getInventory().getStack(slotId);
}
@Override
public void run() {
super.run();
byte[] songData;
try {
songData = SPConverter.getBytesFromSong(song);
} catch (IOException e) {
SongPlayer.addChatMessage("§cError creating song item: §4" + e.getMessage());
return;
}
SongPlayer.MC.execute(() -> {
if (SongPlayer.MC.world == null) {
return;
}
if (!SongPlayer.MC.player.getInventory().getStack(slotId).equals(stack)) {
SongPlayer.addChatMessage("§cCould not create song item because item has moved");
}
ItemStack newStack;
if (stack.isEmpty()) {
newStack = Items.PAPER.getDefaultStack();
}
else {
newStack = stack.copy();
}
newStack = SongItemUtils.createSongItem(newStack, songData, filename, song.name);
SongPlayer.MC.player.getInventory().setStack(slotId, newStack);
SongPlayer.MC.interactionManager.clickCreativeStack(SongPlayer.MC.player.getStackInHand(Hand.MAIN_HAND), 36 + slotId);
SongPlayer.addChatMessage(Text.literal("§6Successfully assigned song data to §3").append(newStack.getItem().getName()));
});
}
}

View file

@ -0,0 +1,57 @@
package com.github.hhhzzzsss.songplayer.item;
import com.github.hhhzzzsss.songplayer.conversion.SPConverter;
import com.github.hhhzzzsss.songplayer.song.Note;
import com.github.hhhzzzsss.songplayer.song.SongLoaderThread;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import java.io.IOException;
public class SongItemLoaderThread extends SongLoaderThread {
public byte[] songData;
public String displayName;
public int maxNotesPerSecond = 0;
public double avgNotesPerSecond = 0;
public SongItemLoaderThread(ItemStack stack) throws IOException {
songData = SongItemUtils.getSongData(stack);
if (songData == null) {
throw new IOException("Song data is missing");
}
NbtCompound songItemNbt = SongItemUtils.getSongItemTag(stack);
displayName = songItemNbt.getString(SongItemUtils.DISPLAY_NAME_KEY);
filename = songItemNbt.getString(SongItemUtils.DISPLAY_NAME_KEY);
}
@Override
public void run() {
try {
song = SPConverter.getSongFromBytes(songData, filename);
if (displayName == null || displayName.length() > 0) {
song.name = displayName;
}
if (song.name == null || song.name.length() == 0) {
song.name = "unnamed";
}
song.sort();
int j = 0;
int notesInSecond = 0;
for (Note currNote : song.notes) {
notesInSecond++;
while (song.notes.get(j).time + 1000 < currNote.time) {
j++;
notesInSecond--;
}
maxNotesPerSecond = Math.max(notesInSecond, maxNotesPerSecond);
}
avgNotesPerSecond = song.notes.size() * 1000.0 / song.length;
}
catch (Exception e) {
exception = e;
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,41 @@
package com.github.hhhzzzsss.songplayer.item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import java.util.Base64;
public class SongItemUtils {
public static final String SONG_ITEM_KEY = "SongItemData";
public static final String SONG_DATA_KEY = "SongData";
public static final String FILE_NAME_KEY = "FileName";
public static final String DISPLAY_NAME_KEY = "DisplayName";
public static ItemStack createSongItem(ItemStack stack, byte[] songData, String filename, String displayName) {
NbtCompound songPlayerNbt = new NbtCompound();
stack.setSubNbt(SONG_ITEM_KEY, songPlayerNbt);
songPlayerNbt.putString(SONG_DATA_KEY, Base64.getEncoder().encodeToString(songData));
songPlayerNbt.putString(FILE_NAME_KEY, filename);
songPlayerNbt.putString(DISPLAY_NAME_KEY, displayName);
return stack;
}
public static NbtCompound getSongItemTag(ItemStack stack) {
return stack.getSubNbt(SONG_ITEM_KEY);
}
public static boolean isSongItem(ItemStack stack) {
return getSongItemTag(stack) != null;
}
public static byte[] getSongData(ItemStack stack) {
NbtCompound songPlayerNbt = getSongItemTag(stack);
if (songPlayerNbt == null || !songPlayerNbt.contains(SONG_DATA_KEY, NbtElement.STRING_TYPE)) {
return null;
}
else {
return Base64.getDecoder().decode(songPlayerNbt.getString(SONG_DATA_KEY));
}
}
}

View file

@ -1,14 +1,20 @@
package com.github.hhhzzzsss.songplayer.mixin;
import com.github.hhhzzzsss.songplayer.SongPlayer;
import com.github.hhhzzzsss.songplayer.item.SongItemConfirmationScreen;
import com.github.hhhzzzsss.songplayer.item.SongItemUtils;
import com.github.hhhzzzsss.songplayer.playing.ProgressDisplay;
import com.github.hhhzzzsss.songplayer.playing.SongHandler;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.io.IOException;
@Mixin(MinecraftClient.class)
public class MinecraftClientMixin {
@Inject(at = @At("HEAD"), method = "render(Z)V")
@ -27,4 +33,16 @@ public class MinecraftClientMixin {
}
ProgressDisplay.getInstance().onTick();
}
@Inject(at = @At("HEAD"), method = "doItemUse()V", cancellable = true)
private void onDoItemUse(CallbackInfo ci) {
ItemStack stack = SongPlayer.MC.player.getStackInHand(Hand.MAIN_HAND);
if (SongItemUtils.isSongItem(stack)) {
try {
SongPlayer.MC.setScreen(new SongItemConfirmationScreen(stack));
} catch (IOException e) {
SongPlayer.addChatMessage("§cFailed to load song item: §4" + e.getMessage());
}
}
}
}

View file

@ -140,6 +140,18 @@ public class SongHandler {
}
}
public void loadSong(SongLoaderThread thread) {
if (loaderThread != null) {
SongPlayer.addChatMessage("§cAlready loading a song, cannot load another");
}
else if (currentPlaylist != null) {
SongPlayer.addChatMessage("§cCannot load a song while a playlist is playing");
}
else {
loaderThread = thread;
}
}
public void setSong(Song song) {
currentSong = song;
building = true;

View file

@ -1,370 +0,0 @@
package com.github.hhhzzzsss.songplayer.song;
import javax.sound.midi.*;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
public class MidiConverter {
public static final int SET_INSTRUMENT = 0xC0;
public static final int SET_TEMPO = 0x51;
public static final int NOTE_ON = 0x90;
public static final int NOTE_OFF = 0x80;
public static Song getSongFromUrl(URL url) throws IOException, InvalidMidiDataException, URISyntaxException, NoSuchAlgorithmException, KeyManagementException {
Sequence sequence = MidiSystem.getSequence(DownloadUtils.DownloadToInputStream(url, 5*1024*1024));
return getSong(sequence, Paths.get(url.toURI().getPath()).getFileName().toString());
}
public static Song getSongFromFile(Path file) throws InvalidMidiDataException, IOException {
Sequence sequence = MidiSystem.getSequence(file.toFile());
return getSong(sequence, file.getFileName().toString());
}
public static Song getSongFromBytes(byte[] bytes, String name) throws InvalidMidiDataException, IOException {
Sequence sequence = MidiSystem.getSequence(new ByteArrayInputStream(bytes));
return getSong(sequence, name);
}
public static Song getSong(Sequence sequence, String name) {
Song song = new Song(name);
long tpq = sequence.getResolution();
ArrayList<MidiEvent> tempoEvents = new ArrayList<>();
for (Track track : sequence.getTracks()) {
for (int i = 0; i < track.size(); i++) {
MidiEvent event = track.get(i);
MidiMessage message = event.getMessage();
if (message instanceof MetaMessage) {
MetaMessage mm = (MetaMessage) message;
if (mm.getType() == SET_TEMPO) {
tempoEvents.add(event);
}
}
}
}
Collections.sort(tempoEvents, (a, b) -> Long.compare(a.getTick(), b.getTick()));
for (Track track : sequence.getTracks()) {
long microTime = 0;
int[] instrumentIds = new int[16];
int mpq = 500000;
int tempoEventIdx = 0;
long prevTick = 0;
for (int i = 0; i < track.size(); i++) {
MidiEvent event = track.get(i);
MidiMessage message = event.getMessage();
while (tempoEventIdx < tempoEvents.size() && event.getTick() > tempoEvents.get(tempoEventIdx).getTick()) {
long deltaTick = tempoEvents.get(tempoEventIdx).getTick() - prevTick;
prevTick = tempoEvents.get(tempoEventIdx).getTick();
microTime += (mpq/tpq) * deltaTick;
MetaMessage mm = (MetaMessage) tempoEvents.get(tempoEventIdx).getMessage();
byte[] data = mm.getData();
int new_mpq = (data[2]&0xFF) | ((data[1]&0xFF)<<8) | ((data[0]&0xFF)<<16);
if (new_mpq != 0) mpq = new_mpq;
tempoEventIdx++;
}
if (message instanceof ShortMessage) {
ShortMessage sm = (ShortMessage) message;
if (sm.getCommand() == SET_INSTRUMENT) {
instrumentIds[sm.getChannel()] = sm.getData1();
}
else if (sm.getCommand() == NOTE_ON) {
if (sm.getData2() == 0) continue;
int pitch = sm.getData1();
long deltaTick = event.getTick() - prevTick;
prevTick = event.getTick();
microTime += (mpq/tpq) * deltaTick;
Note note;
if (sm.getChannel() == 9) {
note = getMidiPercussionNote(pitch, microTime);
}
else {
note = getMidiInstrumentNote(instrumentIds[sm.getChannel()], pitch, microTime);
}
if (note != null) {
song.add(note);
}
long time = microTime / 1000L;
if (time > song.length) {
song.length = time;
}
}
else if (sm.getCommand() == NOTE_OFF) {
long deltaTick = event.getTick() - prevTick;
prevTick = event.getTick();
microTime += (mpq/tpq) * deltaTick;
long time = microTime / 1000L;
if (time > song.length) {
song.length = time;
}
}
}
}
}
song.sort();
return song;
}
public static Note getMidiInstrumentNote(int midiInstrument, int midiPitch, long microTime) {
Instrument instrument = null;
Instrument[] instrumentList = instrumentMap.get(midiInstrument);
if (instrumentList != null) {
for (Instrument candidateInstrument : instrumentList) {
if (midiPitch >= candidateInstrument.offset && midiPitch <= candidateInstrument.offset+24) {
instrument = candidateInstrument;
break;
}
}
}
if (instrument == null) {
return null;
}
int pitch = midiPitch-instrument.offset;
int noteId = pitch + instrument.instrumentId*25;
long time = microTime / 1000L;
return new Note(noteId, time);
}
private static Note getMidiPercussionNote(int midiPitch, long microTime) {
if (percussionMap.containsKey(midiPitch)) {
int noteId = percussionMap.get(midiPitch);
long time = microTime / 1000L;
return new Note(noteId, time);
}
return null;
}
public static HashMap<Integer, Instrument[]> instrumentMap = new HashMap<>();
static {
// Piano (HARP BASS BELL)
instrumentMap.put(0, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Acoustic Grand Piano
instrumentMap.put(1, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Bright Acoustic Piano
instrumentMap.put(2, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL}); // Electric Grand Piano
instrumentMap.put(3, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Honky-tonk Piano
instrumentMap.put(4, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL}); // Electric Piano 1
instrumentMap.put(5, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL}); // Electric Piano 2
instrumentMap.put(6, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Harpsichord
instrumentMap.put(7, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Clavinet
// Chromatic Percussion (IRON_XYLOPHONE XYLOPHONE BASS)
instrumentMap.put(8, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); // Celesta
instrumentMap.put(9, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); // Glockenspiel
instrumentMap.put(10, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); // Music Box
instrumentMap.put(11, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); // Vibraphone
instrumentMap.put(12, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); // Marimba
instrumentMap.put(13, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); // Xylophone
instrumentMap.put(14, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); // Tubular Bells
instrumentMap.put(15, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE}); // Dulcimer
// Organ (BIT DIDGERIDOO BELL)
instrumentMap.put(16, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Drawbar Organ
instrumentMap.put(17, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Percussive Organ
instrumentMap.put(18, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Rock Organ
instrumentMap.put(19, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Church Organ
instrumentMap.put(20, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Reed Organ
instrumentMap.put(21, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Accordian
instrumentMap.put(22, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Harmonica
instrumentMap.put(23, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Tango Accordian
// Guitar (BIT DIDGERIDOO BELL)
instrumentMap.put(24, new Instrument[]{Instrument.GUITAR, Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Acoustic Guitar (nylon)
instrumentMap.put(25, new Instrument[]{Instrument.GUITAR, Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Acoustic Guitar (steel)
instrumentMap.put(26, new Instrument[]{Instrument.GUITAR, Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Electric Guitar (jazz)
instrumentMap.put(27, new Instrument[]{Instrument.GUITAR, Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Electric Guitar (clean)
instrumentMap.put(28, new Instrument[]{Instrument.GUITAR, Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Electric Guitar (muted)
instrumentMap.put(29, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Overdriven Guitar
instrumentMap.put(30, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Distortion Guitar
instrumentMap.put(31, new Instrument[]{Instrument.GUITAR, Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Guitar Harmonics
// Bass
instrumentMap.put(32, new Instrument[]{Instrument.BASS, Instrument.HARP, Instrument.BELL}); // Acoustic Bass
instrumentMap.put(33, new Instrument[]{Instrument.BASS, Instrument.HARP, Instrument.BELL}); // Electric Bass (finger)
instrumentMap.put(34, new Instrument[]{Instrument.BASS, Instrument.HARP, Instrument.BELL}); // Electric Bass (pick)
instrumentMap.put(35, new Instrument[]{Instrument.BASS, Instrument.HARP, Instrument.BELL}); // Fretless Bass
instrumentMap.put(36, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Slap Bass 1
instrumentMap.put(37, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Slap Bass 2
instrumentMap.put(38, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Synth Bass 1
instrumentMap.put(39, new Instrument[]{Instrument.DIDGERIDOO, Instrument.BIT, Instrument.XYLOPHONE}); // Synth Bass 2
// Strings
instrumentMap.put(40, new Instrument[]{Instrument.FLUTE, Instrument.GUITAR, Instrument.BASS, Instrument.BELL}); // Violin
instrumentMap.put(41, new Instrument[]{Instrument.FLUTE, Instrument.GUITAR, Instrument.BASS, Instrument.BELL}); // Viola
instrumentMap.put(42, new Instrument[]{Instrument.FLUTE, Instrument.GUITAR, Instrument.BASS, Instrument.BELL}); // Cello
instrumentMap.put(43, new Instrument[]{Instrument.FLUTE, Instrument.GUITAR, Instrument.BASS, Instrument.BELL}); // Contrabass
instrumentMap.put(44, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL}); // Tremolo Strings
instrumentMap.put(45, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Pizzicato Strings
instrumentMap.put(46, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.CHIME}); // Orchestral Harp
instrumentMap.put(47, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Timpani
// Ensenble
instrumentMap.put(48, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // String Ensemble 1
instrumentMap.put(49, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // String Ensemble 2
instrumentMap.put(50, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Synth Strings 1
instrumentMap.put(51, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Synth Strings 2
instrumentMap.put(52, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Choir Aahs
instrumentMap.put(53, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Voice Oohs
instrumentMap.put(54, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Synth Choir
instrumentMap.put(55, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Orchestra Hit
// Brass
instrumentMap.put(56, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL});
instrumentMap.put(57, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL});
instrumentMap.put(58, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL});
instrumentMap.put(59, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL});
instrumentMap.put(60, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL});
instrumentMap.put(61, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL});
instrumentMap.put(62, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL});
instrumentMap.put(63, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL});
// Reed
instrumentMap.put(64, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL});
instrumentMap.put(65, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL});
instrumentMap.put(66, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL});
instrumentMap.put(67, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL});
instrumentMap.put(68, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL});
instrumentMap.put(69, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL});
instrumentMap.put(70, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL});
instrumentMap.put(71, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL});
// Pipe
instrumentMap.put(72, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL});
instrumentMap.put(73, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL});
instrumentMap.put(74, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL});
instrumentMap.put(75, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL});
instrumentMap.put(76, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL});
instrumentMap.put(77, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL});
instrumentMap.put(78, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL});
instrumentMap.put(79, new Instrument[]{Instrument.FLUTE, Instrument.DIDGERIDOO, Instrument.IRON_XYLOPHONE, Instrument.BELL});
// Synth Lead
instrumentMap.put(80, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
instrumentMap.put(81, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
instrumentMap.put(82, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
instrumentMap.put(83, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
instrumentMap.put(84, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
instrumentMap.put(85, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
instrumentMap.put(86, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
instrumentMap.put(87, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
// Synth Pad
instrumentMap.put(88, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
instrumentMap.put(89, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
instrumentMap.put(90, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
instrumentMap.put(91, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
instrumentMap.put(92, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
instrumentMap.put(93, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
instrumentMap.put(94, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
instrumentMap.put(95, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
// Synth Effects
// instrumentMap.put(96, new Instrument[]{});
// instrumentMap.put(97, new Instrument[]{});
instrumentMap.put(98, new Instrument[]{Instrument.BIT, Instrument.DIDGERIDOO, Instrument.BELL});
instrumentMap.put(99, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
instrumentMap.put(100, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
instrumentMap.put(101, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
instrumentMap.put(102, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
instrumentMap.put(103, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL});
// Ethnic
instrumentMap.put(104, new Instrument[]{Instrument.BANJO, Instrument.BASS, Instrument.BELL});
instrumentMap.put(105, new Instrument[]{Instrument.BANJO, Instrument.BASS, Instrument.BELL});
instrumentMap.put(106, new Instrument[]{Instrument.BANJO, Instrument.BASS, Instrument.BELL});
instrumentMap.put(107, new Instrument[]{Instrument.BANJO, Instrument.BASS, Instrument.BELL});
instrumentMap.put(108, new Instrument[]{Instrument.BANJO, Instrument.BASS, Instrument.BELL});
instrumentMap.put(109, new Instrument[]{Instrument.HARP, Instrument.DIDGERIDOO, Instrument.BELL});
instrumentMap.put(110, new Instrument[]{Instrument.HARP, Instrument.DIDGERIDOO, Instrument.BELL});
instrumentMap.put(111, new Instrument[]{Instrument.HARP, Instrument.DIDGERIDOO, Instrument.BELL});
// Percussive
instrumentMap.put(112, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE});
instrumentMap.put(113, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE});
instrumentMap.put(114, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE});
instrumentMap.put(115, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE});
instrumentMap.put(116, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE});
instrumentMap.put(117, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE});
instrumentMap.put(118, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE});
instrumentMap.put(119, new Instrument[]{Instrument.IRON_XYLOPHONE, Instrument.BASS, Instrument.XYLOPHONE});
}
public static HashMap<Integer, Integer> percussionMap = new HashMap<>();
static {
percussionMap.put(35, 10 + 25*Instrument.BASEDRUM.instrumentId);
percussionMap.put(36, 6 + 25*Instrument.BASEDRUM.instrumentId);
percussionMap.put(37, 6 + 25*Instrument.HAT.instrumentId);
percussionMap.put(38, 8 + 25*Instrument.SNARE.instrumentId);
percussionMap.put(39, 6 + 25*Instrument.HAT.instrumentId);
percussionMap.put(40, 4 + 25*Instrument.SNARE.instrumentId);
percussionMap.put(41, 6 + 25*Instrument.BASEDRUM.instrumentId);
percussionMap.put(42, 22 + 25*Instrument.SNARE.instrumentId);
percussionMap.put(43, 13 + 25*Instrument.BASEDRUM.instrumentId);
percussionMap.put(44, 22 + 25*Instrument.SNARE.instrumentId);
percussionMap.put(45, 15 + 25*Instrument.BASEDRUM.instrumentId);
percussionMap.put(46, 18 + 25*Instrument.SNARE.instrumentId);
percussionMap.put(47, 20 + 25*Instrument.BASEDRUM.instrumentId);
percussionMap.put(48, 23 + 25*Instrument.BASEDRUM.instrumentId);
percussionMap.put(49, 17 + 25*Instrument.SNARE.instrumentId);
percussionMap.put(50, 23 + 25*Instrument.BASEDRUM.instrumentId);
percussionMap.put(51, 24 + 25*Instrument.SNARE.instrumentId);
percussionMap.put(52, 8 + 25*Instrument.SNARE.instrumentId);
percussionMap.put(53, 13 + 25*Instrument.SNARE.instrumentId);
percussionMap.put(54, 18 + 25*Instrument.HAT.instrumentId);
percussionMap.put(55, 18 + 25*Instrument.SNARE.instrumentId);
percussionMap.put(56, 1 + 25*Instrument.HAT.instrumentId);
percussionMap.put(57, 13 + 25*Instrument.SNARE.instrumentId);
percussionMap.put(58, 2 + 25*Instrument.HAT.instrumentId);
percussionMap.put(59, 13 + 25*Instrument.SNARE.instrumentId);
percussionMap.put(60, 9 + 25*Instrument.HAT.instrumentId);
percussionMap.put(61, 2 + 25*Instrument.HAT.instrumentId);
percussionMap.put(62, 8 + 25*Instrument.HAT.instrumentId);
percussionMap.put(63, 22 + 25*Instrument.BASEDRUM.instrumentId);
percussionMap.put(64, 15 + 25*Instrument.BASEDRUM.instrumentId);
percussionMap.put(65, 13 + 25*Instrument.SNARE.instrumentId);
percussionMap.put(66, 8 + 25*Instrument.SNARE.instrumentId);
percussionMap.put(67, 8 + 25*Instrument.HAT.instrumentId);
percussionMap.put(68, 3 + 25*Instrument.HAT.instrumentId);
percussionMap.put(69, 20 + 25*Instrument.HAT.instrumentId);
percussionMap.put(70, 23 + 25*Instrument.HAT.instrumentId);
percussionMap.put(71, 24 + 25*Instrument.HAT.instrumentId);
percussionMap.put(72, 24 + 25*Instrument.HAT.instrumentId);
percussionMap.put(73, 17 + 25*Instrument.HAT.instrumentId);
percussionMap.put(74, 11 + 25*Instrument.HAT.instrumentId);
percussionMap.put(75, 18 + 25*Instrument.HAT.instrumentId);
percussionMap.put(76, 9 + 25*Instrument.HAT.instrumentId);
percussionMap.put(77, 5 + 25*Instrument.HAT.instrumentId);
percussionMap.put(78, 22 + 25*Instrument.HAT.instrumentId);
percussionMap.put(79, 19 + 25*Instrument.SNARE.instrumentId);
percussionMap.put(80, 17 + 25*Instrument.HAT.instrumentId);
percussionMap.put(81, 22 + 25*Instrument.HAT.instrumentId);
percussionMap.put(82, 22 + 25*Instrument.SNARE.instrumentId);
percussionMap.put(83, 24 + 25*Instrument.CHIME.instrumentId);
percussionMap.put(84, 24 + 25*Instrument.CHIME.instrumentId);
percussionMap.put(85, 21 + 25*Instrument.HAT.instrumentId);
percussionMap.put(86, 14 + 25*Instrument.BASEDRUM.instrumentId);
percussionMap.put(87, 7 + 25*Instrument.BASEDRUM.instrumentId);
}
}

View file

@ -16,6 +16,12 @@ public class Note implements Comparable<Note> {
else if (time > other.time) {
return 1;
}
else if (noteId < other.noteId) {
return -1;
}
else if (noteId > other.noteId) {
return 1;
}
else {
return 0;
}

View file

@ -1,6 +1,8 @@
package com.github.hhhzzzsss.songplayer.song;
import com.github.hhhzzzsss.songplayer.SongPlayer;
import com.github.hhhzzzsss.songplayer.conversion.MidiConverter;
import com.github.hhhzzzsss.songplayer.conversion.NBSConverter;
import java.io.IOException;
import java.net.URL;
@ -15,9 +17,12 @@ public class SongLoaderThread extends Thread{
private URL songUrl;
public Exception exception;
public Song song;
public String filename;
private boolean isUrl = false;
protected SongLoaderThread() {}
public SongLoaderThread(String location) throws IOException {
this.location = location;
if (location.startsWith("http://") || location.startsWith("https://")) {
@ -48,24 +53,23 @@ public class SongLoaderThread extends Thread{
public void run() {
try {
byte[] bytes;
String name;
if (isUrl) {
bytes = DownloadUtils.DownloadToByteArray(songUrl, 10*1024*1024);
name = Paths.get(songUrl.toURI().getPath()).getFileName().toString();
filename = Paths.get(songUrl.toURI().getPath()).getFileName().toString();
}
else {
bytes = Files.readAllBytes(songPath);
name = songPath.getFileName().toString();
filename = songPath.getFileName().toString();
}
try {
song = MidiConverter.getSongFromBytes(bytes, name);
song = MidiConverter.getSongFromBytes(bytes, filename);
}
catch (Exception e) {}
if (song == null) {
try {
song = NBSConverter.getSongFromBytes(bytes, name);
song = NBSConverter.getSongFromBytes(bytes, filename);
}
catch (Exception e) {}
}
@ -73,7 +77,6 @@ public class SongLoaderThread extends Thread{
if (song == null) {
throw new IOException("Invalid song format");
}
}
catch (Exception e) {
exception = e;
@ -81,8 +84,6 @@ public class SongLoaderThread extends Thread{
}
private Path getSongFile(String name) {
System.out.println(SongPlayer.SONG_DIR.resolve(name));
System.out.println(Files.exists(SongPlayer.SONG_DIR.resolve(name)));
return SongPlayer.SONG_DIR.resolve(name);
}
}