diff options
author | Christian Pointner <equinox@spreadspace.org> | 2019-02-10 21:38:17 +0100 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2019-02-10 21:38:17 +0100 |
commit | 390f67a115551cb51069155cdcc032dc841fc978 (patch) | |
tree | 4eb69829c47656359433fc6928696c1c8493b3d3 /cmd/dolmetschctld/statemachine.go | |
parent | improved fader movement (diff) |
added telnet command to set main-to-voice ratio
Diffstat (limited to 'cmd/dolmetschctld/statemachine.go')
-rw-r--r-- | cmd/dolmetschctld/statemachine.go | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/cmd/dolmetschctld/statemachine.go b/cmd/dolmetschctld/statemachine.go index d094875..5ded49f 100644 --- a/cmd/dolmetschctld/statemachine.go +++ b/cmd/dolmetschctld/statemachine.go @@ -77,20 +77,29 @@ type MixerChannels struct { } type selectLangRequest struct { - l Language + lang Language + resultCh chan error +} + +type setMain2VoiceRatioRequest struct { + ratio float32 resultCh chan error } type StateMachine struct { - mixer *mixer.Mixer - selectLangCh chan selectLangRequest - quitCh chan bool - exitedCh chan struct{} - mixerEventCh chan mixer.Event + mixer *mixer.Mixer + + selectLangCh chan selectLangRequest + setMain2VoiceRatioCh chan setMain2VoiceRatioRequest + quitCh chan bool + exitedCh chan struct{} + mixerEventCh chan mixer.Event languages map[Language]*MixerChannels channel2lang map[mixer.Channel]Language + main2VoiceRatio float32 + currentState State currentLang Language targetLang Language @@ -107,7 +116,6 @@ func (sm *StateMachine) handleMixerEvent(ev mixer.Event) { mcs, exists := sm.languages[lang] if !exists { panic(fmt.Sprintf("channel2lang map contains unknown language entries!")) - return } var mc *MixerChannel @@ -118,7 +126,6 @@ func (sm *StateMachine) handleMixerEvent(ev mixer.Event) { mc = &mcs.voice default: panic(fmt.Sprintf("channel2lang points to language that does not use the channel!")) - return } switch ev.Type { @@ -157,6 +164,15 @@ func (sm *StateMachine) selectLang(l Language) error { return nil } +func (sm *StateMachine) setMain2VoiceRatio(r float32) error { + if r < 0.0 || r > 1.0 { + return fmt.Errorf("voice-to-main ratio '%1.3f' is invalid, must be between 0.0 and 1.0", r) + } + sm.main2VoiceRatio = r + log.Printf("new voice-to-main ratio: '%1.3f'", r) + return nil +} + func calcNextLevel(target, current mixer.FaderLevel) mixer.FaderLevel { next := target if current != mixer.FaderLevelUnknown { @@ -175,7 +191,10 @@ func (sm *StateMachine) reconcile(ticker bool) { mcs.main.target.level = mixer.FaderLevel0db mcs.voice.target.level = mixer.FaderLevelOff } else { - mcs.main.target.level = mixer.FaderLevel(float32(mixer.FaderLevel0db) * 0.5) // TODO: hardcoded Value!! + mcs.main.target.level = mixer.FaderLevel(float32(mixer.FaderLevel0db) * sm.main2VoiceRatio) + if mcs.main.target.level > mixer.FaderLevelMax { + mcs.main.target.level = mixer.FaderLevelMax + } mcs.voice.target.level = mixer.FaderLevel0db } } @@ -208,7 +227,10 @@ func (sm *StateMachine) run() { sm.reconcile(true) } case req := <-sm.selectLangCh: - req.resultCh <- sm.selectLang(req.l) + req.resultCh <- sm.selectLang(req.lang) + sm.reconcile(false) + case req := <-sm.setMain2VoiceRatioCh: + req.resultCh <- sm.setMain2VoiceRatio(req.ratio) sm.reconcile(false) case ev := <-sm.mixerEventCh: sm.handleMixerEvent(ev) @@ -222,6 +244,7 @@ func (sm *StateMachine) run() { func NewStateMachine(m *mixer.Mixer) (*StateMachine, error) { sm := &StateMachine{mixer: m} sm.selectLangCh = make(chan selectLangRequest, 10) + sm.setMain2VoiceRatioCh = make(chan setMain2VoiceRatioRequest, 10) sm.quitCh = make(chan bool, 1) sm.exitedCh = make(chan struct{}) sm.mixerEventCh = make(chan mixer.Event, 1000) @@ -259,9 +282,11 @@ func (sm *StateMachine) AddLanguage(name Language, main, voice mixer.Channel) er sm.languages[name] = &MixerChannels{chMain, chVoice} sm.channel2lang[main] = name sm.channel2lang[voice] = name - sm.mixer.Subscribe(main, sm.mixerEventCh) sm.mixer.Subscribe(voice, sm.mixerEventCh) + + sm.main2VoiceRatio = 0.5 // TODO: hardcoded value + return nil } @@ -275,6 +300,12 @@ func (sm *StateMachine) SelectLanguage(l Language) error { return <-resultCh } +func (sm *StateMachine) SetMain2VoiceRatio(r float32) error { + resultCh := make(chan error) + sm.setMain2VoiceRatioCh <- setMain2VoiceRatioRequest{r, resultCh} + return <-resultCh +} + func (sm *StateMachine) Shutdown() { select { case sm.quitCh <- true: |