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.

sEditSong.py 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import FSM
  2. import utils as u
  3. import menus as m
  4. from itertools import cycle
  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 EditSong(State):
  19. def __init__(self,FSM):
  20. super(EditSong, self).__init__(FSM)
  21. def Enter(self):
  22. o = self.FSM.owner
  23. o.header_text = "Edit Song"
  24. o.pub.register("beat", self)
  25. if o.keyState[16] > 0 or o.keyState[17] > 0:
  26. pass
  27. else:
  28. u.draw_header(o)
  29. self.draw_main(o)
  30. # o.draw.text((20, 30), "Current Song", font=o.h2, fill=o.light_grey)
  31. # o.draw.text((20, 50), str(o.song), font=o.h2, fill=o.light_grey)
  32. o.update_display(0)
  33. self.new_song = []
  34. super(EditSong, self).Enter()
  35. def Execute(self):
  36. o = self.FSM.owner
  37. m.menu1_actions(self, o)
  38. m.menu2_actions_song(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_main(o)
  45. # if self.new_song == []:
  46. # o.draw.text((20, 30), "Current Song", font=o.h2, fill=o.light_grey)
  47. # o.draw.text((20, 50), str(o.song), font=o.h2, fill=o.light_grey)
  48. # else:
  49. # o.draw.text((20, 30), "New Song", font=o.h2, fill=o.pink)
  50. # o.draw.text((20, 50), str(self.new_song), font=o.h2, fill=o.pink)
  51. o.update_display(0)
  52. if o.keyState[17] == 1:
  53. m.draw_menu2_song(o)
  54. o.update_display(0)
  55. elif o.keyState[17] == 4:
  56. u.draw_header(o)
  57. self.draw_main(o)
  58. o.update_display(0)
  59. if o.keyState[16] > 0 or o.keyState[17] > 0:
  60. #if o.keyState[16] > 0:
  61. pass
  62. else:
  63. _id = 0
  64. for k in self.FSM.owner.keyState:
  65. if k == 1 and _id < 16:
  66. self.new_song.append((_id + (o.pat_bank * 16)))
  67. u.draw_header(o)
  68. self.draw_main(o)
  69. #o.draw.text((20, 30), "New Song", font=o.h2, fill=o.pink)
  70. #o.draw.text((20, 50), str(self.new_song), font=o.h2, fill=o.pink)
  71. o.update_display(0)
  72. _id += 1
  73. def draw_main(self, o):
  74. ypos = 35
  75. ysize = 20
  76. tmp_song = [8, 6, 7, 5, 3, 0, 9]
  77. lines = u.breakup_song_text(o.song)
  78. #lines = u.breakup_song_text(tmp_song)
  79. if self.new_song != []:
  80. #o.draw.text((20, 30), "New Song", font=o.h2, fill=o.pink)
  81. lines = u.breakup_song_text(self.new_song)
  82. o.center_block("New Song", o.h2, [0, ypos, o.width, ypos + ysize], o.pink)
  83. else:
  84. #o.draw.text((20, 30), "Current Song", font=o.h2, fill=o.light_grey)
  85. o.center_block("Current Song", o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
  86. ypos += ysize
  87. o.center_block(lines[0], o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
  88. ypos += ysize
  89. o.center_block(lines[1], o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
  90. ypos += ysize
  91. o.center_block(lines[2], o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
  92. ypos += ysize
  93. o.center_block(lines[3], o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
  94. def ReceiveMessage(self, message):
  95. _id = 0
  96. o = self.FSM.owner
  97. u.play_seq(o, message)
  98. def Exit(self):
  99. o = self.FSM.owner
  100. self.FSM.owner.pub.unregister("beat", self)
  101. if self.new_song != []:
  102. o.song = self.new_song
  103. o.songCycle = cycle(self.new_song)
  104. self.curPattern = next(o.songCycle)
  105. o.songStart = o.curPattern
  106. #====================================