-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0278e4e
commit a27f74b
Showing
3 changed files
with
61 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/com/jagrosh/jmusicbot/commands/dj/BassBoostCmd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.jagrosh.jmusicbot.commands.dj; | ||
|
||
import com.jagrosh.jdautilities.command.CommandEvent; | ||
import com.jagrosh.jmusicbot.Bot; | ||
import com.jagrosh.jmusicbot.audio.AudioHandler; | ||
import com.jagrosh.jmusicbot.commands.DJCommand; | ||
import com.jagrosh.jmusicbot.utils.FormatUtil; | ||
import com.sedmelluq.discord.lavaplayer.filter.equalizer.EqualizerFactory; | ||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; | ||
|
||
public class BassBoostCmd extends DJCommand { | ||
private static final float[] BASS_BOOST = {0.05f, 0.05f, 0.05f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, | ||
0.0f, 0.0f, -0.05f, -0.05f, -0.05f}; | ||
|
||
private static final float MULT_CONSTANT = 0.01f; | ||
|
||
private final EqualizerFactory equalizer; | ||
|
||
public BassBoostCmd(Bot bot) { | ||
super(bot); | ||
this.name = "bassboost"; | ||
this.aliases = bot.getConfig().getAliases(this.name); | ||
this.equalizer = new EqualizerFactory(); | ||
this.help = "設定或是顯示重低音調整(預設為0)"; | ||
this.arguments = "[0-100]"; | ||
for (int i = 0; i < BASS_BOOST.length; i++) { | ||
equalizer.setGain(i, BASS_BOOST[i]); | ||
} | ||
} | ||
|
||
@Override | ||
public void doCommand(CommandEvent event) { | ||
AudioHandler handler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler(); | ||
AudioPlayer player = handler.getPlayer(); | ||
int bassboost = Math.round(this.equalizer.getGain(3) / MULT_CONSTANT); | ||
player.setFilterFactory(equalizer); | ||
if (event.getArgs().isEmpty()) { | ||
event.reply(FormatUtil.volumeIcon(bassboost) + " 現在的重低音等級為 `" + bassboost + "`"); | ||
} else { | ||
int nbassboost; | ||
try { | ||
nbassboost = Integer.parseInt(event.getArgs()); | ||
} catch (NumberFormatException e) { | ||
nbassboost = -1; | ||
} | ||
if (nbassboost < 0 || nbassboost > 100) | ||
event.reply(event.getClient().getError() + | ||
" 重低音等級要在 1~100 之間"); | ||
else { | ||
for (int i = 0; i < BASS_BOOST.length; i++) { | ||
equalizer.setGain(i, BASS_BOOST[i] + MULT_CONSTANT * nbassboost); | ||
} | ||
event.reply(FormatUtil.volumeIcon(nbassboost) + | ||
" 重低音等級調整至 `" + nbassboost + "`"); | ||
} | ||
} | ||
} | ||
} |