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.

StatesProg.py 37KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  1. import random
  2. import time
  3. import pygame
  4. import pyaudio
  5. import wave
  6. import glob
  7. import os
  8. from itertools import cycle
  9. from datetime import datetime
  10. import ast
  11. #====================================
  12. State = type("State", (object,), {})
  13. #====================================
  14. class State(object):
  15. def __init__(self, FSM):
  16. self.FSM = FSM
  17. self.timer = 0
  18. self.startTime = 0
  19. def Enter(self):
  20. self.timer = 0
  21. self.startTime = 0
  22. def Execute(self):
  23. print('Executing')
  24. def Exit(self):
  25. print('Exiting')
  26. #====================================
  27. def play_seq(o, message):
  28. _id = 0
  29. for s in o.soundSlots:
  30. #print('mes ', message)
  31. #print('thi ', s.notes[message[0]][message[1]])
  32. #print(s.notes[message[0]])
  33. #if s.notes[message[1]][0] == 1:
  34. if s.notes[message[0]][message[1]][0] == 1:
  35. #o.soundSlots[_id].set_volume(s.notes[message[0]][message[1]][1])
  36. o.soundSlots[_id].play(s.notes[message[0]][message[1]][1])
  37. #print('play')
  38. #o.soundSlots[_id].play(s.notes[message[1]][1])
  39. #o.soundSlots[_id].play(s.notes[message[0]])
  40. _id += 1
  41. def draw_header(o):
  42. o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
  43. o.center_text(o.header_text, o.h1, o.width, 25, o.light_grey)
  44. o.center_text("----------------------", o.h2, o.width, 55, o.light_grey)
  45. #o.draw.text((0, 0), o.header_text, font=o.h1, fill=o.light_grey)
  46. #o.disp.image(o.image, o.rotation)
  47. def text_box1(o, a, b):
  48. w1 = 0
  49. w2 = (o.width / 2) - 50
  50. h1 = 45
  51. h2 = h1 + 10
  52. o.center_block(a, o.h2, [w1,h1,w2,h2], o.light_grey)
  53. o.center_block(b, o.h2, [w1,h1+10,w2,h2+25], o.light_grey)
  54. def text_box2(o, a, b):
  55. w1 = 0
  56. w2 = (o.width / 2) - 50
  57. h1 = 90
  58. h2 = h1 + 10
  59. o.center_block(a, o.h2, [w1,h1,w2,h2], o.light_grey)
  60. o.center_block(b, o.h2, [w1,h1+10,w2,h2+25], o.light_grey)
  61. def text_box3(o, a, b):
  62. w1 = (o.width / 2) + 40
  63. w2 = o.width
  64. h1 = 45
  65. h2 = h1 + 10
  66. o.center_block(a, o.h2, [w1,h1,w2,h2], o.light_grey)
  67. o.center_block(b, o.h2, [w1,h1+10,w2,h2+25], o.light_grey)
  68. def text_box4(o, a, b):
  69. w1 = (o.width / 2) + 40
  70. w2 = o.width
  71. h1 = 90
  72. h2 = h1 + 10
  73. o.center_block(a, o.h2, [w1,h1,w2,h2], o.light_grey)
  74. o.center_block(b, o.h2, [w1,h1+10,w2,h2+25], o.light_grey)
  75. def text_center(o, a, b):
  76. w1 = 0
  77. w2 = o.width
  78. h1 = 45
  79. h2 = h1 + 10
  80. o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
  81. o.center_block(a, o.h1, [w1,h1,w2,h2], o.light_grey)
  82. o.center_block(b, o.h1, [w1,h1+20,w2,h2+45], o.light_grey)
  83. def draw_menu1(o):
  84. #o = self.FSM.owner
  85. bpm_inc = 4
  86. x_size = o.width / 4
  87. y_size = o.height / 4
  88. og_x = 0
  89. o_x = og_x
  90. o_y = o.height
  91. text_padding = 6
  92. _id = 0
  93. while _id < 16:
  94. o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.blue)
  95. if _id == 0:
  96. o.center_block("Main", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  97. if _id == 1:
  98. o.center_block("Note", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  99. if _id == 2:
  100. o.center_block("Patt", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  101. if _id == 3:
  102. o.center_block("Song", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  103. if _id == 4:
  104. o.center_block("File", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  105. if _id == 5:
  106. o.center_block("Util", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  107. if _id == 6:
  108. o.center_block("Bank-", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  109. if _id == 7:
  110. o.center_block("Bank+", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  111. if _id == 8:
  112. o.center_block("Vol-", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  113. #if o.volume > 0:
  114. #o.volume -= 1
  115. if _id == 9:
  116. o.center_block("Vol+", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  117. #if o.volume < 16:
  118. #o.volume += 1
  119. if _id == 11:
  120. o.center_block("Save", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  121. if _id == 12:
  122. o.center_block("Play", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  123. if _id == 13:
  124. o.center_block("Stop", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  125. if _id == 14:
  126. o.center_block("BPM-", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  127. if _id == 15:
  128. o.center_block("BPM+", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  129. o_x = o_x + x_size
  130. _id += 1
  131. if _id % 4 == 0:
  132. o_y -= y_size
  133. o_x = og_x
  134. def draw_menu2(o):
  135. #o = self.FSM.owner
  136. bpm_inc = 4
  137. x_size = o.width / 4
  138. y_size = o.height / 4
  139. og_x = 0
  140. o_x = og_x
  141. o_y = o.height
  142. text_padding = 6
  143. _id = 0
  144. while _id < 16:
  145. o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.dark_grey)
  146. # if _id == 0:
  147. # o.center_block("Main", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  148. # if _id == 1:
  149. # o.center_block("Note", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  150. # if _id == 2:
  151. # o.center_block("Patt", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  152. # if _id == 3:
  153. # o.center_block("Song", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  154. # if _id == 4:
  155. # o.center_block("File", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  156. # if _id == 5:
  157. # o.center_block("Util", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  158. # if _id == 6:
  159. # o.center_block("Bank-", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  160. # if _id == 7:
  161. # o.center_block("Bank+", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  162. # if _id == 8:
  163. # o.center_block("Vol-", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  164. # #if o.volume > 0:
  165. # #o.volume -= 1
  166. # if _id == 9:
  167. # o.center_block("Vol+", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  168. # #if o.volume < 16:
  169. # #o.volume += 1
  170. # if _id == 11:
  171. # o.center_block("Save", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  172. # if _id == 12:
  173. # o.center_block("Play", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  174. # if _id == 13:
  175. # o.center_block("Stop", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  176. # if _id == 14:
  177. # o.center_block("BPM-", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  178. # if _id == 15:
  179. # o.center_block("BPM+", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
  180. o_x = o_x + x_size
  181. _id += 1
  182. if _id % 4 == 0:
  183. o_y -= y_size
  184. o_x = og_x
  185. def menu1_actions(self, o):
  186. if o.keyState[16] == 2:
  187. if o.keyState[0] == 1:
  188. self.FSM.ToTransition('toMain')
  189. elif o.keyState[1] == 1:
  190. self.FSM.ToTransition('toEditSoundSequence')
  191. elif o.keyState[2] == 1:
  192. self.FSM.ToTransition('toSelectPattern')
  193. elif o.keyState[3] == 1:
  194. self.FSM.ToTransition('toEditSong')
  195. elif o.keyState[4] == 1:
  196. self.FSM.ToTransition('toFile')
  197. elif o.keyState[5] == 1:
  198. self.FSM.ToTransition('toClock')
  199. if o.keyState[12] == 1:
  200. o.start_playback()
  201. if o.keyState[13] == 1:
  202. o.stop_playback()
  203. if o.keyState[6] == 1:
  204. if o.note_bank > 0:
  205. o.note_bank -= 1
  206. if o.keyState[7] == 1:
  207. if o.note_bank < 4:
  208. o.note_bank += 1
  209. if o.keyState[8] == 1:
  210. if o.volume > 0:
  211. o.volume -= 1
  212. text_center(o, "Master Volume", str(o.volume))
  213. o.disp.image(o.image, o.rotation)
  214. if o.keyState[9] == 1:
  215. if o.volume < 16:
  216. o.volume += 1
  217. text_center(o, "Master Volume", str(o.volume))
  218. o.disp.image(o.image, o.rotation)
  219. if o.keyState[11] == 1:
  220. o.save_song()
  221. if o.keyState[14] == 1:
  222. if o.sconf.as_int('bpm') > 60:
  223. o.sconf['bpm'] = o.sconf.as_int('bpm') - o.bpm_inc
  224. o.update_bpm()
  225. text_center(o, "Master BPM", str(o.sconf['bpm']))
  226. o.disp.image(o.image, o.rotation)
  227. if o.keyState[15] == 1:
  228. if o.sconf.as_int('bpm') < 240:
  229. o.sconf['bpm'] = o.sconf.as_int('bpm') + o.bpm_inc
  230. o.update_bpm()
  231. text_center(o, "Master BPM", str(o.sconf['bpm']))
  232. o.disp.image(o.image, o.rotation)
  233. class Example(State):
  234. def __init__(self,FSM):
  235. super(Example, self).__init__(FSM)
  236. def Enter(self):
  237. self.FSM.stateLife = 1
  238. super(Example, self).Enter()
  239. def Execute(self):
  240. self.FSM.stateLife += 1
  241. #self.FSM.ToTransition('toLand')
  242. def Exit(self):
  243. pass
  244. #====================================
  245. class Startup(State):
  246. def __init__(self,FSM):
  247. super(Startup, self).__init__(FSM)
  248. def Enter(self):
  249. self.FSM.stateLife = 1
  250. self.birth = time.perf_counter()
  251. super(Startup, self).Enter()
  252. def Execute(self):
  253. self.FSM.stateLife += 1
  254. print('startup state')
  255. if hasattr(self, 'birth'):
  256. pass
  257. else:
  258. self.birth = time.perf_counter()
  259. self.FSM.ToTransition('toIntro')
  260. def Exit(self):
  261. pass
  262. #====================================
  263. class Intro(State):
  264. def __init__(self,FSM):
  265. super(Intro, self).__init__(FSM)
  266. def Enter(self):
  267. self.FSM.stateLife = 1
  268. o = self.FSM.owner
  269. self.FSM.owner.draw.rectangle((0, 0, self.FSM.owner.width, self.FSM.owner.height), outline=0, fill=o.blue)
  270. super(Intro, self).Enter()
  271. def Execute(self):
  272. self.FSM.stateLife += 1
  273. o = self.FSM.owner
  274. self.FSM.ToTransition('toLoadDefault')
  275. self.FSM.owner.draw.rectangle((0, 0, self.FSM.owner.width, self.FSM.owner.height), outline=0, fill=o.blue)
  276. #self.FSM.owner.draw.text((0, 0), str(self.FSM.owner.playhead), font=self.FSM.owner.font, fill="#FFFFFF")
  277. self.FSM.owner.draw.text((0, 0), str(self.FSM.owner.playhead), font=self.FSM.owner.font, fill="#FF0000")
  278. def Exit(self):
  279. pass
  280. #====================================
  281. class LoadDefault(State):
  282. def __init__(self,FSM):
  283. super(LoadDefault, self).__init__(FSM)
  284. def Enter(self):
  285. self.FSM.stateLife = 1
  286. o = self.FSM.owner
  287. o.load_song()
  288. self.bank = 0
  289. self.sounds = []
  290. self.globbed = glob.glob('/home/pi/skull/*.wav') + glob.glob('/home/pi/skull/*.mp3')
  291. self.globbed.sort()
  292. obj_id = 0
  293. # for f in self.globbed:
  294. # #self.sounds.append(pygame.mixer.Sound(f))
  295. # p1 = self.FSM.owner.SoundSlot(f, obj_id)
  296. # self.FSM.owner.soundSlots.append(p1)
  297. # obj_id += 1
  298. # self.sound_names = [os.path.basename(x) for x in self.globbed]
  299. for s in o.sconf['sounds']:
  300. #print('aaaaaayyy, ', s)
  301. p1 = self.FSM.owner.SoundSlot(s, obj_id, o)
  302. self.FSM.owner.soundSlots.append(p1)
  303. obj_id += 1
  304. #print(self.globbed)
  305. #print(self.FSM.owner.soundSlots)
  306. #pygame.mixer.Sound.play(self.FSM.owner.sounds[(self.FSM.owner.bank * 2)])
  307. #self.FSM.owner.soundSlots[2].play()
  308. #o.sconf.to_list(o.sconf['notes'])
  309. #lst = o.sconf.as_list('notes')
  310. _iter = 0
  311. lst = ast.literal_eval(o.sconf['notes'][0])
  312. print('length ', len(lst))
  313. for n in o.soundSlots:
  314. #print(lst[_iter])
  315. #print(n.notes)
  316. #print('---', len(n.notes[0]), _iter)
  317. m = []
  318. lst = ast.literal_eval(o.sconf.as_list('notes')[_iter])
  319. #n.notes = lst[_iter]
  320. n.notes = lst
  321. _iter += 1
  322. #print(self.FSM.owner.soundSlots[0].notes[0])
  323. # self.FSM.owner.soundSlots[0].notes[0] = [[1,16,0],[0,0,0],[0,0,0],[0,0,0],
  324. # [0,0,0],[0,0,0],[0,0,0],[0,0,0],
  325. # [0,0,0],[0,0,0],[1,16,0],[0,0,0],
  326. # [0,0,0],[0,0,0],[1,16,0],[0,0,0]]
  327. # self.FSM.owner.soundSlots[3].notes[0] = [[1,16,0],[0,0,0],[1,16,0],[1,16,0],
  328. # [1,16,0],[0,0,0],[1,16,0],[1,16,0],
  329. # [1,16,0],[1,16,0],[1,16,0],[0,0,0],
  330. # [1,16,0],[0,0,0],[0,0,0],[0,0,0]]
  331. # self.FSM.owner.soundSlots[2].notes[0] = [[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  332. # [1,16,0],[0,0,0],[0,0,0],[0,0,0],
  333. # [0,0,0],[0,0,0],[0,0,0],[0,0,0],
  334. # [1,16,0],[0,0,0],[0,0,0],[0,0,0]]
  335. # self.FSM.owner.soundSlots[0].notes[1] = [[1,16,0],[0,0,0],[0,0,0],[0,0,0],
  336. # [0,0,0],[0,0,0],[0,0,0],[0,0,0],
  337. # [0,0,0],[0,0,0],[1,16,0],[0,0,0],
  338. # [0,0,0],[0,0,0],[0,0,0],[0,0,0]]
  339. # self.FSM.owner.soundSlots[3].notes[1] = [[1,16,0],[0,0,0],[1,16,0],[0,0,0],
  340. # [1,16,0],[0,0,0],[1,16,0],[1,16,0],
  341. # [1,16,0],[0,0,0],[1,16,0],[0,0,0],
  342. # [1,16,0],[0,0,0],[0,0,0],[0,0,0]]
  343. # self.FSM.owner.soundSlots[2].notes[1] = [[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  344. # [1,16,0],[0,0,0],[0,0,0],[0,0,0],
  345. # [0,0,0],[0,0,0],[0,0,0],[0,0,0],
  346. # [1,16,0],[0,0,0],[0,0,0],[0,0,0]]
  347. # self.FSM.owner.soundSlots[0].notes[2] = [[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  348. # [0,0,0],[0,0,0],[0,0,0],[0,0,0],
  349. # [0,0,0],[0,0,0],[0,0,0],[0,0,0],
  350. # [0,0,0],[0,0,0],[0,0,0],[0,0,0]]
  351. # self.FSM.owner.soundSlots[3].notes[2] = [[1,16,0],[0,0,0],[1,16,0],[0,0,0],
  352. # [1,16,0],[0,0,0],[1,16,0],[1,16,0],
  353. # [1,16,0],[0,0,0],[1,16,0],[0,0,0],
  354. # [1,16,0],[0,0,0],[1,16,0],[0,0,0]]
  355. # self.FSM.owner.soundSlots[2].notes[2] = [[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  356. # [0,0,0],[0,0,0],[0,0,0],[0,0,0],
  357. # [0,0,0],[0,0,0],[0,0,0],[0,0,0],
  358. # [0,0,0],[0,0,0],[0,0,0],[0,0,0]]
  359. # self.FSM.owner.soundSlots[0].notes[3] = [[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  360. # [0,0,0],[0,0,0],[0,0,0],[0,0,0],
  361. # [1,16,0],[0,0,0],[0,0,0],[0,0,0],
  362. # [1,16,0],[0,0,0],[1,16,0],[0,0,0]]
  363. # self.FSM.owner.soundSlots[3].notes[3] = [[1,16,0],[0,0,0],[1,16,0],[0,0,0],
  364. # [1,16,0],[0,0,0],[1,16,0],[1,16,0],
  365. # [1,16,0],[0,0,0],[1,16,0],[0,0,0],
  366. # [1,16,0],[0,0,0],[1,16,0],[0,0,0]]
  367. # self.FSM.owner.soundSlots[2].notes[3] = [[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  368. # [0,0,0],[0,0,0],[0,0,0],[0,0,0],
  369. # [0,0,0],[0,0,0],[0,0,0],[0,0,0],
  370. # [0,0,0],[0,0,0],[0,0,0],[0,0,0]]
  371. #for n in self.FSM.owner.soundSlots[0].notes:
  372. #print('sound ', self.id, ' ', n)
  373. super(LoadDefault, self).Enter()
  374. def Execute(self):
  375. self.FSM.stateLife += 1
  376. #self.FSM.owner.save_song()
  377. self.FSM.ToTransition('toMain')
  378. #self.FSM.ToTransition('toMain')
  379. def Exit(self):
  380. pass
  381. #====================================
  382. #====================================
  383. class Main(State):
  384. def __init__(self,FSM):
  385. super(Main, self).__init__(FSM)
  386. def Enter(self):
  387. print('hello main')
  388. self.FSM.owner.pub.register("beat", self)
  389. self.FSM.stateLife = 1
  390. o = self.FSM.owner
  391. o.header_text = "Main"
  392. if o.keyState[16] > 0 or o.keyState[17] > 0:
  393. pass
  394. else:
  395. draw_header(o)
  396. self.draw_square()
  397. text_box1(o, "Vol", str(o.sconf['volume']))
  398. text_box2(o, "BPM", str(o.sconf['bpm']))
  399. text_box4(o, "Bank", str(o.note_bank))
  400. #text_box3(o, "BPM", "90.0")
  401. o.disp.image(o.image, o.rotation)
  402. #o.start_playback()
  403. #should be pattner len 16
  404. print('this sound ', o.soundSlots[0].notes[0])
  405. o.soundSlots[2].volume = 2
  406. super(Main, self).Enter()
  407. def Execute(self):
  408. o = self.FSM.owner
  409. # if o.keyState[16] > 0:
  410. # print('okey ', o.keyState[16])
  411. menu1_actions(self, o)
  412. if o.keyState[16] == 1:
  413. draw_menu1(o)
  414. o.disp.image(o.image, o.rotation)
  415. elif o.keyState[16] == 4:
  416. draw_header(o)
  417. self.draw_square()
  418. text_box1(o, "Vol", str(o.volume))
  419. text_box2(o, "BPM", str(o.sconf['bpm']))
  420. text_box4(o, "Bank", str(o.note_bank))
  421. #text_box3(o, "BPM", "90.0")
  422. o.disp.image(o.image, o.rotation)
  423. if o.keyState[17] == 1:
  424. draw_menu2(o)
  425. o.disp.image(o.image, o.rotation)
  426. elif o.keyState[17] == 4:
  427. draw_header(o)
  428. self.draw_square()
  429. text_box1(o, "Vol", str(o.volume))
  430. text_box2(o, "BPM", str(o.sconf['bpm']))
  431. text_box4(o, "Bank", str(o.note_bank))
  432. #text_box3(o, "BPM", "90.0")
  433. o.disp.image(o.image, o.rotation)
  434. # if o.keyState[17] == 1:
  435. # o.draw.rectangle((20, 100, 40, 120), outline=0, fill=o.color_b)
  436. # o.disp.image(o.image, o.rotation)
  437. # elif o.keyState[17] == 4:
  438. # o.draw.rectangle((20, 100, 40, 120), outline=0, fill=o.dark_grey)
  439. # o.disp.image(o.image, o.rotation)
  440. _id = 0
  441. for k in o.keyState:
  442. if _id > 15:
  443. pass
  444. else:
  445. if o.keyState[16] > 0 or o.keyState[17] > 0:
  446. pass
  447. else:
  448. if k == 1:
  449. #_id2
  450. #o.eSound = _id
  451. #o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
  452. #o.draw.text((0, 0), "SelSou", font=o.h1, fill=o.color_a)
  453. #o.draw.text((20, 60), str(o.eSound), font=o.h2, fill=o.color_b)
  454. note = _id + o.note_bank * 16
  455. if len(o.soundSlots) > note:
  456. self.FSM.owner.soundSlots[note].play(o.note_vol)
  457. o.eSound = note
  458. print('now editing sound ', o.eSound)
  459. #draw_header(o)
  460. #self.draw_square()
  461. text_box1(o, "Vol", str(o.volume))
  462. text_box2(o, "BPM", str(o.sconf['bpm']))
  463. text_box4(o, "Bank", str(o.note_bank))
  464. self.draw_square()
  465. o.disp.image(o.image, o.rotation)
  466. _id += 1
  467. def ReceiveMessage(self, message):
  468. _id = 0
  469. o = self.FSM.owner
  470. play_seq(o, message)
  471. # for s in o.soundSlots:
  472. # print('--', s.notes[message[0]][message[1]])
  473. # if s.notes[message[0]][message[1]][0] == 1:
  474. # o.soundSlots[_id].play()
  475. # _id += 1
  476. _id = 0
  477. if o.keyState[16] > 0 or o.keyState[17] > 0:
  478. pass
  479. else:
  480. draw_header(o)
  481. self.draw_square()
  482. def draw_square(self):
  483. o = self.FSM.owner
  484. size = 22
  485. og_x = (o.width / 2) - (size * 2)
  486. o_x = og_x
  487. o_y = 127
  488. _id = o.note_bank * 16
  489. #o.draw.rectangle((o_x + 4, o_y + 4, o_x + (size *4) + 4 , (o_y - (size * 4) + 4)), outline="#000000", fill="#000000", width=1)
  490. #for n in o.soundSlots[o.eSound].notes[o.ePattern]:
  491. while _id < ((o.note_bank * 16) + 16):
  492. #print('n is ' ,n)
  493. if _id == o.eSound:
  494. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.light_grey, width=1)
  495. else:
  496. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.blue, width=1)
  497. o_x = o_x + size
  498. _id += 1
  499. if _id % 4 == 0:
  500. o_y -= size
  501. o_x = og_x
  502. def Exit(self):
  503. self.FSM.owner.pub.unregister("beat", self)
  504. #====================================
  505. #====================================
  506. class PadPlayer(State):
  507. def __init__(self,FSM):
  508. super(PadPlayer, self).__init__(FSM)
  509. def Enter(self):
  510. self.FSM.stateLife = 1
  511. print('entering pad player')
  512. super(PadPlayer, self).Enter()
  513. def Execute(self):
  514. self.FSM.stateLife += 1
  515. _id = 0
  516. for k in self.FSM.owner.keyState:
  517. if _id < 16 and k == 1:
  518. self.FSM.owner.soundSlots[_id].play()
  519. _id += 1
  520. if self.FSM.owner.keys:
  521. print("Pressed: ", self.FSM.owner.keys)
  522. #self.FSM.ToTransition('toLand')
  523. def Exit(self):
  524. pass
  525. #====================================
  526. class SeqPlayer(State):
  527. def __init__(self,FSM):
  528. super(SeqPlayer, self).__init__(FSM)
  529. def Enter(self):
  530. self.FSM.stateLife = 1
  531. self.beat = 0
  532. self.FSM.owner.pub.register("beat", self)
  533. print('entering seq player')
  534. o = self.FSM.owner
  535. o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
  536. o.draw.text((20, 0), 'SeqPlayer', font=o.h1, fill="#FFFFFF")
  537. o.disp.image(o.image, o.rotation)
  538. super(SeqPlayer, self).Enter()
  539. def Execute(self):
  540. self.FSM.stateLife += 1
  541. o = self.FSM.owner
  542. # if o.playhead != self.beat:
  543. # #print('beat')
  544. # o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=(0, 0, 0))
  545. # o.draw.text((0, 0), str(o.playhead), font=o.font, fill="#FFFFFF")
  546. # #if (o.playhead % 8) == 0:
  547. # o.disp.image(o.image, o.rotation)
  548. # _id = 0
  549. # for s in o.soundSlots:
  550. # #if s.pattern[o.playhead] == 1:
  551. # if s.notes[o.curPattern][o.playhead] == 1:
  552. # o.soundSlots[_id].play()
  553. # _id += 1
  554. if o.keyState[12] == 1:
  555. o.start_playback()
  556. if o.keyState[13] == 1:
  557. o.stop_playback()
  558. #self.beat = o.playhead
  559. #print('key0 ', o.keyState[16])
  560. if o.keyState[16] == 2:
  561. #print('key0 ', o.keyState[16])
  562. if o.keyState[0] == 1:
  563. print('to main')
  564. self.FSM.ToTransition('toMain')
  565. def ReceiveMessage(self, message):
  566. #print(self.name, 'got message', message)
  567. o = self.FSM.owner
  568. o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
  569. o.draw.text((20, 0), str(message[0]) + ' - ' + str(message[1]), font=o.h1, fill="#FFFFFF")
  570. o.disp.image(o.image, o.rotation)
  571. play_seq(o, message)
  572. # _id = 0
  573. # for s in o.soundSlots:
  574. # if s.notes[message[0]][message[1]][0] == 1:
  575. # o.soundSlots[_id].play()
  576. # _id += 1
  577. def Exit(self):
  578. self.FSM.owner.pub.unregister("beat", self)
  579. #====================================
  580. #====================================
  581. class SelectSound(State):
  582. def __init__(self,FSM):
  583. super(SelectSound, self).__init__(FSM)
  584. def Enter(self):
  585. self.FSM.stateLife = 1
  586. o = self.FSM.owner
  587. o.header_text = "SelSou"
  588. o.pub.register("beat", self)
  589. #o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=(0, 0, 0))
  590. #o.draw.text((0, 0), "SelSou", font=o.h1, fill="#FFFFFF")
  591. draw_header(o)
  592. self.draw_square()
  593. o.disp.image(o.image, o.rotation)
  594. super(SelectSound, self).Enter()
  595. def Execute(self):
  596. o = self.FSM.owner
  597. if o.keyState[16] == 1:
  598. draw_menu1(o)
  599. o.disp.image(o.image, o.rotation)
  600. elif o.keyState[16] == 4:
  601. draw_header(o)
  602. self.draw_square()
  603. o.disp.image(o.image, o.rotation)
  604. if o.keyState[16] == 2:
  605. if o.keyState[0] == 1:
  606. self.FSM.ToTransition('toMain')
  607. else:
  608. _id = 0
  609. for k in o.keyState:
  610. if _id > 15:
  611. pass
  612. else:
  613. if k == 1:
  614. o.eSound = _id
  615. o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
  616. o.draw.text((0, 0), "SelSou", font=o.h1, fill=o.color_a)
  617. o.draw.text((20, 60), str(o.eSound), font=o.h2, fill=o.color_b)
  618. self.draw_square()
  619. o.disp.image(o.image, o.rotation)
  620. self.FSM.owner.soundSlots[_id].play()
  621. print('now editing sound ', _id)
  622. _id += 1
  623. #self.FSM.ToTransition('toLand')
  624. def ReceiveMessage(self, message):
  625. _id = 0
  626. o = self.FSM.owner
  627. o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=(0, 0, 0))
  628. o.draw.text((0, 0), "SelSou", font=o.h1, fill="#FFFFFF")
  629. #o.disp.image(o.image, o.rotation)
  630. #o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=(0, 0, 0))
  631. o.draw.text((0, 20), str(o.eSound), font=o.h2, fill="#FFFFFF")
  632. o.disp.image(o.image, o.rotation)
  633. play_seq(o, message)
  634. # for s in o.soundSlots:
  635. # if s.notes[message[0]][message[1]][0] == 1:
  636. # o.soundSlots[_id].play()
  637. # _id += 1
  638. def draw_square(self):
  639. o = self.FSM.owner
  640. size = 32
  641. og_x = 110
  642. o_x = og_x
  643. o_y = 0
  644. _id = 0
  645. for n in o.soundSlots[o.eSound].notes[o.ePattern]:
  646. #print('n is ' ,n)
  647. if _id == o.eSound:
  648. o.draw.rectangle((o_x, o_y, o_x + size, o_y + size), outline=0, fill=o.color_b)
  649. else:
  650. o.draw.rectangle((o_x, o_y, o_x + size, o_y + size), outline=0, fill=o.dark_grey)
  651. o_x = o_x + size
  652. _id += 1
  653. if _id % 4 == 0:
  654. o_y += size
  655. o_x = og_x
  656. def Exit(self):
  657. self.FSM.owner.pub.unregister("beat", self)
  658. #====================================
  659. #====================================
  660. class SelectPattern(State):
  661. def __init__(self,FSM):
  662. super(SelectPattern, self).__init__(FSM)
  663. def Enter(self):
  664. self.FSM.stateLife = 1
  665. o = self.FSM.owner
  666. o.header_text = "Select Pattern"
  667. o.pub.register("beat", self)
  668. if o.keyState[16] > 0 or o.keyState[17] > 0:
  669. pass
  670. else:
  671. draw_header(o)
  672. self.draw_square()
  673. o.disp.image(o.image, o.rotation)
  674. super(SelectPattern, self).Enter()
  675. def Execute(self):
  676. o = self.FSM.owner
  677. menu1_actions(self, o)
  678. if o.keyState[16] == 1:
  679. draw_menu1(o)
  680. o.disp.image(o.image, o.rotation)
  681. elif o.keyState[16] == 4:
  682. draw_header(o)
  683. self.draw_square()
  684. o.disp.image(o.image, o.rotation)
  685. if o.keyState[16] > 0 or o.keyState[17] > 0:
  686. pass
  687. # if o.keyState[0] == 1:
  688. # self.FSM.ToTransition('toMain')
  689. else:
  690. _id = 0
  691. for k in o.keyState:
  692. if _id > 15:
  693. pass
  694. else:
  695. if k == 1:
  696. o.ePattern = _id
  697. o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
  698. o.draw.text((0, 0), "SelPat", font=o.h1, fill=o.color_a)
  699. o.draw.text((20, 60), str(o.ePattern), font=o.h2, fill=o.color_b)
  700. self.draw_square()
  701. o.disp.image(o.image, o.rotation)
  702. print('now editing sound ', _id)
  703. _id += 1
  704. def ReceiveMessage(self, message):
  705. _id = 0
  706. o = self.FSM.owner
  707. play_seq(o, message)
  708. # for s in o.soundSlots:
  709. # if s.notes[message[0]][message[1]][0] == 1:
  710. # o.soundSlots[_id].play()
  711. # _id += 1
  712. def draw_square(self):
  713. o = self.FSM.owner
  714. size = 22
  715. og_x = (o.width / 2) - (size * 2)
  716. o_x = og_x
  717. o_y = 127
  718. _id = 0
  719. for n in o.soundSlots[o.eSound].notes[o.ePattern]:
  720. if _id == o.ePattern:
  721. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.olive, fill=o.olive, width=1)
  722. else:
  723. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.blue, width=1)
  724. o_x = o_x + size
  725. _id += 1
  726. if _id % 4 == 0:
  727. o_y -= size
  728. o_x = og_x
  729. #////////////////////////////////////////////
  730. # for n in o.soundSlots[o.eSound].notes[o.ePattern]:
  731. # #print('n is ' ,n)
  732. # if _id == o.ePattern:
  733. # o.draw.rectangle((o_x, o_y, o_x + size, o_y + size), outline=0, fill=o.color_b)
  734. # else:
  735. # o.draw.rectangle((o_x, o_y, o_x + size, o_y + size), outline=0, fill=o.dark_grey)
  736. # o_x = o_x + size
  737. # _id += 1
  738. # if _id % 4 == 0:
  739. # o_y += size
  740. # o_x = og_x
  741. def Exit(self):
  742. self.FSM.owner.pub.unregister("beat", self)
  743. #====================================
  744. class EditSoundSequence(State):
  745. def __init__(self,FSM):
  746. super(EditSoundSequence, self).__init__(FSM)
  747. def Enter(self):
  748. self.FSM.stateLife = 1
  749. o = self.FSM.owner
  750. o.header_text = "Note Edit"
  751. o.pub.register("beat", self)
  752. if o.keyState[16] > 0 or o.keyState[17] > 0:
  753. pass
  754. else:
  755. draw_header(o)
  756. self.draw_square()
  757. o.disp.image(o.image, o.rotation)
  758. super(EditSoundSequence, self).Enter()
  759. def Execute(self):
  760. o = self.FSM.owner
  761. menu1_actions(self, o)
  762. if o.keyState[16] == 1:
  763. draw_menu1(o)
  764. o.disp.image(o.image, o.rotation)
  765. elif o.keyState[16] == 4:
  766. draw_header(o)
  767. self.draw_square()
  768. o.disp.image(o.image, o.rotation)
  769. if o.keyState[16] == 2:
  770. pass
  771. else:
  772. _id = 0
  773. for k in self.FSM.owner.keyState:
  774. if _id < 16 and k == 1:
  775. if o.soundSlots[o.eSound].notes[o.ePattern][_id][0] == 1:
  776. print('turn note off')
  777. o.soundSlots[o.eSound].notes[o.ePattern][_id][0] = 0
  778. else:
  779. print('turn note on')
  780. o.soundSlots[o.eSound].notes[o.ePattern][_id][0] = 1
  781. #self.FSM.owner.soundSlots[_id].play()
  782. _id += 1
  783. def draw_square(self):
  784. o = self.FSM.owner
  785. size = 22
  786. og_x = (o.width / 2) - (size * 2)
  787. o_x = og_x
  788. o_y = 127
  789. _id = 0
  790. for n in o.soundSlots[o.eSound].notes[o.ePattern]:
  791. if _id == o.playhead:
  792. if o.curPattern == o.ePattern:
  793. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.olive, fill=o.olive, width=1)
  794. else:
  795. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.olive, fill=o.pink, width=1)
  796. elif n[0] == 1:
  797. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.light_grey, width=1)
  798. else:
  799. o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.blue, width=1)
  800. o_x = o_x + size
  801. _id += 1
  802. if _id % 4 == 0:
  803. o_y -= size
  804. o_x = og_x
  805. def ReceiveMessage(self, message):
  806. _id = 0
  807. o = self.FSM.owner
  808. play_seq(o, message)
  809. if o.keyState[16] > 0 or o.keyState[17] > 0:
  810. pass
  811. else:
  812. draw_header(o)
  813. self.draw_square()
  814. o.disp.image(o.image, o.rotation)
  815. # for s in o.soundSlots:
  816. # if s.notes[message[0]][message[1]][0] == 1:
  817. # o.soundSlots[_id].play()
  818. # _id += 1
  819. def Exit(self):
  820. self.FSM.owner.pub.unregister("beat", self)
  821. #====================================
  822. class EditSong(State):
  823. def __init__(self,FSM):
  824. super(EditSong, self).__init__(FSM)
  825. def Enter(self):
  826. o = self.FSM.owner
  827. o.header_text = "Edit Song"
  828. o.pub.register("beat", self)
  829. if o.keyState[16] > 0 or o.keyState[17] > 0:
  830. pass
  831. else:
  832. draw_header(o)
  833. o.draw.text((20, 30), "Current Song", font=o.h2, fill=o.light_grey)
  834. o.draw.text((20, 50), str(o.song), font=o.h2, fill=o.light_grey)
  835. o.disp.image(o.image, o.rotation)
  836. self.new_song = []
  837. super(EditSong, self).Enter()
  838. def Execute(self):
  839. o = self.FSM.owner
  840. menu1_actions(self, o)
  841. if o.keyState[16] == 1:
  842. draw_menu1(o)
  843. o.disp.image(o.image, o.rotation)
  844. elif o.keyState[16] == 4:
  845. draw_header(o)
  846. if self.new_song == []:
  847. o.draw.text((20, 30), "Current Song", font=o.h2, fill=o.light_grey)
  848. o.draw.text((20, 50), str(o.song), font=o.h2, fill=o.light_grey)
  849. else:
  850. o.draw.text((20, 30), "New Song", font=o.h2, fill=o.pink)
  851. o.draw.text((20, 50), str(self.new_song), font=o.h2, fill=o.pink)
  852. #self.draw_square()
  853. o.disp.image(o.image, o.rotation)
  854. if o.keyState[16] > 0:
  855. pass
  856. else:
  857. _id = 0
  858. for k in self.FSM.owner.keyState:
  859. if k == 1 and _id < 16:
  860. self.new_song.append(_id)
  861. #o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
  862. draw_header(o)
  863. #o.draw.text((0, 0), "SonEdt", font=o.h1, fill=o.light_grey)
  864. o.draw.text((20, 30), "New Song", font=o.h2, fill=o.pink)
  865. o.draw.text((20, 50), str(self.new_song), font=o.h2, fill=o.pink)
  866. o.disp.image(o.image, o.rotation)
  867. _id += 1
  868. def ReceiveMessage(self, message):
  869. _id = 0
  870. o = self.FSM.owner
  871. play_seq(o, message)
  872. # for s in o.soundSlots:
  873. # if s.notes[message[0]][message[1]][0] == 1:
  874. # o.soundSlots[_id].play()
  875. # _id += 1
  876. def Exit(self):
  877. o = self.FSM.owner
  878. self.FSM.owner.pub.unregister("beat", self)
  879. if self.new_song != []:
  880. o.song = self.new_song
  881. o.songCycle = cycle(self.new_song)
  882. self.curPattern = next(o.songCycle)
  883. o.songStart = o.curPattern
  884. #====================================
  885. class File(State):
  886. def __init__(self,FSM):
  887. super(File, self).__init__(FSM)
  888. def Enter(self):
  889. self.FSM.stateLife = 1
  890. o = self.FSM.owner
  891. o.header_text = "File"
  892. o.pub.register("beat", self)
  893. if o.keyState[16] > 0 or o.keyState[17] > 0:
  894. pass
  895. else:
  896. draw_header(o)
  897. o.disp.image(o.image, o.rotation)
  898. super(File, self).Enter()
  899. def Execute(self):
  900. o = self.FSM.owner
  901. menu1_actions(self, o)
  902. if o.keyState[16] == 1:
  903. draw_menu1(o)
  904. o.disp.image(o.image, o.rotation)
  905. elif o.keyState[16] == 4:
  906. draw_header(o)
  907. #self.draw_square()
  908. o.disp.image(o.image, o.rotation)
  909. def ReceiveMessage(self, message):
  910. _id = 0
  911. o = self.FSM.owner
  912. play_seq(o, message)
  913. if o.keyState[16] > 0 or o.keyState[17] > 0:
  914. pass
  915. else:
  916. draw_header(o)
  917. #self.draw_square()
  918. o.disp.image(o.image, o.rotation)
  919. # for s in o.soundSlots:
  920. # if s.notes[message[0]][message[1]][0] == 1:
  921. # o.soundSlots[_id].play()
  922. # _id += 1
  923. def Exit(self):
  924. pass
  925. class Util(State):
  926. def __init__(self,FSM):
  927. super(Util, self).__init__(FSM)
  928. def Enter(self):
  929. o = self.FSM.owner
  930. o.header_text = "Utilities"
  931. o.pub.register("beat", self)
  932. if o.keyState[16] > 0 or o.keyState[17] > 0:
  933. pass
  934. else:
  935. draw_header(o)
  936. o.disp.image(o.image, o.rotation)
  937. super(Util, self).Enter()
  938. def Execute(self):
  939. o = self.FSM.owner
  940. menu1_actions(self, o)
  941. if o.keyState[16] == 1:
  942. draw_menu1(o)
  943. o.disp.image(o.image, o.rotation)
  944. elif o.keyState[16] == 4:
  945. draw_header(o)
  946. #self.draw_square()
  947. o.disp.image(o.image, o.rotation)
  948. #self.FSM.ToTransition('toLand')
  949. def ReceiveMessage(self, message):
  950. _id = 0
  951. o = self.FSM.owner
  952. play_seq(o, message)
  953. if o.keyState[16] > 0 or o.keyState[17] > 0:
  954. pass
  955. else:
  956. draw_header(o)
  957. #self.draw_square()
  958. o.disp.image(o.image, o.rotation)
  959. #play_seq(o, message)
  960. # for s in o.soundSlots:
  961. # if s.notes[message[0]][message[1]][0] == 1:
  962. # o.soundSlots[_id].play()
  963. #id += 1
  964. def Exit(self):
  965. pass
  966. class Ball(State):
  967. def __init__(self,FSM):
  968. super(Ball, self).__init__(FSM)
  969. def Enter(self):
  970. self.ball_size = 10
  971. self.ballx = self.ball_size
  972. self.bally = self.ball_size
  973. self.ball_speed = 15
  974. self.ball_x_dir = 1
  975. self.ball_y_dir = 1
  976. self.ball2x = self.ball_size + 180
  977. self.ball2y = self.ball_size + 70
  978. self.ball2_x_dir = -1
  979. self.ball2_y_dir = -1
  980. o = self.FSM.owner
  981. o.header_text = "Utilities"
  982. o.pub.register("beat", self)
  983. if o.keyState[16] > 0 or o.keyState[17] > 0:
  984. pass
  985. else:
  986. draw_header(o)
  987. o.disp.image(o.image, o.rotation)
  988. super(Ball, self).Enter()
  989. def Execute(self):
  990. o = self.FSM.owner
  991. menu1_actions(self, o)
  992. if o.keyState[16] == 1:
  993. draw_menu1(o)
  994. o.disp.image(o.image, o.rotation)
  995. else:
  996. now = datetime.now()
  997. current_time = time.strftime("%-I:%M %p")
  998. #current_time = now.strftime("%H:%M:%S")
  999. #print("Current Time =", current_time)
  1000. if self.ballx > (o.width - self.ball_size) or self.ballx < (0 + self.ball_size):
  1001. self.ball_x_dir *= -1
  1002. if (self.bally > o.height - self.ball_size) or (self.bally < 0 + self.ball_size):
  1003. self.ball_y_dir *= -1
  1004. self.ballx += self.ball_speed * self.ball_x_dir
  1005. self.bally += self.ball_speed * self.ball_y_dir
  1006. if self.ball2x > (o.width - self.ball_size) or self.ball2x < (0 + self.ball_size):
  1007. self.ball2_x_dir *= -1
  1008. if (self.ball2y > o.height - self.ball_size) or (self.ball2y < 0 + self.ball_size):
  1009. self.ball2_y_dir *= -1
  1010. self.ball2x += self.ball_speed * self.ball2_x_dir
  1011. self.ball2y += self.ball_speed * self.ball2_y_dir
  1012. o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
  1013. o.draw.ellipse((self.ballx - self.ball_size, self.bally - self.ball_size, self.ballx + self.ball_size, self.bally + self.ball_size), fill = o.light_grey, outline =o.light_grey)
  1014. o.draw.ellipse((self.ball2x - self.ball_size, self.ball2y - self.ball_size, self.ball2x + self.ball_size, self.ball2y + self.ball_size), fill = o.light_grey, outline =o.light_grey)
  1015. o.center_block(current_time, o.h3, [0,0,o.width,o.height], o.pink)
  1016. o.disp.image(o.image, o.rotation)
  1017. def ReceiveMessage(self, message):
  1018. o = self.FSM.owner
  1019. play_seq(o, message)
  1020. def Exit(self):
  1021. pass
  1022. #====================================
  1023. class Clock(State):
  1024. def __init__(self,FSM):
  1025. super(Clock, self).__init__(FSM)
  1026. def Enter(self):
  1027. o = self.FSM.owner
  1028. current_time = time.strftime("%-I:%M:%S")
  1029. #current_time = time.strftime("%-I:%M:%S %p")
  1030. #self.ball_sizex, self.ball_sizey = o.h3.getsize(current_time)
  1031. self.ball_sizex, self.ball_sizey = o.h3.getsize("18:88:88")
  1032. self.ball_sizex /= 2
  1033. self.ball_sizey /= 2
  1034. self.ballx = o.width / 2
  1035. self.bally = o.height / 2
  1036. self.ball_speed = 1
  1037. self.ball_x_dir = 1
  1038. self.ball_y_dir = 1
  1039. o.header_text = "Utilities"
  1040. o.pub.register("beat", self)
  1041. if o.keyState[16] > 0 or o.keyState[17] > 0:
  1042. pass
  1043. else:
  1044. pass
  1045. #draw_header(o)
  1046. #o.disp.image(o.image, o.rotation)
  1047. super(Clock, self).Enter()
  1048. def Execute(self):
  1049. o = self.FSM.owner
  1050. menu1_actions(self, o)
  1051. if o.keyState[16] == 1:
  1052. draw_menu1(o)
  1053. o.disp.image(o.image, o.rotation)
  1054. else:
  1055. #now = datetime.now()
  1056. current_time = time.strftime("%-I:%M:%S")
  1057. #current_time = time.strftime("%-I:%M:%S %p")
  1058. #current_time = now.strftime("%H:%M:%S")
  1059. #print("Current Time =", current_time)
  1060. #self.ball_sizex, self.ball_sizey = o.h3.getsize(current_time)
  1061. #self.ball_sizex /= 2
  1062. #self.ball_sizey /= 2
  1063. if self.ballx > (o.width - self.ball_sizex) or self.ballx < (0 + self.ball_sizex):
  1064. self.ball_x_dir *= -1
  1065. if (self.bally > o.height - self.ball_sizey) or (self.bally < 0 + self.ball_sizey):
  1066. self.ball_y_dir *= -1
  1067. self.ballx += self.ball_speed * self.ball_x_dir
  1068. self.bally += self.ball_speed * self.ball_y_dir
  1069. o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.black)
  1070. #o.draw.ellipse((self.ballx - self.ball_sizex, self.bally - self.ball_sizey, self.ballx + self.ball_sizex, self.bally + self.ball_sizey), fill = o.light_grey, outline =o.light_grey)
  1071. o.draw.text((self.ballx - self.ball_sizex, self.bally - self.ball_sizey), current_time, align='center', font=o.h3, fill=o.olive)
  1072. #o.center_block(current_time, o.h3, [0,0,o.width,o.height], o.pink)
  1073. o.disp.image(o.image, o.rotation)
  1074. def ReceiveMessage(self, message):
  1075. o = self.FSM.owner
  1076. play_seq(o, message)
  1077. def Exit(self):
  1078. pass
  1079. #====================================
  1080. #main
  1081. #select pattern
  1082. #pattern
  1083. #song