summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/dolmetschctld/dolmetschctld.go4
-rw-r--r--cmd/dolmetschctld/statemachine.go174
-rw-r--r--cmd/dolmetschctld/telnet.go4
3 files changed, 91 insertions, 91 deletions
diff --git a/cmd/dolmetschctld/dolmetschctld.go b/cmd/dolmetschctld/dolmetschctld.go
index 1df4efb..4c31dbf 100644
--- a/cmd/dolmetschctld/dolmetschctld.go
+++ b/cmd/dolmetschctld/dolmetschctld.go
@@ -29,8 +29,8 @@ import (
"spreadspace.org/dolmetschctl/pkg/mixer"
)
-func addLanguage(sm *StateMachine, name Language, main, voice mixer.Channel) {
- if err := sm.AddLanguage(name, main, voice); err != nil {
+func addLanguage(sm *StateMachine, name Language, original, interpreter mixer.Channel) {
+ if err := sm.AddLanguage(name, original, interpreter); err != nil {
log.Printf("adding language '%s' failed: %v", name, err)
os.Exit(1)
}
diff --git a/cmd/dolmetschctld/statemachine.go b/cmd/dolmetschctld/statemachine.go
index c7f4ac5..b8946d6 100644
--- a/cmd/dolmetschctld/statemachine.go
+++ b/cmd/dolmetschctld/statemachine.go
@@ -72,48 +72,48 @@ type MixerChannel struct {
}
type MixerChannels struct {
- main MixerChannel
- voice MixerChannel
+ original MixerChannel
+ interpreter MixerChannel
}
-type setLanguageRequest struct {
- lang Language
- resultCh chan error
+type setLanguageReq struct {
+ lang Language
+ resCh chan error
}
-type getLanguageRequest struct {
- resultCh chan Language
+type getLanguageReq struct {
+ resCh chan Language
}
-type setMain2VoiceRatioRequest struct {
- ratio float32
- resultCh chan error
+type setOriginal2InterpreterRatioReq struct {
+ ratio float32
+ resCh chan error
}
-type getMain2VoiceRatioRequest struct {
- resultCh chan float32
+type getOriginal2InterpreterRatioReq struct {
+ resCh chan float32
}
-type getStateRequest struct {
- resultCh chan State
+type getStateReq struct {
+ resCh chan State
}
type StateMachine struct {
mixer *mixer.Mixer
- setLanguageCh chan setLanguageRequest
- getLanguageCh chan getLanguageRequest
- setMain2VoiceRatioCh chan setMain2VoiceRatioRequest
- getMain2VoiceRatioCh chan getMain2VoiceRatioRequest
- getStateCh chan getStateRequest
- quitCh chan bool
- exitedCh chan struct{}
- mixerEventCh chan mixer.Event
+ setLanguageCh chan setLanguageReq
+ getLanguageCh chan getLanguageReq
+ setOriginal2InterpreterRatioCh chan setOriginal2InterpreterRatioReq
+ getOriginal2InterpreterRatioCh chan getOriginal2InterpreterRatioReq
+ getStateCh chan getStateReq
+ quitCh chan bool
+ exitedCh chan struct{}
+ mixerEventCh chan mixer.Event
languages map[Language]*MixerChannels
channel2lang map[mixer.Channel]Language
- main2VoiceRatio float32
+ original2InterpreterRatio float32
state State
language Language
@@ -134,10 +134,10 @@ func (sm *StateMachine) handleMixerEvent(ev mixer.Event) {
var mc *MixerChannel
switch ev.Channel {
- case mcs.main.num:
- mc = &mcs.main
- case mcs.voice.num:
- mc = &mcs.voice
+ case mcs.original.num:
+ mc = &mcs.original
+ case mcs.interpreter.num:
+ mc = &mcs.interpreter
default:
panic(fmt.Sprintf("channel2lang points to language that does not use the channel!"))
}
@@ -153,13 +153,13 @@ func (sm *StateMachine) handleMixerEvent(ev mixer.Event) {
// 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)
- mcs.main.target.level = mixer.FaderLevel0db
+ 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.voice.num, mixer.FaderLevelOff+1)
- sm.mixer.SetLevel(mcs.voice.num, mixer.FaderLevelOff)
- mcs.voice.target.level = mixer.FaderLevelOff
+ 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 = ""
sm.state = StateSettled
@@ -177,12 +177,12 @@ func (sm *StateMachine) setLanguage(l Language) error {
return nil
}
-func (sm *StateMachine) setMain2VoiceRatio(r float32) error {
+func (sm *StateMachine) setOriginal2InterpreterRatio(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)
+ return fmt.Errorf("original-interpreter 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)
+ sm.original2InterpreterRatio = r
+ log.Printf("new original-interpreter ratio: '%1.3f'", r)
return nil
}
@@ -200,15 +200,15 @@ 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.voice.current.mute == mixer.MuteMuted {
- mcs.main.target.level = mixer.FaderLevel0db
- mcs.voice.target.level = mixer.FaderLevelOff
+ if sm.language == "" || lang == sm.language || mcs.interpreter.current.mute == mixer.MuteMuted {
+ mcs.original.target.level = mixer.FaderLevel0db
+ mcs.interpreter.target.level = mixer.FaderLevelOff
} else {
- 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.original.target.level = mixer.FaderLevel(float32(mixer.FaderLevel0db) * sm.original2InterpreterRatio)
+ if mcs.original.target.level > mixer.FaderLevelMax {
+ mcs.original.target.level = mixer.FaderLevelMax
}
- mcs.voice.target.level = mixer.FaderLevel0db
+ mcs.interpreter.target.level = mixer.FaderLevel0db
}
}
@@ -217,12 +217,12 @@ func (sm *StateMachine) reconcile(ticker bool) {
}
sm.state = StateSettled
for _, mcs := range sm.languages {
- if mcs.main.target.level != mcs.main.current.level {
- sm.mixer.SetLevel(mcs.main.num, calcNextLevel(mcs.main.target.level, mcs.main.current.level))
+ if mcs.original.target.level != mcs.original.current.level {
+ sm.mixer.SetLevel(mcs.original.num, calcNextLevel(mcs.original.target.level, mcs.original.current.level))
sm.state = StateSettling
}
- if mcs.voice.target.level != mcs.voice.current.level {
- sm.mixer.SetLevel(mcs.voice.num, calcNextLevel(mcs.voice.target.level, mcs.voice.current.level))
+ if mcs.interpreter.target.level != mcs.interpreter.current.level {
+ sm.mixer.SetLevel(mcs.interpreter.num, calcNextLevel(mcs.interpreter.target.level, mcs.interpreter.current.level))
sm.state = StateSettling
}
}
@@ -240,17 +240,17 @@ func (sm *StateMachine) run() {
sm.reconcile(true)
}
case req := <-sm.setLanguageCh:
- req.resultCh <- sm.setLanguage(req.lang)
+ req.resCh <- sm.setLanguage(req.lang)
sm.reconcile(false)
case req := <-sm.getLanguageCh:
- req.resultCh <- sm.language
- case req := <-sm.setMain2VoiceRatioCh:
- req.resultCh <- sm.setMain2VoiceRatio(req.ratio)
+ req.resCh <- sm.language
+ case req := <-sm.setOriginal2InterpreterRatioCh:
+ req.resCh <- sm.setOriginal2InterpreterRatio(req.ratio)
sm.reconcile(false)
- case req := <-sm.getMain2VoiceRatioCh:
- req.resultCh <- sm.main2VoiceRatio
+ case req := <-sm.getOriginal2InterpreterRatioCh:
+ req.resCh <- sm.original2InterpreterRatio
case req := <-sm.getStateCh:
- req.resultCh <- sm.state
+ req.resCh <- sm.state
case ev := <-sm.mixerEventCh:
sm.handleMixerEvent(ev)
sm.reconcile(false)
@@ -262,11 +262,11 @@ func (sm *StateMachine) run() {
func NewStateMachine(m *mixer.Mixer) (*StateMachine, error) {
sm := &StateMachine{mixer: m}
- sm.setLanguageCh = make(chan setLanguageRequest, 10)
- sm.getLanguageCh = make(chan getLanguageRequest, 10)
- sm.setMain2VoiceRatioCh = make(chan setMain2VoiceRatioRequest, 10)
- sm.getMain2VoiceRatioCh = make(chan getMain2VoiceRatioRequest, 10)
- sm.getStateCh = make(chan getStateRequest, 10)
+ sm.setLanguageCh = make(chan setLanguageReq, 10)
+ sm.getLanguageCh = make(chan getLanguageReq, 10)
+ sm.setOriginal2InterpreterRatioCh = make(chan setOriginal2InterpreterRatioReq, 10)
+ sm.getOriginal2InterpreterRatioCh = make(chan getOriginal2InterpreterRatioReq, 10)
+ sm.getStateCh = make(chan getStateReq, 10)
sm.quitCh = make(chan bool, 1)
sm.exitedCh = make(chan struct{})
sm.mixerEventCh = make(chan mixer.Event, 1000)
@@ -280,7 +280,7 @@ func NewStateMachine(m *mixer.Mixer) (*StateMachine, error) {
}
// TODO: currently we can only deal with 2 languages...
-func (sm *StateMachine) AddLanguage(name Language, main, voice mixer.Channel) error {
+func (sm *StateMachine) AddLanguage(name Language, original, interpreter mixer.Channel) error {
if sm.state != StateNew {
return fmt.Errorf("adding languages is only allowed during startup")
}
@@ -290,23 +290,23 @@ func (sm *StateMachine) AddLanguage(name Language, main, voice mixer.Channel) er
if _, exists := sm.languages[name]; exists {
return fmt.Errorf("language '%s' already exists", name)
}
- for ch := range []mixer.Channel{main, voice} {
+ for ch := range []mixer.Channel{original, interpreter} {
if _, exists := sm.languages[name]; exists {
return fmt.Errorf("mixer channel %v is already in use by language '%s'", ch, name)
}
}
unknown := MixerChannelState{level: mixer.FaderLevelUnknown, mute: mixer.MuteUnknown}
- chMain := MixerChannel{num: main, current: unknown, target: unknown}
- chVoice := MixerChannel{num: voice, current: unknown, target: unknown}
+ chOriginal := MixerChannel{num: original, current: unknown, target: unknown}
+ chInterpreter := MixerChannel{num: interpreter, current: unknown, target: unknown}
- 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.languages[name] = &MixerChannels{chOriginal, chInterpreter}
+ sm.channel2lang[original] = name
+ sm.channel2lang[interpreter] = name
+ sm.mixer.Subscribe(original, sm.mixerEventCh)
+ sm.mixer.Subscribe(interpreter, sm.mixerEventCh)
- sm.main2VoiceRatio = 0.5 // TODO: hardcoded value
+ sm.original2InterpreterRatio = 0.5 // TODO: hardcoded value
return nil
}
@@ -316,33 +316,33 @@ func (sm *StateMachine) Start() {
}
func (sm *StateMachine) SetLanguage(l Language) error {
- resultCh := make(chan error)
- sm.setLanguageCh <- setLanguageRequest{l, resultCh}
- return <-resultCh
+ resCh := make(chan error)
+ sm.setLanguageCh <- setLanguageReq{l, resCh}
+ return <-resCh
}
func (sm *StateMachine) GetLanguage() Language {
- resultCh := make(chan Language)
- sm.getLanguageCh <- getLanguageRequest{resultCh}
- return <-resultCh
+ resCh := make(chan Language)
+ sm.getLanguageCh <- getLanguageReq{resCh}
+ return <-resCh
}
-func (sm *StateMachine) SetMain2VoiceRatio(r float32) error {
- resultCh := make(chan error)
- sm.setMain2VoiceRatioCh <- setMain2VoiceRatioRequest{r, resultCh}
- return <-resultCh
+func (sm *StateMachine) SetOriginal2InterpreterRatio(r float32) error {
+ resCh := make(chan error)
+ sm.setOriginal2InterpreterRatioCh <- setOriginal2InterpreterRatioReq{r, resCh}
+ return <-resCh
}
-func (sm *StateMachine) GetMain2VoiceRatio() float32 {
- resultCh := make(chan float32)
- sm.getMain2VoiceRatioCh <- getMain2VoiceRatioRequest{resultCh}
- return <-resultCh
+func (sm *StateMachine) GetOriginal2InterpreterRatio() float32 {
+ resCh := make(chan float32)
+ sm.getOriginal2InterpreterRatioCh <- getOriginal2InterpreterRatioReq{resCh}
+ return <-resCh
}
func (sm *StateMachine) GetState() State {
- resultCh := make(chan State)
- sm.getStateCh <- getStateRequest{resultCh}
- return <-resultCh
+ resCh := make(chan State)
+ sm.getStateCh <- getStateReq{resCh}
+ return <-resCh
}
func (sm *StateMachine) Shutdown() {
diff --git a/cmd/dolmetschctld/telnet.go b/cmd/dolmetschctld/telnet.go
index d6a5c4a..a7ede85 100644
--- a/cmd/dolmetschctld/telnet.go
+++ b/cmd/dolmetschctld/telnet.go
@@ -58,7 +58,7 @@ func telnetCmdRatio(c *telgo.Client, args []string, sm *StateMachine) bool {
return false
}
if len(args) == 1 {
- c.Sayln("current ratio: %1.3f", sm.GetMain2VoiceRatio())
+ c.Sayln("current ratio: %1.3f", sm.GetOriginal2InterpreterRatio())
return false
}
@@ -68,7 +68,7 @@ func telnetCmdRatio(c *telgo.Client, args []string, sm *StateMachine) bool {
return false
}
- if err := sm.SetMain2VoiceRatio(float32(r)); err != nil {
+ if err := sm.SetOriginal2InterpreterRatio(float32(r)); err != nil {
c.Sayln("setting ratio failed: %v", err)
}
return false