From 97c1d5b96364723a5daa4f12c0ed2226522fc119 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 20 Aug 2023 17:52:40 +0700 Subject: [PATCH] port songplayer test song for some reason --- .../chomens_bot/commands/MusicCommand.java | 46 +++++++++++++++++++ .../chayapak/chomens_bot/song/Song.java | 8 ++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java index 258871f..9334871 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java @@ -6,7 +6,9 @@ import land.chipmunk.chayapak.chomens_bot.command.Command; import land.chipmunk.chayapak.chomens_bot.command.CommandContext; import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; import land.chipmunk.chayapak.chomens_bot.plugins.MusicPlayerPlugin; +import land.chipmunk.chayapak.chomens_bot.song.Instrument; import land.chipmunk.chayapak.chomens_bot.song.Loop; +import land.chipmunk.chayapak.chomens_bot.song.Note; import land.chipmunk.chayapak.chomens_bot.song.Song; import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities; import land.chipmunk.chayapak.chomens_bot.util.TimestampUtilities; @@ -81,6 +83,7 @@ public class MusicCommand extends Command { case "noteinstrument" -> noteInstrument(context, args); case "pause", "resume" -> pause(context); case "info" -> info(context); + case "testsong" -> testSong(context); default -> Component.text("Invalid action").color(NamedTextColor.RED); }; } @@ -435,4 +438,47 @@ public class MusicCommand extends Command { Component.text(songDescription).color(NamedTextColor.AQUA) ).color(NamedTextColor.GOLD); } + + public Component testSong (CommandContext context) { + final Bot bot = context.bot; + + final Song song = new Song( + "test_song", + bot, + "Test Song", + "chayapak", + "hhhzzzsss", + "SongPlayer's test song ported to ChomeNS Bot", + false + ); + + int instrumentId = 0; + int j = 0; + for (int i = 0; i < 400; i++) { + j++; + + song.add( + new Note( + Instrument.fromId(instrumentId), + j, + 1, + i * 50, + -1, + 100 + ) + ); + + if (j > 15) { + instrumentId++; + if (instrumentId > 15) instrumentId = 0; + j = 0; + } + } + + song.length = 400 * 50; + + bot.music.songQueue.add(song); + + return Component.text("Test song has been added to the song queue").color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor)); + } } 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 b8960ac..f9c38bf 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 @@ -37,20 +37,20 @@ public class Song { if (isNotNullAndNotBlank(songOriginalAuthor) && !isNotNullAndNotBlank(songAuthor)) name = String.format( "%s - %s", songOriginalAuthor, - originalName + isNotNullAndNotBlank(songName) ? songName : originalName ); else if (!isNotNullAndNotBlank(songOriginalAuthor) && isNotNullAndNotBlank(songAuthor)) name = String.format( "%s - %s", songAuthor, - originalName + isNotNullAndNotBlank(songName) ? songName : originalName ); else if (isNotNullAndNotBlank(songOriginalAuthor) && isNotNullAndNotBlank(songAuthor)) name = String.format( "%s/%s - %s", songOriginalAuthor, songAuthor, - originalName + isNotNullAndNotBlank(songName) ? songName : originalName ); - else name = originalName; + else name = isNotNullAndNotBlank(songName) ? songName : originalName; this.originalName = originalName; this.name = name;