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

View file

@ -35,6 +35,7 @@ public class MidiConverter implements Converter {
String songName = null;
final StringBuilder tracks = new StringBuilder();
final StringBuilder text = new StringBuilder();
boolean isFirst = true;
@ -49,10 +50,15 @@ public class MidiConverter implements Converter {
if (message instanceof MetaMessage mm) {
if (mm.getType() == SET_TEMPO) {
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);
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)
isFirst = false;
@ -69,10 +75,13 @@ public class MidiConverter implements Converter {
}
}
String stringTracks = tracks.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));

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) {
song.loopPosition = getMilliTime(loopStartTick, tempo);
// song.loopCount = maxLoopCount;

View file

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

View file

@ -42,7 +42,7 @@ public class SongPlayerConverter implements Converter {
int loopCount = buffer.get() & 0xFF;
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.looping = loop > 0;
// song.loopCount = loopCount;

View file

@ -13,7 +13,7 @@ public class TextFileConverter implements Converter {
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")) {
if (line.isBlank()) continue;

View file

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