port-registration-callback.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python
  2. # PYTHON_ARGCOMPLETE_OK
  3. import sys
  4. import jack
  5. import time
  6. import argparse
  7. def port_registered_callback(client, port):
  8. print(str(port) + ' registered')
  9. def port_unregistered_callback(client, port):
  10. print(str(port) + ' unregistered')
  11. def run():
  12. client = jack.Client("port registration callback");
  13. client.set_port_registered_callback(port_registered_callback)
  14. client.set_port_unregistered_callback(port_unregistered_callback)
  15. client.activate();
  16. print("client name: " + client.get_name())
  17. while True:
  18. try:
  19. time.sleep(1);
  20. except KeyboardInterrupt:
  21. break
  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:]))