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.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
// Author: _ChipMC_ & chayapak <3
@ -234,42 +233,43 @@ public class MusicPlayerPlugin extends Bot.Listener {
}
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;
if (lyrics.isEmpty()) return;
// this will be a piece of text for now
/*
final List<String> lyricsList = new ArrayList<>();
for (Map.Entry<Long, String> entry : lyrics.entrySet()) {
final long time = entry.getKey();
final String _lyric = entry.getValue();
String _lyric = entry.getValue();
if (time > currentSong.time) continue;
StringBuilder lyric = new StringBuilder();
for (char character : _lyric.toCharArray()) {
if (character == '\n' || character == '\r') {
lyricsList.clear();
continue;
}
if (character < ' ' || character == '<27>') continue;
if ((character != '\n' && character != '\r' && character < ' ') || character == '<27>') continue;
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() {

View file

@ -5,6 +5,7 @@ import land.chipmunk.chayapak.chomens_bot.Bot;
import javax.sound.midi.*;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import static javax.sound.midi.ShortMessage.SYSTEM_RESET;
@ -49,7 +50,7 @@ public class MidiConverter implements Converter {
if (mm.getType() == SET_TEMPO) {
tempoEvents.add(event);
} 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()) {
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;
}
} else if (mm.getType() == TEXT) {
text.append(new String(mm.getData()));
text.append(new String(mm.getData(), StandardCharsets.UTF_8));
text.append('\n');
} 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);
}

View file

@ -13,6 +13,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
@ -259,7 +260,7 @@ public class NBSConverter implements Converter {
}
byte[] arr = new byte[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) {

View file

@ -2,10 +2,12 @@ package land.chipmunk.chayapak.chomens_bot.song;
import land.chipmunk.chayapak.chomens_bot.Bot;
import java.nio.charset.StandardCharsets;
public class TextFileConverter implements Converter {
@Override
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;