summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2019-02-10 18:35:53 +0100
committerChristian Pointner <equinox@spreadspace.org>2019-02-10 18:35:53 +0100
commit0700d7817e64db219a4184b373392d19fdc77956 (patch)
tree7dde67fa35d84af161f3b0eec7c89d984358a6e5 /cmd
parentrefactored fader levels and mute state (diff)
make target and current channel state explicit
Diffstat (limited to 'cmd')
-rw-r--r--cmd/dolmetschctld/statemachine.go57
1 files changed, 43 insertions, 14 deletions
diff --git a/cmd/dolmetschctld/statemachine.go b/cmd/dolmetschctld/statemachine.go
index e5ea0a9..0198c7d 100644
--- a/cmd/dolmetschctld/statemachine.go
+++ b/cmd/dolmetschctld/statemachine.go
@@ -59,12 +59,17 @@ func (l Language) String() string {
return string(l)
}
-type MixerChannel struct {
- num mixer.Channel
+type MixerChannelState struct {
level mixer.FaderLevel
mute mixer.Mute
}
+type MixerChannel struct {
+ num mixer.Channel
+ target MixerChannelState
+ current MixerChannelState
+}
+
type MixerChannels struct {
main MixerChannel
voice MixerChannel
@@ -128,27 +133,46 @@ func (sm *StateMachine) handleMixerEvent(ev mixer.Event) {
switch ev.Type {
case mixer.EventFaderChange:
- mc.level = ev.Level
+ mc.current.level = ev.Level
case mixer.EventMute:
- mc.mute = ev.Mute
+ mc.current.mute = ev.Mute
}
+}
- log.Printf("status of mixer channels for language '%s' is now:", lang)
- log.Printf(" main(%d): level=%s, muted=%s", mcs.main.num, mcs.main.level, mcs.main.mute)
- log.Printf(" voice(%d): level=%s, muted=%s", mcs.voice.num, mcs.voice.level, mcs.voice.mute)
+// make sure that our state and the mixer are in sync
+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.targetLang == sm.currentLang {
- sm.currentState = StateSettled
- return
+ if sm.currentState == StateSettled {
+
}
- sm.currentState = StateSettling
+
+ // TODO: implement me!!!!
}
func (sm *StateMachine) run() {
defer close(sm.exitedCh)
+ sm.initMixer()
for {
select {
case req := <-sm.selectLangCh:
@@ -180,11 +204,14 @@ func NewStateMachine(m *mixer.Mixer) (*StateMachine, error) {
sm.currentState = StateNew
sm.currentLang = ""
sm.targetLang = ""
-
return sm, nil
}
+// TODO: currently we can only deal with 2 languages...
func (sm *StateMachine) AddLanguage(name Language, main, voice mixer.Channel) error {
+ if sm.currentState != StateNew {
+ return fmt.Errorf("adding languages is only allowed during startup")
+ }
if name == "none" {
return fmt.Errorf("language 'none' is reserved")
}
@@ -197,8 +224,10 @@ func (sm *StateMachine) AddLanguage(name Language, main, voice mixer.Channel) er
}
}
- chMain := MixerChannel{main, mixer.FaderLevelUnknown, mixer.MuteUnknown}
- chVoice := MixerChannel{voice, mixer.FaderLevelUnknown, mixer.MuteUnknown}
+ unknown := MixerChannelState{level: mixer.FaderLevelUnknown, mute: mixer.MuteUnknown}
+ chMain := MixerChannel{num: main, current: unknown, target: unknown}
+ chVoice := MixerChannel{num: voice, current: unknown, target: unknown}
+
sm.languages[name] = &MixerChannels{chMain, chVoice}
sm.channel2lang[main] = name
sm.channel2lang[voice] = name