You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

runner_midi.py 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/python3
  2. import argparse
  3. import re
  4. import redis
  5. import runner_lib as runner
  6. import time
  7. novationRows = [
  8. [ 0, 1, 2, 3, 4, 5, 6, 7 ],
  9. [ *range(16,24)],
  10. [ *range(32,40)],
  11. [ *range(48,56)]
  12. ]
  13. argsparser = argparse.ArgumentParser(description="Playlist midi")
  14. argsparser.add_argument("playlist",help="JSON playlist file ",type=str)
  15. argsparser.add_argument("-i","--ip",help="IP address of the Redis server ",default="127.0.0.1",type=str)
  16. argsparser.add_argument("-r","--row",help="Row of Novation pad. Default:1 ",default=1,type=str)
  17. argsparser.add_argument("-k","--key",help="Redis key to update",default="0",type=str)
  18. argsparser.add_argument("-l","--laser",help="Laser number. Default:0 ",default=0,type=int)
  19. argsparser.add_argument("-p","--port",help="Port of the Redis server ",default="6379",type=str)
  20. argsparser.add_argument("-s","--scene",help="Laser scene. Default:0 ",default=0,type=int)
  21. argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose")
  22. args = argsparser.parse_args()
  23. ip = args.ip
  24. port = args.port
  25. key = args.key
  26. verbose=args.verbose
  27. laser = args.laser
  28. scene = args.scene
  29. playlist = args.playlist
  30. row = args.row - 1
  31. rowKeys = novationRows[row]
  32. # Subscriber
  33. r = redis.StrictRedis(host=ip, port=port, db=0)
  34. p = r.pubsub()
  35. p.subscribe('/midi/last_event')
  36. runner._killBill()
  37. # Set Laser and scene
  38. runner._setKey( laser = laser, scene = scene)
  39. # Load playlist
  40. runner._loadPlaylist( playlist )
  41. print("Loaded playlist : {}".format(runner.currentPlayList))
  42. runner.action_info()
  43. runner.current_id = -1
  44. while True:
  45. runner._killBill()
  46. message = p.get_message()
  47. if message:
  48. #runner._ok ("Subscriber: %s" % message['data'])
  49. # b'/midi/noteon/0/19/127'
  50. match = re.match(".*/([0-9]+)/[0-9]+",str(message['data']))
  51. if not match:
  52. continue
  53. key = int(match.group(1))
  54. # Check if the event is for us
  55. if key not in rowKeys:
  56. print("key {} not in {} ".format(key,rowKeys))
  57. continue
  58. try:
  59. command_id = rowKeys.index(key)
  60. cmd = runner.currentPlayList[command_id]
  61. if command_id != runner.current_id :
  62. runner._ok("Launching command #{}\n Previous was {}\n Cmd:{}".format(command_id,runner.current_id,cmd))
  63. runner.action_match(command_id)
  64. runner.action_runCommand()
  65. else :
  66. runner._err("Not running {} : already running.".format(command_id))
  67. except Exception as e :
  68. print("Woops.",e)