raspberry pi zero based drum machine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

sSelectSound.py 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #print('now editing sound ', _id)
  56. _id += 1
  57. def ReceiveMessage(self, message):
  58. _id = 0
  59. o = self.FSM.owner
  60. o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=(0, 0, 0))
  61. o.draw.text((0, 0), "SelSou", font=o.h1, fill="#FFFFFF")
  62. o.draw.text((0, 20), str(o.eSound), font=o.h2, fill="#FFFFFF")
  63. o.update_display(0)
  64. u.play_seq(o, message)
  65. def draw_square(self):
  66. o = self.FSM.owner
  67. size = 32
  68. og_x = 110
  69. o_x = og_x
  70. o_y = 0
  71. _id = 0
  72. for n in o.soundSlots[o.eSound].notes[o.ePattern]:
  73. if _id == o.eSound:
  74. o.draw.rectangle((o_x, o_y, o_x + size, o_y + size), outline=0, fill=o.light_grey)
  75. else:
  76. o.draw.rectangle((o_x, o_y, o_x + size, o_y + size), outline=0, fill=o.dark_grey)
  77. o_x = o_x + size
  78. _id += 1
  79. if _id % 4 == 0:
  80. o_y += size
  81. o_x = og_x
  82. def Exit(self):
  83. self.FSM.owner.pub.unregister("beat", self)