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.

sMain.py 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import FSM
  2. import utils as u
  3. import menus as m
  4. import pygame
  5. #====================================
  6. State = type("State", (object,), {})
  7. #====================================
  8. class State(object):
  9. def __init__(self, FSM):
  10. self.FSM = FSM
  11. def Enter(self):
  12. pass
  13. def Execute(self):
  14. pass
  15. def Exit(self):
  16. pass
  17. #====================================
  18. class Main(State):
  19. def __init__(self,FSM):
  20. super(Main, self).__init__(FSM)
  21. def Enter(self):
  22. print('hello main')
  23. self.FSM.owner.pub.register("beat", self)
  24. self.FSM.stateLife = 1
  25. o = self.FSM.owner
  26. o.header_text = "Sound Select"
  27. if o.keyState[16] > 0 or o.keyState[17] > 0:
  28. pass
  29. else:
  30. u.draw_header(o)
  31. self.draw_square()
  32. u.text_box1(o, "Vol", str(o.soundSlots[o.eSound].volume))
  33. u.text_box2(o, "BPM", str(o.bpm))
  34. u.text_box4(o, "Bank", str(o.note_bank))
  35. u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
  36. o.update_display(0)
  37. self.recording = True
  38. self.record_queue = []
  39. self.undo_queue = []
  40. o.erase = False
  41. o.erase_queue = []
  42. o.mute = False
  43. o.mute_queue = []
  44. super(Main, self).Enter()
  45. def Execute(self):
  46. o = self.FSM.owner
  47. m.menu1_actions(self, o)
  48. m.menu2_actions_sample(self, o)
  49. if o.keyState[16] == 1:
  50. m.draw_menu1(o)
  51. o.update_display(0)
  52. elif o.keyState[16] == 4:
  53. u.draw_header(o)
  54. self.draw_square()
  55. u.text_box1(o, "Vol", str(o.soundSlots[o.eSound].volume))
  56. u.text_box2(o, "BPM", str(o.bpm))
  57. u.text_box4(o, "Bank", str(o.note_bank))
  58. u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
  59. o.button_repeater(1, [])
  60. o.update_display(0)
  61. if o.keyState[17] == 1:
  62. m.draw_menu2_sample(o)
  63. o.update_display(0)
  64. elif o.keyState[17] == 4:
  65. u.draw_header(o)
  66. self.draw_square()
  67. u.text_box1(o, "Vol", str(o.soundSlots[o.eSound].volume))
  68. u.text_box2(o, "BPM", str(o.bpm))
  69. u.text_box4(o, "Bank", str(o.note_bank))
  70. u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
  71. o.update_display(0)
  72. _id = 0
  73. for k in o.keyState:
  74. if _id > 15:
  75. pass
  76. else:
  77. if o.keyState[16] > 0 or o.keyState[17] > 0:
  78. pass
  79. else:
  80. note = _id + o.note_bank * 16
  81. if k == 1:
  82. self.record_queue = pygame.time.get_ticks()
  83. if not o.erase and not o.mute:
  84. o.soundSlots[note].play(o.note_vol)
  85. o.eSound = note
  86. u.draw_header(o)
  87. u.text_box1(o, "SVol", str(o.slots[o.eSound].volume))
  88. u.text_box2(o, "BPM", str(o.bpm))
  89. u.text_box4(o, "Bank", str(o.note_bank))
  90. u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
  91. self.draw_square()
  92. o.update_display(0)
  93. if o.erase:
  94. o.erase_buf.append(note)
  95. if o.mute:
  96. o.mute_buf.append(note)
  97. if k == 3:
  98. if note in o.erase_buf:
  99. o.erase_buf.remove(note)
  100. if note in o.mute_buf:
  101. o.mute_buf.remove(note)
  102. _id += 1
  103. def ReceiveMessage(self, message):
  104. o = self.FSM.owner
  105. if o.erase == True:
  106. u.play_seq(o, message)
  107. else:
  108. u.play_seq(o, message)
  109. if o.keyState[16] > 0 or o.keyState[17] > 0:
  110. pass
  111. else:
  112. u.draw_header(o)
  113. self.draw_square()
  114. u.text_box1(o, "SVol", str(o.soundSlots[o.eSound].volume))
  115. u.text_box2(o, "BPM", str(o.bpm))
  116. u.text_box4(o, "Bank", str(o.note_bank))
  117. u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
  118. o.update_display(0)
  119. if self.record_queue != []:
  120. cur_time = pygame.time.get_ticks()
  121. note_pos = (cur_time - self.record_queue) - (o.half_bpm / 2)
  122. if o.odub == True:
  123. if note_pos > (o.half_bpm):
  124. _note = 0
  125. if message[1] == 0:
  126. _note = 15
  127. else:
  128. _note = message[1] - 1
  129. if o.soundSlots[o.eSound].notes[message[0]][_note][0] != 1:
  130. o.soundSlots[o.eSound].notes[message[0]][_note][0] = 1
  131. o.soundSlots[o.eSound].notes[message[0]][_note][1] = o.note_vol
  132. o.undo_buf.append([o.eSound, message[0], _note])
  133. else:
  134. if o.soundSlots[o.eSound].notes[message[0]][message[1]][0] != 1:
  135. o.soundSlots[o.eSound].notes[message[0]][message[1]][0] = 1
  136. o.soundSlots[o.eSound].notes[message[0]][message[1]][1] = o.note_vol
  137. o.undo_buf.append([o.eSound, message[0], message[1]])
  138. self.record_queue = []
  139. def draw_square(self):
  140. o = self.FSM.owner
  141. size = 22
  142. og_x = (o.width / 2) - (size * 2)
  143. o_x = og_x
  144. o_y = 127
  145. _id = o.note_bank * 16
  146. while _id < ((o.note_bank * 16) + 16):
  147. if _id == o.eSound:
  148. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.light_grey, width=1)
  149. elif o.notes_on[_id] == 1:
  150. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.grey, width=1)
  151. elif self.has_sample(o, _id) == False:
  152. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.dark_grey, width=1)
  153. else:
  154. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.blue, width=1)
  155. o_x = o_x + size
  156. _id += 1
  157. if _id % 4 == 0:
  158. o_y -= size
  159. o_x = og_x
  160. def has_sample(self, o, slot):
  161. if o.soundSlots[slot].file != None:
  162. return True
  163. else:
  164. return False
  165. def Exit(self):
  166. self.FSM.owner.pub.unregister("beat", self)