Compare commits

...

2 commits

7 changed files with 55 additions and 36 deletions

View file

@ -31,6 +31,8 @@ import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static me.chayapak1.chomens_bot.util.StringUtilities.isNotNullAndNotBlank;
public class MusicCommand extends Command { public class MusicCommand extends Command {
private Path root; private Path root;
@ -599,11 +601,12 @@ public class MusicCommand extends Command {
final TextColor keyColor = ColorUtilities.getColorByString(bot.config.colorPalette.secondary); final TextColor keyColor = ColorUtilities.getColorByString(bot.config.colorPalette.secondary);
final TextColor valueColor = ColorUtilities.getColorByString(bot.config.colorPalette.string); final TextColor valueColor = ColorUtilities.getColorByString(bot.config.colorPalette.string);
if (currentSong.name != null) components.add(Component.translatable("Title/Filename: %s", Component.text(currentSong.name).color(valueColor)).color(keyColor)); if (isNotNullAndNotBlank(currentSong.name)) components.add(Component.translatable("Title/Filename: %s", Component.text(currentSong.name).color(valueColor)).color(keyColor));
if (currentSong.requester != null) components.add(Component.translatable("Requester: %s", Component.text(currentSong.requester).color(valueColor)).color(keyColor)); if (isNotNullAndNotBlank(currentSong.requester)) components.add(Component.translatable("Requester: %s", Component.text(currentSong.requester).color(valueColor)).color(keyColor));
if (currentSong.songAuthor != null && !currentSong.songAuthor.isBlank()) components.add(Component.translatable("Author: %s", Component.text(currentSong.songAuthor).color(valueColor)).color(keyColor)); if (isNotNullAndNotBlank(currentSong.songAuthor)) components.add(Component.translatable("Author: %s", Component.text(currentSong.songAuthor).color(valueColor)).color(keyColor));
if (currentSong.songOriginalAuthor != null && !currentSong.songOriginalAuthor.isBlank()) components.add(Component.translatable("Original author: %s", Component.text(currentSong.songOriginalAuthor).color(valueColor)).color(keyColor)); if (isNotNullAndNotBlank(currentSong.songOriginalAuthor)) components.add(Component.translatable("Original author: %s", Component.text(currentSong.songOriginalAuthor).color(valueColor)).color(keyColor));
if (currentSong.songDescription != null && !currentSong.songDescription.isBlank()) components.add(Component.translatable("Description: %s", Component.text(currentSong.songDescription).color(valueColor)).color(keyColor)); if (isNotNullAndNotBlank(currentSong.tracks)) components.add(Component.translatable("Tracks: %s", Component.text(currentSong.tracks).color(valueColor)).color(keyColor));
if (isNotNullAndNotBlank(currentSong.songDescription)) components.add(Component.translatable("Description: %s", Component.text(currentSong.songDescription).color(valueColor)).color(keyColor));
return Component.join(JoinConfiguration.newlines(), components); return Component.join(JoinConfiguration.newlines(), components);
} }
@ -620,6 +623,7 @@ public class MusicCommand extends Command {
"chayapak", "chayapak",
"hhhzzzsss", "hhhzzzsss",
"SongPlayer's test song ported to ChomeNS Bot", "SongPlayer's test song ported to ChomeNS Bot",
null,
false false
); );

View file

@ -35,6 +35,7 @@ public class MidiConverter implements Converter {
String songName = null; String songName = null;
final StringBuilder tracks = new StringBuilder();
final StringBuilder text = new StringBuilder(); final StringBuilder text = new StringBuilder();
boolean isFirst = true; boolean isFirst = true;
@ -49,10 +50,15 @@ public class MidiConverter implements Converter {
if (message instanceof MetaMessage mm) { if (message instanceof MetaMessage mm) {
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) {
final String stringTitle = new String(mm.getData(), StandardCharsets.UTF_8); final String stringTitle = new String(mm.getData(), StandardCharsets.UTF_8);
if (!stringTitle.isBlank()) { if (stringTitle.isBlank()) continue;
tracks.append(stringTitle);
tracks.append("\n");
if (isFirst) {
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)
isFirst = false; isFirst = false;
@ -69,10 +75,13 @@ public class MidiConverter implements Converter {
} }
} }
String stringTracks = tracks.toString();
String stringText = text.toString(); String stringText = text.toString();
if (stringText.endsWith("\n")) stringText = stringText.substring(0, stringText.length() - 1);
final Song song = new Song(name, bot, songName, null, null, stringText, false); if (stringText.endsWith("\n")) stringText = stringText.substring(0, stringText.length() - 1);
if (stringTracks.endsWith("\n")) stringTracks = stringTracks.substring(0, stringTracks.length() - 1);
final Song song = new Song(name, bot, songName, null, null, stringText, stringTracks, false);
tempoEvents.sort(Comparator.comparingLong(MidiEvent::getTick)); tempoEvents.sort(Comparator.comparingLong(MidiEvent::getTick));

View file

@ -165,7 +165,16 @@ public class NBSConverter implements Converter {
} }
} }
Song song = new Song(!songName.isBlank() ? songName : fileName, bot, songName, songAuthor, songOriginalAuthor, songDescription, true); final StringBuilder layerNames = new StringBuilder();
for (NBSLayer layer : nbsLayers) {
layerNames.append(layer.name);
layerNames.append("\n");
}
final String stringLayerNames = layerNames.toString();
Song song = new Song(!songName.isBlank() ? songName : fileName, bot, songName, songAuthor, songOriginalAuthor, songDescription, stringLayerNames.substring(0, stringLayerNames.length() - 1), true);
if (loop > 0) { if (loop > 0) {
song.loopPosition = getMilliTime(loopStartTick, tempo); song.loopPosition = getMilliTime(loopStartTick, tempo);
// song.loopCount = maxLoopCount; // song.loopCount = maxLoopCount;

View file

@ -4,6 +4,8 @@ import me.chayapak1.chomens_bot.Bot;
import java.util.*; import java.util.*;
import static me.chayapak1.chomens_bot.util.StringUtilities.isNotNullAndNotBlank;
// Author: hhhzzzsss & _ChipMC_ but i changed most of the stuff // Author: hhhzzzsss & _ChipMC_ but i changed most of the stuff
public class Song { public class Song {
public final ArrayList<Note> notes = new ArrayList<>(); public final ArrayList<Note> notes = new ArrayList<>();
@ -24,6 +26,8 @@ public class Song {
public String songOriginalAuthor; public String songOriginalAuthor;
public String songDescription; public String songDescription;
public String tracks;
public final boolean nbs; public final boolean nbs;
// public int loopCount = 0; // Number of times to loop // public int loopCount = 0; // Number of times to loop
@ -31,43 +35,32 @@ public class Song {
private final Bot bot; private final Bot bot;
public Song (String originalName, Bot bot, String songName, String songAuthor, String songOriginalAuthor, String songDescription, boolean nbs) { public Song (String originalName, Bot bot, String songName, String songAuthor, String songOriginalAuthor, String songDescription, String tracks, boolean nbs) {
this.originalName = originalName; this.originalName = originalName;
this.bot = bot; this.bot = bot;
this.songName = songName; this.songName = songName;
this.songAuthor = songAuthor; this.songAuthor = songAuthor;
this.songOriginalAuthor = songOriginalAuthor; this.songOriginalAuthor = songOriginalAuthor;
this.songDescription = songDescription; this.songDescription = songDescription;
this.tracks = tracks;
this.nbs = nbs; this.nbs = nbs;
updateName(); updateName();
} }
public void updateName() { public void updateName() {
// real ohio code String authorPart = null;
// TODO: clean this up
if (isNotNullAndNotBlank(songOriginalAuthor) && !isNotNullAndNotBlank(songAuthor)) name = String.format(
"%s - %s",
songOriginalAuthor,
isNotNullAndNotBlank(songName) ? songName : originalName
);
else if (!isNotNullAndNotBlank(songOriginalAuthor) && isNotNullAndNotBlank(songAuthor)) name = String.format(
"%s - %s",
songAuthor,
isNotNullAndNotBlank(songName) ? songName : originalName
);
else if (isNotNullAndNotBlank(songOriginalAuthor) && isNotNullAndNotBlank(songAuthor)) name = String.format(
"%s/%s - %s",
songOriginalAuthor,
songAuthor,
isNotNullAndNotBlank(songName) ? songName : originalName
);
else name = isNotNullAndNotBlank(songName) ? songName : originalName;
}
// should this be in idk, util? if (isNotNullAndNotBlank(songOriginalAuthor) && isNotNullAndNotBlank(songAuthor)) {
private boolean isNotNullAndNotBlank (String text) { authorPart = String.format("%s/%s", songOriginalAuthor, songAuthor);
return text != null && !text.isBlank(); } else if (isNotNullAndNotBlank(songOriginalAuthor)) {
authorPart = songOriginalAuthor;
} else if (isNotNullAndNotBlank(songAuthor)) {
authorPart = songAuthor;
}
String namePart = isNotNullAndNotBlank(songName) ? songName : originalName;
name = (authorPart != null) ? String.format("%s - %s", authorPart, namePart) : namePart;
} }
public Note get (int i) { public Note get (int i) {

View file

@ -42,7 +42,7 @@ public class SongPlayerConverter implements Converter {
int loopCount = buffer.get() & 0xFF; int loopCount = buffer.get() & 0xFF;
long loopPosition = buffer.getLong(); long loopPosition = buffer.getLong();
Song song = new Song(fileName, bot, !songName.trim().isEmpty() ? songName : null, null, null, null, false); Song song = new Song(fileName, bot, !songName.trim().isEmpty() ? songName : null, null, null, null, null, false);
song.length = songLength; song.length = songLength;
// song.looping = loop > 0; // song.looping = loop > 0;
// song.loopCount = loopCount; // song.loopCount = loopCount;

View file

@ -13,7 +13,7 @@ public class TextFileConverter implements Converter {
int length = 0; int length = 0;
final Song song = new Song(fileName, bot, null, null, null, null, false); final Song song = new Song(fileName, bot, null, null, null, null, null, false);
for (String line : data.split("\r\n|\r|\n")) { for (String line : data.split("\r\n|\r|\n")) {
if (line.isBlank()) continue; if (line.isBlank()) continue;

View file

@ -50,4 +50,8 @@ public class StringUtilities {
return false; return false;
} }
public static boolean isNotNullAndNotBlank (String text) {
return text != null && !text.isBlank();
}
} }