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.

sEnterText.py 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. import FSM
  2. import utils as u
  3. import menus as m
  4. import pygame
  5. from itertools import cycle
  6. from datetime import datetime
  7. from datetime import date
  8. #====================================
  9. State = type("State", (object,), {})
  10. #====================================
  11. class State(object):
  12. def __init__(self, FSM):
  13. self.FSM = FSM
  14. def Enter(self):
  15. pass
  16. def Execute(self):
  17. pass
  18. def Exit(self):
  19. pass
  20. class EnterText(State):
  21. def __init__(self,FSM):
  22. super(EnterText, self).__init__(FSM)
  23. def Enter(self):
  24. o = self.FSM.owner
  25. m.menu1_actions(self, o)
  26. if o.keyState[16] == 1:
  27. m.draw_menu1(o)
  28. o.update_display(0)
  29. elif o.keyState[16] == 4:
  30. self.draw(o)
  31. o.update_display(0)
  32. self.input_string = ""
  33. if o.sconf['title'] == 'blank':
  34. self.input_string += str(datetime.today().strftime('%Y%m%d'))
  35. else:
  36. self.input_string += o.sconf['title']
  37. o.header_text = "EnterText"
  38. o.pub.register("beat", self)
  39. self.last_action = pygame.time.get_ticks()
  40. self.caps = False
  41. self.cur_but = 18
  42. self.cur_letter = ""
  43. if o.keyState[16] > 0 or o.keyState[17] > 0:
  44. pass
  45. else:
  46. pass
  47. self.skips = [7, 3, 11, 12, 13, 14, 15]
  48. self.lc_labels = [["p", "q", "r", "s"], ["t", "u", "v"], ["w", "x", "y", "z"], ["C", "A", "P", "S"],
  49. ["g", "h", "i"], ["j", "k", "l"], ["m", "n", "o"], ["D", "E", "L"],
  50. ["_", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-"], ["a", "b", "c"], ["d", "e", "f"], ["O", "K"],
  51. [], [], [], []]
  52. self.uc_labels = [["P", "Q", "R", "S"], ["T", "U", "V"], ["W", "X", "Y", "Z"], ["C", "A", "P", "S"],
  53. ["G", "H", "I"], ["J", "K", "L"], ["M", "N", "O"], ["D", "E", "L"],
  54. ["_", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-"], ["A", "B", "C"], ["D", "E", "F"], ["O", "K"],
  55. [], [], [], []]
  56. self.labels = self.lc_labels
  57. self.cycles = []
  58. for l in self.labels:
  59. self.cycles.append(cycle(l))
  60. self.draw(o)
  61. o.update_display(0)
  62. super(EnterText, self).Enter()
  63. def Execute(self):
  64. o = self.FSM.owner
  65. y_size = o.height / 4
  66. if o.keyState[11] == 1:
  67. if self.input_string != 'blank':
  68. o.title = self.input_string
  69. o.sconf['title'] = self.input_string
  70. o.save_song()
  71. self.FSM.ToTransition('toFile')
  72. m.menu1_actions(self, o)
  73. m.menu2_actions_saveas(self, o)
  74. if o.keyState[16] == 1:
  75. m.draw_menu1(o)
  76. o.update_display(0)
  77. elif o.keyState[16] == 4:
  78. u.draw_header(o)
  79. self.draw(o)
  80. o.update_display(0)
  81. if o.keyState[17] == 1:
  82. m.draw_menu_saveas(o)
  83. o.update_display(0)
  84. elif o.keyState[17] == 4:
  85. u.draw_header(o)
  86. self.draw(o)
  87. o.update_display(0)
  88. if o.keyState[16] > 0 or o.keyState[17] > 0:
  89. pass
  90. else:
  91. _iter = 0
  92. for k in o.keyState:
  93. if k == 1:
  94. cur_time = pygame.time.get_ticks()
  95. if _iter not in self.skips:
  96. self.last_action = cur_time
  97. if _iter < len(self.cycles):
  98. self.cur_letter = next(self.cycles[_iter])
  99. self.cur_but = _iter
  100. self.draw(o)
  101. o.center_block(self.input_string + self.cur_letter, o.h2, [0, 0, o.width, y_size], o.light_grey)
  102. if _iter == 7:
  103. self.input_string = self.input_string[:-1]
  104. self.last_action = 100000000
  105. self.draw(o)
  106. o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
  107. elif _iter == 3:
  108. if self.caps:
  109. self.caps = False
  110. self.labels = self.lc_labels
  111. else:
  112. self.caps = True
  113. self.labels = self.uc_labels
  114. self.draw(o)
  115. o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
  116. self.cycles = []
  117. for l in self.labels:
  118. self.cycles.append(cycle(l))
  119. o.update_display(0)
  120. _iter += 1
  121. cur_time = pygame.time.get_ticks()
  122. delay = cur_time - self.last_action
  123. if delay > 1000 and delay < 100000:
  124. self.input_string += self.cur_letter
  125. self.last_action = 100000000
  126. self.reset_cycles()
  127. self.draw(o)
  128. o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
  129. o.update_display(0)
  130. def ReceiveMessage(self, message):
  131. o = self.FSM.owner
  132. u.play_seq(o, message)
  133. def draw(self, o):
  134. x_size = o.width / 4
  135. y_size = o.height / 4
  136. og_x = 0
  137. o_x = og_x
  138. o_y = o.height
  139. text_padding = 6
  140. _id = 0
  141. while _id < 16:
  142. lab = ""
  143. for i in self.labels[_id]:
  144. lab += i
  145. if _id == 8:
  146. lab = "_12"
  147. o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.blue)
  148. o.center_block(lab, o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  149. o_x = o_x + x_size
  150. _id += 1
  151. if _id % 4 == 0:
  152. o_y -= y_size
  153. o_x = og_x
  154. o.draw.rectangle((0, 0, o.width, y_size), outline=0, fill=o.blue)
  155. def reset_cycles(self):
  156. self.cycles = []
  157. for l in self.labels:
  158. self.cycles.append(cycle(l))
  159. def Exit(self):
  160. self.FSM.owner.pub.unregister("beat", self)