Add volume changing logic
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"rhemawavetech.com/rhemawave/internal/db"
|
||||
"rhemawavetech.com/rhemawave/internal/fontManager"
|
||||
"rhemawavetech.com/rhemawave/internal/logger"
|
||||
"rhemawavetech.com/rhemawave/internal/mixer"
|
||||
"rhemawavetech.com/rhemawave/internal/shaderManager"
|
||||
)
|
||||
|
||||
@@ -128,6 +129,31 @@ func (p *AudioDevices) ToggleAudio() {
|
||||
p.CreateAudioStatusItem()
|
||||
}
|
||||
|
||||
// UpdateVolume increments or decrements system volume by level (percent change)
|
||||
func (p *AudioDevices) UpdateVolume(level int) {
|
||||
// Calculate the new volume
|
||||
newVol := mixer.ConvertVolume(level) + p.Context.CfgPtr.SavedVolume
|
||||
// Check that it's within bounds
|
||||
if newVol < 0.0 || newVol > 1.0 {
|
||||
return
|
||||
}
|
||||
// Force 1.0 rather than 0.99999999999999989
|
||||
if newVol > .99 {
|
||||
newVol = 1.0
|
||||
}
|
||||
// Update the config
|
||||
p.Context.CfgPtr.SavedVolume = newVol
|
||||
fmt.Printf("New Volume: %f", newVol)
|
||||
// Update the database
|
||||
p.Context.DbPtr.Save(&p.Context.CfgPtr)
|
||||
// Set the new volume
|
||||
err := mixer.SetAllSinkVolumes(newVol)
|
||||
if err != nil {
|
||||
fmt.Printf("Error setting allSinkVolumes: %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (p *AudioDevices) HandleEvent(event *sdl.Event) error {
|
||||
e, ok := (*event).(*sdl.KeyboardEvent)
|
||||
if !ok || e.Type != sdl.KEYDOWN {
|
||||
@@ -135,9 +161,12 @@ func (p *AudioDevices) HandleEvent(event *sdl.Event) error {
|
||||
}
|
||||
|
||||
switch e.Keysym.Sym {
|
||||
|
||||
case sdl.K_RETURN:
|
||||
p.ToggleAudio()
|
||||
case sdl.K_RIGHT: // Right increase
|
||||
p.UpdateVolume(10)
|
||||
case sdl.K_LEFT: // Left decrease
|
||||
p.UpdateVolume(-10)
|
||||
case sdl.K_BACKSPACE:
|
||||
p.Context.NavigateTo(SETTINGS)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user