Implemented volume control

pull/18/head
Matthieu Grieger 2014-12-27 09:41:27 -08:00
parent e0af70945b
commit aa642dcca5
4 changed files with 7 additions and 5 deletions

View File

@ -11,6 +11,7 @@ MumbleDJ Changelog
* Added an admin skip command that allows an admin to force skip a song.
* Added `mumbledj.gcfg`, where all configuration options are now stored.
* Added a reload command, used to reload the configuration when a change is made.
* Implemented volume control. Now changes volume while audio is playing!
### December 8, 2014
* Switched from Ruby to Go, using `gumble` instead of `mumble-ruby` now.

View File

@ -71,12 +71,12 @@ func parseCommand(user *gumble.User, username, command string) {
case dj.conf.Aliases.VolumeAlias:
if dj.HasPermission(username, dj.conf.Permissions.AdminVolume) {
if argument == "" {
dj.client.Self().Channel().Send(fmt.Sprintf(CUR_VOLUME_HTML, dj.conf.Volume.DefaultVolume), false)
dj.client.Self().Channel().Send(fmt.Sprintf(CUR_VOLUME_HTML, dj.audioStream.Volume()), false)
} else {
if err := volume(username, argument); err == nil {
dj.client.Self().Channel().Send(fmt.Sprintf(VOLUME_SUCCESS_HTML, username, argument), false)
} else {
user.Send(NOT_IN_VOLUME_RANGE_MSG)
user.Send(fmt.Sprintf(NOT_IN_VOLUME_RANGE_MSG, dj.conf.Volume.LowestVolume, dj.conf.Volume.HighestVolume))
}
}
} else {
@ -177,7 +177,7 @@ func volume(user, value string) error {
if parsedVolume, err := strconv.ParseFloat(value, 32); err == nil {
newVolume := float32(parsedVolume)
if newVolume >= dj.conf.Volume.LowestVolume && newVolume <= dj.conf.Volume.HighestVolume {
dj.conf.Volume.DefaultVolume = newVolume
dj.audioStream.SetVolume(newVolume)
return nil
} else {
return errors.New("The volume supplied was not in the allowed range.")

View File

@ -49,6 +49,7 @@ func (dj *mumbledj) OnConnect(e *gumble.ConnectEvent) {
if audioStream, err := gumble_ffmpeg.New(dj.client); err == nil {
dj.audioStream = audioStream
dj.audioStream.Done = dj.OnSongFinished
dj.audioStream.SetVolume(dj.conf.Volume.DefaultVolume)
} else {
panic(err)
}

View File

@ -27,7 +27,7 @@ const NO_MUSIC_PLAYING_MSG = "There is no music playing at the moment."
const NO_ARGUMENT_MSG = "The command you issued requires an argument and you did not provide one."
// Message shown to users when they try to change the volume to a value outside the volume range.
const NOT_IN_VOLUME_RANGE_MSG = "Out of range. The volume must be between %g and %g."
const NOT_IN_VOLUME_RANGE_MSG = "Out of range. The volume must be between %f and %f."
// Message shown to user when a successful configuration reload finishes.
const CONFIG_RELOAD_SUCCESS_MSG = "The configuration has been successfully reloaded."
@ -65,7 +65,7 @@ const SONG_SKIPPED_HTML = `
// Message shown to users when they ask for the current volume (volume command without argument)
const CUR_VOLUME_HTML = `
The current volume is <b>%g</b>.
The current volume is <b>%f</b>.
`
// Message shown to users when another user votes to skip the current song.