fix: partially fix music speed
This commit is contained in:
@@ -404,7 +404,7 @@ public class MusicCommand extends Command {
|
||||
|
||||
if (currentSong == null) throw new CommandException(Component.text("No song is currently playing"));
|
||||
|
||||
if (timestamp < 0 || timestamp > currentSong.length)
|
||||
if (timestamp < 0 || timestamp > currentSong.length * bot.music.speed)
|
||||
throw new CommandException(Component.text("Invalid timestamp"));
|
||||
|
||||
currentSong.setTime(timestamp);
|
||||
@@ -436,14 +436,14 @@ public class MusicCommand extends Command {
|
||||
final Bot bot = context.bot;
|
||||
final Song currentSong = bot.music.currentSong;
|
||||
|
||||
final float speed = context.getFloat(true, false);
|
||||
final double speed = context.getDouble(true, false);
|
||||
|
||||
if (speed > 5) throw new CommandException(Component.text("Too fast!"));
|
||||
else if (speed < 0) throw new CommandException(Component.text("Invalid speed"));
|
||||
|
||||
long oldTime = -1;
|
||||
double oldTime = -1;
|
||||
|
||||
if (currentSong != null) oldTime = currentSong.time;
|
||||
if (currentSong != null) oldTime = currentSong.time / speed;
|
||||
|
||||
bot.music.speed = speed;
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ public class MusicPlayerPlugin implements Listener {
|
||||
|
||||
private static final String BOSS_BAR_NAME = "music";
|
||||
|
||||
private static final DecimalFormat FORMATTER = new DecimalFormat("#,###");
|
||||
|
||||
static {
|
||||
try {
|
||||
if (!Files.exists(SONG_DIR)) Files.createDirectory(SONG_DIR);
|
||||
@@ -55,8 +57,8 @@ public class MusicPlayerPlugin implements Listener {
|
||||
public Loop loop = Loop.OFF;
|
||||
|
||||
// sus nightcore stuff,..,.,.
|
||||
public float pitch = 0;
|
||||
public float speed = 1;
|
||||
public double pitch = 0;
|
||||
public double speed = 1;
|
||||
|
||||
public float volume = 0;
|
||||
public int amplify = 1;
|
||||
@@ -166,8 +168,8 @@ public class MusicPlayerPlugin implements Listener {
|
||||
if (bossBar != null && bot.options.useCore) {
|
||||
bossBar.setTitle(generateBossBar());
|
||||
bossBar.setColor(bossBarColor);
|
||||
bossBar.setValue((int) Math.floor(((double) (currentSong.time * speed) / 1000)));
|
||||
bossBar.setMax((long) (currentSong.length * speed) / 1000);
|
||||
bossBar.setValue((int) Math.floor(((currentSong.time / speed) / 1000)));
|
||||
bossBar.setMax((long) (currentSong.length / speed) / 1000);
|
||||
}
|
||||
|
||||
if (currentSong.paused || bot.core.isRateLimited()) return;
|
||||
@@ -322,20 +324,18 @@ public class MusicPlayerPlugin implements Listener {
|
||||
.append(
|
||||
Component
|
||||
.translatable("%s / %s",
|
||||
formatTime((long) (currentSong.time * speed)).color(NamedTextColor.GRAY),
|
||||
formatTime((long) (currentSong.length * speed)).color(NamedTextColor.GRAY)).color(NamedTextColor.DARK_GRAY)
|
||||
formatTime((long) (currentSong.time / speed)).color(NamedTextColor.GRAY),
|
||||
formatTime((long) (currentSong.length / speed)).color(NamedTextColor.GRAY)).color(NamedTextColor.DARK_GRAY)
|
||||
);
|
||||
|
||||
final DecimalFormat formatter = new DecimalFormat("#,###");
|
||||
|
||||
if (!bot.core.hasRateLimit()) {
|
||||
component = component
|
||||
.append(Component.text(" | ").color(NamedTextColor.DARK_GRAY))
|
||||
.append(
|
||||
Component.translatable(
|
||||
"%s / %s",
|
||||
Component.text(formatter.format(currentSong.position), NamedTextColor.GRAY),
|
||||
Component.text(formatter.format(currentSong.size()), NamedTextColor.GRAY)
|
||||
Component.text(FORMATTER.format(currentSong.position), NamedTextColor.GRAY),
|
||||
Component.text(FORMATTER.format(currentSong.size()), NamedTextColor.GRAY)
|
||||
).color(NamedTextColor.DARK_GRAY)
|
||||
);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ public class Note implements Comparable<Note> {
|
||||
public final double shiftedPitch;
|
||||
public final double originalPitch;
|
||||
public final float volume;
|
||||
public final long time;
|
||||
public final double time;
|
||||
public final int panning;
|
||||
public final int stereo;
|
||||
public final boolean isRainbowToggle;
|
||||
@@ -18,7 +18,7 @@ public class Note implements Comparable<Note> {
|
||||
final double pitch,
|
||||
final double originalPitch,
|
||||
final float volume,
|
||||
final long time,
|
||||
final double time,
|
||||
final int panning,
|
||||
final int stereo,
|
||||
final boolean isRainbowToggle
|
||||
@@ -42,7 +42,7 @@ public class Note implements Comparable<Note> {
|
||||
final double shiftedPitch,
|
||||
final double originalPitch,
|
||||
final float volume,
|
||||
final long time,
|
||||
final double time,
|
||||
final int panning,
|
||||
final int stereo
|
||||
) {
|
||||
@@ -60,6 +60,6 @@ public class Note implements Comparable<Note> {
|
||||
|
||||
@Override
|
||||
public int compareTo (final Note other) {
|
||||
return Long.compare(time, other.time);
|
||||
return Double.compare(time, other.time);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ public class Song {
|
||||
public String requester = "Unknown";
|
||||
public int position = 0; // Current note index
|
||||
public boolean paused = true;
|
||||
public long startTime = 0; // Start time in millis since unix epoch
|
||||
public long length = 0; // Milliseconds in the song
|
||||
public long time = 0; // Time since start of song
|
||||
public double startTime = 0; // Start time in millis since unix epoch
|
||||
public double length = 0; // Milliseconds in the song
|
||||
public double time = 0; // Time since start of song
|
||||
public long loopPosition = 0; // Milliseconds into the song to start looping
|
||||
|
||||
public final Map<Long, String> lyrics = new HashMap<>();
|
||||
@@ -100,26 +100,26 @@ public class Song {
|
||||
}
|
||||
}
|
||||
|
||||
public void setTime (final long t) {
|
||||
public void setTime (final double t) {
|
||||
time = t;
|
||||
startTime = System.currentTimeMillis() - time;
|
||||
position = 0;
|
||||
while (position < notes.size() && notes.get(position).time < t) {
|
||||
while (position < notes.size() && notes.get(position).time / bot.music.speed <= t) {
|
||||
position++;
|
||||
}
|
||||
}
|
||||
|
||||
public void advanceTime () {
|
||||
time = (long) ((System.currentTimeMillis() - startTime) * bot.music.speed);
|
||||
time = (System.currentTimeMillis() - startTime) * bot.music.speed;
|
||||
}
|
||||
|
||||
public boolean reachedNextNote () {
|
||||
if (position < notes.size()) {
|
||||
return notes.get(position).time <= time * bot.music.speed;
|
||||
return notes.get(position).time / bot.music.speed <= time;
|
||||
} else {
|
||||
if (finished() && bot.music.loop != Loop.OFF) {
|
||||
if (position < notes.size()) {
|
||||
return notes.get(position).time <= time * bot.music.speed;
|
||||
return notes.get(position).time / bot.music.speed <= time;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -133,7 +133,7 @@ public class Song {
|
||||
position = 0;
|
||||
startTime += length - loopPosition;
|
||||
time -= length - loopPosition;
|
||||
while (position < notes.size() && notes.get(position).time < loopPosition) {
|
||||
while (position < notes.size() && notes.get(position).time / bot.music.speed < loopPosition) {
|
||||
position++;
|
||||
}
|
||||
}
|
||||
@@ -144,7 +144,7 @@ public class Song {
|
||||
}
|
||||
|
||||
public boolean finished () {
|
||||
return (time * bot.music.speed) > length || position >= size();
|
||||
return time > length || position >= size();
|
||||
}
|
||||
|
||||
public int size () {
|
||||
|
||||
Reference in New Issue
Block a user