summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/dolmetschctld/statemachine.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/cmd/dolmetschctld/statemachine.go b/cmd/dolmetschctld/statemachine.go
index 7e37af1..1fe4023 100644
--- a/cmd/dolmetschctld/statemachine.go
+++ b/cmd/dolmetschctld/statemachine.go
@@ -25,6 +25,7 @@ package main
import (
"fmt"
"log"
+ "time"
"spreadspace.org/dolmetschctl/pkg/mixer"
)
@@ -156,6 +157,18 @@ func (sm *StateMachine) selectLang(l Language) error {
return nil
}
+func calcNextLevel(target, current mixer.FaderLevel) mixer.FaderLevel {
+ next := target
+ if current != mixer.FaderLevelUnknown {
+ if next > current {
+ next = current + 1
+ } else {
+ next = current - 1
+ }
+ }
+ return next
+}
+
func (sm *StateMachine) reconcile() {
for lang, mcs := range sm.languages {
if sm.targetLang == "" || lang == sm.targetLang || mcs.voice.current.mute == mixer.MuteMuted {
@@ -170,11 +183,11 @@ func (sm *StateMachine) reconcile() {
sm.currentState = StateSettled
for _, mcs := range sm.languages {
if mcs.main.target.level != mcs.main.current.level {
- sm.mixer.SetLevel(mcs.main.num, mcs.main.target.level) // TODO: implement smooth fading!!
+ sm.mixer.SetLevel(mcs.main.num, calcNextLevel(mcs.main.target.level, mcs.main.current.level))
sm.currentState = StateSettling
}
if mcs.voice.target.level != mcs.voice.current.level {
- sm.mixer.SetLevel(mcs.voice.num, mcs.voice.target.level) // TODO: implement smooth fading!!
+ sm.mixer.SetLevel(mcs.voice.num, calcNextLevel(mcs.voice.target.level, mcs.voice.current.level))
sm.currentState = StateSettling
}
}
@@ -184,8 +197,13 @@ func (sm *StateMachine) run() {
defer close(sm.exitedCh)
sm.initMixer()
+ t := time.NewTicker(10 * time.Millisecond)
for {
select {
+ case <-t.C:
+ if sm.currentState == StateSettling {
+ sm.reconcile()
+ }
case req := <-sm.selectLangCh:
req.resultCh <- sm.selectLang(req.l)
sm.reconcile()