diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/dolmetschctld/dolmetschctld.go | 8 | ||||
-rw-r--r-- | cmd/dolmetschctld/statemachine.go | 40 | ||||
-rw-r--r-- | cmd/dolmetschctld/telnet.go | 2 |
3 files changed, 25 insertions, 25 deletions
diff --git a/cmd/dolmetschctld/dolmetschctld.go b/cmd/dolmetschctld/dolmetschctld.go index 38f71ad..3242dde 100644 --- a/cmd/dolmetschctld/dolmetschctld.go +++ b/cmd/dolmetschctld/dolmetschctld.go @@ -44,14 +44,14 @@ func main() { // ************************************* // * initialize core - m, err := mixer.NewMixer(mixer.Config{DevIn: "ESI MIDIMATE eX MIDI 2", DevOut: "ESI MIDIMATE eX MIDI 1"}) + m, err := mixer.NewMixer(mixer.Config{Host: "192.168.48.232"}) if err != nil { log.Printf("Error opening the mixer: %v", err) os.Exit(1) } defer m.Shutdown() - log.Printf("successfully connected to mixer!") + log.Printf("successfully connected to mixer: %s", m.String()) if err = m.Init(); err != nil { log.Printf("Error initializeing the mixer: %v", err) @@ -67,8 +67,8 @@ func main() { log.Printf("state machine successfully initialized!") // TODO: make this configurable - addLanguage(sm, "en", 0x20, 0x24) - addLanguage(sm, "de", 0x22, 0x25) + addLanguage(sm, "en", "auxin/01", "auxin/05") + addLanguage(sm, "de", "auxin/03", "auxin/06") sm.Start() defer sm.Shutdown() diff --git a/cmd/dolmetschctld/statemachine.go b/cmd/dolmetschctld/statemachine.go index 3e92f00..1abb5fd 100644 --- a/cmd/dolmetschctld/statemachine.go +++ b/cmd/dolmetschctld/statemachine.go @@ -42,6 +42,7 @@ type MixerChannel struct { num mixer.Channel target MixerChannelState current MixerChannelState + real MixerChannelState } type MixerChannels struct { @@ -133,7 +134,7 @@ func (sm *StateMachine) publishState() { sm.stateSubscribers.Remove(entry) default: select { - case sub.publish <- types.FullState{sm.state, sm.original2InterpreterRatio, sm.language}: + case sub.publish <- types.FullState{State: sm.state, Ratio: sm.original2InterpreterRatio, Language: sm.language}: default: // subscriber is not responding... log.Printf("statemachine: removing subscriber '%v', because it is not responding", sub.publish) @@ -169,21 +170,16 @@ func (sm *StateMachine) handleMixerEvent(ev mixer.Event) { switch ev.Type { case mixer.EventFaderChange: - mc.current.level = ev.Level + mc.real.level = ev.Level case mixer.EventMute: - mc.current.mute = ev.Mute + mc.real.mute = ev.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.original.num, mixer.FaderLevel0db-1) - sm.mixer.SetLevel(mcs.original.num, mixer.FaderLevel0db) mcs.original.target.level = mixer.FaderLevel0db - - sm.mixer.SetLevel(mcs.interpreter.num, mixer.FaderLevelOff+1) - sm.mixer.SetLevel(mcs.interpreter.num, mixer.FaderLevelOff) mcs.interpreter.target.level = mixer.FaderLevelOff } sm.language = "" @@ -209,7 +205,6 @@ func (sm *StateMachine) setLanguage(l types.Language) error { } } sm.language = l - log.Printf("new target language: '%s'", sm.language) return nil } @@ -218,17 +213,16 @@ func (sm *StateMachine) setOriginal2InterpreterRatio(r float32) error { return fmt.Errorf("original-interpreter ratio '%1.3f' is invalid, must be between 0.0 and 1.0", r) } sm.original2InterpreterRatio = r - log.Printf("new original-interpreter ratio: '%1.3f'", r) 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 + if next > (current + mixer.FaderLevelIncrement/2) { + next = current + mixer.FaderLevelIncrement + } else if next < (current - mixer.FaderLevelIncrement/2) { + next = current - mixer.FaderLevelIncrement } } return next @@ -236,7 +230,7 @@ func calcNextLevel(target, current mixer.FaderLevel) mixer.FaderLevel { func (sm *StateMachine) reconcile(ticker bool) { for lang, mcs := range sm.languages { - if sm.language == "" || lang == sm.language || mcs.interpreter.current.mute == mixer.MuteMuted { + if sm.language == "" || lang == sm.language { mcs.original.target.level = mixer.FaderLevel0db mcs.interpreter.target.level = mixer.FaderLevelOff } else { @@ -251,14 +245,19 @@ func (sm *StateMachine) reconcile(ticker bool) { if sm.state != types.StateSettled && !ticker { return } + sm.state = types.StateSettled for _, mcs := range sm.languages { if mcs.original.target.level != mcs.original.current.level { - sm.mixer.SetLevel(mcs.original.num, calcNextLevel(mcs.original.target.level, mcs.original.current.level)) + nextLevel := calcNextLevel(mcs.original.target.level, mcs.original.current.level) + sm.mixer.SetLevel(mcs.original.num, nextLevel) + mcs.original.current.level = nextLevel sm.state = types.StateSettling } if mcs.interpreter.target.level != mcs.interpreter.current.level { - sm.mixer.SetLevel(mcs.interpreter.num, calcNextLevel(mcs.interpreter.target.level, mcs.interpreter.current.level)) + nextLevel := calcNextLevel(mcs.interpreter.target.level, mcs.interpreter.current.level) + sm.mixer.SetLevel(mcs.interpreter.num, nextLevel) + mcs.interpreter.current.level = nextLevel sm.state = types.StateSettling } } @@ -292,7 +291,7 @@ func (sm *StateMachine) run() { case req := <-sm.getOriginal2InterpreterRatioCh: req.resCh <- sm.original2InterpreterRatio case req := <-sm.getStateCh: - req.resCh <- getStateRes{types.FullState{sm.state, sm.original2InterpreterRatio, sm.language}} + req.resCh <- getStateRes{types.FullState{State: sm.state, Ratio: sm.original2InterpreterRatio, Language: sm.language}} case ev := <-sm.mixerEventCh: sm.handleMixerEvent(ev) sm.reconcile(false) @@ -301,6 +300,7 @@ func (sm *StateMachine) run() { } if oldState != sm.state || oldOriginal2InterpreterRadio != sm.original2InterpreterRatio || oldLanguage != sm.language { + log.Printf("update: lang=%s, ratio=%1.3f (%s)", sm.language, sm.original2InterpreterRatio, sm.state) sm.publishState() } } @@ -344,8 +344,8 @@ func (sm *StateMachine) AddLanguage(name types.Language, original, interpreter m } unknown := MixerChannelState{level: mixer.FaderLevelUnknown, mute: mixer.MuteUnknown} - chOriginal := MixerChannel{num: original, current: unknown, target: unknown} - chInterpreter := MixerChannel{num: interpreter, current: unknown, target: unknown} + chOriginal := MixerChannel{num: original, target: unknown, current: unknown, real: unknown} + chInterpreter := MixerChannel{num: interpreter, target: unknown, current: unknown, real: unknown} sm.languages[name] = &MixerChannels{chOriginal, chInterpreter} sm.channel2lang[original] = name diff --git a/cmd/dolmetschctld/telnet.go b/cmd/dolmetschctld/telnet.go index 5618ebe..55c3bf0 100644 --- a/cmd/dolmetschctld/telnet.go +++ b/cmd/dolmetschctld/telnet.go @@ -78,7 +78,7 @@ func telnetCmdState(c *telgo.Client, args []string, sm *StateMachine) bool { } state, ratio, lang := sm.GetState() c.Sayln("current state: %s", state) - c.Sayln("current ratio: %s", ratio) + c.Sayln("current ratio: %f", ratio) c.Sayln("current language: %s", lang) return false } |