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.

sEditSoundSequence.py 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 EditSoundSequence(State):
  18. def __init__(self,FSM):
  19. super(EditSoundSequence, self).__init__(FSM)
  20. def Enter(self):
  21. self.FSM.stateLife = 1
  22. o = self.FSM.owner
  23. o.header_text = "Note Edit"
  24. o.pub.register("beat", self)
  25. self.curPattern = o.ePattern
  26. if o.keyState[16] > 0 or o.keyState[17] > 0:
  27. pass
  28. else:
  29. u.draw_header(o)
  30. self.draw_square()
  31. u.text_box3(o, "Vol", str(o.note_vol))
  32. u.text_box1(o, "Pat", str(self.curPattern))
  33. o.update_display(0)
  34. super(EditSoundSequence, self).Enter()
  35. def Execute(self):
  36. o = self.FSM.owner
  37. m.menu1_actions(self, o)
  38. m.menu2_actions_note(self, o)
  39. if o.keyState[16] == 1:
  40. m.draw_menu1(o)
  41. o.update_display(0)
  42. elif o.keyState[16] == 4:
  43. u.draw_header(o)
  44. self.draw_square()
  45. u.text_box3(o, "Vol", str(o.note_vol))
  46. u.text_box1(o, "Pat", str(self.curPattern))
  47. o.update_display(0)
  48. if o.keyState[17] == 1:
  49. m.draw_menu2_note(o)
  50. o.update_display(0)
  51. elif o.keyState[17] == 4:
  52. u.draw_header(o)
  53. self.draw_square()
  54. u.text_box3(o, "Vol", str(o.note_vol))
  55. u.text_box1(o, "Pat", str(self.curPattern))
  56. o.update_display(0)
  57. if o.keyState[16] > 0 or o.keyState[17] > 0:
  58. pass
  59. else:
  60. _id = 0
  61. for k in self.FSM.owner.keyState:
  62. if _id < 16 and k == 1:
  63. if o.soundSlots[o.eSound].notes[self.curPattern][_id][0] == 1:
  64. o.soundSlots[o.eSound].notes[self.curPattern][_id][0] = 0
  65. o.soundSlots[o.eSound].notes[self.curPattern][_id][1] = 0
  66. else:
  67. o.soundSlots[o.eSound].notes[self.curPattern][_id][0] = 1
  68. o.soundSlots[o.eSound].notes[self.curPattern][_id][1] = o.note_vol
  69. u.draw_header(o)
  70. self.draw_square()
  71. u.text_box3(o, "Vol", str(o.note_vol))
  72. u.text_box1(o, "Pat", str(self.curPattern))
  73. o.update_display(0)
  74. _id += 1
  75. def draw_square(self):
  76. o = self.FSM.owner
  77. size = 22
  78. og_x = (o.width / 2) - (size * 2)
  79. o_x = og_x
  80. o_y = 127
  81. _id = 0
  82. for n in o.soundSlots[o.eSound].notes[self.curPattern]:
  83. if _id == o.playhead and o.playing:
  84. if o.curPattern == self.curPattern:
  85. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.olive, width=1)
  86. else:
  87. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.pink, width=1)
  88. elif n[0] == 1:
  89. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.light_grey, width=1)
  90. else:
  91. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.blue, width=1)
  92. o_x = o_x + size
  93. _id += 1
  94. if _id % 4 == 0:
  95. o_y -= size
  96. o_x = og_x
  97. def ReceiveMessage(self, message):
  98. _id = 0
  99. o = self.FSM.owner
  100. u.play_seq(o, message)
  101. if o.keyState[16] > 0 or o.keyState[17] > 0:
  102. pass
  103. else:
  104. u.draw_header(o)
  105. self.draw_square()
  106. u.text_box3(o, "Vol", str(o.note_vol))
  107. u.text_box1(o, "Pat", str(self.curPattern))
  108. if o.patternFollow:
  109. self.curPattern = message[0]
  110. else:
  111. self.curPattern = o.ePattern
  112. o.update_display(0)
  113. def Exit(self):
  114. self.FSM.owner.pub.unregister("beat", self)