From ed8c89bcb262b168a8dbd2514a3bb5ab6fb5b705 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Wed, 27 Sep 2023 12:31:58 +0700 Subject: [PATCH] add an unused lyrics in midi --- .../chayapak/chomens_bot/song/MidiConverter.java | 16 ++++++++++++---- .../chipmunk/chayapak/chomens_bot/song/Song.java | 5 +++-- 2 files changed, 15 insertions(+), 6 deletions(-) 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 e155a19..773f9bb 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 @@ -5,15 +5,13 @@ import land.chipmunk.chayapak.chomens_bot.Bot; import javax.sound.midi.*; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.HashMap; +import java.util.*; // Author: hhhzzzsss public class MidiConverter implements Converter { public static final int TEXT = 0x01; public static final int TRACK_NAME = 0x03; + public static final int LYRICS = 0x05; public static final int SET_INSTRUMENT = 0xC0; public static final int SET_TEMPO = 0x51; public static final int NOTE_ON = 0x90; @@ -26,6 +24,8 @@ public class MidiConverter implements Converter { } public static Song getSong(Sequence sequence, String name, Bot bot) { + final Map lyrics = new HashMap<>(); + long tpq = sequence.getResolution(); String songName = null; @@ -55,6 +55,10 @@ public class MidiConverter implements Converter { } else if (mm.getType() == TEXT) { text.append(new String(mm.getData())); text.append('\n'); + } else if (mm.getType() == LYRICS) { + final String lyric = new String(mm.getMessage()); + + lyrics.put(event.getTick(), lyric); } } } @@ -130,6 +134,10 @@ public class MidiConverter implements Converter { } } } + + if (lyrics.get(event.getTick()) != null) { + song.lyrics.put(microTime / 1000L, lyrics.get(event.getTick())); + } } } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/Song.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/Song.java index 218a72b..65891ea 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/Song.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/Song.java @@ -2,8 +2,7 @@ package land.chipmunk.chayapak.chomens_bot.song; import land.chipmunk.chayapak.chomens_bot.Bot; -import java.util.ArrayList; -import java.util.Collections; +import java.util.*; // Author: hhhzzzsss & _ChipMC_ but i changed most of the stuff public class Song { @@ -18,6 +17,8 @@ public class Song { public long time = 0; // Time since start of song public long loopPosition = 200; // Milliseconds into the song to start looping + public final Map lyrics = new HashMap<>(); + public String songName; public String songAuthor; public String songOriginalAuthor;