1
0

connect-ports.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python
  2. # PYTHON_ARGCOMPLETE_OK
  3. import sys
  4. import jack
  5. import random
  6. import argparse
  7. def run():
  8. client = jack.Client("connect test");
  9. client.activate();
  10. print("client name: " + client.get_name())
  11. midi_ports = [p for p in client.get_ports() if 'midi' in p.get_type()]
  12. source_ports = [p for p in midi_ports if p.is_output()]
  13. target_ports = [p for p in midi_ports if p.is_input()]
  14. source_port = random.choice(source_ports)
  15. target_port = random.choice(target_ports)
  16. print(source_port)
  17. print(target_port)
  18. try:
  19. client.connect(source_port, target_port)
  20. except jack.ConnectionExists:
  21. print('ports already connected')
  22. def _init_argparser():
  23. argparser = argparse.ArgumentParser(description = None)
  24. return argparser
  25. def main(argv):
  26. argparser = _init_argparser()
  27. try:
  28. import argcomplete
  29. argcomplete.autocomplete(argparser)
  30. except ImportError:
  31. pass
  32. args = argparser.parse_args(argv)
  33. run(**vars(args))
  34. return 0
  35. if __name__ == "__main__":
  36. sys.exit(main(sys.argv[1:]))