more attempt on this shit

This commit is contained in:
Chayapak 2023-10-12 16:38:27 +07:00
parent 7269e8440d
commit 7956646940
4 changed files with 25 additions and 21 deletions

View file

@ -22,7 +22,6 @@ import java.nio.file.Path;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
// Author: _ChipMC_ & chayapak <3 // Author: _ChipMC_ & chayapak <3
@ -234,42 +233,43 @@ public class MusicPlayerPlugin extends Bot.Listener {
} }
private void handleLyrics () { private void handleLyrics () {
// please help, this is many attempts trying to get this working
// midi lyrics are very weird
// i need some karaoke players too see how this works
/*
final Map<Long, String> lyrics = currentSong.lyrics; final Map<Long, String> lyrics = currentSong.lyrics;
if (lyrics.isEmpty()) return; if (lyrics.isEmpty()) return;
// this will be a piece of text for now
/*
final List<String> lyricsList = new ArrayList<>(); final List<String> lyricsList = new ArrayList<>();
for (Map.Entry<Long, String> entry : lyrics.entrySet()) { for (Map.Entry<Long, String> entry : lyrics.entrySet()) {
final long time = entry.getKey(); final long time = entry.getKey();
final String _lyric = entry.getValue(); String _lyric = entry.getValue();
if (time > currentSong.time) continue; if (time > currentSong.time) continue;
StringBuilder lyric = new StringBuilder(); StringBuilder lyric = new StringBuilder();
for (char character : _lyric.toCharArray()) { for (char character : _lyric.toCharArray()) {
if (character == '\n' || character == '\r') { if ((character != '\n' && character != '\r' && character < ' ') || character == '<27>') continue;
lyricsList.clear();
continue;
}
if (character < ' ' || character == '<27>') continue;
lyric.append(character); lyric.append(character);
} }
while (lyricsList.size() > 10) lyricsList.remove(0); final String stringLyric = lyric.toString();
lyricsList.add(lyric.toString()); if ( stringLyric.equals("\n") || stringLyric.equals("\r") || stringLyric.equals("\r\n") || stringLyric.equals("\n\r")) {
lyricsList.clear();
}
lyricsList.add(stringLyric);
// while (lyricsList.size() > 10) lyricsList.remove(0);
} }
currentLyrics = String.join("", lyricsList); currentLyrics = String.join("", lyricsList); */
*/
} }
public void removeBossBar() { public void removeBossBar() {

View file

@ -5,6 +5,7 @@ import land.chipmunk.chayapak.chomens_bot.Bot;
import javax.sound.midi.*; import javax.sound.midi.*;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import static javax.sound.midi.ShortMessage.SYSTEM_RESET; import static javax.sound.midi.ShortMessage.SYSTEM_RESET;
@ -49,7 +50,7 @@ public class MidiConverter implements Converter {
if (mm.getType() == SET_TEMPO) { if (mm.getType() == SET_TEMPO) {
tempoEvents.add(event); tempoEvents.add(event);
} else if (mm.getType() == TRACK_NAME && isFirst) { } else if (mm.getType() == TRACK_NAME && isFirst) {
final String stringTitle = new String(mm.getData()); final String stringTitle = new String(mm.getData(), StandardCharsets.UTF_8);
if (!stringTitle.isBlank()) { if (!stringTitle.isBlank()) {
songName = stringTitle + " (" + name + ")"; // i have put the ` (filename)` just in case the sequence is getting sus (like Track 2 for example) songName = stringTitle + " (" + name + ")"; // i have put the ` (filename)` just in case the sequence is getting sus (like Track 2 for example)
@ -57,10 +58,10 @@ public class MidiConverter implements Converter {
isFirst = false; isFirst = false;
} }
} else if (mm.getType() == TEXT) { } else if (mm.getType() == TEXT) {
text.append(new String(mm.getData())); text.append(new String(mm.getData(), StandardCharsets.UTF_8));
text.append('\n'); text.append('\n');
} else if (mm.getType() == LYRICS) { } else if (mm.getType() == LYRICS) {
final String lyric = new String(mm.getMessage()); final String lyric = new String(mm.getMessage(), StandardCharsets.UTF_8);
lyrics.put(event.getTick(), lyric); lyrics.put(event.getTick(), lyric);
} }

View file

@ -13,6 +13,7 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -259,7 +260,7 @@ public class NBSConverter implements Converter {
} }
byte[] arr = new byte[length]; byte[] arr = new byte[length];
buffer.get(arr, 0, length); buffer.get(arr, 0, length);
return new String(arr); return new String(arr, StandardCharsets.UTF_8);
} }
private static int getMilliTime(int tick, int tempo) { private static int getMilliTime(int tick, int tempo) {

View file

@ -2,10 +2,12 @@ package land.chipmunk.chayapak.chomens_bot.song;
import land.chipmunk.chayapak.chomens_bot.Bot; import land.chipmunk.chayapak.chomens_bot.Bot;
import java.nio.charset.StandardCharsets;
public class TextFileConverter implements Converter { public class TextFileConverter implements Converter {
@Override @Override
public Song getSongFromBytes(byte[] bytes, String fileName, Bot bot) { public Song getSongFromBytes(byte[] bytes, String fileName, Bot bot) {
final String data = new String(bytes); final String data = new String(bytes, StandardCharsets.UTF_8);
if (!data.contains(":")) return null; if (!data.contains(":")) return null;