diff options
-rw-r--r-- | cmd/dolmetschctld/statemachine.go | 57 | ||||
-rw-r--r-- | pkg/mixer/mixer.go | 4 |
2 files changed, 45 insertions, 16 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 diff --git a/pkg/mixer/mixer.go b/pkg/mixer/mixer.go index a3348d9..7b46abc 100644 --- a/pkg/mixer/mixer.go +++ b/pkg/mixer/mixer.go @@ -63,7 +63,7 @@ type FaderLevel uint8 const ( FaderLevelUnknown = FaderLevel(0xFF) FaderLevelMax = FaderLevel(0x7F) - FaderLevel0db = FaderLevel(0x5F) + FaderLevel0db = FaderLevel(0x60) FaderLevelOff = FaderLevel(0x00) ) @@ -234,7 +234,7 @@ func (m *Mixer) Mute(ch Channel) error { return m.sendMute(byte(ch), 0x7F) } -func (m *Mixer) UnMute(ch Channel) error { +func (m *Mixer) Unmute(ch Channel) error { return m.sendMute(byte(ch), 0x00) } |