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.

menus.py 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. import utils as u
  2. import pygame
  3. from itertools import cycle
  4. def draw_menu1(o):
  5. bpm_inc = 4
  6. x_size = o.width / 4
  7. y_size = o.height / 4
  8. og_x = 0
  9. o_x = og_x
  10. o_y = o.height
  11. text_padding = 6
  12. _id = 0
  13. while _id < 16:
  14. o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.blue)
  15. if _id == 0:
  16. o.center_block("Main", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  17. if _id == 1:
  18. o.center_block("Note", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  19. if _id == 2:
  20. o.center_block("Patt", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  21. if _id == 3:
  22. o.center_block("Song", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  23. if _id == 4:
  24. o.center_block("File", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  25. if _id == 5:
  26. o.center_block("Util", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  27. # if _id == 6:
  28. # o.center_block("Bank-", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  29. # if _id == 7:
  30. # o.center_block("Bank+", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  31. if _id == 8:
  32. o.center_block("Vol-", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  33. if _id == 9:
  34. o.center_block("Vol+", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  35. #if _id == 11:
  36. #o.center_block("", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  37. if _id == 12:
  38. o.center_block("Play", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  39. if _id == 13:
  40. o.center_block("Stop", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  41. if _id == 10:
  42. o.center_block("BPM-", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  43. if _id == 11:
  44. o.center_block("BPM+", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  45. o_x = o_x + x_size
  46. _id += 1
  47. if _id % 4 == 0:
  48. o_y -= y_size
  49. o_x = og_x
  50. def draw_menu2_sample(o):
  51. bpm_inc = 4
  52. x_size = o.width / 4
  53. y_size = o.height / 4
  54. og_x = 0
  55. o_x = og_x
  56. o_y = o.height
  57. text_padding = 6
  58. _id = 0
  59. while _id < 16:
  60. o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.dark_grey)
  61. if _id == 0:
  62. o.center_block("Copy", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  63. if _id == 1:
  64. o.center_block("Paste", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  65. if _id == 2:
  66. o.center_block("Del", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  67. if _id == 3:
  68. o.center_block("Load", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  69. if _id == 4:
  70. if o.prev == True:
  71. o.center_block("Prev", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.pink)
  72. else:
  73. o.center_block("Prev", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  74. if _id == 8:
  75. o.center_block("Vol-", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  76. if _id == 9:
  77. o.center_block("Vol+", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  78. if _id == 6:
  79. o.center_block("Bank-", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  80. if _id == 7:
  81. o.center_block("Bank+", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  82. if _id == 10:
  83. o.center_block("Pitch-", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  84. if _id == 11:
  85. o.center_block("Pitch+", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  86. if _id == 12:
  87. if o.odub == True:
  88. o.center_block("Odub", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.pink)
  89. else:
  90. o.center_block("Odub", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  91. if _id == 13:
  92. o.center_block("Undo", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  93. if _id == 14:
  94. if o.erase == True:
  95. o.center_block("Erase", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.pink)
  96. else:
  97. o.center_block("Erase", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  98. if _id == 15:
  99. if o.mute == True:
  100. o.center_block("Mute", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.pink)
  101. else:
  102. o.center_block("Mute", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  103. o_x = o_x + x_size
  104. _id += 1
  105. if _id % 4 == 0:
  106. o_y -= y_size
  107. o_x = og_x
  108. def draw_menu2_pattern(o):
  109. bpm_inc = 4
  110. x_size = o.width / 4
  111. y_size = o.height / 4
  112. og_x = 0
  113. o_x = og_x
  114. o_y = o.height
  115. text_padding = 6
  116. _id = 0
  117. while _id < 16:
  118. o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.dark_grey)
  119. if _id == 0:
  120. o.center_block("Copy", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  121. if _id == 1:
  122. o.center_block("Paste", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  123. if _id == 2:
  124. o.center_block("Clear", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  125. if _id == 6:
  126. o.center_block("Bank -", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  127. if _id == 7:
  128. o.center_block("Bank +", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  129. if _id == 12:
  130. if o.pat_odub:
  131. o.center_block("Odub", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.pink)
  132. else:
  133. o.center_block("Odub", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  134. if _id == 13:
  135. if o.pat_perf:
  136. o.center_block("Perf", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.pink)
  137. else:
  138. o.center_block("Perf", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  139. o_x = o_x + x_size
  140. _id += 1
  141. if _id % 4 == 0:
  142. o_y -= y_size
  143. o_x = og_x
  144. def draw_menu2_note(o):
  145. bpm_inc = 4
  146. x_size = o.width / 4
  147. y_size = o.height / 4
  148. og_x = 0
  149. o_x = og_x
  150. o_y = o.height
  151. text_padding = 6
  152. _id = 0
  153. while _id < 16:
  154. o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.dark_grey)
  155. if _id == 8:
  156. o.center_block("Vol -", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  157. elif _id == 9:
  158. o.center_block("Vol +", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  159. elif _id == 12:
  160. if o.patternFollow:
  161. o.center_block("Follow", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.pink)
  162. else:
  163. o.center_block("Follow", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  164. o_x = o_x + x_size
  165. _id += 1
  166. if _id % 4 == 0:
  167. o_y -= y_size
  168. o_x = og_x
  169. def draw_menu2_song(o):
  170. bpm_inc = 4
  171. x_size = o.width / 4
  172. y_size = o.height / 4
  173. og_x = 0
  174. o_x = og_x
  175. o_y = o.height
  176. text_padding = 6
  177. _id = 0
  178. while _id < 16:
  179. o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.dark_grey)
  180. if _id == 6:
  181. o.center_block("Bank -", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  182. if _id == 7:
  183. o.center_block("Bank +", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  184. o_x = o_x + x_size
  185. _id += 1
  186. if _id % 4 == 0:
  187. o_y -= y_size
  188. o_x = og_x
  189. def draw_menu_saveas(o):
  190. bpm_inc = 4
  191. x_size = o.width / 2
  192. y_size = o.height / 4
  193. og_x = 0
  194. o_x = og_x
  195. o_y = o.height
  196. text_padding = 6
  197. _id = 0
  198. while _id < 8:
  199. o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.dark_grey)
  200. if _id == 6:
  201. o.center_block("Select Folder", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  202. if _id == 7:
  203. o.center_block("New Folder", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  204. o_x = o_x + x_size
  205. _id += 1
  206. if _id % 2 == 0:
  207. o_y -= y_size
  208. o_x = og_x
  209. def menu1_actions(self, o):
  210. if o.keyState[8] == 4 or o.keyState[8] == 3:
  211. #print('reset repeat from menu')
  212. o.button_repeater(1,[])
  213. if o.keyState[9] == 4 or o.keyState[9] == 3:
  214. #print('reset repeat from menu')
  215. o.button_repeater(1,[])
  216. if o.keyState[16] == 2:
  217. #print('key 8 ', o.keyState[8])
  218. #o.button_repeater(0, [8,9,14,15])
  219. if o.keyState[0] == 1:
  220. self.FSM.ToTransition('toMain')
  221. elif o.keyState[1] == 1:
  222. self.FSM.ToTransition('toEditSoundSequence')
  223. elif o.keyState[2] == 1:
  224. self.FSM.ToTransition('toSelectPattern')
  225. elif o.keyState[3] == 1:
  226. self.FSM.ToTransition('toEditSong')
  227. elif o.keyState[4] == 1:
  228. self.FSM.ToTransition('toFile')
  229. elif o.keyState[5] == 1:
  230. self.FSM.ToTransition('toUtil')
  231. if o.keyState[12] == 1:
  232. o.start_playback()
  233. u.play_seq(o, [o.curPattern, 0])
  234. if o.keyState[13] == 1:
  235. o.stop_playback()
  236. if o.keyState[8] == 2:
  237. if (o.repeater_states[8] != None and ((pygame.time.get_ticks() - o.repeater_states[8]) > 500)):
  238. if o.volume > 0:
  239. o.volume -= 1
  240. u.text_center(o, "Master Volume", str(o.volume))
  241. o.update_display(0)
  242. o.repeater_states[8] = pygame.time.get_ticks()
  243. if o.keyState[8] == 1:
  244. o.repeater_states[8] = pygame.time.get_ticks()
  245. if o.volume > 0:
  246. o.volume -= 1
  247. u.text_center(o, "Master Volume", str(o.volume))
  248. o.update_display(0)
  249. if o.keyState[9] == 2:
  250. if (o.repeater_states[9] != None and ((pygame.time.get_ticks() - o.repeater_states[9]) > 500)):
  251. if o.volume < 16:
  252. o.volume += 1
  253. u.text_center(o, "Master Volume", str(o.volume))
  254. o.update_display(0)
  255. o.repeater_states[9] = pygame.time.get_ticks()
  256. if o.keyState[9] == 1:
  257. o.repeater_states[9] = pygame.time.get_ticks()
  258. if o.volume < 16:
  259. o.volume += 1
  260. u.text_center(o, "Master Volume", str(o.volume))
  261. o.update_display(0)
  262. if o.keyState[11] == 1:
  263. #o.save_song()
  264. pass
  265. if o.keyState[10] == 2:
  266. if (o.repeater_states[10] != None and ((pygame.time.get_ticks() - o.repeater_states[10]) > 500)):
  267. if o.bpm > 60:
  268. o.bpm = o.bpm - o.bpm_inc
  269. o.update_bpm()
  270. u.text_center(o, "Master BPM", str(o.bpm))
  271. o.update_display(0)
  272. o.repeater_states[10] = pygame.time.get_ticks()
  273. if o.keyState[10] == 1:
  274. o.repeater_states[10] = pygame.time.get_ticks()
  275. if o.bpm > 60:
  276. o.bpm = o.bpm - o.bpm_inc
  277. o.update_bpm()
  278. u.text_center(o, "Master BPM", str(o.bpm))
  279. o.update_display(0)
  280. if o.keyState[11] == 2:
  281. if (o.repeater_states[11] != None and ((pygame.time.get_ticks() - o.repeater_states[11]) > 500)):
  282. if o.bpm < 240:
  283. o.bpm = o.bpm + o.bpm_inc
  284. o.update_bpm()
  285. u.text_center(o, "Master BPM", str(o.bpm))
  286. o.update_display(0)
  287. o.repeater_states[11] = pygame.time.get_ticks()
  288. if o.keyState[11] == 1:
  289. o.repeater_states[11] = pygame.time.get_ticks()
  290. if o.bpm < 240:
  291. o.bpm = o.bpm + o.bpm_inc
  292. o.update_bpm()
  293. u.text_center(o, "Master BPM", str(o.bpm))
  294. o.update_display(0)
  295. def menu2_actions_sample(self, o):
  296. if o.keyState[6] == 4 or o.keyState[6] == 3:
  297. #print('reset repeat from menu')
  298. o.button_repeater(1,[])
  299. if o.keyState[7] == 4 or o.keyState[7] == 3:
  300. #print('reset repeat from menu')
  301. o.button_repeater(1,[])
  302. if o.keyState[8] == 4 or o.keyState[8] == 3:
  303. #print('reset repeat from menu')
  304. o.button_repeater(1,[])
  305. if o.keyState[9] == 4 or o.keyState[9] == 3:
  306. #print('reset repeat from menu')
  307. o.button_repeater(1,[])
  308. if o.keyState[10] == 4 or o.keyState[10] == 3:
  309. #print('reset repeat from menu')
  310. o.button_repeater(1,[])
  311. if o.keyState[11] == 4 or o.keyState[11] == 3:
  312. #print('reset repeat from menu')
  313. o.button_repeater(1,[])
  314. if o.keyState[17] == 2:
  315. if o.keyState[0] == 1:
  316. if o.soundSlots[o.eSound].volume > 0:
  317. #print('copy')
  318. o.soundClipboard = [o.soundSlots[o.eSound].file, o.soundSlots[o.eSound].volume, o.soundSlots[o.eSound].pitch]
  319. #print(o.soundClipboard)
  320. if o.keyState[1] == 1:
  321. if o.soundClipboard != []:
  322. #print('pasting ', o.soundClipboard)
  323. o.soundSlots[o.eSound].file = o.soundClipboard[0]
  324. o.soundSlots[o.eSound].volume = o.soundClipboard[1]
  325. o.soundSlots[o.eSound].pitch = o.soundClipboard[2]
  326. o.soundSlots[o.eSound].create_sound()
  327. o.soundSlots[o.eSound].set_pitch()
  328. if o.keyState[2] == 1:
  329. #print('delete sound ', o.eSound)
  330. o.soundSlots[o.eSound].file = None
  331. o.soundSlots[o.eSound].volume = 16
  332. o.soundSlots[o.eSound].pitch = 0
  333. if o.keyState[3] == 1:
  334. #print('load')
  335. o.FSM.FSM.ToTransition("toLoadSound")
  336. if o.keyState[4] == 1:
  337. o.prev = not o.prev
  338. draw_menu2_sample(o)
  339. o.update_display(0)
  340. if o.keyState[8] == 2:
  341. if (o.repeater_states[8] != None and ((pygame.time.get_ticks() - o.repeater_states[8]) > 500)):
  342. if o.soundSlots[o.eSound].volume > 0:
  343. o.soundSlots[o.eSound].volume -= 1
  344. u.text_center(o, "Sample Volume", str(o.soundSlots[o.eSound].volume))
  345. o.update_display(0)
  346. o.repeater_states[8] = pygame.time.get_ticks()
  347. if o.keyState[8] == 1:
  348. if o.soundSlots[o.eSound].volume > 0:
  349. o.soundSlots[o.eSound].volume -= 1
  350. u.text_center(o, "Sample Volume", str(o.soundSlots[o.eSound].volume))
  351. o.update_display(0)
  352. o.repeater_states[8] = pygame.time.get_ticks()
  353. if o.keyState[9] == 2:
  354. if (o.repeater_states[9] != None and ((pygame.time.get_ticks() - o.repeater_states[9]) > 500)):
  355. if o.soundSlots[o.eSound].volume < 16:
  356. o.soundSlots[o.eSound].volume += 1
  357. u.text_center(o, "Sample Volume", str(o.soundSlots[o.eSound].volume))
  358. o.update_display(0)
  359. o.repeater_states[9] = pygame.time.get_ticks()
  360. if o.keyState[9] == 1:
  361. if o.soundSlots[o.eSound].volume < 16:
  362. o.soundSlots[o.eSound].volume += 1
  363. u.text_center(o, "Sample Volume", str(o.soundSlots[o.eSound].volume))
  364. o.update_display(0)
  365. o.repeater_states[9] = pygame.time.get_ticks()
  366. if o.keyState[6] == 2:
  367. if (o.repeater_states[6] != None and ((pygame.time.get_ticks() - o.repeater_states[6]) > 500)):
  368. if o.note_bank > 0:
  369. o.note_bank -= 1
  370. u.text_center(o, "Sound Bank", str(o.note_bank))
  371. o.update_display(0)
  372. o.repeater_states[6] = pygame.time.get_ticks()
  373. if o.keyState[6] == 1:
  374. if o.note_bank > 0:
  375. o.note_bank -= 1
  376. u.text_center(o, "Sound Bank", str(o.note_bank))
  377. o.repeater_states[6] = pygame.time.get_ticks()
  378. o.update_display(0)
  379. if o.keyState[7] == 2:
  380. if (o.repeater_states[7] != None and ((pygame.time.get_ticks() - o.repeater_states[7]) > 500)):
  381. if o.note_bank < 3:
  382. o.note_bank += 1
  383. u.text_center(o, "Sound Bank", str(o.note_bank))
  384. o.update_display(0)
  385. o.repeater_states[7] = pygame.time.get_ticks()
  386. if o.keyState[7] == 1:
  387. if o.note_bank < 3:
  388. o.note_bank += 1
  389. u.text_center(o, "Sound Bank", str(o.note_bank))
  390. o.repeater_states[7] = pygame.time.get_ticks()
  391. o.update_display(0)
  392. if o.keyState[10] == 2:
  393. if (o.repeater_states[10] != None and ((pygame.time.get_ticks() - o.repeater_states[10]) > 500)):
  394. if o.soundSlots[o.eSound].pitch > -10:
  395. o.soundSlots[o.eSound].pitch -= 1
  396. u.text_center(o, "Sample Pitch", str(o.soundSlots[o.eSound].pitch))
  397. o.soundSlots[o.eSound].set_pitch()
  398. o.update_display(0)
  399. o.repeater_states[10] = pygame.time.get_ticks()
  400. if o.keyState[10] == 1:
  401. if o.soundSlots[o.eSound].pitch > -10:
  402. o.soundSlots[o.eSound].pitch -= 1
  403. u.text_center(o, "Sample Pitch", str(o.soundSlots[o.eSound].pitch))
  404. o.soundSlots[o.eSound].set_pitch()
  405. o.repeater_states[10] = pygame.time.get_ticks()
  406. o.update_display(0)
  407. if o.keyState[11] == 2:
  408. if (o.repeater_states[11] != None and ((pygame.time.get_ticks() - o.repeater_states[11]) > 500)):
  409. if o.soundSlots[o.eSound].pitch < 10:
  410. o.soundSlots[o.eSound].pitch += 1
  411. u.text_center(o, "Sample Pitch", str(o.soundSlots[o.eSound].pitch))
  412. o.soundSlots[o.eSound].set_pitch()
  413. o.update_display(0)
  414. o.repeater_states[11] = pygame.time.get_ticks()
  415. if o.keyState[11] == 1:
  416. if o.soundSlots[o.eSound].pitch < 10:
  417. o.soundSlots[o.eSound].pitch += 1
  418. u.text_center(o, "Sample Pitch", str(o.soundSlots[o.eSound].pitch))
  419. o.soundSlots[o.eSound].set_pitch()
  420. o.repeater_states[11] = pygame.time.get_ticks()
  421. o.update_display(0)
  422. if o.keyState[12] == 1:
  423. o.odub = not o.odub
  424. o.undo_buf = []
  425. #print('odub now is ', o.odub)
  426. draw_menu2_sample(o)
  427. o.update_display(0)
  428. if o.keyState[13] == 1:
  429. #print('undo something')
  430. for i in o.undo_buf:
  431. o.soundSlots[i[0]].notes[i[1]][i[2]][0] = 0
  432. o.soundSlots[i[0]].notes[i[1]][i[2]][1] = 0
  433. o.undo_buf = []
  434. if o.keyState[14] == 1:
  435. o.erase = not o.erase
  436. o.erase_buf = []
  437. #print('erase now is ', o.erase)
  438. if o.erase:
  439. o.mute = False
  440. o.mute_buf = []
  441. draw_menu2_sample(o)
  442. o.update_display(0)
  443. if o.keyState[15] == 1:
  444. o.mute = not o.mute
  445. o.mute_buf = []
  446. #print('mute now is ', o.mute)
  447. if o.mute:
  448. o.erase = False
  449. o.erase_buf = []
  450. draw_menu2_sample(o)
  451. o.update_display(0)
  452. def menu2_actions_pattern(self, o):
  453. if o.keyState[17] == 2:
  454. if o.keyState[0] == 1:
  455. print('copy')
  456. o.patternClipboard = []
  457. for s in o.soundSlots:
  458. notes = []
  459. for i in s.notes[o.ePattern]:
  460. notes.append([i[0], i[1]])
  461. o.patternClipboard.append(notes)
  462. print('adding to clip ', notes)
  463. elif o.keyState[1] == 1:
  464. print('paste')
  465. if o.patternClipboard != []:
  466. p = 0
  467. for s in o.soundSlots:
  468. n = 0
  469. for i in s.notes[o.ePattern]:
  470. i[0] = o.patternClipboard[p][n][0]
  471. i[1] = o.patternClipboard[p][n][1]
  472. n += 1
  473. print('added ', o.patternClipboard[p])
  474. p += 1
  475. else:
  476. print('nothing to paste')
  477. elif o.keyState[2] == 1:
  478. print('clear')
  479. print(o.soundSlots[o.eSound].notes[o.ePattern])
  480. for s in o.soundSlots:
  481. for i in s.notes[o.ePattern]:
  482. i[0] = 0
  483. i[1] = 0
  484. elif o.keyState[6] == 1:
  485. if o.pat_bank > 0:
  486. o.pat_bank -= 1
  487. u.text_center(o, "Pattern Bank", str(o.pat_bank))
  488. o.update_display(0)
  489. elif o.keyState[7] == 1:
  490. if o.pat_bank < 3:
  491. o.pat_bank += 1
  492. u.text_center(o, "Pattern Bank", str(o.pat_bank))
  493. o.update_display(0)
  494. #--------------------------------------------
  495. elif o.keyState[12] == 1:
  496. o.pat_odub = not o.pat_odub
  497. if o.pat_odub:
  498. if o.playing:
  499. o.stop_playback()
  500. o.song_in = [o.curPattern]
  501. if o.pat_perf:
  502. pass
  503. else:
  504. o.pat_perf = True
  505. else:
  506. o.pat_perf = False
  507. o.song = o.song_in
  508. o.pat_buf = o.song_in
  509. o.song_in = []
  510. o.songCycle = cycle(o.song)
  511. o.songStart = o.song[0]
  512. draw_menu2_pattern(o)
  513. o.update_display(0)
  514. elif o.keyState[13] == 1:
  515. o.pat_perf = not o.pat_perf
  516. if o.pat_perf:
  517. o.pat_buf = o.song
  518. o.song = []
  519. print('song is now ', o.song)
  520. else:
  521. o.song = o.pat_buf
  522. print('song is now ', o.song)
  523. draw_menu2_pattern(o)
  524. o.update_display(0)
  525. def menu2_actions_song(self, o):
  526. if o.keyState[17] == 2:
  527. if o.keyState[6] == 1:
  528. if o.pat_bank > 0:
  529. o.pat_bank -= 1
  530. u.text_center(o, "Pattern Bank", str(o.pat_bank))
  531. o.update_display(0)
  532. elif o.keyState[7] == 1:
  533. if o.pat_bank < 3:
  534. o.pat_bank += 1
  535. u.text_center(o, "Pattern Bank", str(o.pat_bank))
  536. o.update_display(0)
  537. def menu2_actions_note(self, o):
  538. if o.keyState[8] == 4 or o.keyState[8] == 3:
  539. #print('reset repeat from menu')
  540. o.button_repeater(1,[])
  541. if o.keyState[9] == 4 or o.keyState[9] == 3:
  542. #print('reset repeat from menu')
  543. o.button_repeater(1,[])
  544. if o.keyState[17] == 2:
  545. if o.keyState[8] == 2:
  546. if (o.repeater_states[8] != None and ((pygame.time.get_ticks() - o.repeater_states[8]) > 500)):
  547. if o.note_vol > 0:
  548. o.note_vol -= 1
  549. u.text_center(o, "Note Volume", str(o.note_vol))
  550. o.update_display(0)
  551. o.repeater_states[8] = pygame.time.get_ticks()
  552. if o.keyState[8] == 1:
  553. if o.note_vol > 0:
  554. o.note_vol -= 1
  555. u.text_center(o, "Note Volume", str(o.note_vol))
  556. o.repeater_states[8] = pygame.time.get_ticks()
  557. o.update_display(0)
  558. if o.keyState[9] == 2:
  559. if (o.repeater_states[9] != None and ((pygame.time.get_ticks() - o.repeater_states[9]) > 500)):
  560. if o.note_vol < 16:
  561. o.note_vol += 1
  562. u.text_center(o, "Note Volume", str(o.note_vol))
  563. o.update_display(0)
  564. o.repeater_states[9] = pygame.time.get_ticks()
  565. if o.keyState[9] == 1:
  566. if o.note_vol < 16:
  567. o.note_vol += 1
  568. u.text_center(o, "Note Volume", str(o.note_vol))
  569. o.repeater_states[9] = pygame.time.get_ticks()
  570. o.update_display(0)
  571. if o.keyState[12] == 1:
  572. if o.patternFollow:
  573. o.patternFollow = False
  574. else:
  575. o.patternFollow = True
  576. #print('pattern follow is ', o.patternFollow)
  577. draw_menu2_note(o)
  578. o.update_display(0)
  579. def menu2_actions_saveas(self, o):
  580. if o.keyState[17] == 2:
  581. if o.keyState[12] == 1:
  582. #print('select folder')
  583. self.FSM.ToTransition('toSelectFolder')
  584. elif o.keyState[14] == 1:
  585. #print('new folder')
  586. self.FSM.ToTransition('toNewDir')
  587. def util_command(self, o, command):
  588. if command == "Clock":
  589. self.FSM.ToTransition('toClock')
  590. elif command == "Balls":
  591. self.FSM.ToTransition('toBall')
  592. elif command == "Defender":
  593. self.FSM.ToTransition('toDefender')
  594. elif command == "Calculator":
  595. self.FSM.ToTransition('toCalculator')
  596. elif command == "Exit":
  597. self.FSM.ToTransition('toExit')
  598. elif command == "Theme":
  599. self.FSM.ToTransition('toSelTheme')
  600. elif command == "Reboot":
  601. self.FSM.ToTransition('toReboot')
  602. elif command == "Update":
  603. self.FSM.ToTransition('toUpdate')
  604. elif command == "Shutdown":
  605. self.FSM.ToTransition('toShutdown')
  606. elif command == "Ping":
  607. self.FSM.ToTransition('toPing')
  608. elif command == "Wifi":
  609. self.FSM.ToTransition('toWifi')
  610. elif command == "About":
  611. self.FSM.ToTransition('toAbout')
  612. def file_command(self, o, command):
  613. if command == "Save":
  614. if o.sconf['title'] != "blank":
  615. o.save_song()
  616. else:
  617. pass
  618. #print('cant save over blank')
  619. elif command == "Open":
  620. self.FSM.ToTransition('toOpenSong')
  621. elif command == "Save As":
  622. self.FSM.ToTransition('toEnterText')
  623. elif command == "New":
  624. o.song_dir = o.base_song_dir
  625. o.mconf['default_song'] = '_blank'
  626. o.load_song()
  627. self.FSM.ToTransition('toMain')