From aa642dcca51b6d7e80f0a2506a2d7a35059ce24d Mon Sep 17 00:00:00 2001 From: Matthieu Grieger Date: Sat, 27 Dec 2014 09:41:27 -0800 Subject: [PATCH] Implemented volume control --- CHANGELOG.md | 1 + commands.go | 6 +++--- main.go | 1 + strings.go | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 762d618..5507973 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/commands.go b/commands.go index 489394b..daf55da 100644 --- a/commands.go +++ b/commands.go @@ -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.") diff --git a/main.go b/main.go index c2fa5e9..552937b 100644 --- a/main.go +++ b/main.go @@ -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) } diff --git a/strings.go b/strings.go index e882aab..ac34301 100644 --- a/strings.go +++ b/strings.go @@ -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 %g. + The current volume is %f. ` // Message shown to users when another user votes to skip the current song.