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.

sDeleteSound.py 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 DeleteSound(State):
  18. def __init__(self,FSM):
  19. super(DeleteSound, self).__init__(FSM)
  20. def Enter(self):
  21. o = self.FSM.owner
  22. o.header_text = "Delete Sound"
  23. o.pub.register("beat", self)
  24. if o.keyState[16] > 0 or o.keyState[17] > 0:
  25. pass
  26. else:
  27. u.draw_header(o)
  28. o.update_display(0)
  29. self.draw_main(o)
  30. self.draw_footer(o)
  31. super(DeleteSound, self).Enter()
  32. def Execute(self):
  33. o = self.FSM.owner
  34. m.menu1_actions(self, o)
  35. if o.keyState[16] == 1:
  36. m.draw_menu1(o)
  37. o.update_display(0)
  38. elif o.keyState[16] == 4:
  39. u.draw_header(o)
  40. self.draw_main(o)
  41. self.draw_footer(o)
  42. o.update_display(0)
  43. if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
  44. u.draw_header(o)
  45. self.draw_main(o)
  46. self.draw_footer(o)
  47. o.update_display(0)
  48. if o.keyState[0] == 1 or o.keyState[1] == 1 or o.keyState[2] == 1 or o.keyState[3] == 1:
  49. o.soundSlots[o.eSound].file = None
  50. o.soundSlots[o.eSound].volume = 16
  51. o.soundSlots[o.eSound].pitch = 0
  52. o.FSM.FSM.ToTransition("toMain")
  53. def draw_main(self, o):
  54. o.center_block("You sure?", o.h2, [0, 0, o.width, o.height], o.light_grey)
  55. def draw_footer(self, o):
  56. _iter = 0
  57. width = o.width
  58. xpos = 0
  59. yposa = 135 - 25
  60. yposb = 135
  61. opts = ["Delete Sound"]
  62. while _iter < 1:
  63. o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.blue)
  64. if o.keyState[_iter] == 1:
  65. o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.light_grey)
  66. o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.blue)
  67. else:
  68. o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
  69. xpos += width
  70. _iter += 1
  71. def ReceiveMessage(self, message):
  72. o = self.FSM.owner
  73. u.play_seq(o, message)
  74. def Exit(self):
  75. self.FSM.owner.pub.unregister("beat", self)