소스 검색

added option to define instructions via a config file

Fabian Peter Hammerle 9 년 전
부모
커밋
4b27ce808b
2개의 변경된 파일98개의 추가작업 그리고 0개의 파일을 삭제
  1. 67 0
      example.yml
  2. 31 0
      scripts/jack-plumber

+ 67 - 0
example.yml

@@ -0,0 +1,67 @@
+instructions:
+  - type: rename port
+    client_pattern: system
+    port_pattern: capture_1
+    new_port_name: capture-1
+  - type: rename port
+    client_pattern: system
+    port_pattern: capture_2
+    new_port_name: capture-2
+  - type: rename port
+    client_pattern: 'system'
+    port_pattern: 'playback_1'
+    new_port_name: 'speakers-left'
+  - type: rename port
+    client_pattern: 'system'
+    port_pattern: 'playback_2'
+    new_port_name: 'speakers-right'
+  - type: rename port
+    client_pattern: 'system'
+    port_pattern: 'playback_3'
+    new_port_name: 'headphones-left'
+  - type: rename port
+    client_pattern: 'system'
+    port_pattern: 'playback_4'
+    new_port_name: 'headphones-right'
+  - type: rename port
+    client_pattern: 'a2j'
+    port_pattern: 'Midi Through.*playback'
+    new_port_name: 'midi-through/midi-in'
+  - type: rename port
+    client_pattern: 'a2j'
+    port_pattern: 'Midi Through.*capture'
+    new_port_name: 'midi-through/midi-out'
+  - type: rename port
+    client_pattern: 'a2j'
+    port_pattern: 'USB-MIDI.*playback'
+    new_port_name: 'kawai-vpc1/midi-in'
+  - type: rename port
+    client_pattern: 'a2j'
+    port_pattern: 'USB-MIDI.*capture'
+    new_port_name: 'kawai-vpc1/midi-out'
+  - type: rename port
+    client_pattern: 'a2j'
+    port_pattern: 'Scarlett 2i4 USB.*playback'
+    new_port_name: 'scarlett-2i4/midi-in'
+  - type: rename port
+    client_pattern: 'a2j'
+    port_pattern: 'Scarlett 2i4 USB.*capture'
+    new_port_name: 'scarlett-2i4/midi-out'
+  - type: rename port
+    client_pattern: 'a2j'
+    port_pattern: 'Launchpad Mini 9.*playback'
+    new_port_name: 'launchpad-mini-9/midi-in'
+  - type: rename port
+    client_pattern: 'a2j'
+    port_pattern: 'Launchpad Mini 9.*capture'
+    new_port_name: 'launchpad-mini-9/midi-out'
+  - type: connect ports
+    client_pattern_1: 'a2j'
+    port_pattern_1: 'kawai-vpc./midi-out'
+    client_pattern_2: 'a2j'
+    port_pattern_2: 'scarlett-.*/midi-in'
+  - type: connect ports
+    client_pattern_1: 'a2j'
+    port_pattern_1: 'scarlett-.*/midi-in'
+    client_pattern_2: 'a2j'
+    port_pattern_2: 'scarlett-.*/midi-out'

+ 31 - 0
scripts/jack-plumber

@@ -80,6 +80,12 @@ def _init_argparser():
 
     import argparse
     argparser = argparse.ArgumentParser(description = None)
+    argparser.add_argument(
+            '-c', '--config',
+            metavar = 'path',
+            dest = 'config_path',
+            help = 'path to config file',
+            )
     argparser.add_argument(
             '--dbus',
             action='store_true',
@@ -124,6 +130,31 @@ def main(argv):
     args = argparser.parse_args(argv)
 
     instructions = {}
+    if args.config_path:
+        import yaml
+        with open(args.config_path) as config_file:
+            config = yaml.load(config_file.read())
+        for instruction in config['instructions']:
+            if instruction['type'] == 'rename port':
+                register_instruction(
+                    instruction['client_pattern'],
+                    instruction['port_pattern'],
+                    PortRenameInstruction(instruction['new_port_name']),
+                    instructions,
+                    )
+            elif instruction['type'] == 'connect ports':
+                register_instruction(
+                    instruction['client_pattern_1'],
+                    instruction['port_pattern_1'],
+                    PortConnectInstruction(instruction['client_pattern_2'], instruction['port_pattern_2']),
+                    instructions,
+                    )
+                register_instruction(
+                    instruction['client_pattern_2'],
+                    instruction['port_pattern_2'],
+                    PortConnectInstruction(instruction['client_pattern_1'], instruction['port_pattern_1']),
+                    instructions,
+                    )
     if args.port_renaming_instructions:
         for renaming_instruction in args.port_renaming_instructions:
             (client_pattern, port_pattern, new_port_name) = renaming_instruction