From bf369ac3a57852c83a26ca349d0c6e13f6603003 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 23 Sep 2023 14:00:23 +0700 Subject: [PATCH] midi name (finally) --- .../chayapak/chomens_bot/commands/MusicCommand.java | 2 +- .../chayapak/chomens_bot/song/MidiConverter.java | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java index 53675c9..523a537 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java @@ -434,7 +434,7 @@ public class MusicCommand extends Command { if (currentSong == null) throw new CommandException(Component.text("No song is currently playing")); // ig very code yup - final String title = currentSong.originalName; + final String title = currentSong.name; final String songAuthor = currentSong.songAuthor == null || currentSong.songAuthor.equals("") ? "N/A" : currentSong.songAuthor; final String songOriginalAuthor = currentSong.songOriginalAuthor == null || currentSong.songOriginalAuthor.equals("") ? "N/A" : currentSong.songOriginalAuthor; final String songDescription = currentSong.songDescription == null || currentSong.songDescription.equals("") ? "N/A" : currentSong.songDescription; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/MidiConverter.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/MidiConverter.java index 13dca47..caa7495 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/MidiConverter.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/MidiConverter.java @@ -11,6 +11,7 @@ import java.util.HashMap; // Author: hhhzzzsss public class MidiConverter implements Converter { + public static final int TRACK_NAME = 0x03; public static final int SET_INSTRUMENT = 0xC0; public static final int SET_TEMPO = 0x51; public static final int NOTE_ON = 0x90; @@ -23,10 +24,10 @@ public class MidiConverter implements Converter { } public static Song getSong(Sequence sequence, String name, Bot bot) { - Song song = new Song(name, bot, null, null, null, null, false); - long tpq = sequence.getResolution(); + String songName = null; + ArrayList tempoEvents = new ArrayList<>(); for (Track track : sequence.getTracks()) { final int trackSize = track.size(); @@ -37,10 +38,14 @@ public class MidiConverter implements Converter { if (message instanceof MetaMessage mm) { if (mm.getType() == SET_TEMPO) { tempoEvents.add(event); + } else if (mm.getType() == TRACK_NAME) { + songName = new String(mm.getData()) + " (" + name + ")"; // i have put the ` (filename)` just in case the sequence is getting sus (like Track 2 for example) } } } } + + final Song song = new Song(name, bot, songName, null, null, null, false); tempoEvents.sort(Comparator.comparingLong(MidiEvent::getTick));