Skip to content

Commit

Permalink
Updated bass boost function with persistent mode fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aidswidjaja committed Sep 28, 2021
1 parent 2230bed commit 4f50933
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 15 deletions.
34 changes: 34 additions & 0 deletions src/main/java/com/jagrosh/jmusicbot/audio/AudioHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.jagrosh.jmusicbot.JMusicBot;
import com.jagrosh.jmusicbot.playlist.PlaylistLoader.Playlist;
import com.sedmelluq.discord.lavaplayer.filter.equalizer.EqualizerFactory;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
Expand Down Expand Up @@ -55,6 +56,11 @@ public class AudioHandler extends AudioEventAdapter implements AudioSendHandler

private AudioFrame lastFrame;

public static final float[] BASS_BOOST = {0.2f, 0.15f, 0.1f, 0.05f, 0.0f, -0.05f, -0.1f, -0.1f, -0.1f, -0.1f, -0.1f,
-0.1f, -0.1f, -0.1f, -0.1f};

public static EqualizerFactory equalizer;

protected AudioHandler(PlayerManager manager, Guild guild, AudioPlayer player)
{
this.manager = manager;
Expand Down Expand Up @@ -184,6 +190,34 @@ public void onTrackStart(AudioPlayer player, AudioTrack track)
{
votes.clear();
manager.getBot().getNowplayingHandler().onTrackUpdate(guildId, track, this);

/* bass boost when the mode is enabled but the bot had died before */
/* refer to repeat mode class */

Settings s = manager.getBot().getSettingsManager().getSettings(guildId);

this.equalizer = new EqualizerFactory();

getPlayer().setFilterFactory(equalizer);

if (s.getBassBoost()) {

for (int i = 0; i < BASS_BOOST.length; i++) {
equalizer.setGain(i, BASS_BOOST[i] + 2);
}

for (int i = 0; i < BASS_BOOST.length; i++) {
equalizer.setGain(i, -BASS_BOOST[i] + 1);

}

}
else
{

getPlayer().setFilterFactory(null);

}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected void execute(CommandEvent event)
"\n • See what's new on BopBot with the new `changelog` command (yep this one!)" +
"\n • Fixed the bass boost feature, which lets you add bass boost to any track with the new `bassboost` command" +
"\n\n**Check out our website at [bopbot.adrian.id.au](https://bopbot.adrian.id.au)**")
.setFooter("You're using version 1.1.3 of BopBot" +
.setFooter("You're using version 1.1.4 of BopBot" +
"\nFeature requests can be messaged to aidswidjaja#2805");
event.getChannel().sendMessage(builder.setEmbed(ebuilder.build()).build()).queue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ else if(event.getArgs().equalsIgnoreCase("true") || event.getArgs().equalsIgnore
{
event.reply("\uD83D\uDC1F Turning bass boost **on**! It might take a couple seconds..."); // 🐟

s.setBassBoost(true);

for (int i = 0; i < BASS_BOOST.length; i++) {
equalizer.setGain(i, BASS_BOOST[i] + 2);
}
Expand All @@ -94,7 +96,6 @@ else if(event.getArgs().equalsIgnoreCase("true") || event.getArgs().equalsIgnore

}

s.setBassBoost(true);
}
}
else if (event.getArgs().equalsIgnoreCase("false") || event.getArgs().equalsIgnoreCase("off")) // turns bass boost off
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/com/jagrosh/jmusicbot/commands/music/PlayCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,6 @@ public void doCommand(CommandEvent event)

event.reply("\uD83C\uDFA3 Heads up! Bass boost is **on!!**"); // 🎣

for (int i = 0; i < BASS_BOOST.length; i++) {
equalizer.setGain(i, BASS_BOOST[i] + 2);
}

for (int i = 0; i < BASS_BOOST.length; i++) {
equalizer.setGain(i, -BASS_BOOST[i] + 1);

}
} else {
handler.getPlayer().setFilterFactory(null);
}
}

Expand Down
Binary file modified target/JMusicBot-Snapshot-All.jar
Binary file not shown.
Binary file modified target/JMusicBot-Snapshot.jar
Binary file not shown.
Binary file modified target/classes/com/jagrosh/jmusicbot/audio/AudioHandler.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified target/classes/com/jagrosh/jmusicbot/commands/music/PlayCmd.class
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite tests="2" failures="0" name="com.jagrosh.jmusicbot.FairQueueTest" time="0.015" errors="0" skipped="0">
<testsuite tests="2" failures="0" name="com.jagrosh.jmusicbot.FairQueueTest" time="0.013" errors="0" skipped="0">
<properties>
<property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
<property name="sun.boot.library.path" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home/jre/lib"/>
Expand Down Expand Up @@ -60,6 +60,6 @@
<property name="sun.io.unicode.encoding" value="UnicodeBig"/>
<property name="sun.cpu.isalist" value=""/>
</properties>
<testcase classname="com.jagrosh.jmusicbot.FairQueueTest" name="sameIdentifierSize" time="0.011"/>
<testcase classname="com.jagrosh.jmusicbot.FairQueueTest" name="differentIdentifierSize" time="0.004"/>
<testcase classname="com.jagrosh.jmusicbot.FairQueueTest" name="sameIdentifierSize" time="0.007"/>
<testcase classname="com.jagrosh.jmusicbot.FairQueueTest" name="differentIdentifierSize" time="0.006"/>
</testsuite>

0 comments on commit 4f50933

Please sign in to comment.