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.

sSelectPattern.py 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 SelectPattern(State):
  18. def __init__(self,FSM):
  19. super(SelectPattern, self).__init__(FSM)
  20. def Enter(self):
  21. self.FSM.stateLife = 1
  22. o = self.FSM.owner
  23. o.header_text = "Select Pattern"
  24. o.pub.register("beat", self)
  25. self.cur_playing = 0
  26. self.active_patterns = []
  27. self.get_active_patterns(o)
  28. if o.keyState[16] > 0 or o.keyState[17] > 0:
  29. pass
  30. else:
  31. u.draw_header(o)
  32. self.draw_square()
  33. u.text_box1(o, "Pat", str(o.ePattern))
  34. u.text_box4(o, "Bank", str(o.pat_bank))
  35. o.update_display(0)
  36. super(SelectPattern, self).Enter()
  37. def Execute(self):
  38. o = self.FSM.owner
  39. m.menu1_actions(self, o)
  40. m.menu2_actions_pattern(self, o)
  41. if o.keyState[16] == 1:
  42. m.draw_menu1(o)
  43. o.update_display(0)
  44. elif o.keyState[16] == 4:
  45. u.draw_header(o)
  46. self.draw_square()
  47. u.text_box1(o, "Pat", str(o.ePattern))
  48. u.text_box4(o, "Bank", str(o.pat_bank))
  49. o.update_display(0)
  50. if o.keyState[17] == 1:
  51. m.draw_menu2_pattern(o)
  52. o.update_display(0)
  53. elif o.keyState[17] == 4:
  54. u.draw_header(o)
  55. self.get_active_patterns(o)
  56. self.draw_square()
  57. u.text_box1(o, "Pat", str(o.ePattern))
  58. u.text_box4(o, "Bank", str(o.pat_bank))
  59. o.update_display(0)
  60. if o.keyState[16] > 0 or o.keyState[17] > 0:
  61. pass
  62. else:
  63. _id = 0
  64. for k in o.keyState:
  65. if _id > 15:
  66. pass
  67. else:
  68. if k == 1:
  69. o.ePattern = (o.pat_bank * 16) +_id
  70. u.draw_header(o)
  71. self.draw_square()
  72. u.text_box1(o, "Pat", str(o.ePattern))
  73. u.text_box4(o, "Bank", str(o.pat_bank))
  74. o.update_display(0)
  75. _id += 1
  76. def ReceiveMessage(self, message):
  77. o = self.FSM.owner
  78. u.play_seq(o, message)
  79. if message[0] != self.cur_playing:
  80. #print('playing ', message)
  81. self.cur_playing = message[0]
  82. if o.keyState[16] > 0 or o.keyState[17] > 0:
  83. pass
  84. else:
  85. u.draw_header(o)
  86. self.draw_square()
  87. u.text_box1(o, "Pat", str(o.ePattern))
  88. u.text_box4(o, "Bank", str(o.pat_bank))
  89. o.update_display(0)
  90. def draw_square(self):
  91. o = self.FSM.owner
  92. size = 22
  93. og_x = (o.width / 2) - (size * 2)
  94. o_x = og_x
  95. o_y = 127
  96. _id = 0
  97. for n in o.soundSlots[o.eSound].notes[o.ePattern]:
  98. if (_id + (o.pat_bank * 16)) == o.ePattern:
  99. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.olive, width=1)
  100. elif (_id + (o.pat_bank * 16)) == self.cur_playing:
  101. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.light_grey, width=1)
  102. elif self.active_patterns[_id] == 1:
  103. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.blue, width=1)
  104. else:
  105. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.dark_grey, width=1)
  106. o_x = o_x + size
  107. _id += 1
  108. if _id % 4 == 0:
  109. o_y -= size
  110. o_x = og_x
  111. def get_active_patterns(self, o):
  112. #for n in o.soundSlots[o.eSound]
  113. self.active_patterns = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
  114. pat_iter = o.pat_bank * 16
  115. _iter = 0
  116. #print('is this note on? ', o.soundSlots[0].notes[0][0][0])
  117. while pat_iter < ((o.pat_bank * 16) + 16):
  118. for s in o.soundSlots:
  119. #print('checking soundSlot ', s.id)
  120. pat_used = 0
  121. for p in s.notes[pat_iter]:
  122. if self.active_patterns[_iter] == 1:
  123. break
  124. if p[0] == 1:
  125. #pat_used = 1
  126. self.active_patterns[_iter] = 1
  127. #print('found ', pat_iter, ' -- ', p[0])
  128. break
  129. #self.active_patterns.append(pat_used)
  130. pat_iter += 1
  131. _iter += 1
  132. #print('active patterns ', self.active_patterns)
  133. def Exit(self):
  134. self.FSM.owner.pub.unregister("beat", self)