paintpad.py 823 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/python
  2. import time
  3. from pad import Pad
  4. from simplemidi.midimessage import MidiType
  5. from simplemidi.options import *
  6. class PaintPad(Pad):
  7. _DEFAULT_PARAMS=dictAssign(Pad._DEFAULT_PARAMS, {
  8. })
  9. def __init__(self, adapter, params):
  10. param=initParams(PaintPad._DEFAULT_PARAMS, params)
  11. Pad.__init__(self, adapter, {})
  12. self.learn=True
  13. self.iport.setInputCallback(self.onControlChange, self, MidiType.CONTROL_CHANGE)
  14. def onNoteOn(self, ch, idx, val):
  15. if idx==89:
  16. self.clear()
  17. elif idx==84:
  18. if self.learn:
  19. self[idx].off()
  20. else:
  21. self[idx].on()
  22. self.learn= not self.learn()
  23. elif idx==98:
  24. pass
  25. elif self.input[98]:
  26. self[idx].prev()
  27. else:
  28. self[idx].next()
  29. def clear(self):
  30. Pad.clear(self)
  31. def start(self):
  32. self.clear()
  33. while True:
  34. time.sleep(1)