raspberry pi zero based drum machine
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.

sSelectSound.py 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import FSM
  2. import utils as u
  3. import menus as m
  4. #====================================
  5. State = type("State", (object,), {})
  6. #====================================
  7. class State(object):
  8. def __init__(self, FSM):
  9. self.FSM = FSM
  10. def Enter(self):
  11. pass
  12. def Execute(self):
  13. pass
  14. def Exit(self):
  15. pass
  16. #====================================
  17. class SelectSound(State):
  18. def __init__(self,FSM):
  19. super(SelectSound, self).__init__(FSM)
  20. def Enter(self):
  21. self.FSM.stateLife = 1
  22. o = self.FSM.owner
  23. o.header_text = "SelSou"
  24. o.pub.register("beat", self)
  25. u.draw_header(o)
  26. self.draw_square()
  27. o.update_display(0)
  28. super(SelectSound, self).Enter()
  29. def Execute(self):
  30. o = self.FSM.owner
  31. if o.keyState[16] == 1:
  32. m.draw_menu1(o)
  33. o.update_display(0)
  34. elif o.keyState[16] == 4:
  35. u.draw_header(o)
  36. self.draw_square()
  37. o.update_display(0)
  38. if o.keyState[16] == 2:
  39. if o.keyState[0] == 1:
  40. self.FSM.ToTransition('toMain')
  41. else:
  42. _id = 0
  43. for k in o.keyState:
  44. if _id > 15:
  45. pass
  46. else:
  47. if k == 1:
  48. o.eSound = _id
  49. o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
  50. o.draw.text((0, 0), "SelSou", font=o.h1, fill=o.light_blue)
  51. o.draw.text((20, 60), str(o.eSound), font=o.h2, fill=o.light_grey)
  52. self.draw_square()
  53. o.update_display(0)
  54. self.FSM.owner.soundSlots[_id].play()
  55. _id += 1
  56. def ReceiveMessage(self, message):
  57. _id = 0
  58. o = self.FSM.owner
  59. o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=(0, 0, 0))
  60. o.draw.text((0, 0), "SelSou", font=o.h1, fill="#FFFFFF")
  61. o.draw.text((0, 20), str(o.eSound), font=o.h2, fill="#FFFFFF")
  62. o.update_display(0)
  63. u.play_seq(o, message)
  64. def draw_square(self):
  65. o = self.FSM.owner
  66. size = 32
  67. og_x = 110
  68. o_x = og_x
  69. o_y = 0
  70. _id = 0
  71. for n in o.soundSlots[o.eSound].notes[o.ePattern]:
  72. if _id == o.eSound:
  73. o.draw.rectangle((o_x, o_y, o_x + size, o_y + size), outline=0, fill=o.light_grey)
  74. else:
  75. o.draw.rectangle((o_x, o_y, o_x + size, o_y + size), outline=0, fill=o.dark_grey)
  76. o_x = o_x + size
  77. _id += 1
  78. if _id % 4 == 0:
  79. o_y += size
  80. o_x = og_x
  81. def Exit(self):
  82. self.FSM.owner.pub.unregister("beat", self)