summaryrefslogtreecommitdiff
path: root/src/rhctl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rhctl')
-rw-r--r--src/rhctl/audio_switch_command.go115
1 files changed, 109 insertions, 6 deletions
diff --git a/src/rhctl/audio_switch_command.go b/src/rhctl/audio_switch_command.go
index 2aed51f..df357a6 100644
--- a/src/rhctl/audio_switch_command.go
+++ b/src/rhctl/audio_switch_command.go
@@ -130,8 +130,8 @@ const (
SwitchCmdStatusRelay SwitchCmdString = "*uSR"
SwitchCmdStatusSilence SwitchCmdString = "*uSS"
- SwitchCmdAudioSelectInput SwitchCmdString = "*uiio"
- SwitchCmdAudioSelectInputAll SwitchCmdString = "*uiiA"
+ SwitchCmdAudioApplyInput SwitchCmdString = "*uiio"
+ SwitchCmdAudioApplyInputAll SwitchCmdString = "*uiiA"
SwitchCmdAudioAddInputTo1 SwitchCmdString = "*uii3"
SwitchCmdAudioAddInputTo2 SwitchCmdString = "*uii4"
SwitchCmdAudioRemoveInputFrom1 SwitchCmdString = "*uii5"
@@ -140,9 +140,8 @@ const (
SwitchCmdAudioMuteInputAll SwitchCmdString = "*uiiMA"
SwitchCmdAudioMuteOutput SwitchCmdString = "*uMo"
SwitchCmdAudioMuteOutputAll SwitchCmdString = "*uMA"
-
- SwitchCmdAudioFadeUpInput SwitchCmdString = "*uFUii"
- SwitchCmdAudioFadeDownInput SwitchCmdString = "*uFDii"
+ SwitchCmdAudioFadeUpInput SwitchCmdString = "*uFUii"
+ SwitchCmdAudioFadeDownInput SwitchCmdString = "*uFDii"
SwitchCmdOCUnlatch SwitchCmdString = "*uOOcF"
SwitchCmdOCLatch SwitchCmdString = "*uOOcL"
@@ -200,9 +199,111 @@ func SwitchCommandParseStatus(args []string) (cmdstr SwitchCmdString, cmdargs []
}
return
}
+
+func SwitchCommandParseAudio(args []string) (cmdstr SwitchCmdString, cmdargs []interface{}, err error) {
+ if len(args) < 2 || len(args) > 3 {
+ err = fmt.Errorf("wrong number of arguments")
+ return
+ }
+
+ var onum SwitchOutputNum
+ if args[0] != "all" {
+ if err = onum.FromString(args[0]); err != nil {
+ return
+ }
+ cmdargs = append(cmdargs, onum)
+ }
+ var inum SwitchInputNum
+ if len(args) == 3 {
+ if err = inum.FromString(args[2]); err != nil {
+ return
+ }
+ cmdargs = append(cmdargs, inum)
+ }
+
+ switch args[1] {
+ case "apply":
+ if len(args) != 3 {
+ err = fmt.Errorf("wrong number of arguments")
+ return
+ }
+ if onum == 0 {
+ cmdstr = SwitchCmdAudioApplyInputAll
+ } else {
+ cmdstr = SwitchCmdAudioApplyInput
+ }
+ case "add":
+ if len(args) != 3 {
+ err = fmt.Errorf("wrong number of arguments")
+ return
+ }
+ switch onum {
+ case 1:
+ cmdstr = SwitchCmdAudioAddInputTo1
+ case 2:
+ cmdstr = SwitchCmdAudioAddInputTo2
+ default:
+ err = fmt.Errorf("this operation cannot be applied to all outputs")
+ return
+ }
+ case "remove":
+ if len(args) != 3 {
+ err = fmt.Errorf("wrong number of arguments")
+ return
+ }
+ switch onum {
+ case 1:
+ cmdstr = SwitchCmdAudioRemoveInputFrom1
+ case 2:
+ cmdstr = SwitchCmdAudioRemoveInputFrom2
+ default:
+ err = fmt.Errorf("this operation cannot be applied to all outputs")
+ return
+ }
+ case "up":
+ if len(args) != 3 {
+ err = fmt.Errorf("wrong number of arguments")
+ return
+ }
+ if onum != 1 {
+ err = fmt.Errorf("this operation is only allowed on output 1")
+ return
+ }
+ cmdstr = SwitchCmdAudioFadeUpInput
+ case "down":
+ if len(args) != 3 {
+ err = fmt.Errorf("wrong number of arguments")
+ return
+ }
+ if onum != 1 {
+ err = fmt.Errorf("this operation is only allowed on output 1")
+ return
+ }
+ cmdstr = SwitchCmdAudioFadeDownInput
+ case "mute":
+ if len(args) == 3 {
+ if onum == 0 {
+ cmdstr = SwitchCmdAudioMuteInputAll
+ } else {
+ cmdstr = SwitchCmdAudioMuteInput
+ }
+ } else {
+ if onum == 0 {
+ cmdstr = SwitchCmdAudioMuteOutputAll
+ } else {
+ cmdstr = SwitchCmdAudioMuteOutput
+ }
+ }
+ default:
+ err = fmt.Errorf("unknown operation: '%s', must be one of latch, unlatch, pulse", args[1])
+ return
+ }
+ return
+}
+
func SwitchCommandParseRelay(args []string) (cmdstr SwitchCmdString, cmdargs []interface{}, err error) {
if len(args) != 2 {
- err = fmt.Errorf("wrong number of arguments, expecting: <oc-num> (latch|unlatch|pulse)")
+ err = fmt.Errorf("wrong number of arguments, expecting: <relay-num> (latch|unlatch|pulse)")
return
}
var num SwitchRelayNum
@@ -253,6 +354,8 @@ func NewSwitchCommandFromStrings(cmd string, args ...string) (c *SwitchCommand,
switch cmd {
case "status":
c.Cmd, c.Args, err = SwitchCommandParseStatus(args)
+ case "out":
+ c.Cmd, c.Args, err = SwitchCommandParseAudio(args)
case "relay":
c.Cmd, c.Args, err = SwitchCommandParseRelay(args)
case "oc":