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.

sEditSoundSequence.py 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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_box1(o, "Note Vol", str(o.note_vol))
  32. u.text_box3(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_box1(o, "Note Vol", str(o.note_vol))
  46. u.text_box3(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_box1(o, "Note Vol", str(o.note_vol))
  55. u.text_box3(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. #print('turn note off')
  65. o.soundSlots[o.eSound].notes[self.curPattern][_id][0] = 0
  66. o.soundSlots[o.eSound].notes[self.curPattern][_id][1] = 0
  67. else:
  68. #print('turn note on')
  69. o.soundSlots[o.eSound].notes[self.curPattern][_id][0] = 1
  70. o.soundSlots[o.eSound].notes[self.curPattern][_id][1] = o.note_vol
  71. u.draw_header(o)
  72. self.draw_square()
  73. u.text_box1(o, "Note Vol", str(o.note_vol))
  74. u.text_box3(o, "Pat", str(self.curPattern))
  75. o.update_display(0)
  76. _id += 1
  77. def draw_square(self):
  78. o = self.FSM.owner
  79. size = 22
  80. og_x = (o.width / 2) - (size * 2)
  81. o_x = og_x
  82. o_y = 127
  83. _id = 0
  84. for n in o.soundSlots[o.eSound].notes[self.curPattern]:
  85. if _id == o.playhead and o.playing:
  86. if o.curPattern == self.curPattern:
  87. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.olive, width=1)
  88. else:
  89. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.pink, width=1)
  90. elif n[0] == 1:
  91. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.light_grey, width=1)
  92. else:
  93. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.blue, width=1)
  94. o_x = o_x + size
  95. _id += 1
  96. if _id % 4 == 0:
  97. o_y -= size
  98. o_x = og_x
  99. def ReceiveMessage(self, message):
  100. _id = 0
  101. o = self.FSM.owner
  102. u.play_seq(o, message)
  103. if o.keyState[16] > 0 or o.keyState[17] > 0:
  104. pass
  105. else:
  106. u.draw_header(o)
  107. self.draw_square()
  108. u.text_box1(o, "Note Vol", str(o.note_vol))
  109. u.text_box3(o, "Pat", str(self.curPattern))
  110. if o.patternFollow:
  111. self.curPattern = message[0]
  112. else:
  113. self.curPattern = o.ePattern
  114. #print('message ', message)
  115. o.update_display(0)
  116. def Exit(self):
  117. self.FSM.owner.pub.unregister("beat", self)