diff options
author | Christian Pointner <equinox@spreadspace.org> | 2019-02-10 19:24:55 +0100 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2019-02-10 19:24:55 +0100 |
commit | ea4f08d69003803396b411bb9f0c4144befeef0e (patch) | |
tree | f0ae9eb944a3fc3e8cb0e5423611cb34fc87b9a3 /cmd/dolmetschctld/statemachine.go | |
parent | make target and current channel state explicit (diff) |
basic functionality works now
Diffstat (limited to 'cmd/dolmetschctld/statemachine.go')
-rw-r--r-- | cmd/dolmetschctld/statemachine.go | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/cmd/dolmetschctld/statemachine.go b/cmd/dolmetschctld/statemachine.go index 0198c7d..afe2ac0 100644 --- a/cmd/dolmetschctld/statemachine.go +++ b/cmd/dolmetschctld/statemachine.go @@ -95,17 +95,6 @@ type StateMachine struct { targetLang Language } -func (sm *StateMachine) selectLang(l Language) error { - if l != "" { - if _, exists := sm.languages[l]; !exists { - return fmt.Errorf("language '%s' does not exist", l) - } - } - sm.targetLang = l - log.Printf("new target language: '%s'", sm.targetLang) - return nil -} - func (sm *StateMachine) handleMixerEvent(ev mixer.Event) { lang, exists := sm.channel2lang[ev.Channel] if !exists { @@ -144,29 +133,47 @@ func (sm *StateMachine) initMixer() { for _, mcs := range sm.languages { sm.mixer.SetLevel(mcs.main.num, mixer.FaderLevel0db-1) sm.mixer.SetLevel(mcs.main.num, mixer.FaderLevel0db) - sm.mixer.Mute(mcs.main.num) - sm.mixer.Unmute(mcs.main.num) mcs.main.target.level = mixer.FaderLevel0db - mcs.main.target.mute = mixer.MuteUnmuted sm.mixer.SetLevel(mcs.voice.num, mixer.FaderLevelOff+1) sm.mixer.SetLevel(mcs.voice.num, mixer.FaderLevelOff) - sm.mixer.Unmute(mcs.voice.num) - sm.mixer.Mute(mcs.voice.num) mcs.voice.target.level = mixer.FaderLevelOff - mcs.voice.target.mute = mixer.MuteMuted } sm.currentLang = "" sm.targetLang = "" sm.currentState = StateSettled } -func (sm *StateMachine) reconcile() { - if sm.currentState == StateSettled { - +// the "current language" is what is currently spoken on stage +func (sm *StateMachine) selectLang(l Language) error { + if l != "" { + if _, exists := sm.languages[l]; !exists { + return fmt.Errorf("language '%s' does not exist", l) + } + } + sm.targetLang = l + for lang, mcs := range sm.languages { + if sm.targetLang == "" || lang == sm.targetLang { + mcs.main.target.level = mixer.FaderLevel0db + mcs.voice.target.level = mixer.FaderLevelOff + } else { + mcs.main.target.level = 30 // TODO: hardcoded Value!! + mcs.voice.target.level = mixer.FaderLevel0db + } } + log.Printf("new target language: '%s'", sm.targetLang) + return nil +} - // TODO: implement me!!!! +func (sm *StateMachine) reconcile() { + 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!! + } + if mcs.voice.target.level != mcs.voice.current.level { + sm.mixer.SetLevel(mcs.voice.num, mcs.voice.target.level) // TODO: implement smooth fading!! + } + } } func (sm *StateMachine) run() { @@ -177,17 +184,13 @@ func (sm *StateMachine) run() { select { case req := <-sm.selectLangCh: req.resultCh <- sm.selectLang(req.l) + sm.reconcile() case ev := <-sm.mixerEventCh: sm.handleMixerEvent(ev) + sm.reconcile() case <-sm.quitCh: return } - - oldState := sm.currentState - sm.reconcile() - if oldState != sm.currentState { - log.Printf("new state: %s", sm.currentState) - } } } |