raspberry pi zero based drum machine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sEditSong.py 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.update_display(0)
  31. self.new_song = []
  32. super(EditSong, self).Enter()
  33. def Execute(self):
  34. o = self.FSM.owner
  35. m.menu1_actions(self, o)
  36. m.menu2_actions_song(self, o)
  37. if o.keyState[16] == 1:
  38. m.draw_menu1(o)
  39. o.update_display(0)
  40. elif o.keyState[16] == 4:
  41. u.draw_header(o)
  42. self.draw_main(o)
  43. o.update_display(0)
  44. if o.keyState[17] == 1:
  45. m.draw_menu2_song(o)
  46. o.update_display(0)
  47. elif o.keyState[17] == 4:
  48. u.draw_header(o)
  49. self.draw_main(o)
  50. o.update_display(0)
  51. if o.keyState[16] > 0 or o.keyState[17] > 0:
  52. pass
  53. else:
  54. _id = 0
  55. for k in self.FSM.owner.keyState:
  56. if k == 1 and _id < 16:
  57. self.new_song.append((_id + (o.pat_bank * 16)))
  58. u.draw_header(o)
  59. self.draw_main(o)
  60. o.update_display(0)
  61. _id += 1
  62. def draw_main(self, o):
  63. ypos = 35
  64. ysize = 20
  65. tmp_song = [8, 6, 7, 5, 3, 0, 9]
  66. lines = u.breakup_song_text(o.song)
  67. if self.new_song != []:
  68. lines = u.breakup_song_text(self.new_song)
  69. o.center_block("New Song", o.h2, [0, ypos, o.width, ypos + ysize], o.pink)
  70. else:
  71. o.center_block("Current Song", o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
  72. ypos += ysize
  73. o.center_block(lines[0], o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
  74. ypos += ysize
  75. o.center_block(lines[1], o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
  76. ypos += ysize
  77. o.center_block(lines[2], o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
  78. ypos += ysize
  79. o.center_block(lines[3], o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
  80. def ReceiveMessage(self, message):
  81. _id = 0
  82. o = self.FSM.owner
  83. u.play_seq(o, message)
  84. def Exit(self):
  85. o = self.FSM.owner
  86. self.FSM.owner.pub.unregister("beat", self)
  87. if self.new_song != []:
  88. o.song = self.new_song
  89. o.songCycle = cycle(self.new_song)
  90. self.curPattern = next(o.songCycle)
  91. o.songStart = o.curPattern
  92. #====================================