diff --git a/config.go b/config.go index 5c52818..4253907 100644 --- a/config.go +++ b/config.go @@ -74,6 +74,8 @@ func (ac *AppConfig) parseBindings() error { switch { case ac.Driver == "": + case ac.Driver == "exec": + driverProtocol = "exec" case ac.Driver == "xdotool": case strings.HasPrefix(ac.Driver, "osc://"): addr, err := url.Parse(ac.Driver) @@ -89,10 +91,14 @@ func (ac *AppConfig) parseBindings() error { driverProtocol = "osc" oscClient = osc.NewClient(hostParts[0], int(port)) default: - return fmt.Errorf(`invalid driver %q, use one of: "xdotool" (default), "osc://address:port"`, ac.Driver) + return fmt.Errorf(`invalid driver %q, use one of: "xdotool" (default), "exec", "osc://address:port"`, ac.Driver) } for key, value := range ac.Bindings { + if strings.HasPrefix(key, "_") { + continue + } + binding, description := bindingAndDescription(driverProtocol, value) newBinding := &deviceBinding{heldButtons: make(map[int]bool), rawKey: key, rawValue: value, original: binding, description: description, driver: driverProtocol, oscClient: oscClient} @@ -149,7 +155,7 @@ var oscDescriptionRE = regexp.MustCompile(`([^#]*)(\s*# *(.+))?`) func bindingAndDescription(protocol, input string) (string, string) { re := xdoDescriptionRE - if protocol == "osc" { + if protocol == "osc" || protocol == "exec" { re = oscDescriptionRE } diff --git a/config_test.go b/config_test.go index 4d5cc7c..8f535d1 100644 --- a/config_test.go +++ b/config_test.go @@ -19,7 +19,7 @@ func TestBindingAndDescription(t *testing.T) { } for idx, test := range tests { - bind, desc := bindingAndDescription(test.in) + bind, desc := bindingAndDescription("xdo", test.in) assert.Equal(t, test.bind, bind, "%d", idx) assert.Equal(t, test.desc, desc, "%d", idx) } diff --git a/mapper.go b/mapper.go index 642584f..2d0dc10 100644 --- a/mapper.go +++ b/mapper.go @@ -172,6 +172,9 @@ func (m *Mapper) EmitKeys(modifiers map[int]bool, keyDown int) error { func (m *Mapper) executeBinding(binding *deviceBinding) error { time.Sleep(25 * time.Millisecond) switch binding.driver { + case "exec": + fmt.Printf("EXEC: /bin/bash -c %q\n", binding.original) + return exec.Command("/bin/bash", "-c", binding.original).Run() case "xdotool", "": fmt.Println("xdotool key --clearmodifiers", binding.original) return exec.Command("xdotool", "key", "--clearmodifiers", binding.original).Run() diff --git a/sample_config.json b/sample_config.json index ea7ab36..de2fcc0 100644 --- a/sample_config.json +++ b/sample_config.json @@ -91,12 +91,12 @@ "__see_ardour_docs_for_actions": "http://manual.ardour.org/appendix/menu-actions-list/ and http://manual.ardour.org/using-control-surfaces/controlling-ardour-with-osc/osc-control/", "bindings": { "F1": "/access_action Transport/record-roll", - "F2": "/transport_stop + /sleep 0.25 + /access_action Editor/playhead-to-previous-region-boundary + /sleep 0.05 + /access_action Common/finish-range + /sleep 0.05 + /jump_seconds -0.1 + /sleep 0.05 + /access_action Common/start-range + /sleep 0.05 + /access_action Editor/editor-cut # Clears Marks on Lightworks", + "F2": "/transport_stop + /sleep 0.25 + /access_action Editor/playhead-to-previous-region-boundary + /sleep 0.05 + /access_action Common/finish-range + /sleep 0.05 + /jump_seconds -0.1 + /sleep 0.05 + /access_action Common/start-range + /sleep 0.05 + /access_action Editor/editor-cut # Stop recording and clear the last 0.05 second of recording (because it might catch the click of the Shuttle !)", "M1+F2": "Cyrillic_YA # Swap In-Out Marks", - "F3": "/access_action Editor/editor-cut + /access_action Editor/playhead-to-previous-region-boundary # Delete", + "F3": "/access_action Common/finish-range + /access_action Editor/playhead-to-range-start + /access_action Editor/editor-cut", "M1+F3": "z # Blackout", - "F4": "v # Insert", + "F4": "/access_action Common/start-range + /sleep 0.05 + /access_action Editor/editor-cut # Truncate end of clip", "M1+F4": "b # Replace", "B2+F4": "f # Clipboard Insert", "B2+M1+F4": "g # Clipboard Replace",