info@shuvit.org 2 years ago
parent
commit
f2669ef999
30 changed files with 3071 additions and 2372 deletions
  1. 3
    2
      config.txt
  2. 5
    1
      lib/FSM.py
  3. 22
    2342
      lib/StatesProg.py
  4. 45
    2
      lib/menus.py
  5. 1
    1
      lib/sAbout.py
  6. 118
    0
      lib/sBall.py
  7. 90
    0
      lib/sClock.py
  8. 52
    0
      lib/sDefender.py
  9. 121
    0
      lib/sEditSong.py
  10. 130
    0
      lib/sEditSoundSequence.py
  11. 221
    0
      lib/sEnterText.py
  12. 39
    0
      lib/sExit.py
  13. 141
    0
      lib/sFile.py
  14. 264
    0
      lib/sLoadSound.py
  15. 202
    0
      lib/sMain.py
  16. 222
    0
      lib/sNewDir.py
  17. 260
    0
      lib/sOpenSong.py
  18. 76
    0
      lib/sPing.py
  19. 43
    0
      lib/sReboot.py
  20. 167
    0
      lib/sSelTheme.py
  21. 224
    0
      lib/sSelectFolder.py
  22. 158
    0
      lib/sSelectPattern.py
  23. 92
    0
      lib/sSelectSound.py
  24. 46
    0
      lib/sShutdown.py
  25. 146
    0
      lib/sUtil.py
  26. 85
    0
      lib/sWifi.py
  27. 80
    0
      lib/utils.py
  28. 18
    19
      main.py
  29. 0
    5
      user/songs/Roland_TR-808.sng
  30. 0
    0
      user/songs/other/thing.nope

+ 3
- 2
config.txt View File

@@ -1,5 +1,6 @@
1
-default_song = Roland_TR-808
2
-theme = green2
1
+default_song = 20211217
2
+theme = default
3 3
 title = default
4 4
 bpm = 90
5 5
 volume = 10
6
+song_dir = /home/pi/zpc_ct/user/songs/drum_machines/

+ 5
- 1
lib/FSM.py View File

@@ -1,6 +1,8 @@
1 1
 
2 2
 import StatesProg
3 3
 import StatesDefender   
4
+
5
+
4 6
 #====================================
5 7
 class Transition(object):
6 8
     def __init__(self, toState):
@@ -91,7 +93,9 @@ class ProgFSM(Char):
91 93
         'Defender',
92 94
         'Update',
93 95
         'Calculator',
94
-        'About'
96
+        'About',
97
+        'SelectFolder',
98
+        'NewDir'
95 99
         ]
96 100
         
97 101
         for s in state_list:

+ 22
- 2342
lib/StatesProg.py View File

@@ -1,4 +1,3 @@
1
-
2 1
 import random
3 2
 import time
4 3
 import pygame
@@ -13,17 +12,37 @@ from datetime import date
13 12
 import ast
14 13
 import random
15 14
 from pathlib import Path
16
-import socket 
15
+#import socket 
17 16
 import FSM
18 17
 
19 18
 import utils as u
20 19
 import menus as m
21 20
 
22 21
 #states
22
+from sMain import Main
23
+from sSelectSound import SelectSound
24
+from sSelectPattern import SelectPattern
25
+from sEditSong import EditSong
26
+from sEditSoundSequence import EditSoundSequence
27
+from sFile import File
28
+from sUtil import Util
29
+from sBall import Ball
30
+from sExit import Exit
31
+from sReboot import Reboot
32
+from sClock import Clock
33
+from sShutdown import Shutdown
34
+from sSelTheme import SelTheme
35
+from sOpenSong import OpenSong
36
+from sEnterText import EnterText
37
+from sLoadSound import LoadSound
38
+from sPing import Ping
39
+from sWifi import Wifi
40
+from sDefender import Defender
23 41
 from sCalculator import Calculator
24 42
 from sAbout import About
25 43
 from sUpdate import Update
26
-
44
+from sSelectFolder import SelectFolder
45
+from sNewDir import NewDir
27 46
 #====================================     
28 47
 
29 48
 State = type("State", (object,), {})
@@ -163,182 +182,6 @@ class LoadDefault(State):
163 182
 
164 183
 #==================================== 
165 184
 			
166
-class Main(State):
167
-	def __init__(self,FSM):
168
-		super(Main, self).__init__(FSM)    
169
-		
170
-	def Enter(self):
171
-		print('hello main')
172
-		self.FSM.owner.pub.register("beat", self)
173
-		self.FSM.stateLife = 1
174
-		o = self.FSM.owner 
175
-		o.header_text = "Sound Select"
176
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
177
-			pass
178
-		else:
179
-			u.draw_header(o)
180
-			self.draw_square()
181
-
182
-			u.text_box1(o, "Vol", str(o.soundSlots[o.eSound].volume))
183
-			u.text_box2(o, "BPM", str(o.bpm))
184
-			u.text_box4(o, "Bank", str(o.note_bank))
185
-			u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
186
-			o.update_display(0)
187
-
188
-		#o.soundSlots[2].volume = 2
189
-		self.recording = True
190
-		self.record_queue = []
191
-		self.undo_queue = []
192
-		super(Main, self).Enter()        
193
-		
194
-	def Execute(self):
195
-		o = self.FSM.owner 
196
-		
197
-		# if o.keyState[16] == 2:
198
-		# 	o.button_repeater(0, [8,9,14,15])
199
-
200
-		#if o.keyState[17] == 2:
201
-		#	o.button_repeater(0, [4,5,6,7,8,9])
202
-
203
-		m.menu1_actions(self, o)
204
-		m.menu2_actions_sample(self, o)
205
-		#self.FSM.ToTransition('toClock')
206
-		if o.keyState[16] == 1:
207
-			m.draw_menu1(o)
208
-			o.update_display(0)
209
-		elif o.keyState[16] == 4:
210
-			u.draw_header(o)
211
-			self.draw_square()
212
-			#print('esound ', o.eSound)
213
-			#print('oss ', o.soundSlots[o.eSound].volume)
214
-			u.text_box1(o, "Vol", str(o.soundSlots[o.eSound].volume))
215
-			u.text_box2(o, "BPM", str(o.bpm))
216
-			u.text_box4(o, "Bank", str(o.note_bank))
217
-			u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
218
-			o.button_repeater(1, [])
219
-			o.update_display(0)
220
-
221
-		
222
-
223
-
224
-		if o.keyState[17] == 1:
225
-			m.draw_menu2_sample(o)
226
-			o.update_display(0)
227
-		elif o.keyState[17] == 4:
228
-			u.draw_header(o)
229
-			self.draw_square()
230
-			u.text_box1(o, "Vol", str(o.soundSlots[o.eSound].volume))
231
-			u.text_box2(o, "BPM", str(o.bpm))
232
-			u.text_box4(o, "Bank", str(o.note_bank))
233
-			u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
234
-			o.update_display(0)
235
-
236
-		_id = 0
237
-		for k in o.keyState:
238
-			if _id > 15:
239
-				pass
240
-			else:
241
-				if o.keyState[16] > 0 or o.keyState[17] > 0:
242
-					pass
243
-				else:
244
-					if k == 1:
245
-						note = _id + o.note_bank * 16
246
-						self.record_queue = pygame.time.get_ticks()
247
-						print('bpm is ', o.half_bpm, ' ', self.record_queue)
248
-
249
-						o.soundSlots[note].play(o.note_vol)
250
-						o.eSound = note
251
-						#print('now editing sound ', o.eSound) 
252
-						u.draw_header(o)
253
-						#u.text_box1(o, "SVol", str(o.soundSlots[o.eSound].volume))
254
-						u.text_box1(o, "SVol", str(o.slots[o.eSound].volume))
255
-						u.text_box2(o, "BPM", str(o.bpm))
256
-						u.text_box4(o, "Bank", str(o.note_bank))
257
-						#u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
258
-						u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
259
-						self.draw_square()
260
-						o.update_display(0)
261
-			_id += 1
262
-
263
-	def ReceiveMessage(self, message):
264
-		o = self.FSM.owner 
265
-		u.play_seq(o, message)
266
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
267
-			pass
268
-		else:
269
-			u.draw_header(o)            
270
-			self.draw_square()   
271
-			u.text_box1(o, "SVol", str(o.soundSlots[o.eSound].volume))
272
-			u.text_box2(o, "BPM", str(o.bpm))
273
-			u.text_box4(o, "Bank", str(o.note_bank))
274
-			u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))			         
275
-			o.update_display(0)
276
-		if self.record_queue != []:
277
-			cur_time = pygame.time.get_ticks()
278
-			note_pos = (cur_time - self.record_queue) - (o.half_bpm / 2)
279
-			#print(note_pos)
280
-			if o.odub == True:
281
-				if note_pos > (o.half_bpm):
282
-					_note = 0
283
-					if message[1] == 0:
284
-						_note = 15
285
-					else:
286
-						_note = message[1] - 1
287
-					
288
-					if o.soundSlots[o.eSound].notes[message[0]][_note][0] != 1:
289
-						o.soundSlots[o.eSound].notes[message[0]][_note][0] = 1
290
-						o.soundSlots[o.eSound].notes[message[0]][_note][1] = o.note_vol
291
-						o.undo_buf.append([o.eSound, message[0], _note])
292
-						print(o.undo_buf)
293
-
294
-				else:
295
-					if o.soundSlots[o.eSound].notes[message[0]][message[1]][0] != 1:
296
-						o.soundSlots[o.eSound].notes[message[0]][message[1]][0] = 1
297
-						o.soundSlots[o.eSound].notes[message[0]][message[1]][1] = o.note_vol
298
-						o.undo_buf.append([o.eSound, message[0], message[1]])
299
-						print(o.undo_buf)
300
-
301
-		self.record_queue = []
302
-
303
-	
304
-	def draw_square(self):
305
-		o = self.FSM.owner 
306
-		size = 22
307
-		og_x = (o.width / 2) - (size * 2)
308
-		o_x = og_x
309
-		o_y = 127
310
-		_id = o.note_bank * 16 
311
-	
312
-		while _id < ((o.note_bank * 16) + 16):
313
-			if _id == o.eSound:
314
-				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.light_grey, width=1)
315
-			elif o.notes_on[_id] == 1:
316
-				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.grey, width=1)
317
-			#elif _id > (len(o.soundSlots) - 1):
318
-			elif self.has_sample(o, _id) == False:
319
-				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.dark_grey, width=1)
320
-
321
-
322
-			else:
323
-				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.blue, width=1)
324
-			o_x = o_x + size
325
-			_id += 1
326
-			if _id % 4 == 0:
327
-				o_y -= size
328
-				o_x = og_x
329
-
330
-	def has_sample(self, o, slot):
331
-		if o.soundSlots[slot].file != None:
332
-			return True
333
-		else:
334
-			return False
335
-
336
-	def Exit(self):
337
-		self.FSM.owner.pub.unregister("beat", self)
338
-
339
-#==================================== 
340
-#==================================== 
341
-			
342 185
 class PadPlayer(State):
343 186
 	def __init__(self,FSM):
344 187
 		super(PadPlayer, self).__init__(FSM)    
@@ -411,2166 +254,3 @@ class SeqPlayer(State):
411 254
 		self.FSM.owner.pub.unregister("beat", self)
412 255
 
413 256
 #==================================== 
414
-#==================================== 
415
-			
416
-class SelectSound(State):
417
-	def __init__(self,FSM):
418
-		super(SelectSound, self).__init__(FSM)    
419
-		
420
-	def Enter(self):
421
-		self.FSM.stateLife = 1
422
-		o = self.FSM.owner 
423
-		o.header_text = "SelSou"
424
-		o.pub.register("beat", self)
425
-		u.draw_header(o)
426
-		self.draw_square()
427
-		o.update_display(0)
428
-		super(SelectSound, self).Enter()        
429
-		
430
-	def Execute(self):
431
-		o = self.FSM.owner 
432
-		if o.keyState[16] == 1:
433
-			m.draw_menu1(o)
434
-			o.update_display(0)
435
-		elif o.keyState[16] == 4:
436
-			u.draw_header(o)
437
-			self.draw_square()
438
-			o.update_display(0)
439
-
440
-		if o.keyState[16] == 2:
441
-			if o.keyState[0] == 1:
442
-				self.FSM.ToTransition('toMain')
443
-		else:
444
-			_id = 0
445
-			for k in o.keyState:
446
-				if _id > 15:
447
-					pass
448
-				else:
449
-					if k == 1:
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.light_blue)
453
-						o.draw.text((20, 60), str(o.eSound), font=o.h2, fill=o.light_grey)
454
-						self.draw_square()
455
-						o.update_display(0)
456
-						self.FSM.owner.soundSlots[_id].play()
457
-						#print('now editing sound ', _id)    
458
-				_id += 1        
459
-
460
-	def ReceiveMessage(self, message):
461
-		_id = 0
462
-		o = self.FSM.owner 
463
-		o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=(0, 0, 0))
464
-		o.draw.text((0, 0), "SelSou", font=o.h1, fill="#FFFFFF")
465
-		o.draw.text((0, 20), str(o.eSound), font=o.h2, fill="#FFFFFF")
466
-		o.update_display(0)
467
-		u.play_seq(o, message)
468
-
469
-	def draw_square(self):
470
-		o = self.FSM.owner 
471
-		size = 32
472
-		og_x = 110
473
-		o_x = og_x
474
-		o_y = 0
475
-		_id = 0
476
-	
477
-		for n in o.soundSlots[o.eSound].notes[o.ePattern]:
478
-			if _id == o.eSound:
479
-				o.draw.rectangle((o_x, o_y, o_x + size, o_y + size), outline=0, fill=o.light_grey)
480
-			else:
481
-				o.draw.rectangle((o_x, o_y, o_x + size, o_y + size), outline=0, fill=o.dark_grey)
482
-			o_x = o_x + size
483
-			_id += 1
484
-			if _id % 4 == 0:
485
-				o_y += size
486
-				o_x = og_x
487
-
488
-		
489
-	def Exit(self):
490
-		self.FSM.owner.pub.unregister("beat", self)
491
-
492
-#==================================== 
493
-			
494
-class SelectPattern(State):
495
-	def __init__(self,FSM):
496
-		super(SelectPattern, self).__init__(FSM)    
497
-		
498
-	def Enter(self):
499
-		self.FSM.stateLife = 1
500
-		o = self.FSM.owner 
501
-		o.header_text = "Select Pattern"
502
-		o.pub.register("beat", self)
503
-		self.cur_playing = 0
504
-		self.active_patterns = []
505
-		self.get_active_patterns(o)
506
-
507
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
508
-			pass
509
-		else:
510
-			u.draw_header(o)
511
-			self.draw_square()
512
-			u.text_box1(o, "Pat", str(o.ePattern))
513
-			u.text_box4(o, "Bank", str(o.pat_bank))
514
-			o.update_display(0)
515
-		
516
-		super(SelectPattern, self).Enter()        
517
-		
518
-	def Execute(self):
519
-		o = self.FSM.owner 
520
-		m.menu1_actions(self, o)
521
-		m.menu2_actions_pattern(self, o)
522
-		if o.keyState[16] == 1:
523
-			m.draw_menu1(o)
524
-			o.update_display(0)
525
-		elif o.keyState[16] == 4:
526
-			u.draw_header(o)
527
-			self.draw_square()
528
-			u.text_box1(o, "Pat", str(o.ePattern))
529
-			u.text_box4(o, "Bank", str(o.pat_bank))
530
-			o.update_display(0)
531
-
532
-		if o.keyState[17] == 1:
533
-			m.draw_menu2_pattern(o)
534
-			o.update_display(0)
535
-		elif o.keyState[17] == 4:
536
-			u.draw_header(o)
537
-			self.get_active_patterns(o)
538
-			self.draw_square()
539
-			u.text_box1(o, "Pat", str(o.ePattern))
540
-			u.text_box4(o, "Bank", str(o.pat_bank))
541
-			
542
-			o.update_display(0)
543
-
544
-
545
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
546
-			pass
547
-		else:
548
-			_id = 0
549
-			for k in o.keyState:
550
-				if _id > 15:
551
-					pass
552
-				else:
553
-					if k == 1:
554
-						o.ePattern = (o.pat_bank * 16) +_id 
555
-
556
-						u.draw_header(o)
557
-						self.draw_square()
558
-						
559
-						u.text_box1(o, "Pat", str(o.ePattern))
560
-						u.text_box4(o, "Bank", str(o.pat_bank))
561
-						o.update_display(0)
562
-						
563
-
564
-				_id += 1        
565
-
566
-	def ReceiveMessage(self, message):
567
-		o = self.FSM.owner
568
-		u.play_seq(o, message) 
569
-		
570
-		if message[0] != self.cur_playing:
571
-			#print('playing ', message)
572
-			self.cur_playing = message[0]
573
-			if o.keyState[16] > 0 or o.keyState[17] > 0:
574
-				pass
575
-			else:
576
-				u.draw_header(o)
577
-				self.draw_square()
578
-				u.text_box1(o, "Pat", str(o.ePattern))
579
-				u.text_box4(o, "Bank", str(o.pat_bank))
580
-				o.update_display(0)
581
-
582
-	def draw_square(self):
583
-		o = self.FSM.owner 
584
-		size = 22
585
-		og_x = (o.width / 2) - (size * 2)
586
-		o_x = og_x
587
-		o_y = 127
588
-		_id = 0
589
-		for n in o.soundSlots[o.eSound].notes[o.ePattern]:
590
-			if (_id + (o.pat_bank * 16)) == o.ePattern:
591
-				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.olive, width=1)
592
-			elif (_id + (o.pat_bank * 16)) == self.cur_playing:
593
-				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.light_grey, width=1)
594
-			elif self.active_patterns[_id] == 1:
595
-				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.blue, width=1)
596
-			else:
597
-				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.dark_grey, width=1)
598
-			o_x = o_x + size
599
-			_id += 1
600
-			if _id % 4 == 0:
601
-				o_y -= size
602
-				o_x = og_x          
603
-
604
-	def get_active_patterns(self, o):
605
-		#for n in o.soundSlots[o.eSound]
606
-		self.active_patterns = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
607
-		pat_iter = o.pat_bank * 16
608
-		_iter = 0
609
-		#print('is this note on? ', o.soundSlots[0].notes[0][0][0])
610
-
611
-
612
-		while pat_iter < ((o.pat_bank * 16) + 16):
613
-			
614
-			for s in o.soundSlots:
615
-				#print('checking soundSlot ', s.id)
616
-				pat_used = 0
617
-				for p in s.notes[pat_iter]:
618
-					if self.active_patterns[_iter] == 1:
619
-						break
620
-					if p[0] == 1:
621
-						#pat_used = 1
622
-						self.active_patterns[_iter] = 1
623
-						#print('found ', pat_iter, ' -- ', p[0])
624
-						break
625
-				#self.active_patterns.append(pat_used)
626
-			pat_iter += 1
627
-			_iter += 1
628
-	
629
-		#print('active patterns ', self.active_patterns)
630
-
631
-	def Exit(self):
632
-		self.FSM.owner.pub.unregister("beat", self)
633
-
634
-#==================================== 
635
-			
636
-class EditSoundSequence(State):
637
-	def __init__(self,FSM):
638
-		super(EditSoundSequence, self).__init__(FSM)    
639
-		
640
-	def Enter(self):
641
-		self.FSM.stateLife = 1
642
-		o = self.FSM.owner 
643
-		o.header_text = "Note Edit"
644
-		o.pub.register("beat", self)
645
-		self.curPattern = o.ePattern
646
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
647
-			pass
648
-		else:
649
-			u.draw_header(o)
650
-			self.draw_square()
651
-			u.text_box1(o, "Note Vol", str(o.note_vol))
652
-			u.text_box3(o, "Pat", str(self.curPattern))
653
-			o.update_display(0)
654
-		super(EditSoundSequence, self).Enter()        
655
-		
656
-	def Execute(self):
657
-		o = self.FSM.owner 
658
-		m.menu1_actions(self, o)
659
-		m.menu2_actions_note(self, o)
660
-		if o.keyState[16] == 1:
661
-			m.draw_menu1(o)
662
-			o.update_display(0)
663
-		elif o.keyState[16] == 4:
664
-			u.draw_header(o)
665
-			self.draw_square()
666
-			u.text_box1(o, "Note Vol", str(o.note_vol))
667
-			u.text_box3(o, "Pat", str(self.curPattern))
668
-			o.update_display(0)
669
-
670
-		if o.keyState[17] == 1:
671
-			m.draw_menu2_note(o)
672
-			o.update_display(0)
673
-		elif o.keyState[17] == 4:
674
-			u.draw_header(o)
675
-			self.draw_square()
676
-			u.text_box1(o, "Note Vol", str(o.note_vol))
677
-			u.text_box3(o, "Pat", str(self.curPattern))
678
-			o.update_display(0)
679
-
680
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
681
-			pass
682
-
683
-		else:
684
-			_id = 0
685
-			for k in self.FSM.owner.keyState:
686
-				if _id < 16 and k == 1:
687
-					if o.soundSlots[o.eSound].notes[self.curPattern][_id][0] == 1:
688
-						#print('turn note off')
689
-						o.soundSlots[o.eSound].notes[self.curPattern][_id][0] = 0
690
-						o.soundSlots[o.eSound].notes[self.curPattern][_id][1] = 0
691
-					else:
692
-						#print('turn note on')
693
-						o.soundSlots[o.eSound].notes[self.curPattern][_id][0] = 1
694
-						o.soundSlots[o.eSound].notes[self.curPattern][_id][1] = o.note_vol
695
-					u.draw_header(o)
696
-					self.draw_square()
697
-					u.text_box1(o, "Note Vol", str(o.note_vol))			
698
-					u.text_box3(o, "Pat", str(self.curPattern))
699
-					o.update_display(0)
700
-				_id += 1
701
-
702
-
703
-		
704
-	def draw_square(self):
705
-		o = self.FSM.owner 
706
-		size = 22
707
-		og_x = (o.width / 2) - (size * 2)
708
-		o_x = og_x
709
-		o_y = 127
710
-		_id = 0
711
-		for n in o.soundSlots[o.eSound].notes[self.curPattern]:
712
-			if _id == o.playhead and o.playing:
713
-				if o.curPattern == self.curPattern:
714
-					o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.olive, width=1)
715
-				else:
716
-					o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.pink, width=1)
717
-			elif n[0] == 1:
718
-				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.light_grey, width=1)
719
-			else:
720
-				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.blue, width=1)
721
-			o_x = o_x + size
722
-			_id += 1
723
-			if _id % 4 == 0:
724
-				o_y -= size
725
-				o_x = og_x
726
-
727
-	def ReceiveMessage(self, message):
728
-		_id = 0
729
-		o = self.FSM.owner 
730
-		u.play_seq(o, message)
731
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
732
-			pass
733
-		else:
734
-			u.draw_header(o)            
735
-			self.draw_square()  
736
-			u.text_box1(o, "Note Vol", str(o.note_vol))
737
-			u.text_box3(o, "Pat", str(self.curPattern))
738
-		if o.patternFollow:
739
-			self.curPattern = message[0]
740
-		else:
741
-			self.curPattern = o.ePattern
742
-		#print('message ', message)
743
-		o.update_display(0)
744
-		
745
-	def Exit(self):
746
-		self.FSM.owner.pub.unregister("beat", self)
747
-
748
-
749
-class EditSong(State):
750
-	def __init__(self,FSM):
751
-		super(EditSong, self).__init__(FSM)    
752
-		
753
-	def Enter(self):
754
-		o = self.FSM.owner 
755
-		o.header_text = "Edit Song"
756
-		o.pub.register("beat", self)
757
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
758
-			pass
759
-		else:
760
-			u.draw_header(o)
761
-			self.draw_main(o)
762
-			# o.draw.text((20, 30), "Current Song", font=o.h2, fill=o.light_grey)
763
-			# o.draw.text((20, 50), str(o.song), font=o.h2, fill=o.light_grey)
764
-			o.update_display(0)
765
-		self.new_song = []
766
-		super(EditSong, self).Enter()        
767
-		
768
-	def Execute(self):
769
-		o = self.FSM.owner 
770
-
771
-		m.menu1_actions(self, o)
772
-		m.menu2_actions_song(self, o)
773
-		if o.keyState[16] == 1:
774
-			m.draw_menu1(o)
775
-			o.update_display(0)
776
-		elif o.keyState[16] == 4:
777
-			u.draw_header(o)
778
-			self.draw_main(o)
779
-			# if self.new_song == []:
780
-			# 	o.draw.text((20, 30), "Current Song", font=o.h2, fill=o.light_grey)
781
-			# 	o.draw.text((20, 50), str(o.song), font=o.h2, fill=o.light_grey)
782
-			# else:
783
-			# 	o.draw.text((20, 30), "New Song", font=o.h2, fill=o.pink)
784
-			# 	o.draw.text((20, 50), str(self.new_song), font=o.h2, fill=o.pink)
785
-			o.update_display(0)
786
-
787
-		if o.keyState[17] == 1:
788
-			m.draw_menu2_song(o)
789
-			o.update_display(0)
790
-		elif o.keyState[17] == 4:
791
-			u.draw_header(o)
792
-			self.draw_main(o)
793
-			o.update_display(0)
794
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
795
-
796
-		#if o.keyState[16] > 0:
797
-			pass
798
-		else:
799
-			_id = 0
800
-			for k in self.FSM.owner.keyState:
801
-				if k == 1 and _id < 16:
802
-					self.new_song.append((_id + (o.pat_bank * 16)))
803
-					u.draw_header(o)
804
-					self.draw_main(o)
805
-					#o.draw.text((20, 30), "New Song", font=o.h2, fill=o.pink)
806
-					#o.draw.text((20, 50), str(self.new_song), font=o.h2, fill=o.pink)
807
-					o.update_display(0)
808
-				_id += 1        
809
-
810
-
811
-	def draw_main(self, o):
812
-		ypos = 35
813
-		ysize = 20
814
-		tmp_song = [8, 6, 7, 5, 3, 0, 9]
815
-		lines = u.breakup_song_text(o.song)
816
-		#lines = u.breakup_song_text(tmp_song)
817
-
818
-		if self.new_song != []:
819
-			#o.draw.text((20, 30), "New Song", font=o.h2, fill=o.pink)
820
-			lines = u.breakup_song_text(self.new_song)
821
-			o.center_block("New Song", o.h2, [0, ypos, o.width, ypos + ysize], o.pink)
822
-		else:
823
-			#o.draw.text((20, 30), "Current Song", font=o.h2, fill=o.light_grey)
824
-			o.center_block("Current Song", o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
825
-
826
-		ypos += ysize	
827
-		o.center_block(lines[0], o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
828
-		ypos += ysize
829
-		o.center_block(lines[1], o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
830
-		ypos += ysize
831
-		o.center_block(lines[2], o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
832
-		ypos += ysize
833
-		o.center_block(lines[3], o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
834
-
835
-	def ReceiveMessage(self, message):
836
-		_id = 0
837
-		o = self.FSM.owner 
838
-		u.play_seq(o, message)
839
-
840
-	def Exit(self):
841
-		o = self.FSM.owner 
842
-		self.FSM.owner.pub.unregister("beat", self)
843
-		if self.new_song != []:
844
-			o.song = self.new_song
845
-			o.songCycle = cycle(self.new_song)
846
-			self.curPattern = next(o.songCycle)
847
-			o.songStart = o.curPattern
848
-
849
-#==================================== 
850
-
851
-class File(State):
852
-	def __init__(self,FSM):
853
-		super(File, self).__init__(FSM)    
854
-		
855
-	def Enter(self):
856
-		self.FSM.stateLife = 1
857
-		o = self.FSM.owner 
858
-		o.header_text = "File"
859
-		o.pub.register("beat", self)
860
-		self.cur_el = 0
861
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
862
-			pass
863
-		else:
864
-			u.draw_header(o)
865
-			self.draw_footer(o)
866
-			self.draw_main(o)
867
-			o.update_display(0)
868
-		self.menu = ["Save", "Save As", "Open", "New"]
869
-		
870
-		super(File, self).Enter()        
871
-		
872
-	def Execute(self):
873
-		o = self.FSM.owner 
874
-		m.menu1_actions(self, o)
875
-		if o.keyState[16] == 1:
876
-			m.draw_menu1(o)
877
-			#self.draw_footer(o)
878
-			o.update_display(0)
879
-		elif o.keyState[16] == 4:
880
-			u.draw_header(o)
881
-			self.draw_footer(o)
882
-			self.draw_main(o)
883
-			o.update_display(0)
884
-
885
-		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
886
-			u.draw_header(o)
887
-			self.draw_footer(o)
888
-			self.draw_main(o)
889
-			o.update_display(0)	
890
-			print('draw butt')				
891
-
892
-
893
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
894
-			pass
895
-		else:
896
-			if o.keyState[0] == 1:
897
-				if self.cur_el > 0:
898
-					self.cur_el -= 1
899
-					print('cur el down is ', self.cur_el)
900
-			if o.keyState[1] == 1:
901
-				if self.cur_el < (len(self.menu) - 1):
902
-					self.cur_el += 1
903
-					print('cur el up is ', self.cur_el)
904
-			
905
-			if o.keyState[3] == 1:
906
-				m.file_command(self, o, self.menu[self.cur_el])
907
-				pass
908
-
909
-	def draw_footer(self, o):
910
-		_iter = 0
911
-		width = o.width / 4
912
-		xpos = 0
913
-		yposa = 135 - 25
914
-		yposb = 135
915
-		opts = ["Up", "Down", "Esc", "OK"]
916
-		while _iter < 4:
917
-			o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.blue)
918
-			
919
-			if o.keyState[_iter] == 1:
920
-				o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.light_grey)
921
-				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.blue)
922
-			else:
923
-				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
924
-			
925
-			xpos += width
926
-			_iter += 1
927
-
928
-
929
-	def draw_main(self, o):
930
-		al = []
931
-		ypos = 30
932
-		if self.cur_el == 0:
933
-			_iter = 0
934
-			while len(al) < 4:
935
-				al.append(self.menu[_iter])
936
-				_iter += 1
937
-		elif self.cur_el == 1:
938
-			al.append(self.menu[self.cur_el - 1])
939
-			al.append(self.menu[self.cur_el])
940
-			al.append(self.menu[self.cur_el + 1])
941
-			al.append(self.menu[self.cur_el + 2])
942
-		elif self.cur_el == (len(self.menu) - 2):
943
-			al.append(self.menu[self.cur_el - 2])
944
-			al.append(self.menu[self.cur_el - 1])
945
-			al.append(self.menu[self.cur_el])
946
-			al.append(self.menu[self.cur_el + 1])
947
-		elif self.cur_el == (len(self.menu) - 1):
948
-			al.append(self.menu[self.cur_el - 3])
949
-			al.append(self.menu[self.cur_el - 2])
950
-			al.append(self.menu[self.cur_el - 1])
951
-			al.append(self.menu[self.cur_el])
952
-		else:
953
-			al.append(self.menu[self.cur_el - 1])
954
-			al.append(self.menu[self.cur_el])
955
-			al.append(self.menu[self.cur_el + 1])
956
-			al.append(self.menu[self.cur_el + 2])
957
-		_iter = 0 
958
-		for i in al:
959
-			if i == self.menu[self.cur_el]:
960
-			#if _iter == self.cur_el:
961
-				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.light_grey)
962
-				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.blue)
963
-			else:
964
-				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.blue)
965
-				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.light_grey)
966
-			ypos += 20
967
-			_iter += 1
968
-
969
-	def ReceiveMessage(self, message):
970
-		o = self.FSM.owner 
971
-		u.play_seq(o, message)
972
-		
973
-	def Exit(self):
974
-		self.FSM.owner.pub.unregister("beat", self)
975
-
976
-class Util(State):
977
-	def __init__(self,FSM):
978
-		super(Util, self).__init__(FSM)    
979
-		
980
-	def Enter(self):
981
-		o = self.FSM.owner 
982
-		o.header_text = "Utilities"
983
-		o.pub.register("beat", self)
984
-		self.menu = ["Clock", "Balls", "Defender", "Calculator", "Exit", "Shutdown", "Reboot", "Theme", "Ping", "Wifi", "Update", "About"]
985
-		self.cur_el = 0
986
-
987
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
988
-			pass
989
-		else:
990
-			u.draw_header(o)
991
-			self.draw_footer(o)
992
-			self.draw_main(o)
993
-			o.update_display(0)
994
-
995
-		
996
-		super(Util, self).Enter()        
997
-		
998
-	def Execute(self):
999
-		o = self.FSM.owner 
1000
-		m.menu1_actions(self, o)
1001
-		if o.keyState[16] == 1:
1002
-			m.draw_menu1(o)
1003
-			o.update_display(0)
1004
-		elif o.keyState[16] == 4:
1005
-			u.draw_header(o)
1006
-			self.draw_footer(o)
1007
-			self.draw_main(o)
1008
-			o.update_display(0)
1009
-
1010
-		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
1011
-			u.draw_header(o)
1012
-			self.draw_footer(o)
1013
-			self.draw_main(o)
1014
-			o.update_display(0)	
1015
-			print('draw butt')				
1016
-
1017
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
1018
-			pass
1019
-		else:
1020
-			if o.keyState[0] == 1:
1021
-				if self.cur_el > 0:
1022
-					self.cur_el -= 1
1023
-					print('cur el down is ', self.cur_el)
1024
-			if o.keyState[1] == 1:
1025
-				if self.cur_el < (len(self.menu) - 1):
1026
-					self.cur_el += 1
1027
-					print('cur el up is ', self.cur_el)
1028
-			
1029
-			if o.keyState[3] == 1:
1030
-				m.util_command(self, o, self.menu[self.cur_el])
1031
-		
1032
-	def ReceiveMessage(self, message):
1033
-		_id = 0
1034
-		o = self.FSM.owner 
1035
-		u.play_seq(o, message)
1036
-		# if o.keyState[16] > 0 or o.keyState[17] > 0:
1037
-		# 	pass
1038
-		# else:
1039
-		# 	u.draw_header(o)           		
1040
-		# o.update_display(0)
1041
-
1042
-	def draw_main(self, o):
1043
-		al = []
1044
-		ypos = 30
1045
-		if self.cur_el == 0:
1046
-			_iter = 0
1047
-			while len(al) < 4:
1048
-				al.append(self.menu[_iter])
1049
-				_iter += 1
1050
-		elif self.cur_el == 1:
1051
-			al.append(self.menu[self.cur_el - 1])
1052
-			al.append(self.menu[self.cur_el])
1053
-			al.append(self.menu[self.cur_el + 1])
1054
-			al.append(self.menu[self.cur_el + 2])
1055
-		elif self.cur_el == (len(self.menu) - 2):
1056
-			al.append(self.menu[self.cur_el - 2])
1057
-			al.append(self.menu[self.cur_el - 1])
1058
-			al.append(self.menu[self.cur_el])
1059
-			al.append(self.menu[self.cur_el + 1])
1060
-		elif self.cur_el == (len(self.menu) - 1):
1061
-			al.append(self.menu[self.cur_el - 3])
1062
-			al.append(self.menu[self.cur_el - 2])
1063
-			al.append(self.menu[self.cur_el - 1])
1064
-			al.append(self.menu[self.cur_el])
1065
-		else:
1066
-			al.append(self.menu[self.cur_el - 1])
1067
-			al.append(self.menu[self.cur_el])
1068
-			al.append(self.menu[self.cur_el + 1])
1069
-			al.append(self.menu[self.cur_el + 2])
1070
-		_iter = 0 
1071
-		for i in al:
1072
-			if i == self.menu[self.cur_el]:
1073
-			#if _iter == self.cur_el:
1074
-				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.light_grey)
1075
-				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.blue)
1076
-			else:
1077
-				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.blue)
1078
-				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.light_grey)
1079
-			ypos += 20
1080
-			_iter += 1
1081
-
1082
-	def draw_footer(self, o):
1083
-		_iter = 0
1084
-		width = o.width / 4
1085
-		xpos = 0
1086
-		yposa = 135 - 25
1087
-		yposb = 135
1088
-		opts = ["Up", "Down", "Esc", "OK"]
1089
-		while _iter < 4:
1090
-			o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.blue)
1091
-			
1092
-			if o.keyState[_iter] == 1:
1093
-				o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.light_grey)
1094
-				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.blue)
1095
-			else:
1096
-				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
1097
-			
1098
-			xpos += width
1099
-			_iter += 1
1100
-
1101
-	def Exit(self):
1102
-		self.FSM.owner.pub.unregister("beat", self)        
1103
-
1104
-
1105
-
1106
-class Ball(State):
1107
-	def __init__(self,FSM):
1108
-		super(Ball, self).__init__(FSM)    
1109
-		
1110
-	def Enter(self):
1111
-		self.ball_size = 10
1112
-		self.ballx = self.ball_size
1113
-		self.bally = self.ball_size
1114
-		
1115
-		self.ball_speed = 8
1116
-		self.ball_x_dir = 1
1117
-		self.ball_y_dir = 1
1118
-		
1119
-		self.ball2x = self.ball_size + 180
1120
-		self.ball2y = self.ball_size + 70
1121
-	
1122
-		self.ball2_x_dir = -1
1123
-		self.ball2_y_dir = -1
1124
-
1125
-		self.xmult = 1.0
1126
-
1127
-		o = self.FSM.owner 
1128
-		o.header_text = "Balls"
1129
-		o.pub.register("beat", self)
1130
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
1131
-			pass
1132
-		else:
1133
-			u.draw_header(o)
1134
-			o.update_display(0)
1135
-		super(Ball, self).Enter()        
1136
-		
1137
-	def Execute(self):
1138
-		o = self.FSM.owner 
1139
-		m.menu1_actions(self, o)
1140
-		if o.keyState[16] == 1:
1141
-			m.draw_menu1(o)
1142
-			o.update_display(0)
1143
-		
1144
-
1145
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
1146
-			pass
1147
-		else:			
1148
-			now = datetime.now()
1149
-			current_time = time.strftime("%-I:%M %p")
1150
-
1151
-
1152
-			if self.ballx < (0 + self.ball_size):
1153
-				self.ball_x_dir = 1
1154
-			if self.ballx > (o.width - self.ball_size):
1155
-				self.ball_x_dir = -1
1156
-
1157
-			if self.bally < (0 + self.ball_size):
1158
-				self.ball_y_dir = 1
1159
-			if self.bally > (o.height - self.ball_size):
1160
-				self.ball_y_dir = -1
1161
-
1162
-			# if self.ballx > (o.width - self.ball_size) or self.ballx < (0 + self.ball_size):
1163
-			# 	self.ball_x_dir *= -1
1164
-			# if self.bally > (o.height - self.ball_size) or self.bally < (0 + self.ball_size):
1165
-			# 	self.ball_y_dir *= -1
1166
-
1167
-			self.ballx += self.ball_speed * self.ball_x_dir
1168
-			self.bally += self.ball_speed * self.ball_y_dir
1169
-
1170
-
1171
-			if self.ball2x < (0 + self.ball_size):
1172
-				self.ball2_x_dir = 1
1173
-				self.xmult = random.uniform(.6, 1.2)
1174
-			if self.ball2x > (o.width - self.ball_size):
1175
-				self.ball2_x_dir = -1
1176
-				self.xmult = random.uniform(.6, 1.2)
1177
-
1178
-			if self.ball2y < (0 + self.ball_size):
1179
-				self.ball2_y_dir = 1
1180
-			if self.ball2y > (o.height - self.ball_size):
1181
-				self.ball2_y_dir = -1			
1182
-
1183
-
1184
-			# if self.ball2x > (o.width - self.ball_size) or self.ball2x < (0 + self.ball_size):
1185
-			# 	self.ball2_x_dir *= -1
1186
-			# 	self.xmult = random.uniform(.8, 1.2)
1187
-			# if self.ball2y > (o.height - self.ball_size) or self.ball2y < (0 + self.ball_size):
1188
-			# 	self.ball2_y_dir *= -1
1189
-
1190
-			self.ball2x += (self.ball_speed * self.ball2_x_dir) * self.xmult
1191
-			self.ball2y += (self.ball_speed * self.ball2_y_dir) 
1192
-
1193
-			o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
1194
-			
1195
-			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)
1196
-			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)
1197
-			#o.center_block(current_time, o.h3, [0,0,o.width,o.height], o.pink)
1198
-			o.update_display(0)
1199
-		
1200
-	def ReceiveMessage(self, message):
1201
-		o = self.FSM.owner 
1202
-		u.play_seq(o, message)
1203
-		
1204
-	def Exit(self):
1205
-		self.FSM.owner.pub.unregister("beat", self)        
1206
-
1207
-#==================================== 
1208
-
1209
-
1210
-class Clock(State):
1211
-	def __init__(self,FSM):
1212
-		super(Clock, self).__init__(FSM)    
1213
-		
1214
-	def Enter(self):
1215
-		o = self.FSM.owner 
1216
-		current_time = time.strftime("%-I:%M:%S")
1217
-		self.ball_sizex, self.ball_sizey = o.h3.getsize("18:88:88")
1218
-		self.ball_sizex /= 2
1219
-		self.ball_sizey /= 2
1220
-		#self.ball_sizey += 10
1221
-		self.ballx = o.width / 2 
1222
-		self.bally = o.height / 2
1223
-		self.ball_speed = .5
1224
-		self.ball_x_dir = 1
1225
-		self.ball_y_dir = 1
1226
-		
1227
-		o.header_text = "Clock"
1228
-		o.pub.register("beat", self)
1229
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
1230
-			pass
1231
-		else:
1232
-			pass
1233
-		super(Clock, self).Enter()        
1234
-		
1235
-	def Execute(self):
1236
-		o = self.FSM.owner 
1237
-		m.menu1_actions(self, o)
1238
-
1239
-		if o.keyState[16] == 1:
1240
-			m.draw_menu1(o)
1241
-			o.update_display(0)
1242
-
1243
-
1244
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
1245
-			pass
1246
-		else:			
1247
-			current_time = time.strftime("%-I:%M:%S")
1248
-			s = int(time.strftime("%S"))
1249
-			if s % 2 == 0:
1250
-				current_time = time.strftime("%-I:%M.%S")
1251
-
1252
-			if self.ballx > (o.width - self.ball_sizex) or self.ballx < (0 + self.ball_sizex):
1253
-				self.ball_x_dir *= -1
1254
-			if (self.bally > o.height - self.ball_sizey - 20) or (self.bally < 0 + self.ball_sizey):
1255
-				self.ball_y_dir *= -1
1256
-
1257
-			x1 = self.ballx - self.ball_sizex
1258
-			x2 = self.ballx + self.ball_sizex
1259
-			y1 = self.bally - self.ball_sizey
1260
-			y2 = self.bally + self.ball_sizey
1261
-			self.ballx += self.ball_speed * self.ball_x_dir
1262
-			self.bally += self.ball_speed * self.ball_y_dir
1263
-			o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)			
1264
-			#o.draw.rectangle((x1, y1, x2, y2), outline=0, fill=o.dark_grey)			
1265
-
1266
-			#o.draw.text((self.ballx - self.ball_sizex, self.bally - self.ball_sizey), current_time, align='center', font=o.h3, fill=o.light_grey)
1267
-			o.center_block(current_time, o.h3, [x1, y1, x2, y2], o.light_grey)
1268
-			today = date.today()
1269
-			current_date = today.strftime('%A')
1270
-			current_date += ', ' + today.strftime("%b %d, %Y")
1271
-			#o.draw.text((self.ballx - self.ball_sizex, (self.bally + 45) - self.ball_sizey), current_date, align='center', font=o.h2, fill=o.light_grey)
1272
-			o.center_block(current_date, o.h2, [x1, y1 + 35, x2, y2 + 35], o.light_grey)
1273
-			o.update_display(0)
1274
-		
1275
-	def ReceiveMessage(self, message):
1276
-		o = self.FSM.owner 
1277
-		u.play_seq(o, message)
1278
-		
1279
-	def Exit(self):
1280
-		self.FSM.owner.pub.unregister("beat", self)        
1281
-
1282
-#==================================== 
1283
-
1284
-class Exit(State):
1285
-	def __init__(self,FSM):
1286
-		super(Exit, self).__init__(FSM)    
1287
-		
1288
-	def Enter(self):
1289
-		o = self.FSM.owner
1290
-		o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)			
1291
-		o.center_block("goodbye", o.h2, [0, 0, o.width,o.height], o.light_grey)
1292
-		o.update_display(0)
1293
-		pygame.quit()
1294
-		sys.exit()
1295
-		super(Exit, self).Enter()        
1296
-		
1297
-	def Execute(self):
1298
-		self.FSM.stateLife += 1
1299
-		
1300
-	def Exit(self):
1301
-		pass
1302
-
1303
-#==================================== 
1304
-
1305
-#==================================== 
1306
-
1307
-class Reboot(State):
1308
-	def __init__(self,FSM):
1309
-		super(Reboot, self).__init__(FSM)    
1310
-		
1311
-	def Enter(self):
1312
-		o = self.FSM.owner
1313
-		o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)			
1314
-		o.center_block("rebooting", o.h2, [0, 0, o.width,o.height], o.light_grey)
1315
-		o.update_display(0)
1316
-		command = 'bash -c "sleep 5; sudo shutdown -r now"&'
1317
-		os.system(command)
1318
-		pygame.quit()
1319
-		sys.exit()
1320
-		super(Reboot, self).Enter()        
1321
-		
1322
-	def Execute(self):
1323
-		pass
1324
-		#self.FSM.stateLife += 1
1325
-		#os.system('sudo shutdown -r now')
1326
-		
1327
-	def Exit(self):
1328
-		pass
1329
-
1330
-#==================================== 
1331
-
1332
-
1333
-#==================================== 
1334
-
1335
-class Shutdown(State):
1336
-	def __init__(self,FSM):
1337
-		super(Shutdown, self).__init__(FSM)    
1338
-		
1339
-	def Enter(self):
1340
-		o = self.FSM.owner
1341
-		o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)			
1342
-		o.center_block("shutting down", o.h2, [0, 0, o.width,o.height - 20], o.light_grey)
1343
-		o.center_block("(unplug in 20s)", o.h2, [0, 10, o.width,o.height+10], o.light_grey)
1344
-		o.center_block("thank you for playing", o.h2, [0, 30, o.width,o.height+30], o.light_grey)
1345
-		o.update_display(0)
1346
-		command = 'bash -c "sleep 5; sudo shutdown -h now"&'
1347
-		os.system(command)
1348
-		pygame.quit()
1349
-		sys.exit()
1350
-		super(Shutdown, self).Enter()        
1351
-		
1352
-	def Execute(self):
1353
-		pass
1354
-		#self.FSM.stateLife += 1
1355
-		#os.system('sudo shutdown -r now')
1356
-		
1357
-	def Exit(self):
1358
-		pass
1359
-
1360
-#==================================== 
1361
-class SelTheme(State):
1362
-	def __init__(self,FSM):
1363
-		super(SelTheme, self).__init__(FSM)    
1364
-		
1365
-	def Enter(self):
1366
-		o = self.FSM.owner
1367
-		o.header_text = "Select Theme"
1368
-		o.pub.register("beat", self)
1369
-		self.cur_el = 0
1370
-		self.globbed = glob.glob('/home/pi/zpc_ct/user/themes/*.thm')
1371
-		self.globbed.sort()
1372
-		self.names = [os.path.basename(x) for x in self.globbed]
1373
-		self.names = [os.path.splitext(x)[0] for x in self.names]
1374
-		if o.mconf['theme'] in self.names:
1375
-			_id = self.names.index(o.mconf['theme'])
1376
-			self.cur_el = _id
1377
-			#print('found theme ', _id)
1378
-		else:
1379
-			print('nope ', o.mconf['theme'], ' - ', self.globbed)
1380
-		#self.theme = ConfigObj("/home/pi/zpc_ct/themes/" + self.mconf['theme'])
1381
-		#print(os.path.splitext(x)[0])
1382
-		self.menu = self.names
1383
-
1384
-		#self.cur_el = 0
1385
-		print('theme menu is ', self.menu)
1386
-
1387
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
1388
-			pass
1389
-		else:
1390
-			u.draw_header(o)
1391
-			self.draw_main(o)			
1392
-			
1393
-			o.update_display(0)
1394
-		super(SelTheme, self).Enter()    
1395
-
1396
-	def Execute(self):
1397
-		o = self.FSM.owner 
1398
-		m.menu1_actions(self, o)
1399
-		if o.keyState[16] == 1:
1400
-			m.draw_menu1(o)
1401
-			o.update_display(0)
1402
-		elif o.keyState[16] == 4:
1403
-			u.draw_header(o)
1404
-			self.draw_footer(o)
1405
-			self.draw_main(o)
1406
-			o.update_display(0)
1407
-
1408
-		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
1409
-			u.draw_header(o)
1410
-			self.draw_footer(o)
1411
-			self.draw_main(o)
1412
-			o.update_display(0)	
1413
-			print('draw butt')				
1414
-
1415
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
1416
-			pass
1417
-		else:
1418
-			if o.keyState[0] == 1:
1419
-				if self.cur_el > 0:
1420
-					self.cur_el -= 1
1421
-					o.mconf['theme'] = self.menu[self.cur_el]					
1422
-					o.save_config()
1423
-					o.load_config()
1424
-					o.apply_theme()
1425
-					print('cur el down is ', self.cur_el)
1426
-
1427
-					#o.applyTheme
1428
-			if o.keyState[1] == 1:
1429
-				if self.cur_el < (len(self.menu) - 1):
1430
-					self.cur_el += 1
1431
-					o.mconf['theme'] = self.menu[self.cur_el]					
1432
-					o.save_config()
1433
-					o.load_config()
1434
-					o.apply_theme()
1435
-					print('cur el up is ', self.cur_el)
1436
-					print('loading theme ', self.menu[self.cur_el], '-- ', o.mconf['theme'])
1437
-			if o.keyState[3] == 1:
1438
-				m.util_command(self, o, self.menu[self.cur_el])
1439
-
1440
-	def draw_main(self, o):
1441
-		al = []
1442
-		ypos = 30
1443
-		if self.cur_el == 0:
1444
-			_iter = 0
1445
-			while len(al) < 4:
1446
-				al.append(self.menu[_iter])
1447
-				_iter += 1
1448
-		elif self.cur_el == 1:
1449
-			al.append(self.menu[self.cur_el - 1])
1450
-			al.append(self.menu[self.cur_el])
1451
-			al.append(self.menu[self.cur_el + 1])
1452
-			al.append(self.menu[self.cur_el + 2])
1453
-		elif self.cur_el == (len(self.menu) - 2):
1454
-			al.append(self.menu[self.cur_el - 2])
1455
-			al.append(self.menu[self.cur_el - 1])
1456
-			al.append(self.menu[self.cur_el])
1457
-			al.append(self.menu[self.cur_el + 1])
1458
-		elif self.cur_el == (len(self.menu) - 1):
1459
-			al.append(self.menu[self.cur_el - 3])
1460
-			al.append(self.menu[self.cur_el - 2])
1461
-			al.append(self.menu[self.cur_el - 1])
1462
-			al.append(self.menu[self.cur_el])
1463
-		else:
1464
-			al.append(self.menu[self.cur_el - 1])
1465
-			al.append(self.menu[self.cur_el])
1466
-			al.append(self.menu[self.cur_el + 1])
1467
-			al.append(self.menu[self.cur_el + 2])
1468
-		_iter = 0 
1469
-		for i in al:
1470
-			if i == self.menu[self.cur_el]:
1471
-			#if _iter == self.cur_el:
1472
-				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.light_grey)
1473
-				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.blue)
1474
-			else:
1475
-				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.blue)
1476
-				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.light_grey)
1477
-			ypos += 20
1478
-			_iter += 1		    
1479
-
1480
-	def draw_footer(self, o):
1481
-		_iter = 0
1482
-		width = o.width / 4
1483
-		xpos = 0
1484
-		yposa = 135 - 25
1485
-		yposb = 135
1486
-		opts = ["Up", "Down", "", ""]
1487
-		while _iter < 4:
1488
-			o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.blue)
1489
-			
1490
-			if o.keyState[_iter] == 1:
1491
-				o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.light_grey)
1492
-				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.blue)
1493
-			else:
1494
-				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
1495
-			
1496
-			xpos += width
1497
-			_iter += 1
1498
-		
1499
-
1500
-	def ReceiveMessage(self, message):
1501
-		o = self.FSM.owner 
1502
-		u.play_seq(o, message)
1503
-		
1504
-	def Exit(self):
1505
-		self.FSM.owner.pub.unregister("beat", self)
1506
-
1507
-#==================================== 
1508
-
1509
-class OpenSong(State):
1510
-	def __init__(self,FSM):
1511
-		super(OpenSong, self).__init__(FSM)    
1512
-		
1513
-	def Enter(self):
1514
-		o = self.FSM.owner
1515
-		o.header_text = "Open Song"
1516
-		o.pub.register("beat", self)
1517
-		self.cur_el = 0
1518
-		self.globbed = glob.glob('/home/pi/zpc_ct/user/songs/*.sng')
1519
-		self.globbed.sort()
1520
-		if '/home/pi/zpc_ct/user/songs/_blank.sng' in self.globbed:
1521
-			self.globbed.remove('/home/pi/zpc_ct/user/songs/_blank.sng')
1522
-		#del self.globbed[0]
1523
-		self.names = [os.path.basename(x) for x in self.globbed]
1524
-		self.names = [os.path.splitext(x)[0] for x in self.names]
1525
-		print('we got these songs ', self.names)
1526
-		print('in these paths ', self.globbed)
1527
-		if o.mconf['default_song'] in self.names:
1528
-			_id = self.names.index(o.mconf['default_song'])
1529
-			self.cur_el = _id
1530
-		else:
1531
-			print('nope ', o.mconf['default_song'], ' - ', self.globbed)
1532
-		self.menu = self.names
1533
-
1534
-		#self.cur_el = 0
1535
-		#print('theme menu is ', self.menu)
1536
-
1537
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
1538
-			pass
1539
-		else:
1540
-			u.draw_header(o)
1541
-			self.draw_main(o)			
1542
-			
1543
-			o.update_display(0)
1544
-		super(OpenSong, self).Enter()    
1545
-
1546
-	def Execute(self):
1547
-		o = self.FSM.owner 
1548
-		m.menu1_actions(self, o)
1549
-		if o.keyState[16] == 1:
1550
-			m.draw_menu1(o)
1551
-			o.update_display(0)
1552
-		elif o.keyState[16] == 4:
1553
-			u.draw_header(o)
1554
-			self.draw_footer(o)
1555
-			self.draw_main(o)
1556
-			o.update_display(0)
1557
-
1558
-		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
1559
-			u.draw_header(o)
1560
-			self.draw_footer(o)
1561
-			self.draw_main(o)
1562
-			o.update_display(0)	
1563
-			
1564
-
1565
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
1566
-			pass
1567
-		else:
1568
-			if o.keyState[0] == 1:
1569
-				if self.cur_el > 0:
1570
-					self.cur_el -= 1
1571
-					# o.mconf['theme'] = self.menu[self.cur_el]					
1572
-					# o.save_config()
1573
-					# o.load_config()
1574
-					# o.apply_theme()
1575
-					print('cur el down is ', self.cur_el)
1576
-
1577
-					#o.applyTheme
1578
-			if o.keyState[1] == 1:
1579
-				if self.cur_el < (len(self.menu) - 1):
1580
-					self.cur_el += 1
1581
-					# o.mconf['theme'] = self.menu[self.cur_el]					
1582
-					# o.save_config()
1583
-					# o.load_config()
1584
-					# o.apply_theme()
1585
-					print('cur el up is ', self.cur_el)
1586
-					#print('loading theme ', self.menu[self.cur_el], '-- ', o.mconf['theme'])
1587
-			if o.keyState[3] == 1:
1588
-				#open_command(self, o, self.menu[self.cur_el])
1589
-				o.mconf['default_song'] = self.menu[self.cur_el]
1590
-				o.save_config()
1591
-				o.load_song()
1592
-				#pass
1593
-
1594
-	def draw_main(self, o):
1595
-		al = []
1596
-		ypos = 30
1597
-		if self.cur_el == 0:
1598
-			_iter = 0
1599
-			while len(al) < 4:
1600
-				al.append(self.menu[_iter])
1601
-				_iter += 1
1602
-		elif self.cur_el == 1:
1603
-			al.append(self.menu[self.cur_el - 1])
1604
-			al.append(self.menu[self.cur_el])
1605
-			al.append(self.menu[self.cur_el + 1])
1606
-			al.append(self.menu[self.cur_el + 2])
1607
-		elif self.cur_el == (len(self.menu) - 2):
1608
-			al.append(self.menu[self.cur_el - 2])
1609
-			al.append(self.menu[self.cur_el - 1])
1610
-			al.append(self.menu[self.cur_el])
1611
-			al.append(self.menu[self.cur_el + 1])
1612
-		elif self.cur_el == (len(self.menu) - 1):
1613
-			al.append(self.menu[self.cur_el - 3])
1614
-			al.append(self.menu[self.cur_el - 2])
1615
-			al.append(self.menu[self.cur_el - 1])
1616
-			al.append(self.menu[self.cur_el])
1617
-		else:
1618
-			al.append(self.menu[self.cur_el - 1])
1619
-			al.append(self.menu[self.cur_el])
1620
-			al.append(self.menu[self.cur_el + 1])
1621
-			al.append(self.menu[self.cur_el + 2])
1622
-		_iter = 0 
1623
-		for i in al:
1624
-			if i == self.menu[self.cur_el]:
1625
-			#if _iter == self.cur_el:
1626
-				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.light_grey)
1627
-				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.blue)
1628
-			else:
1629
-				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.blue)
1630
-				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.light_grey)
1631
-			ypos += 20
1632
-			_iter += 1		    
1633
-
1634
-	def draw_footer(self, o):
1635
-		_iter = 0
1636
-		width = o.width / 4
1637
-		xpos = 0
1638
-		yposa = 135 - 25
1639
-		yposb = 135
1640
-		opts = ["Up", "Down", "Esc", "Open"]
1641
-		while _iter < 4:
1642
-			o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.blue)
1643
-			
1644
-			if o.keyState[_iter] == 1:
1645
-				o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.light_grey)
1646
-				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.blue)
1647
-			else:
1648
-				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
1649
-			
1650
-			xpos += width
1651
-			_iter += 1
1652
-		
1653
-
1654
-	def ReceiveMessage(self, message):
1655
-		o = self.FSM.owner 
1656
-		u.play_seq(o, message)
1657
-		
1658
-	def Exit(self):
1659
-		self.FSM.owner.pub.unregister("beat", self)
1660
-
1661
-
1662
-class EnterText(State):
1663
-	def __init__(self,FSM):
1664
-		super(EnterText, self).__init__(FSM)    
1665
-		
1666
-	def Enter(self):
1667
-		o = self.FSM.owner 
1668
-	
1669
-		m.menu1_actions(self, o)
1670
-		if o.keyState[16] == 1:
1671
-			m.draw_menu1(o)
1672
-			o.update_display(0)
1673
-		elif o.keyState[16] == 4:
1674
-			u.draw_header(o)
1675
-			self.draw_footer(o)
1676
-			self.draw_main(o)
1677
-			o.update_display(0)
1678
-		self.input_string = ""
1679
-		if o.sconf['title'] == 'blank':
1680
-
1681
-			self.input_string += str(datetime.today().strftime('%Y%m%d'))
1682
-		else:
1683
-
1684
-			self.input_string += o.sconf['title']
1685
-		#if 
1686
-		o.header_text = "EnterText"
1687
-		o.pub.register("beat", self)
1688
-		self.last_action = pygame.time.get_ticks()
1689
-		self.caps = False
1690
-		self.cur_but = 18
1691
-		self.cur_letter = ""
1692
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
1693
-			pass
1694
-		else:
1695
-			pass
1696
-
1697
-		self.skips = [7, 3, 11, 12, 13, 14, 15]
1698
-		
1699
-		self.lc_labels = [["p", "q", "r", "s"], ["t", "u", "v"], ["w", "x", "y", "z"], ["C", "A", "P", "S"], 
1700
-				["g", "h", "i"], ["j", "k", "l"], ["m", "n", "o"], ["D", "E", "L"],
1701
-				["_", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-"], ["a", "b", "c"], ["d", "e", "f"], ["O", "K"],
1702
-				[], [], [], []]
1703
-
1704
-		self.uc_labels = [["P", "Q", "R", "S"], ["T", "U", "V"], ["W", "X", "Y", "Z"], ["C", "A", "P", "S"], 
1705
-				["G", "H", "I"], ["J", "K", "L"], ["M", "N", "O"], ["D", "E", "L"],
1706
-				["_", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-"], ["A", "B", "C"], ["D", "E", "F"], ["O", "K"],
1707
-				[], [], [], []]
1708
-
1709
-		self.labels = self.lc_labels
1710
-
1711
-		#self.songCycle = cycle(self.song)
1712
-		#self.curPattern = next(self.songCycle)
1713
-
1714
-		self.cycles = []
1715
-		for l in self.labels:
1716
-			self.cycles.append(cycle(l))
1717
-
1718
-
1719
-
1720
-		self.draw(o)
1721
-		o.update_display(0)
1722
-		super(EnterText, self).Enter()        
1723
-		
1724
-	def Execute(self):
1725
-		o = self.FSM.owner 
1726
-
1727
-		y_size = o.height / 4
1728
-		if o.keyState[11] == 1:
1729
-			if self.input_string != 'blank':
1730
-				o.title = self.input_string
1731
-				#o.bpm = o.sconf['bpm']
1732
-				o.sconf['title'] = self.input_string
1733
-				
1734
-				print('fsm saving')
1735
-				o.save_song()
1736
-				self.FSM.ToTransition('toFile')	
1737
-
1738
-		m.menu1_actions(self, o)
1739
-		if o.keyState[16] == 1:
1740
-			m.draw_menu1(o)
1741
-			o.update_display(0)
1742
-		elif o.keyState[16] == 4:
1743
-			u.draw_header(o)
1744
-			self.draw(o)
1745
-			#self.draw_main(o)
1746
-			o.update_display(0)
1747
-
1748
-		if o.keyState[17] == 1:
1749
-			m.draw_menu_saveas(o)
1750
-			o.update_display(0)
1751
-		elif o.keyState[17] == 4:
1752
-			u.draw_header(o)
1753
-			self.draw(o)
1754
-			#self.draw_main(o)
1755
-			o.update_display(0)
1756
-
1757
-		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
1758
-			u.draw_header(o)
1759
-			self.draw(o)
1760
-			#self.draw_main(o)
1761
-			o.update_display(0)	
1762
-			
1763
-
1764
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
1765
-			pass
1766
-
1767
-		else:
1768
-			_iter = 0
1769
-			for k in o.keyState:
1770
-				if k == 1:
1771
-					cur_time = pygame.time.get_ticks()
1772
-					print(cur_time - self.last_action)
1773
-					
1774
-					#print('cur letter ', next(self.cycles[_iter]))
1775
-					if _iter not in self.skips:
1776
-						self.last_action = cur_time
1777
-						if _iter < len(self.cycles):
1778
-							self.cur_letter = next(self.cycles[_iter])
1779
-							self.cur_but = _iter
1780
-							self.draw(o)
1781
-							o.center_block(self.input_string + self.cur_letter, o.h2, [0, 0, o.width, y_size], o.light_grey)
1782
-
1783
-					if _iter == 7:
1784
-						
1785
-						self.input_string = self.input_string[:-1]
1786
-						#self.input_string = self.input_string.rstrip(self.input_string[-1])
1787
-						print('deleting')
1788
-						self.last_action = 100000000
1789
-						self.draw(o)
1790
-						o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
1791
-
1792
-					elif _iter == 3:
1793
-						print('caps')
1794
-						if self.caps:
1795
-							self.caps = False
1796
-							self.labels = self.lc_labels
1797
-
1798
-						else:
1799
-							self.caps = True
1800
-							self.labels = self.uc_labels
1801
-						self.draw(o)
1802
-						o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
1803
-						self.cycles = []
1804
-						for l in self.labels:
1805
-							self.cycles.append(cycle(l))
1806
-
1807
-					o.update_display(0)
1808
-				_iter += 1
1809
-
1810
-		cur_time = pygame.time.get_ticks()
1811
-		delay = cur_time - self.last_action
1812
-		if delay > 1000 and delay < 100000:
1813
-			self.input_string += self.cur_letter
1814
-			self.last_action = 100000000
1815
-			self.reset_cycles()
1816
-			self.draw(o)
1817
-
1818
-			o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
1819
-			o.update_display(0)
1820
-	
1821
-	def ReceiveMessage(self, message):
1822
-		o = self.FSM.owner 
1823
-		u.play_seq(o, message)
1824
-
1825
-	def draw(self, o):
1826
-		x_size = o.width / 4
1827
-		y_size = o.height / 4
1828
-		og_x = 0
1829
-		o_x = og_x
1830
-		o_y = o.height
1831
-		text_padding = 6
1832
-		
1833
-		_id = 0
1834
-		while _id < 16:
1835
-			lab = ""
1836
-			for i in self.labels[_id]:
1837
-				lab += i
1838
-
1839
-			if _id == 8:
1840
-				lab = "_12"
1841
-
1842
-			o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.blue)
1843
-			o.center_block(lab, o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
1844
-
1845
-			o_x = o_x + x_size
1846
-			_id += 1
1847
-			if _id % 4 == 0:
1848
-				o_y -= y_size
1849
-				o_x = og_x
1850
-		o.draw.rectangle((0, 0, o.width, y_size), outline=0, fill=o.blue)
1851
-		
1852
-	def reset_cycles(self):
1853
-		self.cycles = []
1854
-		for l in self.labels:
1855
-			self.cycles.append(cycle(l))
1856
-
1857
-	def Exit(self):
1858
-		self.FSM.owner.pub.unregister("beat", self)        
1859
-
1860
-#==================================== 
1861
-
1862
-class LoadSound(State):
1863
-	def __init__(self,FSM):
1864
-		super(LoadSound, self).__init__(FSM)    
1865
-		
1866
-	def Enter(self):
1867
-		o = self.FSM.owner
1868
-		o.header_text = "Load Sound"
1869
-		o.pub.register("beat", self)
1870
-		self.cur_el = 0
1871
-		
1872
-		self.press_ticks_up = None
1873
-		self.press_ticks_down = None
1874
-
1875
-		self.menu = []
1876
-
1877
-		self.menu.append("..")
1878
-		self.menu += self.get_file_list(o)
1879
-		if o.last_load_sound_id != None and o.last_load_sound_id <= len(self.menu):
1880
-			self.cur_el = o.last_load_sound_id
1881
-			print('setting cur_el ', self.cur_el)
1882
-		self.last_preview = None
1883
-
1884
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
1885
-			pass
1886
-		else:
1887
-			u.draw_header(o)
1888
-			self.draw_main(o)			
1889
-			
1890
-			o.update_display(0)
1891
-		super(LoadSound, self).Enter()    
1892
-
1893
-	def Execute(self):
1894
-		o = self.FSM.owner 
1895
-		m.menu1_actions(self, o)
1896
-		if o.keyState[16] == 1:
1897
-			m.draw_menu1(o)
1898
-			o.update_display(0)
1899
-		elif o.keyState[16] == 4:
1900
-			u.draw_header(o)
1901
-			self.draw_footer(o)
1902
-			self.draw_main(o)
1903
-			o.update_display(0)
1904
-
1905
-		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
1906
-			u.draw_header(o)
1907
-			self.draw_footer(o)
1908
-			self.draw_main(o)
1909
-			o.update_display(0)	
1910
-			#print('draw butt')				
1911
-
1912
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
1913
-			pass
1914
-		else:
1915
-
1916
-			since_up = 0		
1917
-			if o.keyState[0] == 2:
1918
-				if self.press_ticks_up == None:
1919
-					self.press_ticks_up = pygame.time.get_ticks()
1920
-				since_up = pygame.time.get_ticks() - self.press_ticks_up
1921
-			else:
1922
-				self.press_ticks_up = None
1923
-
1924
-				self.press_ticks_up = pygame.time.get_ticks()
1925
-
1926
-
1927
-			if o.keyState[0] == 1 or since_up > 250:
1928
-				if self.cur_el > 0:
1929
-					self.cur_el -= 1
1930
-					self.draw_main(o)
1931
-					o.update_display(0)	
1932
-					self.press_ticks_up = pygame.time.get_ticks()
1933
-			
1934
-					
1935
-
1936
-			since_down = 0		
1937
-			if o.keyState[1] == 2:
1938
-				if self.press_ticks_down == None:
1939
-					self.press_ticks_down = pygame.time.get_ticks()
1940
-				since_down = pygame.time.get_ticks() - self.press_ticks_down
1941
-			else:
1942
-				self.press_ticks_down = None
1943
-
1944
-				self.press_ticks_down = pygame.time.get_ticks()
1945
-
1946
-
1947
-			if o.keyState[1] == 1 or since_down > 250:
1948
-				if self.cur_el < (len(self.menu) - 1):
1949
-					self.cur_el += 1
1950
-					self.draw_main(o)
1951
-					o.update_display(0)	
1952
-					self.press_ticks_down = pygame.time.get_ticks()
1953
-			
1954
-			
1955
-
1956
-
1957
-			if o.keyState[2] == 1:
1958
-				if self.is_wav():
1959
-					if self.last_preview == self.menu[self.cur_el]:
1960
-						pass
1961
-					else:
1962
-						snd = pygame.mixer.Sound(o.load_song_dir + self.menu[self.cur_el])
1963
-						pygame.mixer.Sound.play(snd) 
1964
-						#o.last_load_sound_id = self.cur_el
1965
-
1966
-
1967
-			if o.keyState[3] == 1:
1968
-				if self.menu[self.cur_el] == '..':
1969
-					print('directory up')
1970
-					o.last_load_sound_id = None
1971
-					if o.load_song_dir == '/home/pi/zpc_ct/user/sounds/':
1972
-						print('root dir - cant go up')
1973
-					else:
1974
-						o.load_song_dir = os.path.dirname(os.path.dirname(o.load_song_dir))
1975
-						o.load_song_dir += '/'
1976
-						print('new up dir is ', o.load_song_dir)
1977
-						self.menu = []
1978
-						self.menu.append("..")
1979
-						self.menu += self.get_file_list(o)
1980
-
1981
-						self.cur_el = 0
1982
-
1983
-				elif os.path.isdir(o.load_song_dir + self.menu[self.cur_el]):
1984
-					print('this is a directory ', o.load_song_dir + self.menu[self.cur_el])
1985
-					o.load_song_dir = o.load_song_dir + self.menu[self.cur_el] + '/'
1986
-					self.menu = []
1987
-					self.menu.append("..")
1988
-					self.menu += self.get_file_list(o)
1989
-					self.cur_el = 0
1990
-
1991
-				else:
1992
-					print('this is not a directory ', o.load_song_dir + self.menu[self.cur_el])
1993
-					o.soundSlots[o.eSound].file = o.load_song_dir + self.menu[self.cur_el]
1994
-					o.soundSlots[o.eSound].volume = 16
1995
-					o.soundSlots[o.eSound].pitch = 0
1996
-					o.soundSlots[o.eSound].create_sound()
1997
-					o.soundSlots[o.eSound].set_pitch()
1998
-					o.last_load_sound_id = self.cur_el
1999
-					self.FSM.ToTransition('toMain')
2000
-
2001
-	def get_file_list(self, o):
2002
-		#os.path.isdir(o.load_song_dir + self.menu[self.cur_el])
2003
-		dirs = os.listdir(o.load_song_dir)
2004
-		dirs.sort()
2005
-		for i in dirs:
2006
-			if os.path.isdir(o.load_song_dir + i):
2007
-				i += "/asdfasdfasf"
2008
-				print(i, ' is a directory')
2009
-			else:
2010
-				print(i, ' is not a directory')
2011
-		print(dirs)
2012
-		return dirs
2013
-
2014
-	def draw_main(self, o):
2015
-		al = []
2016
-		ypos = 30
2017
-		#print(self.menu)
2018
-		if self.cur_el == 0:
2019
-			_iter = 0
2020
-			while len(al) < 4:
2021
-				if _iter < len(self.menu):
2022
-					#print('appending to al', _iter, ' ', len(self.menu))
2023
-					al.append(self.menu[_iter])
2024
-				else:
2025
-					break
2026
-				_iter += 1
2027
-		elif self.cur_el == 1:
2028
-			al.append(self.menu[self.cur_el - 1])
2029
-			al.append(self.menu[self.cur_el])
2030
-			if (self.cur_el + 1) < len(self.menu):
2031
-				al.append(self.menu[self.cur_el + 1])
2032
-			if (self.cur_el + 2) < len(self.menu):
2033
-				al.append(self.menu[self.cur_el + 2])
2034
-		elif self.cur_el == (len(self.menu) - 2):
2035
-			al.append(self.menu[self.cur_el - 2])
2036
-			al.append(self.menu[self.cur_el - 1])
2037
-			al.append(self.menu[self.cur_el])
2038
-			al.append(self.menu[self.cur_el + 1])
2039
-		elif self.cur_el == (len(self.menu) - 1):
2040
-			al.append(self.menu[self.cur_el - 3])
2041
-			al.append(self.menu[self.cur_el - 2])
2042
-			al.append(self.menu[self.cur_el - 1])
2043
-			al.append(self.menu[self.cur_el])
2044
-		else:
2045
-			al.append(self.menu[self.cur_el - 1])
2046
-			al.append(self.menu[self.cur_el])
2047
-			al.append(self.menu[self.cur_el + 1])
2048
-			al.append(self.menu[self.cur_el + 2])
2049
-		_iter = 0 
2050
-		#print(al)
2051
-		for i in al:
2052
-			# if os.path.isdir(o.load_song_dir + i):
2053
-			# 	i += "/"
2054
-			# 	print(i, ' is a directory')
2055
-			# else:
2056
-			# 	print(i, ' is not a directory')
2057
-
2058
-			if i == self.menu[self.cur_el]:
2059
-			#if _iter == self.cur_el:
2060
-				if os.path.isdir(o.load_song_dir + i):
2061
-					i += "/"
2062
-				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.light_grey)
2063
-				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.blue)
2064
-			else:
2065
-				if os.path.isdir(o.load_song_dir + i):
2066
-					i += "/"
2067
-				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.blue)
2068
-				#i += '/2342'
2069
-				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.light_grey)
2070
-			ypos += 20
2071
-			_iter += 1		    
2072
-
2073
-	def draw_footer(self, o):
2074
-		_iter = 0
2075
-		width = o.width / 4
2076
-		xpos = 0
2077
-		yposa = 135 - 25
2078
-		yposb = 135
2079
-		opts = ["Up", "Down", "Play", "Open"]
2080
-		while _iter < 4:
2081
-			o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.blue)
2082
-			
2083
-			if o.keyState[_iter] == 1:
2084
-				o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.light_grey)
2085
-				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.blue)
2086
-			else:
2087
-				if _iter == 2:
2088
-					if self.is_wav():
2089
-						o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
2090
-					else:
2091
-						o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.dark_grey)	
2092
-				else:
2093
-					o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)	
2094
-			
2095
-			xpos += width
2096
-			_iter += 1
2097
-		
2098
-	def is_wav(self):
2099
-		if len(self.menu[self.cur_el]) > 3 and (self.menu[self.cur_el][-1] == 'V' or self.menu[self.cur_el][-1] == 'v') and (self.menu[self.cur_el][-2] == 'A' or self.menu[self.cur_el][-2] == 'a') and (self.menu[self.cur_el][-3] == 'W' or self.menu[self.cur_el][-3] == 'w'):
2100
-			return True
2101
-		else:
2102
-			return False
2103
-
2104
-	def ReceiveMessage(self, message):
2105
-		o = self.FSM.owner 
2106
-		u.play_seq(o, message)
2107
-		
2108
-	def Exit(self):
2109
-		self.FSM.owner.pub.unregister("beat", self)
2110
-
2111
-#==================================== 
2112
-
2113
-class Ping(State):
2114
-	def __init__(self,FSM):
2115
-		super(Ping, self).__init__(FSM)    
2116
-		
2117
-	def Enter(self):
2118
-		o = self.FSM.owner
2119
-		
2120
-		o.header_text = "Ping"
2121
-		o.pub.register("beat", self)
2122
-
2123
-		#o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)			
2124
-		#o.center_block("ping", o.h2, [0, 0, o.width,o.height], o.light_grey)
2125
-		#o.update_display(0)
2126
-
2127
-		
2128
-		
2129
-
2130
-		self.pinging = self.check_ping()
2131
-
2132
-		self.draw_main(o)
2133
-
2134
-		u.draw_header(o)
2135
-		o.update_display(0)
2136
-		super(Ping, self).Enter()        
2137
-		
2138
-	def Execute(self):
2139
-		o = self.FSM.owner 
2140
-		m.menu1_actions(self, o)
2141
-		if o.keyState[16] == 1:
2142
-			m.draw_menu1(o)
2143
-			o.update_display(0)
2144
-		elif o.keyState[16] == 4:
2145
-			u.draw_header(o)
2146
-			#self.draw_footer(o)
2147
-			self.draw_main(o)
2148
-			o.update_display(0)
2149
-
2150
-		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
2151
-			u.draw_header(o)
2152
-			#self.draw_footer(o)
2153
-			self.draw_main(o)
2154
-			o.update_display(0)	
2155
-			
2156
-		
2157
-	def draw_main(self, o):
2158
-		o.center_block(self.pinging, o.h2, [0, 0, o.width, o.height], o.light_grey)
2159
-
2160
-	def check_ping(self):
2161
-		hostname = "8.8.8.8"
2162
-		response = os.system("ping -c 1 " + hostname)
2163
-		# and then check the response...
2164
-		if response == 0:
2165
-			pingstatus = "Network Active "
2166
-		else:
2167
-			pingstatus = "Network Error "
2168
-
2169
-		return pingstatus
2170
-
2171
-	def ReceiveMessage(self, message):
2172
-		o = self.FSM.owner 
2173
-		u.play_seq(o, message)
2174
-
2175
-	def Exit(self):
2176
-		self.FSM.owner.pub.unregister("beat", self)
2177
-
2178
-#==================================== 
2179
-
2180
-
2181
-class Wifi(State):
2182
-	def __init__(self,FSM):
2183
-		super(Wifi, self).__init__(FSM)    
2184
-		
2185
-	def Enter(self):
2186
-		o = self.FSM.owner
2187
-		
2188
-		o.header_text = "Wifi"
2189
-		o.pub.register("beat", self)
2190
-		
2191
-		self.ipad = self.extract_ip()
2192
-		self.ssid = os.popen("sudo iwgetid -r").read()
2193
-		o.center_block(self.ipad, o.h2, [0, 0, o.width,o.height], o.light_grey)
2194
-
2195
-		u.draw_header(o)
2196
-		self.draw_main(o)
2197
-		o.update_display(0)
2198
-		super(Wifi, self).Enter()        
2199
-		
2200
-	def Execute(self):
2201
-		o = self.FSM.owner 
2202
-		m.menu1_actions(self, o)
2203
-		if o.keyState[16] == 1:
2204
-			m.draw_menu1(o)
2205
-			o.update_display(0)
2206
-		elif o.keyState[16] == 4:
2207
-			u.draw_header(o)
2208
-			#self.draw_footer(o)
2209
-			self.draw_main(o)
2210
-			o.update_display(0)
2211
-
2212
-		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
2213
-			u.draw_header(o)
2214
-			#self.draw_footer(o)
2215
-			self.draw_main(o)
2216
-			o.update_display(0)	
2217
-			
2218
-		
2219
-	def draw_main(self, o):
2220
-		o.center_block(self.ipad, o.h2, [0, 0, o.width, o.height], o.light_grey)
2221
-		o.center_block(self.ssid, o.h2, [0, 40, o.width, o.height+40], o.light_grey)
2222
-
2223
-
2224
-	def extract_ip(self):
2225
-		st = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
2226
-		try:       
2227
-			#st.connect(('10.255.255.255', 1))
2228
-			st.connect(("8.8.8.8", 80))
2229
-			IP = st.getsockname()[0]
2230
-		except Exception:
2231
-			IP = '127.0.0.1'
2232
-		finally:
2233
-			st.close()
2234
-		return IP
2235
-	#print(extract_ip())		
2236
-
2237
-	def ReceiveMessage(self, message):
2238
-		o = self.FSM.owner 
2239
-		u.play_seq(o, message)
2240
-
2241
-	def Exit(self):
2242
-		self.FSM.owner.pub.unregister("beat", self)
2243
-
2244
-#==================================== 
2245
-
2246
-
2247
-
2248
-class Defender(State):
2249
-	def __init__(self,FSM):
2250
-		super(Defender, self).__init__(FSM)    
2251
-		
2252
-	def Enter(self):
2253
-		o = self.FSM.owner 
2254
-		
2255
-		self.gameFSM = FSM.DefenderFSM(o)
2256
-
2257
-		super(Defender, self).Enter()        
2258
-		
2259
-	def Execute(self):
2260
-		o = self.FSM.owner 
2261
-		m.menu1_actions(self, o)
2262
-		if o.keyState[16] == 1:
2263
-			m.draw_menu1(o)
2264
-			o.update_display(0)
2265
-		elif o.keyState[16] == 4:
2266
-			#u.draw_header(o)
2267
-			#self.draw_footer(o)
2268
-			#self.draw_main(o)
2269
-			#o.update_display(0)		
2270
-			pass
2271
-
2272
-		if o.keyState[16] > 0 or o.keyState[17] > 0:
2273
-
2274
-		#if o.keyState[16] > 0:
2275
-			pass
2276
-		else:
2277
-			self.gameFSM.Execute()
2278
-		
2279
-	def Exit(self):
2280
-		pass
2281
-
2282
-#==================================== 
2283
-#==================================== 
2284
-
2285
-
2286
-
2287
-# class Update(State):
2288
-# 	def __init__(self,FSM):
2289
-# 		super(Update, self).__init__(FSM)    
2290
-		
2291
-# 	def Enter(self):
2292
-		
2293
-# 		o = self.FSM.owner 
2294
-# 		o.header_text = "Update"
2295
-# 		o.pub.register("beat", self)
2296
-# 		g = git.cmd.Git("/home/pi/zpc_ct/")
2297
-# 		self.msg = g.pull()
2298
-# 		if o.keyState[16] > 0 or o.keyState[17] > 0:
2299
-# 			pass
2300
-# 		else:
2301
-# 			u.draw_header(o)
2302
-# 			o.update_display(0)
2303
-# 		super(Update, self).Enter()        
2304
-		
2305
-# 	def Execute(self):
2306
-# 		o = self.FSM.owner 
2307
-# 		m.menu1_actions(self, o)
2308
-# 		if o.keyState[16] == 1:
2309
-# 			m.draw_menu1(o)
2310
-# 			o.update_display(0)
2311
-# 		elif o.keyState[16] == 4:
2312
-# 			u.draw_header(o)
2313
-# 			#self.draw_footer(o)
2314
-# 			self.draw_main(o)
2315
-# 			o.update_display(0)
2316
-
2317
-# 		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
2318
-# 			u.draw_header(o)
2319
-# 			#self.draw_footer(o)
2320
-# 			self.draw_main(o)
2321
-# 			o.update_display(0)	
2322
-
2323
-# 		if o.keyState[16] > 0 or o.keyState[17] > 0:
2324
-# 			pass
2325
-# 		else:			
2326
-# 			pass
2327
-# 			#o.update_display(0)
2328
-	
2329
-# 	def draw_main(self, o):
2330
-# 		#o.center_text(self.msg, o.h1, o.width, 25, o.light_grey)
2331
-# 		o.center_block(self.msg, o.h2, [0, 0, o.width, o.height], o.light_grey)
2332
-
2333
-# 	def ReceiveMessage(self, message):
2334
-# 		o = self.FSM.owner 
2335
-# 		u.play_seq(o, message)
2336
-		
2337
-# 	def Exit(self):
2338
-# 		self.FSM.owner.pub.unregister("beat", self)        
2339
-
2340
-#==================================== 
2341
-
2342
-
2343
-
2344
-# class Calculator(State):
2345
-# 	def __init__(self,FSM):
2346
-# 		super(Calculator, self).__init__(FSM)    
2347
-		
2348
-# 	def Enter(self):
2349
-# 		o = self.FSM.owner 
2350
-
2351
-# 		o.pub.register("beat", self)
2352
-		
2353
-# 		self.num1 = ''
2354
-# 		self.num2 = ''
2355
-# 		self.op = ''
2356
-# 		self.result = ''
2357
-
2358
-# 		self.labels = ['.', '0', '=', '/',
2359
-# 						'1', '2', '3', '*',
2360
-# 						'4', '5', '6', '-',
2361
-# 						'7', '8', '9', '+',
2362
-# 						'7', '8', '9', '+']
2363
-
2364
-# 		self.draw_main(o)
2365
-# 		o.update_display(0)
2366
-
2367
-# 		super(Calculator, self).Enter()        
2368
-		
2369
-# 	def Execute(self):
2370
-# 		o = self.FSM.owner 
2371
-# 		m.menu1_actions(self, o)
2372
-# 		if o.keyState[16] == 1:
2373
-# 			m.draw_menu1(o)
2374
-# 			o.update_display(0)
2375
-# 		elif o.keyState[16] == 4:		
2376
-# 			self.draw_main(o)
2377
-# 			o.update_display(0)
2378
-
2379
-# 		if o.keyState[16] > 0:
2380
-# 			pass
2381
-# 		else:
2382
-# 			if o.keyState[17] == 1:
2383
-# 				self.num1 = ''
2384
-# 				self.num2 = ''
2385
-# 				self.op = ''
2386
-# 				self.result = ''
2387
-
2388
-# 			self.check_keys(o)
2389
-
2390
-# 	def append_num(self, num):
2391
-# 		ops = ['+', '-', '*', '/']
2392
-# 		print('appending num ', num)
2393
-# 		if num in ops:
2394
-# 			if self.num1 != '':
2395
-# 				self.op = num
2396
-# 				self.num2 = ''
2397
-# 				self.result = ''
2398
-# 		elif num == '=':
2399
-# 			print('this is that')
2400
-# 			if self.num2 != '':
2401
-# 				if self.result == '':
2402
-# 					if self.op == '+':
2403
-# 						self.result = float(self.num1) + float(self.num2)
2404
-# 						print(self.result)
2405
-# 					if self.op == '-':
2406
-# 						self.result = float(self.num1) - float(self.num2)
2407
-# 						print(self.result)
2408
-# 					if self.op == '*':
2409
-# 						self.result = float(self.num1) * float(self.num2)
2410
-# 						print(self.result)
2411
-# 					if self.op == '/':
2412
-# 						self.result = float(self.num1) / float(self.num2)
2413
-# 						print(self.result)
2414
-# 				else:
2415
-# 					if self.op != '':
2416
-# 						if self.op == '+':
2417
-# 							self.result = self.result + float(self.num2)
2418
-# 							print(self.result)
2419
-# 						if self.op == '-':
2420
-# 							self.result = self.result - float(self.num2)
2421
-# 							print(self.result)
2422
-# 						if self.op == '*':
2423
-# 							self.result = self.result * float(self.num2)
2424
-# 							print(self.result)
2425
-# 						if self.op == '/':
2426
-# 							self.result = self.result / float(self.num2)
2427
-# 							print(self.result)
2428
-
2429
-# 		else:
2430
-# 			if self.result != '':
2431
-# 				self.num1 = ''
2432
-# 				self.num2 = ''
2433
-# 				self.op = ''
2434
-# 				self.result = ''
2435
-# 			if self.op == '':
2436
-# 				self.num1 += num
2437
-# 				print('---append ', num)
2438
-# 			else:
2439
-# 				self.num2 += num
2440
-# 				print('---append ', num)
2441
-
2442
-# 	def check_keys(self, o):
2443
-# 		_iter = 0
2444
-# 		for k in o.keyState:
2445
-# 			if k == 1:
2446
-# 				if _iter == 0:
2447
-# 					if ('.' not in self.num1 and self.num2 == '') or (self.num2 != '' and '.' not in self.num2):
2448
-# 						self.append_num('.')
2449
-# 				if _iter == 1:
2450
-# 					self.append_num('0')
2451
-# 				if _iter == 2:
2452
-# 					self.append_num('=')
2453
-# 				if _iter == 3:
2454
-# 					self.append_num('/')
2455
-# 				if _iter == 4:
2456
-# 					self.append_num('1')
2457
-# 				if _iter == 5:
2458
-# 					self.append_num('2')
2459
-# 				if _iter == 6:
2460
-# 					self.append_num('3')
2461
-# 				if _iter == 7:
2462
-# 					self.append_num('*')
2463
-# 				if _iter == 8:
2464
-# 					self.append_num('4')
2465
-# 				if _iter == 9:
2466
-# 					self.append_num('5')
2467
-# 				if _iter == 10:
2468
-# 					self.append_num('6')
2469
-# 				if _iter == 11:
2470
-# 					self.append_num('-')
2471
-# 				if _iter == 12:
2472
-# 					self.append_num('7')
2473
-# 				if _iter == 13:
2474
-# 					self.append_num('8')
2475
-# 				if _iter == 14:
2476
-# 					self.append_num('9')
2477
-# 				if _iter == 15:
2478
-# 					self.append_num('+')
2479
-
2480
-# 				self.draw_main(o)
2481
-
2482
-# 			_iter += 1
2483
-
2484
-# 	def draw_main(self, o):
2485
-# 		print('drawing ', self.num1)
2486
-# 		x_size = o.width / 4
2487
-# 		y_size = o.height / 5
2488
-# 		og_x = 0
2489
-# 		o_x = og_x
2490
-# 		o_y = o.height
2491
-# 		text_padding = 6
2492
-		
2493
-# 		_id = 0
2494
-# 		while _id < 20:
2495
-# 			# lab = ""
2496
-# 			# for i in self.labels[_id]:
2497
-# 			# 	lab += i
2498
-
2499
-# 			lab = self.labels[_id]
2500
-
2501
-# 			o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.blue)
2502
-# 			o.center_block(lab, o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
2503
-
2504
-# 			o_x = o_x + x_size
2505
-# 			_id += 1
2506
-# 			if _id % 4 == 0:
2507
-# 				o_y -= y_size
2508
-# 				o_x = og_x
2509
-# 		o.draw.rectangle((0, 0, o.width, y_size), outline=0, fill=o.blue)
2510
-# 		#o.center_block('where is my fucking text', o.h2, [0, 0, o.width, y_size], o.light_grey)
2511
-# 		if self.num1 != '':
2512
-# 			if self.result != '':
2513
-# 				o.center_block(str(self.result), o.h2, [0, 0, o.width, y_size], o.light_grey)
2514
-# 			elif self.num2 != '':
2515
-# 				o.center_block(str(self.num2), o.h2, [0, 0, o.width, y_size], o.light_grey)
2516
-# 			elif self.op != '':
2517
-# 				o.center_block(str(self.op), o.h2, [0, 0, o.width, y_size], o.light_grey)
2518
-# 			else:
2519
-# 				o.center_block(str(self.num1), o.h2, [0, 0, o.width, y_size], o.light_grey)
2520
-# 			print('fucking do something')
2521
-# 		else:
2522
-# 			print('num1 is empty')
2523
-# 		o.update_display(0)
2524
-
2525
-# 	def ReceiveMessage(self, message):
2526
-# 		o = self.FSM.owner 
2527
-# 		u.play_seq(o, message)
2528
-
2529
-# 	def Exit(self):
2530
-# 		self.FSM.owner.pub.unregister("beat", self)
2531
-
2532
-#==================================== 
2533
-
2534
-# class About(State):
2535
-# 	def __init__(self,FSM):
2536
-# 		super(About, self).__init__(FSM)    
2537
-		
2538
-# 	def Enter(self):
2539
-		
2540
-# 		o = self.FSM.owner 
2541
-# 		o.header_text = "About"
2542
-# 		o.pub.register("beat", self)
2543
-		
2544
-# 		if o.keyState[16] > 0 or o.keyState[17] > 0:
2545
-# 			pass
2546
-# 		else:
2547
-# 			u.draw_header(o)
2548
-# 			o.update_display(0)
2549
-# 			self.draw_main(o)
2550
-# 		super(About, self).Enter()        
2551
-		
2552
-# 	def Execute(self):
2553
-# 		o = self.FSM.owner 
2554
-# 		m.menu1_actions(self, o)
2555
-# 		if o.keyState[16] == 1:
2556
-# 			m.draw_menu1(o)
2557
-# 			o.update_display(0)
2558
-# 		elif o.keyState[16] == 4:
2559
-# 			u.draw_header(o)
2560
-# 			self.draw_main(o)
2561
-# 			o.update_display(0)
2562
-
2563
-# 		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
2564
-# 			u.draw_header(o)
2565
-# 			self.draw_main(o)
2566
-# 			o.update_display(0)	
2567
-	
2568
-# 	def draw_main(self, o):
2569
-# 		o.center_block("rob@robzilla-beats.com", o.h2, [0, 0, o.width, o.height], o.light_grey)
2570
-
2571
-# 	def ReceiveMessage(self, message):
2572
-# 		o = self.FSM.owner 
2573
-# 		u.play_seq(o, message)
2574
-		
2575
-# 	def Exit(self):
2576
-# 		self.FSM.owner.pub.unregister("beat", self)        

+ 45
- 2
lib/menus.py View File

@@ -98,7 +98,18 @@ def draw_menu2_sample(o):
98 98
 				o.center_block("Odub", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
99 99
 		if _id == 13:
100 100
 			o.center_block("Undo", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
101
+		
102
+		if _id == 14:
103
+			if o.erase == True:
104
+				o.center_block("Erase", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.pink)
105
+			else:
106
+				o.center_block("Erase", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
101 107
 
108
+		if _id == 15:
109
+			if o.mute == True:
110
+				o.center_block("Mute", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.pink)
111
+			else:
112
+				o.center_block("Mute", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
102 113
 
103 114
 		o_x = o_x + x_size
104 115
 		_id += 1
@@ -207,8 +218,7 @@ def draw_menu_saveas(o):
207 218
 			o.center_block("Select Folder", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
208 219
 		if _id == 7:
209 220
 			o.center_block("New Folder", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
210
-		if _id == 4:
211
-			o.center_block("Delete", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
221
+		
212 222
 
213 223
 		o_x = o_x + x_size
214 224
 		_id += 1
@@ -279,6 +289,7 @@ def menu1_actions(self, o):
279 289
 				o.update_display(0)
280 290
 		if o.keyState[11] == 1:
281 291
 			#o.save_song()
292
+
282 293
 			pass
283 294
 
284 295
 		if o.keyState[10] == 2:
@@ -476,6 +487,26 @@ def menu2_actions_sample(self, o):
476 487
 				o.soundSlots[i[0]].notes[i[1]][i[2]][1] = 0
477 488
 			o.undo_buf = []
478 489
 
490
+		if o.keyState[14] == 1:
491
+			o.erase = not o.erase
492
+			o.erase_buf = []
493
+			print('erase now is ', o.erase)
494
+			if o.erase:
495
+				o.mute = False
496
+				o.mute_buf = []
497
+			draw_menu2_sample(o)
498
+			o.update_display(0)
499
+
500
+		if o.keyState[15] == 1:
501
+			o.mute = not o.mute
502
+			o.mute_buf = []
503
+			print('mute now is ', o.mute)
504
+			if o.mute:
505
+				o.erase = False
506
+				o.erase_buf = []
507
+			draw_menu2_sample(o)
508
+			o.update_display(0)
509
+
479 510
 def menu2_actions_pattern(self, o):
480 511
 	if o.keyState[17] == 2:
481 512
 		if o.keyState[0] == 1:
@@ -593,6 +624,18 @@ def menu2_actions_note(self, o):
593 624
 			o.update_display(0)			
594 625
 					
595 626
 
627
+def menu2_actions_saveas(self, o):
628
+	if o.keyState[17] == 2:
629
+		if o.keyState[12] == 1:
630
+			print('select folder')
631
+			self.FSM.ToTransition('toSelectFolder')	
632
+		elif o.keyState[14] == 1:
633
+			print('new folder')
634
+			#o.song_dir
635
+			#os.mkdir(path)
636
+			self.FSM.ToTransition('toNewDir')	
637
+
638
+
596 639
 def util_command(self, o, command):
597 640
 	if command == "Clock":
598 641
 		self.FSM.ToTransition('toClock')		

+ 1
- 1
lib/sAbout.py View File

@@ -14,7 +14,7 @@ class State(object):
14 14
 		pass
15 15
 	def Exit(self):
16 16
 		pass
17
-
17
+#====================================     
18 18
 class About(State):
19 19
 	def __init__(self,FSM):
20 20
 		super(About, self).__init__(FSM)    

+ 118
- 0
lib/sBall.py View File

@@ -0,0 +1,118 @@
1
+import FSM
2
+import utils as u
3
+import menus as m
4
+import random
5
+#====================================     
6
+
7
+State = type("State", (object,), {})
8
+#====================================     
9
+class State(object):
10
+	def __init__(self, FSM):
11
+		self.FSM = FSM
12
+	def Enter(self):
13
+		pass
14
+	def Execute(self):
15
+		pass
16
+	def Exit(self):
17
+		pass
18
+
19
+class Ball(State):
20
+	def __init__(self,FSM):
21
+		super(Ball, self).__init__(FSM)    
22
+		
23
+	def Enter(self):
24
+		self.ball_size = 10
25
+		self.ballx = self.ball_size
26
+		self.bally = self.ball_size
27
+		
28
+		self.ball_speed = 8
29
+		self.ball_x_dir = 1
30
+		self.ball_y_dir = 1
31
+		
32
+		self.ball2x = self.ball_size + 180
33
+		self.ball2y = self.ball_size + 70
34
+	
35
+		self.ball2_x_dir = -1
36
+		self.ball2_y_dir = -1
37
+
38
+		self.xmult = 1.0
39
+
40
+		o = self.FSM.owner 
41
+		o.header_text = "Balls"
42
+		o.pub.register("beat", self)
43
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
44
+			pass
45
+		else:
46
+			u.draw_header(o)
47
+			o.update_display(0)
48
+		super(Ball, self).Enter()        
49
+		
50
+	def Execute(self):
51
+		o = self.FSM.owner 
52
+		m.menu1_actions(self, o)
53
+		if o.keyState[16] == 1:
54
+			m.draw_menu1(o)
55
+			o.update_display(0)
56
+		
57
+
58
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
59
+			pass
60
+		else:			
61
+			#now = datetime.now()
62
+			#current_time = time.strftime("%-I:%M %p")
63
+
64
+
65
+			if self.ballx < (0 + self.ball_size):
66
+				self.ball_x_dir = 1
67
+			if self.ballx > (o.width - self.ball_size):
68
+				self.ball_x_dir = -1
69
+
70
+			if self.bally < (0 + self.ball_size):
71
+				self.ball_y_dir = 1
72
+			if self.bally > (o.height - self.ball_size):
73
+				self.ball_y_dir = -1
74
+
75
+			# if self.ballx > (o.width - self.ball_size) or self.ballx < (0 + self.ball_size):
76
+			# 	self.ball_x_dir *= -1
77
+			# if self.bally > (o.height - self.ball_size) or self.bally < (0 + self.ball_size):
78
+			# 	self.ball_y_dir *= -1
79
+
80
+			self.ballx += self.ball_speed * self.ball_x_dir
81
+			self.bally += self.ball_speed * self.ball_y_dir
82
+
83
+
84
+			if self.ball2x < (0 + self.ball_size):
85
+				self.ball2_x_dir = 1
86
+				self.xmult = random.uniform(.6, 1.2)
87
+			if self.ball2x > (o.width - self.ball_size):
88
+				self.ball2_x_dir = -1
89
+				self.xmult = random.uniform(.6, 1.2)
90
+
91
+			if self.ball2y < (0 + self.ball_size):
92
+				self.ball2_y_dir = 1
93
+			if self.ball2y > (o.height - self.ball_size):
94
+				self.ball2_y_dir = -1			
95
+
96
+
97
+			# if self.ball2x > (o.width - self.ball_size) or self.ball2x < (0 + self.ball_size):
98
+			# 	self.ball2_x_dir *= -1
99
+			# 	self.xmult = random.uniform(.8, 1.2)
100
+			# if self.ball2y > (o.height - self.ball_size) or self.ball2y < (0 + self.ball_size):
101
+			# 	self.ball2_y_dir *= -1
102
+
103
+			self.ball2x += (self.ball_speed * self.ball2_x_dir) * self.xmult
104
+			self.ball2y += (self.ball_speed * self.ball2_y_dir) 
105
+
106
+			o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
107
+			
108
+			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)
109
+			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)
110
+			#o.center_block(current_time, o.h3, [0,0,o.width,o.height], o.pink)
111
+			o.update_display(0)
112
+		
113
+	def ReceiveMessage(self, message):
114
+		o = self.FSM.owner 
115
+		u.play_seq(o, message)
116
+		
117
+	def Exit(self):
118
+		self.FSM.owner.pub.unregister("beat", self)        

+ 90
- 0
lib/sClock.py View File

@@ -0,0 +1,90 @@
1
+import FSM
2
+import utils as u
3
+import menus as m
4
+from datetime import date
5
+import time
6
+#====================================     
7
+
8
+State = type("State", (object,), {})
9
+#====================================     
10
+class State(object):
11
+	def __init__(self, FSM):
12
+		self.FSM = FSM
13
+	def Enter(self):
14
+		pass
15
+	def Execute(self):
16
+		pass
17
+	def Exit(self):
18
+		pass
19
+
20
+class Clock(State):
21
+	def __init__(self,FSM):
22
+		super(Clock, self).__init__(FSM)    
23
+		
24
+	def Enter(self):
25
+		o = self.FSM.owner 
26
+		current_time = time.strftime("%-I:%M:%S")
27
+		self.ball_sizex, self.ball_sizey = o.h3.getsize("18:88:88")
28
+		self.ball_sizex /= 2
29
+		self.ball_sizey /= 2
30
+		#self.ball_sizey += 10
31
+		self.ballx = o.width / 2 
32
+		self.bally = o.height / 2
33
+		self.ball_speed = .5
34
+		self.ball_x_dir = 1
35
+		self.ball_y_dir = 1
36
+		
37
+		o.header_text = "Clock"
38
+		o.pub.register("beat", self)
39
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
40
+			pass
41
+		else:
42
+			pass
43
+		super(Clock, self).Enter()        
44
+		
45
+	def Execute(self):
46
+		o = self.FSM.owner 
47
+		m.menu1_actions(self, o)
48
+
49
+		if o.keyState[16] == 1:
50
+			m.draw_menu1(o)
51
+			o.update_display(0)
52
+
53
+
54
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
55
+			pass
56
+		else:			
57
+			current_time = time.strftime("%-I:%M:%S")
58
+			s = int(time.strftime("%S"))
59
+			if s % 2 == 0:
60
+				current_time = time.strftime("%-I:%M.%S")
61
+
62
+			if self.ballx > (o.width - self.ball_sizex) or self.ballx < (0 + self.ball_sizex):
63
+				self.ball_x_dir *= -1
64
+			if (self.bally > o.height - self.ball_sizey - 20) or (self.bally < 0 + self.ball_sizey):
65
+				self.ball_y_dir *= -1
66
+
67
+			x1 = self.ballx - self.ball_sizex
68
+			x2 = self.ballx + self.ball_sizex
69
+			y1 = self.bally - self.ball_sizey
70
+			y2 = self.bally + self.ball_sizey
71
+			self.ballx += self.ball_speed * self.ball_x_dir
72
+			self.bally += self.ball_speed * self.ball_y_dir
73
+			o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)			
74
+			#o.draw.rectangle((x1, y1, x2, y2), outline=0, fill=o.dark_grey)			
75
+
76
+			#o.draw.text((self.ballx - self.ball_sizex, self.bally - self.ball_sizey), current_time, align='center', font=o.h3, fill=o.light_grey)
77
+			o.center_block(current_time, o.h3, [x1, y1, x2, y2], o.light_grey)
78
+			today = date.today()
79
+			current_date = today.strftime('%A')
80
+			current_date += ', ' + today.strftime("%b %d, %Y")
81
+			#o.draw.text((self.ballx - self.ball_sizex, (self.bally + 45) - self.ball_sizey), current_date, align='center', font=o.h2, fill=o.light_grey)
82
+			o.center_block(current_date, o.h2, [x1, y1 + 35, x2, y2 + 35], o.light_grey)
83
+			o.update_display(0)
84
+		
85
+	def ReceiveMessage(self, message):
86
+		o = self.FSM.owner 
87
+		u.play_seq(o, message)
88
+		
89
+	def Exit(self):
90
+		self.FSM.owner.pub.unregister("beat", self)        

+ 52
- 0
lib/sDefender.py View File

@@ -0,0 +1,52 @@
1
+import FSM
2
+import utils as u
3
+import menus as m
4
+#====================================     
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 Defender(State):
19
+	def __init__(self,FSM):
20
+		super(Defender, self).__init__(FSM)    
21
+		
22
+	def Enter(self):
23
+		o = self.FSM.owner 
24
+		
25
+		self.gameFSM = FSM.DefenderFSM(o)
26
+
27
+		super(Defender, self).Enter()        
28
+		
29
+	def Execute(self):
30
+		o = self.FSM.owner 
31
+		m.menu1_actions(self, o)
32
+		if o.keyState[16] == 1:
33
+			m.draw_menu1(o)
34
+			o.update_display(0)
35
+		elif o.keyState[16] == 4:
36
+			#u.draw_header(o)
37
+			#self.draw_footer(o)
38
+			#self.draw_main(o)
39
+			#o.update_display(0)		
40
+			pass
41
+
42
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
43
+
44
+		#if o.keyState[16] > 0:
45
+			pass
46
+		else:
47
+			self.gameFSM.Execute()
48
+		
49
+	def Exit(self):
50
+		pass
51
+
52
+#==================================== 

+ 121
- 0
lib/sEditSong.py View File

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

+ 130
- 0
lib/sEditSoundSequence.py View File

@@ -0,0 +1,130 @@
1
+import FSM
2
+import utils as u
3
+import menus as m
4
+#====================================     
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
+
19
+class EditSoundSequence(State):
20
+	def __init__(self,FSM):
21
+		super(EditSoundSequence, self).__init__(FSM)    
22
+		
23
+	def Enter(self):
24
+		self.FSM.stateLife = 1
25
+		o = self.FSM.owner 
26
+		o.header_text = "Note Edit"
27
+		o.pub.register("beat", self)
28
+		self.curPattern = o.ePattern
29
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
30
+			pass
31
+		else:
32
+			u.draw_header(o)
33
+			self.draw_square()
34
+			u.text_box1(o, "Note Vol", str(o.note_vol))
35
+			u.text_box3(o, "Pat", str(self.curPattern))
36
+			o.update_display(0)
37
+		super(EditSoundSequence, self).Enter()        
38
+		
39
+	def Execute(self):
40
+		o = self.FSM.owner 
41
+		m.menu1_actions(self, o)
42
+		m.menu2_actions_note(self, o)
43
+		if o.keyState[16] == 1:
44
+			m.draw_menu1(o)
45
+			o.update_display(0)
46
+		elif o.keyState[16] == 4:
47
+			u.draw_header(o)
48
+			self.draw_square()
49
+			u.text_box1(o, "Note Vol", str(o.note_vol))
50
+			u.text_box3(o, "Pat", str(self.curPattern))
51
+			o.update_display(0)
52
+
53
+		if o.keyState[17] == 1:
54
+			m.draw_menu2_note(o)
55
+			o.update_display(0)
56
+		elif o.keyState[17] == 4:
57
+			u.draw_header(o)
58
+			self.draw_square()
59
+			u.text_box1(o, "Note Vol", str(o.note_vol))
60
+			u.text_box3(o, "Pat", str(self.curPattern))
61
+			o.update_display(0)
62
+
63
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
64
+			pass
65
+
66
+		else:
67
+			_id = 0
68
+			for k in self.FSM.owner.keyState:
69
+				if _id < 16 and k == 1:
70
+					if o.soundSlots[o.eSound].notes[self.curPattern][_id][0] == 1:
71
+						#print('turn note off')
72
+						o.soundSlots[o.eSound].notes[self.curPattern][_id][0] = 0
73
+						o.soundSlots[o.eSound].notes[self.curPattern][_id][1] = 0
74
+					else:
75
+						#print('turn note on')
76
+						o.soundSlots[o.eSound].notes[self.curPattern][_id][0] = 1
77
+						o.soundSlots[o.eSound].notes[self.curPattern][_id][1] = o.note_vol
78
+					u.draw_header(o)
79
+					self.draw_square()
80
+					u.text_box1(o, "Note Vol", str(o.note_vol))			
81
+					u.text_box3(o, "Pat", str(self.curPattern))
82
+					o.update_display(0)
83
+				_id += 1
84
+
85
+
86
+		
87
+	def draw_square(self):
88
+		o = self.FSM.owner 
89
+		size = 22
90
+		og_x = (o.width / 2) - (size * 2)
91
+		o_x = og_x
92
+		o_y = 127
93
+		_id = 0
94
+		for n in o.soundSlots[o.eSound].notes[self.curPattern]:
95
+			if _id == o.playhead and o.playing:
96
+				if o.curPattern == self.curPattern:
97
+					o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.olive, width=1)
98
+				else:
99
+					o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.pink, width=1)
100
+			elif n[0] == 1:
101
+				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.light_grey, width=1)
102
+			else:
103
+				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.blue, width=1)
104
+			o_x = o_x + size
105
+			_id += 1
106
+			if _id % 4 == 0:
107
+				o_y -= size
108
+				o_x = og_x
109
+
110
+	def ReceiveMessage(self, message):
111
+		_id = 0
112
+		o = self.FSM.owner 
113
+		u.play_seq(o, message)
114
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
115
+			pass
116
+		else:
117
+			u.draw_header(o)            
118
+			self.draw_square()  
119
+			u.text_box1(o, "Note Vol", str(o.note_vol))
120
+			u.text_box3(o, "Pat", str(self.curPattern))
121
+		if o.patternFollow:
122
+			self.curPattern = message[0]
123
+		else:
124
+			self.curPattern = o.ePattern
125
+		#print('message ', message)
126
+		o.update_display(0)
127
+		
128
+	def Exit(self):
129
+		self.FSM.owner.pub.unregister("beat", self)
130
+

+ 221
- 0
lib/sEnterText.py View File

@@ -0,0 +1,221 @@
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
+#====================================     
10
+
11
+State = type("State", (object,), {})
12
+#====================================     
13
+class State(object):
14
+	def __init__(self, FSM):
15
+		self.FSM = FSM
16
+	def Enter(self):
17
+		pass
18
+	def Execute(self):
19
+		pass
20
+	def Exit(self):
21
+		pass
22
+
23
+class EnterText(State):
24
+	def __init__(self,FSM):
25
+		super(EnterText, self).__init__(FSM)    
26
+		
27
+	def Enter(self):
28
+		o = self.FSM.owner 
29
+	
30
+		m.menu1_actions(self, o)
31
+		if o.keyState[16] == 1:
32
+			m.draw_menu1(o)
33
+			o.update_display(0)
34
+		elif o.keyState[16] == 4:
35
+			#u.draw_header(o)
36
+			#self.draw_footer(o)
37
+			self.draw(o)
38
+			o.update_display(0)
39
+		self.input_string = ""
40
+		if o.sconf['title'] == 'blank':
41
+
42
+			self.input_string += str(datetime.today().strftime('%Y%m%d'))
43
+		else:
44
+
45
+			self.input_string += o.sconf['title']
46
+		#if 
47
+		o.header_text = "EnterText"
48
+		o.pub.register("beat", self)
49
+		self.last_action = pygame.time.get_ticks()
50
+		self.caps = False
51
+		self.cur_but = 18
52
+		self.cur_letter = ""
53
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
54
+			pass
55
+		else:
56
+			pass
57
+
58
+		self.skips = [7, 3, 11, 12, 13, 14, 15]
59
+		
60
+		self.lc_labels = [["p", "q", "r", "s"], ["t", "u", "v"], ["w", "x", "y", "z"], ["C", "A", "P", "S"], 
61
+				["g", "h", "i"], ["j", "k", "l"], ["m", "n", "o"], ["D", "E", "L"],
62
+				["_", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-"], ["a", "b", "c"], ["d", "e", "f"], ["O", "K"],
63
+				[], [], [], []]
64
+
65
+		self.uc_labels = [["P", "Q", "R", "S"], ["T", "U", "V"], ["W", "X", "Y", "Z"], ["C", "A", "P", "S"], 
66
+				["G", "H", "I"], ["J", "K", "L"], ["M", "N", "O"], ["D", "E", "L"],
67
+				["_", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-"], ["A", "B", "C"], ["D", "E", "F"], ["O", "K"],
68
+				[], [], [], []]
69
+
70
+		self.labels = self.lc_labels
71
+
72
+		#self.songCycle = cycle(self.song)
73
+		#self.curPattern = next(self.songCycle)
74
+
75
+		self.cycles = []
76
+		for l in self.labels:
77
+			self.cycles.append(cycle(l))
78
+
79
+
80
+
81
+		self.draw(o)
82
+		o.update_display(0)
83
+		super(EnterText, self).Enter()        
84
+		
85
+	def Execute(self):
86
+		o = self.FSM.owner 
87
+
88
+		y_size = o.height / 4
89
+		if o.keyState[11] == 1:
90
+			if self.input_string != 'blank':
91
+				o.title = self.input_string
92
+				#o.bpm = o.sconf['bpm']
93
+				o.sconf['title'] = self.input_string
94
+				
95
+				print('fsm saving')
96
+				o.save_song()
97
+				self.FSM.ToTransition('toFile')	
98
+
99
+		m.menu1_actions(self, o)
100
+		m.menu2_actions_saveas(self, o)
101
+		if o.keyState[16] == 1:
102
+			m.draw_menu1(o)
103
+			o.update_display(0)
104
+		elif o.keyState[16] == 4:
105
+			u.draw_header(o)
106
+			self.draw(o)
107
+			#self.draw_main(o)
108
+			o.update_display(0)
109
+
110
+		if o.keyState[17] == 1:
111
+			m.draw_menu_saveas(o)
112
+			o.update_display(0)
113
+		elif o.keyState[17] == 4:
114
+			u.draw_header(o)
115
+			self.draw(o)
116
+			#self.draw_main(o)
117
+			o.update_display(0)
118
+
119
+		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
120
+			u.draw_header(o)
121
+			self.draw(o)
122
+			#self.draw_main(o)
123
+			o.update_display(0)	
124
+			
125
+
126
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
127
+			pass
128
+
129
+		else:
130
+			_iter = 0
131
+			for k in o.keyState:
132
+				if k == 1:
133
+					cur_time = pygame.time.get_ticks()
134
+					print(cur_time - self.last_action)
135
+					
136
+					#print('cur letter ', next(self.cycles[_iter]))
137
+					if _iter not in self.skips:
138
+						self.last_action = cur_time
139
+						if _iter < len(self.cycles):
140
+							self.cur_letter = next(self.cycles[_iter])
141
+							self.cur_but = _iter
142
+							self.draw(o)
143
+							o.center_block(self.input_string + self.cur_letter, o.h2, [0, 0, o.width, y_size], o.light_grey)
144
+
145
+					if _iter == 7:
146
+						
147
+						self.input_string = self.input_string[:-1]
148
+						#self.input_string = self.input_string.rstrip(self.input_string[-1])
149
+						print('deleting')
150
+						self.last_action = 100000000
151
+						self.draw(o)
152
+						o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
153
+
154
+					elif _iter == 3:
155
+						print('caps')
156
+						if self.caps:
157
+							self.caps = False
158
+							self.labels = self.lc_labels
159
+
160
+						else:
161
+							self.caps = True
162
+							self.labels = self.uc_labels
163
+						self.draw(o)
164
+						o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
165
+						self.cycles = []
166
+						for l in self.labels:
167
+							self.cycles.append(cycle(l))
168
+
169
+					o.update_display(0)
170
+				_iter += 1
171
+
172
+		cur_time = pygame.time.get_ticks()
173
+		delay = cur_time - self.last_action
174
+		if delay > 1000 and delay < 100000:
175
+			self.input_string += self.cur_letter
176
+			self.last_action = 100000000
177
+			self.reset_cycles()
178
+			self.draw(o)
179
+
180
+			o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
181
+			o.update_display(0)
182
+	
183
+	def ReceiveMessage(self, message):
184
+		o = self.FSM.owner 
185
+		u.play_seq(o, message)
186
+
187
+	def draw(self, o):
188
+		x_size = o.width / 4
189
+		y_size = o.height / 4
190
+		og_x = 0
191
+		o_x = og_x
192
+		o_y = o.height
193
+		text_padding = 6
194
+		
195
+		_id = 0
196
+		while _id < 16:
197
+			lab = ""
198
+			for i in self.labels[_id]:
199
+				lab += i
200
+
201
+			if _id == 8:
202
+				lab = "_12"
203
+
204
+			o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.blue)
205
+			o.center_block(lab, o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
206
+
207
+			o_x = o_x + x_size
208
+			_id += 1
209
+			if _id % 4 == 0:
210
+				o_y -= y_size
211
+				o_x = og_x
212
+		o.draw.rectangle((0, 0, o.width, y_size), outline=0, fill=o.blue)
213
+		
214
+	def reset_cycles(self):
215
+		self.cycles = []
216
+		for l in self.labels:
217
+			self.cycles.append(cycle(l))
218
+
219
+	def Exit(self):
220
+		self.FSM.owner.pub.unregister("beat", self)        
221
+

+ 39
- 0
lib/sExit.py View File

@@ -0,0 +1,39 @@
1
+import FSM
2
+import utils as u
3
+import menus as m
4
+import pygame
5
+import sys
6
+
7
+#====================================     
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
+
21
+
22
+class Exit(State):
23
+	def __init__(self,FSM):
24
+		super(Exit, self).__init__(FSM)    
25
+		
26
+	def Enter(self):
27
+		o = self.FSM.owner
28
+		o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)			
29
+		o.center_block("goodbye", o.h2, [0, 0, o.width,o.height], o.light_grey)
30
+		o.update_display(0)
31
+		pygame.quit()
32
+		sys.exit()
33
+		super(Exit, self).Enter()        
34
+		
35
+	def Execute(self):
36
+		self.FSM.stateLife += 1
37
+		
38
+	def Exit(self):
39
+		pass

+ 141
- 0
lib/sFile.py View File

@@ -0,0 +1,141 @@
1
+import FSM
2
+import utils as u
3
+import menus as m
4
+#====================================     
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 File(State):
19
+	def __init__(self,FSM):
20
+		super(File, self).__init__(FSM)    
21
+		
22
+	def Enter(self):
23
+		self.FSM.stateLife = 1
24
+		o = self.FSM.owner 
25
+		o.header_text = "File"
26
+		o.pub.register("beat", self)
27
+		self.cur_el = 0
28
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
29
+			pass
30
+		else:
31
+			u.draw_header(o)
32
+			self.draw_footer(o)
33
+			self.draw_main(o)
34
+			o.update_display(0)
35
+		self.menu = ["Save", "Save As", "Open", "New"]
36
+		
37
+		super(File, self).Enter()        
38
+		
39
+	def Execute(self):
40
+		o = self.FSM.owner 
41
+		m.menu1_actions(self, o)
42
+		if o.keyState[16] == 1:
43
+			m.draw_menu1(o)
44
+			#self.draw_footer(o)
45
+			o.update_display(0)
46
+		elif o.keyState[16] == 4:
47
+			u.draw_header(o)
48
+			self.draw_footer(o)
49
+			self.draw_main(o)
50
+			o.update_display(0)
51
+
52
+		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
53
+			u.draw_header(o)
54
+			self.draw_footer(o)
55
+			self.draw_main(o)
56
+			o.update_display(0)	
57
+			print('draw butt')				
58
+
59
+
60
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
61
+			pass
62
+		else:
63
+			if o.keyState[0] == 1:
64
+				if self.cur_el > 0:
65
+					self.cur_el -= 1
66
+					print('cur el down is ', self.cur_el)
67
+			if o.keyState[1] == 1:
68
+				if self.cur_el < (len(self.menu) - 1):
69
+					self.cur_el += 1
70
+					print('cur el up is ', self.cur_el)
71
+			
72
+			if o.keyState[3] == 1:
73
+				m.file_command(self, o, self.menu[self.cur_el])
74
+				pass
75
+
76
+	def draw_footer(self, o):
77
+		_iter = 0
78
+		width = o.width / 4
79
+		xpos = 0
80
+		yposa = 135 - 25
81
+		yposb = 135
82
+		opts = ["Up", "Down", "Esc", "OK"]
83
+		while _iter < 4:
84
+			o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.blue)
85
+			
86
+			if o.keyState[_iter] == 1:
87
+				o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.light_grey)
88
+				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.blue)
89
+			else:
90
+				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
91
+			
92
+			xpos += width
93
+			_iter += 1
94
+
95
+
96
+	def draw_main(self, o):
97
+		al = []
98
+		ypos = 30
99
+		if self.cur_el == 0:
100
+			_iter = 0
101
+			while len(al) < 4:
102
+				al.append(self.menu[_iter])
103
+				_iter += 1
104
+		elif self.cur_el == 1:
105
+			al.append(self.menu[self.cur_el - 1])
106
+			al.append(self.menu[self.cur_el])
107
+			al.append(self.menu[self.cur_el + 1])
108
+			al.append(self.menu[self.cur_el + 2])
109
+		elif self.cur_el == (len(self.menu) - 2):
110
+			al.append(self.menu[self.cur_el - 2])
111
+			al.append(self.menu[self.cur_el - 1])
112
+			al.append(self.menu[self.cur_el])
113
+			al.append(self.menu[self.cur_el + 1])
114
+		elif self.cur_el == (len(self.menu) - 1):
115
+			al.append(self.menu[self.cur_el - 3])
116
+			al.append(self.menu[self.cur_el - 2])
117
+			al.append(self.menu[self.cur_el - 1])
118
+			al.append(self.menu[self.cur_el])
119
+		else:
120
+			al.append(self.menu[self.cur_el - 1])
121
+			al.append(self.menu[self.cur_el])
122
+			al.append(self.menu[self.cur_el + 1])
123
+			al.append(self.menu[self.cur_el + 2])
124
+		_iter = 0 
125
+		for i in al:
126
+			if i == self.menu[self.cur_el]:
127
+			#if _iter == self.cur_el:
128
+				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.light_grey)
129
+				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.blue)
130
+			else:
131
+				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.blue)
132
+				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.light_grey)
133
+			ypos += 20
134
+			_iter += 1
135
+
136
+	def ReceiveMessage(self, message):
137
+		o = self.FSM.owner 
138
+		u.play_seq(o, message)
139
+		
140
+	def Exit(self):
141
+		self.FSM.owner.pub.unregister("beat", self)

+ 264
- 0
lib/sLoadSound.py View File

@@ -0,0 +1,264 @@
1
+import FSM
2
+import utils as u
3
+import menus as m
4
+import os
5
+import pygame
6
+#====================================     
7
+
8
+State = type("State", (object,), {})
9
+#====================================     
10
+class State(object):
11
+	def __init__(self, FSM):
12
+		self.FSM = FSM
13
+	def Enter(self):
14
+		pass
15
+	def Execute(self):
16
+		pass
17
+	def Exit(self):
18
+		pass
19
+
20
+#====================================     
21
+
22
+class LoadSound(State):
23
+	def __init__(self,FSM):
24
+		super(LoadSound, self).__init__(FSM)    
25
+		
26
+	def Enter(self):
27
+		o = self.FSM.owner
28
+		o.header_text = "Load Sound"
29
+		o.pub.register("beat", self)
30
+		self.cur_el = 0
31
+		
32
+		self.press_ticks_up = None
33
+		self.press_ticks_down = None
34
+
35
+		self.menu = []
36
+
37
+		self.menu.append("..")
38
+		self.menu += self.get_file_list(o)
39
+
40
+
41
+		dirs = u.get_folders(o.load_sound_dir)
42
+		files = u.get_files(o.load_sound_dir, '.wav')
43
+
44
+		print('directory is ', o.load_sound_dir)
45
+		print('dirs are ', dirs)
46
+		print('files are ', files)
47
+
48
+
49
+		if o.last_load_sound_id != None and o.last_load_sound_id <= len(self.menu):
50
+			self.cur_el = o.last_load_sound_id
51
+			print('setting cur_el ', self.cur_el)
52
+		self.last_preview = None
53
+
54
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
55
+			pass
56
+		else:
57
+			u.draw_header(o)
58
+			self.draw_main(o)			
59
+			
60
+			o.update_display(0)
61
+		super(LoadSound, self).Enter()    
62
+
63
+	def Execute(self):
64
+		o = self.FSM.owner 
65
+		m.menu1_actions(self, o)
66
+		if o.keyState[16] == 1:
67
+			m.draw_menu1(o)
68
+			o.update_display(0)
69
+		elif o.keyState[16] == 4:
70
+			u.draw_header(o)
71
+			self.draw_footer(o)
72
+			self.draw_main(o)
73
+			o.update_display(0)
74
+
75
+		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
76
+			u.draw_header(o)
77
+			self.draw_footer(o)
78
+			self.draw_main(o)
79
+			o.update_display(0)				
80
+
81
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
82
+			pass
83
+		else:
84
+
85
+			since_up = 0		
86
+			if o.keyState[0] == 2:
87
+				if self.press_ticks_up == None:
88
+					self.press_ticks_up = pygame.time.get_ticks()
89
+				since_up = pygame.time.get_ticks() - self.press_ticks_up
90
+			else:
91
+				self.press_ticks_up = None
92
+				self.press_ticks_up = pygame.time.get_ticks()
93
+
94
+			if o.keyState[0] == 1 or since_up > 250:
95
+				if self.cur_el > 0:
96
+					self.cur_el -= 1
97
+					self.draw_main(o)
98
+					o.update_display(0)	
99
+					self.press_ticks_up = pygame.time.get_ticks()
100
+			
101
+			since_down = 0		
102
+			if o.keyState[1] == 2:
103
+				if self.press_ticks_down == None:
104
+					self.press_ticks_down = pygame.time.get_ticks()
105
+				since_down = pygame.time.get_ticks() - self.press_ticks_down
106
+			else:
107
+				self.press_ticks_down = None
108
+				self.press_ticks_down = pygame.time.get_ticks()
109
+
110
+			if o.keyState[1] == 1 or since_down > 250:
111
+				if self.cur_el < (len(self.menu) - 1):
112
+					self.cur_el += 1
113
+					self.draw_main(o)
114
+					o.update_display(0)	
115
+					self.press_ticks_down = pygame.time.get_ticks()
116
+
117
+			if o.keyState[2] == 1:
118
+				if self.is_wav():
119
+					if self.last_preview == self.menu[self.cur_el]:
120
+						pass
121
+					else:
122
+						snd = pygame.mixer.Sound(o.load_sound_dir + self.menu[self.cur_el])
123
+						pygame.mixer.Sound.play(snd) 
124
+
125
+			if o.keyState[3] == 1:
126
+				if self.menu[self.cur_el] == '..':
127
+					print('directory up')
128
+					o.last_load_sound_id = None
129
+					if o.load_sound_dir == '/home/pi/zpc_ct/user/sounds/':
130
+						print('root dir - cant go up')
131
+					else:
132
+						o.load_sound_dir = os.path.dirname(os.path.dirname(o.load_sound_dir))
133
+						o.load_sound_dir += '/'
134
+						print('new up dir is ', o.load_sound_dir)
135
+						self.menu = []
136
+						self.menu.append("..")
137
+						self.menu += self.get_file_list(o)
138
+						self.cur_el = 0
139
+
140
+				elif os.path.isdir(o.load_sound_dir + self.menu[self.cur_el]):
141
+					print('this is a directory ', o.load_sound_dir + self.menu[self.cur_el])
142
+					o.load_sound_dir = o.load_sound_dir + self.menu[self.cur_el] + '/'
143
+					self.menu = []
144
+					self.menu.append("..")
145
+					self.menu += self.get_file_list(o)
146
+					self.cur_el = 0
147
+
148
+				else:
149
+					print('this is not a directory ', o.load_sound_dir + self.menu[self.cur_el])
150
+					o.soundSlots[o.eSound].file = o.load_sound_dir + self.menu[self.cur_el]
151
+					o.soundSlots[o.eSound].volume = 16
152
+					o.soundSlots[o.eSound].pitch = 0
153
+					o.soundSlots[o.eSound].create_sound()
154
+					o.soundSlots[o.eSound].set_pitch()
155
+					o.last_load_sound_id = self.cur_el
156
+					self.FSM.ToTransition('toMain')
157
+
158
+	def get_file_list(self, o):
159
+		dirs = os.listdir(o.load_sound_dir)
160
+		dirs.sort()
161
+		for i in dirs:
162
+			if os.path.isdir(o.load_sound_dir + i):
163
+				i += "/asdfasdfasf"
164
+				print(i, ' is a directory')
165
+			else:
166
+				print(i, ' is not a directory')
167
+		print(dirs)
168
+		return dirs
169
+
170
+	def draw_main(self, o):
171
+		al = []
172
+		ypos = 30
173
+		if self.cur_el == 0:
174
+			_iter = 0
175
+			while len(al) < 4:
176
+				if _iter < len(self.menu):
177
+					al.append(self.menu[_iter])
178
+				else:
179
+					break
180
+				_iter += 1
181
+
182
+		elif self.cur_el == 1:
183
+			al.append(self.menu[self.cur_el - 1])
184
+			al.append(self.menu[self.cur_el])
185
+			if (self.cur_el + 1) < len(self.menu):
186
+				al.append(self.menu[self.cur_el + 1])
187
+			if (self.cur_el + 2) < len(self.menu):
188
+				al.append(self.menu[self.cur_el + 2])
189
+
190
+		elif self.cur_el == (len(self.menu) - 2):
191
+			al.append(self.menu[self.cur_el - 2])
192
+			al.append(self.menu[self.cur_el - 1])
193
+			al.append(self.menu[self.cur_el])
194
+			al.append(self.menu[self.cur_el + 1])
195
+
196
+		elif self.cur_el == (len(self.menu) - 1):
197
+			al.append(self.menu[self.cur_el - 3])
198
+			al.append(self.menu[self.cur_el - 2])
199
+			al.append(self.menu[self.cur_el - 1])
200
+			al.append(self.menu[self.cur_el])
201
+
202
+		else:
203
+			al.append(self.menu[self.cur_el - 1])
204
+			al.append(self.menu[self.cur_el])
205
+			al.append(self.menu[self.cur_el + 1])
206
+			al.append(self.menu[self.cur_el + 2])
207
+		
208
+		_iter = 0 
209
+		for i in al:
210
+
211
+			if i == self.menu[self.cur_el]:
212
+				if os.path.isdir(o.load_sound_dir + i):
213
+					i += "/"
214
+				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.light_grey)
215
+				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.blue)
216
+
217
+			else:
218
+				if os.path.isdir(o.load_sound_dir + i):
219
+					i += "/"
220
+				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.blue)
221
+				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.light_grey)
222
+
223
+			ypos += 20
224
+			_iter += 1		    
225
+
226
+	def draw_footer(self, o):
227
+		_iter = 0
228
+		width = o.width / 4
229
+		xpos = 0
230
+		yposa = 135 - 25
231
+		yposb = 135
232
+		opts = ["Up", "Down", "Play", "Open"]
233
+		while _iter < 4:
234
+
235
+			o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.blue)
236
+			if o.keyState[_iter] == 1:
237
+				o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.light_grey)
238
+				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.blue)
239
+			
240
+			else:
241
+				if _iter == 2:
242
+					if self.is_wav():
243
+						o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
244
+					else:
245
+						o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.dark_grey)	
246
+
247
+				else:
248
+					o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)	
249
+			
250
+			xpos += width
251
+			_iter += 1
252
+		
253
+	def is_wav(self):
254
+		if len(self.menu[self.cur_el]) > 3 and (self.menu[self.cur_el][-1] == 'V' or self.menu[self.cur_el][-1] == 'v') and (self.menu[self.cur_el][-2] == 'A' or self.menu[self.cur_el][-2] == 'a') and (self.menu[self.cur_el][-3] == 'W' or self.menu[self.cur_el][-3] == 'w'):
255
+			return True
256
+		else:
257
+			return False
258
+
259
+	def ReceiveMessage(self, message):
260
+		o = self.FSM.owner 
261
+		u.play_seq(o, message)
262
+		
263
+	def Exit(self):
264
+		self.FSM.owner.pub.unregister("beat", self)

+ 202
- 0
lib/sMain.py View File

@@ -0,0 +1,202 @@
1
+import FSM
2
+import utils as u
3
+import menus as m
4
+import pygame
5
+
6
+#====================================     
7
+
8
+State = type("State", (object,), {})
9
+#====================================     
10
+class State(object):
11
+	def __init__(self, FSM):
12
+		self.FSM = FSM
13
+	def Enter(self):
14
+		pass
15
+	def Execute(self):
16
+		pass
17
+	def Exit(self):
18
+		pass
19
+#====================================     
20
+			
21
+class Main(State):
22
+	def __init__(self,FSM):
23
+		super(Main, self).__init__(FSM)    
24
+		
25
+	def Enter(self):
26
+		print('hello main')
27
+		self.FSM.owner.pub.register("beat", self)
28
+		self.FSM.stateLife = 1
29
+		o = self.FSM.owner 
30
+		o.header_text = "Sound Select"
31
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
32
+			pass
33
+		else:
34
+			u.draw_header(o)
35
+			self.draw_square()
36
+
37
+			u.text_box1(o, "Vol", str(o.soundSlots[o.eSound].volume))
38
+			u.text_box2(o, "BPM", str(o.bpm))
39
+			u.text_box4(o, "Bank", str(o.note_bank))
40
+			u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
41
+			o.update_display(0)
42
+
43
+		self.recording = True
44
+		self.record_queue = []
45
+		self.undo_queue = []
46
+		o.erase = False
47
+		o.erase_queue = []
48
+		o.mute = False
49
+		o.mute_queue = []
50
+
51
+		super(Main, self).Enter()        
52
+		
53
+	def Execute(self):
54
+		o = self.FSM.owner 
55
+
56
+		m.menu1_actions(self, o)
57
+		m.menu2_actions_sample(self, o)
58
+		#self.FSM.ToTransition('toClock')
59
+		if o.keyState[16] == 1:
60
+			m.draw_menu1(o)
61
+			o.update_display(0)
62
+		elif o.keyState[16] == 4:
63
+			u.draw_header(o)
64
+			self.draw_square()
65
+			u.text_box1(o, "Vol", str(o.soundSlots[o.eSound].volume))
66
+			u.text_box2(o, "BPM", str(o.bpm))
67
+			u.text_box4(o, "Bank", str(o.note_bank))
68
+			u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
69
+			o.button_repeater(1, [])
70
+			o.update_display(0)
71
+
72
+		if o.keyState[17] == 1:
73
+			m.draw_menu2_sample(o)
74
+			o.update_display(0)
75
+		elif o.keyState[17] == 4:
76
+			u.draw_header(o)
77
+			self.draw_square()
78
+			u.text_box1(o, "Vol", str(o.soundSlots[o.eSound].volume))
79
+			u.text_box2(o, "BPM", str(o.bpm))
80
+			u.text_box4(o, "Bank", str(o.note_bank))
81
+			u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
82
+			o.update_display(0)
83
+
84
+		_id = 0
85
+		for k in o.keyState:
86
+			if _id > 15:
87
+				pass
88
+			else:
89
+				if o.keyState[16] > 0 or o.keyState[17] > 0:
90
+					pass
91
+				else:
92
+					note = _id + o.note_bank * 16
93
+					if k == 1:
94
+						
95
+						self.record_queue = pygame.time.get_ticks()
96
+						print('bpm is ', o.half_bpm, ' ', self.record_queue)
97
+						if not o.erase and not o.mute:
98
+							o.soundSlots[note].play(o.note_vol)
99
+						o.eSound = note
100
+						u.draw_header(o)
101
+						u.text_box1(o, "SVol", str(o.slots[o.eSound].volume))
102
+						u.text_box2(o, "BPM", str(o.bpm))
103
+						u.text_box4(o, "Bank", str(o.note_bank))
104
+						u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
105
+						self.draw_square()
106
+						o.update_display(0)
107
+						
108
+						if o.erase:
109
+							o.erase_buf.append(note)
110
+							print('adding to erase buf ', k)
111
+						if o.mute:
112
+							o.mute_buf.append(note)
113
+							print('adding to mute buf ', k)
114
+					if k == 3:
115
+						if note in o.erase_buf:
116
+							o.erase_buf.remove(note)
117
+							print('removing from erase buf ', note)
118
+
119
+						if note in o.mute_buf:
120
+							o.mute_buf.remove(note)
121
+							print('removing from mute buf ', note)
122
+			_id += 1
123
+
124
+	def ReceiveMessage(self, message):
125
+		o = self.FSM.owner 
126
+		if o.erase == True:
127
+			#print('do something to erase')
128
+			u.play_seq(o, message)
129
+		else:
130
+			u.play_seq(o, message)
131
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
132
+			pass
133
+		else:
134
+			u.draw_header(o)            
135
+			self.draw_square()   
136
+			u.text_box1(o, "SVol", str(o.soundSlots[o.eSound].volume))
137
+			u.text_box2(o, "BPM", str(o.bpm))
138
+			u.text_box4(o, "Bank", str(o.note_bank))
139
+			u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))			         
140
+			o.update_display(0)
141
+		if self.record_queue != []:
142
+			cur_time = pygame.time.get_ticks()
143
+			note_pos = (cur_time - self.record_queue) - (o.half_bpm / 2)
144
+			#print(note_pos)
145
+			if o.odub == True:
146
+				if note_pos > (o.half_bpm):
147
+					_note = 0
148
+					if message[1] == 0:
149
+						_note = 15
150
+					else:
151
+						_note = message[1] - 1
152
+					
153
+					if o.soundSlots[o.eSound].notes[message[0]][_note][0] != 1:
154
+						o.soundSlots[o.eSound].notes[message[0]][_note][0] = 1
155
+						o.soundSlots[o.eSound].notes[message[0]][_note][1] = o.note_vol
156
+						o.undo_buf.append([o.eSound, message[0], _note])
157
+						print(o.undo_buf)
158
+
159
+				else:
160
+					if o.soundSlots[o.eSound].notes[message[0]][message[1]][0] != 1:
161
+						o.soundSlots[o.eSound].notes[message[0]][message[1]][0] = 1
162
+						o.soundSlots[o.eSound].notes[message[0]][message[1]][1] = o.note_vol
163
+						o.undo_buf.append([o.eSound, message[0], message[1]])
164
+						print(o.undo_buf)
165
+
166
+		self.record_queue = []
167
+
168
+	
169
+	def draw_square(self):
170
+		o = self.FSM.owner 
171
+		size = 22
172
+		og_x = (o.width / 2) - (size * 2)
173
+		o_x = og_x
174
+		o_y = 127
175
+		_id = o.note_bank * 16 
176
+	
177
+		while _id < ((o.note_bank * 16) + 16):
178
+			if _id == o.eSound:
179
+				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.light_grey, width=1)
180
+			elif o.notes_on[_id] == 1:
181
+				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.grey, width=1)
182
+			elif self.has_sample(o, _id) == False:
183
+				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.dark_grey, width=1)
184
+
185
+
186
+			else:
187
+				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.blue, width=1)
188
+			o_x = o_x + size
189
+			_id += 1
190
+			if _id % 4 == 0:
191
+				o_y -= size
192
+				o_x = og_x
193
+
194
+	def has_sample(self, o, slot):
195
+		if o.soundSlots[slot].file != None:
196
+			return True
197
+		else:
198
+			return False
199
+
200
+	def Exit(self):
201
+		self.FSM.owner.pub.unregister("beat", self)
202
+

+ 222
- 0
lib/sNewDir.py View File

@@ -0,0 +1,222 @@
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
+import os
9
+#====================================     
10
+
11
+State = type("State", (object,), {})
12
+#====================================     
13
+class State(object):
14
+	def __init__(self, FSM):
15
+		self.FSM = FSM
16
+	def Enter(self):
17
+		pass
18
+	def Execute(self):
19
+		pass
20
+	def Exit(self):
21
+		pass
22
+
23
+class NewDir(State):
24
+	def __init__(self,FSM):
25
+		super(NewDir, self).__init__(FSM)    
26
+		
27
+	def Enter(self):
28
+		o = self.FSM.owner 
29
+	
30
+		m.menu1_actions(self, o)
31
+		if o.keyState[16] == 1:
32
+			m.draw_menu1(o)
33
+			o.update_display(0)
34
+		elif o.keyState[16] == 4:
35
+			#u.draw_header(o)
36
+			#self.draw_footer(o)
37
+			self.draw(o)
38
+			o.update_display(0)
39
+		self.input_string = ""
40
+		if o.sconf['title'] == 'blank':
41
+
42
+			self.input_string += 'new_folder' + str(datetime.today().strftime('%Y%m%d'))
43
+		else:
44
+
45
+			self.input_string += o.sconf['title']
46
+		#if 
47
+		o.header_text = "EnterText"
48
+		o.pub.register("beat", self)
49
+		self.last_action = pygame.time.get_ticks()
50
+		self.caps = False
51
+		self.cur_but = 18
52
+		self.cur_letter = ""
53
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
54
+			pass
55
+		else:
56
+			pass
57
+
58
+		self.skips = [7, 3, 11, 12, 13, 14, 15]
59
+		
60
+		self.lc_labels = [["p", "q", "r", "s"], ["t", "u", "v"], ["w", "x", "y", "z"], ["C", "A", "P", "S"], 
61
+				["g", "h", "i"], ["j", "k", "l"], ["m", "n", "o"], ["D", "E", "L"],
62
+				["_", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-"], ["a", "b", "c"], ["d", "e", "f"], ["O", "K"],
63
+				[], [], [], []]
64
+
65
+		self.uc_labels = [["P", "Q", "R", "S"], ["T", "U", "V"], ["W", "X", "Y", "Z"], ["C", "A", "P", "S"], 
66
+				["G", "H", "I"], ["J", "K", "L"], ["M", "N", "O"], ["D", "E", "L"],
67
+				["_", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-"], ["A", "B", "C"], ["D", "E", "F"], ["O", "K"],
68
+				[], [], [], []]
69
+
70
+		self.labels = self.lc_labels
71
+
72
+		#self.songCycle = cycle(self.song)
73
+		#self.curPattern = next(self.songCycle)
74
+
75
+		self.cycles = []
76
+		for l in self.labels:
77
+			self.cycles.append(cycle(l))
78
+
79
+
80
+
81
+		self.draw(o)
82
+		o.update_display(0)
83
+		super(NewDir, self).Enter()        
84
+		
85
+	def Execute(self):
86
+		o = self.FSM.owner 
87
+
88
+		y_size = o.height / 4
89
+		if o.keyState[11] == 1:
90
+			if self.input_string != 'blank':
91
+				#o.title = self.input_string
92
+				#o.bpm = o.sconf['bpm']
93
+				#o.sconf['title'] = self.input_string
94
+				np = o.song_dir + '/' + self.input_string
95
+				os.mkdir(np)
96
+				print('fsm new dir ', np)
97
+				#o.save_song()
98
+				self.FSM.ToTransition('toEnterText')	
99
+
100
+		m.menu1_actions(self, o)
101
+		m.menu2_actions_saveas(self, o)
102
+		if o.keyState[16] == 1:
103
+			m.draw_menu1(o)
104
+			o.update_display(0)
105
+		elif o.keyState[16] == 4:
106
+			u.draw_header(o)
107
+			self.draw(o)
108
+			#self.draw_main(o)
109
+			o.update_display(0)
110
+
111
+		if o.keyState[17] == 1:
112
+			m.draw_menu_saveas(o)
113
+			o.update_display(0)
114
+		elif o.keyState[17] == 4:
115
+			u.draw_header(o)
116
+			self.draw(o)
117
+			#self.draw_main(o)
118
+			o.update_display(0)
119
+
120
+		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
121
+			u.draw_header(o)
122
+			self.draw(o)
123
+			#self.draw_main(o)
124
+			o.update_display(0)	
125
+			
126
+
127
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
128
+			pass
129
+
130
+		else:
131
+			_iter = 0
132
+			for k in o.keyState:
133
+				if k == 1:
134
+					cur_time = pygame.time.get_ticks()
135
+					print(cur_time - self.last_action)
136
+					
137
+					#print('cur letter ', next(self.cycles[_iter]))
138
+					if _iter not in self.skips:
139
+						self.last_action = cur_time
140
+						if _iter < len(self.cycles):
141
+							self.cur_letter = next(self.cycles[_iter])
142
+							self.cur_but = _iter
143
+							self.draw(o)
144
+							o.center_block(self.input_string + self.cur_letter, o.h2, [0, 0, o.width, y_size], o.light_grey)
145
+
146
+					if _iter == 7:
147
+						
148
+						self.input_string = self.input_string[:-1]
149
+						#self.input_string = self.input_string.rstrip(self.input_string[-1])
150
+						print('deleting')
151
+						self.last_action = 100000000
152
+						self.draw(o)
153
+						o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
154
+
155
+					elif _iter == 3:
156
+						print('caps')
157
+						if self.caps:
158
+							self.caps = False
159
+							self.labels = self.lc_labels
160
+
161
+						else:
162
+							self.caps = True
163
+							self.labels = self.uc_labels
164
+						self.draw(o)
165
+						o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
166
+						self.cycles = []
167
+						for l in self.labels:
168
+							self.cycles.append(cycle(l))
169
+
170
+					o.update_display(0)
171
+				_iter += 1
172
+
173
+		cur_time = pygame.time.get_ticks()
174
+		delay = cur_time - self.last_action
175
+		if delay > 1000 and delay < 100000:
176
+			self.input_string += self.cur_letter
177
+			self.last_action = 100000000
178
+			self.reset_cycles()
179
+			self.draw(o)
180
+
181
+			o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
182
+			o.update_display(0)
183
+	
184
+	def ReceiveMessage(self, message):
185
+		o = self.FSM.owner 
186
+		u.play_seq(o, message)
187
+
188
+	def draw(self, o):
189
+		x_size = o.width / 4
190
+		y_size = o.height / 4
191
+		og_x = 0
192
+		o_x = og_x
193
+		o_y = o.height
194
+		text_padding = 6
195
+		
196
+		_id = 0
197
+		while _id < 16:
198
+			lab = ""
199
+			for i in self.labels[_id]:
200
+				lab += i
201
+
202
+			if _id == 8:
203
+				lab = "_12"
204
+
205
+			o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.blue)
206
+			o.center_block(lab, o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
207
+
208
+			o_x = o_x + x_size
209
+			_id += 1
210
+			if _id % 4 == 0:
211
+				o_y -= y_size
212
+				o_x = og_x
213
+		o.draw.rectangle((0, 0, o.width, y_size), outline=0, fill=o.blue)
214
+		
215
+	def reset_cycles(self):
216
+		self.cycles = []
217
+		for l in self.labels:
218
+			self.cycles.append(cycle(l))
219
+
220
+	def Exit(self):
221
+		self.FSM.owner.pub.unregister("beat", self)        
222
+

+ 260
- 0
lib/sOpenSong.py View File

@@ -0,0 +1,260 @@
1
+import FSM
2
+import utils as u
3
+import menus as m
4
+import pygame
5
+from itertools import cycle
6
+import glob
7
+import os
8
+
9
+#====================================     
10
+
11
+State = type("State", (object,), {})
12
+#====================================     
13
+class State(object):
14
+	def __init__(self, FSM):
15
+		self.FSM = FSM
16
+	def Enter(self):
17
+		pass
18
+	def Execute(self):
19
+		pass
20
+	def Exit(self):
21
+		pass
22
+
23
+class OpenSong(State):
24
+	def __init__(self,FSM):
25
+		super(OpenSong, self).__init__(FSM)    
26
+		
27
+	def Enter(self):
28
+		o = self.FSM.owner
29
+		o.header_text = "Open Song"
30
+		o.pub.register("beat", self)
31
+		self.cur_el = 0
32
+		self.globbed = glob.glob('/home/pi/zpc_ct/user/songs/*.sng')
33
+		self.globbed.sort()
34
+		files = u.get_files(o.song_dir, '.sng')
35
+		print('---new')
36
+		print(files)
37
+		files_trimmed = [os.path.basename(x) for x in files]
38
+		files_trimmed = [os.path.splitext(x)[0] for x in files_trimmed]
39
+		print('files trimmed ', files_trimmed)
40
+		if '/home/pi/zpc_ct/user/songs/_blank.sng' in self.globbed:
41
+			self.globbed.remove('/home/pi/zpc_ct/user/songs/_blank.sng')
42
+		#del self.globbed[0]
43
+		self.names = [os.path.basename(x) for x in self.globbed]
44
+		self.names = [os.path.splitext(x)[0] for x in self.names]
45
+		print('we got these songs ', self.names)
46
+		print('in these paths ', self.globbed)
47
+		
48
+		#go to last selected
49
+		# if o.mconf['default_song'] in self.names:
50
+		# 	_id = self.names.index(o.mconf['default_song'])
51
+		# 	self.cur_el = _id
52
+		# else:
53
+		# 	print('nope ', o.mconf['default_song'], ' - ', self.globbed)
54
+
55
+		self.menu = self.names
56
+		files_trimmed.insert(0, '..')
57
+		self.menu = files_trimmed
58
+		if '_blank' in self.menu:
59
+			self.menu.remove('_blank')
60
+
61
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
62
+			pass
63
+		else:
64
+			u.draw_header(o)
65
+			self.draw_main(o)			
66
+			
67
+			o.update_display(0)
68
+		super(OpenSong, self).Enter()    
69
+
70
+	def Execute(self):
71
+		o = self.FSM.owner 
72
+		m.menu1_actions(self, o)
73
+		if o.keyState[16] == 1:
74
+			m.draw_menu1(o)
75
+			o.update_display(0)
76
+		elif o.keyState[16] == 4:
77
+			u.draw_header(o)
78
+			self.draw_footer(o)
79
+			self.draw_main(o)
80
+			o.update_display(0)
81
+
82
+		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
83
+			u.draw_header(o)
84
+			self.draw_footer(o)
85
+			self.draw_main(o)
86
+			o.update_display(0)	
87
+			
88
+
89
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
90
+			pass
91
+		else:
92
+			if o.keyState[0] == 1:
93
+				if self.cur_el > 0:
94
+					self.cur_el -= 1
95
+					# o.mconf['theme'] = self.menu[self.cur_el]					
96
+					# o.save_config()
97
+					# o.load_config()
98
+					# o.apply_theme()
99
+					print('cur el down is ', self.cur_el)
100
+
101
+					#o.applyTheme
102
+			if o.keyState[1] == 1:
103
+				if self.cur_el < (len(self.menu) - 1):
104
+					self.cur_el += 1
105
+					# o.mconf['theme'] = self.menu[self.cur_el]					
106
+					# o.save_config()
107
+					# o.load_config()
108
+					# o.apply_theme()
109
+					print('cur el up is ', self.cur_el)
110
+					#print('loading theme ', self.menu[self.cur_el], '-- ', o.mconf['theme'])
111
+			if o.keyState[3] == 1:
112
+				#open_command(self, o, self.menu[self.cur_el])
113
+				if self.menu[self.cur_el] == '..':
114
+					print('move up dir')
115
+					if o.song_dir == o.base_song_dir:
116
+						print('what the fuck')
117
+					else:
118
+						print('old song dir ', o.song_dir)
119
+						o.song_dir = os.path.dirname(os.path.dirname(o.song_dir))
120
+						o.song_dir += '/'
121
+						print('new song dir ', o.song_dir)
122
+						files = u.get_files(o.song_dir, '.sng')
123
+						print('---new')
124
+						print(files)
125
+						files_trimmed = [os.path.basename(x) for x in files]
126
+						files_trimmed = [os.path.splitext(x)[0] for x in files_trimmed]
127
+						print('files trimmed ', files_trimmed)
128
+
129
+						#self.names = [os.path.basename(x) for x in self.globbed]
130
+						#self.names = [os.path.splitext(x)[0] for x in self.names]
131
+
132
+						#self.menu = self.names
133
+						files_trimmed.insert(0, '..')
134
+						self.menu = files_trimmed		
135
+						if '_blank' in self.menu:
136
+							self.menu.remove('_blank')
137
+						u.draw_header(o)
138
+						
139
+						self.draw_footer(o)
140
+						self.draw_main(o)
141
+						o.update_display(0)			
142
+
143
+				elif os.path.isdir(o.song_dir + self.menu[self.cur_el]):
144
+					o.song_dir += self.menu[self.cur_el] + '/'
145
+					print('new song dir is ', o.song_dir)
146
+					
147
+					files = u.get_files(o.song_dir, '.sng')
148
+					print('---new')
149
+					print(files)
150
+					files_trimmed = [os.path.basename(x) for x in files]
151
+					files_trimmed = [os.path.splitext(x)[0] for x in files_trimmed]
152
+					print('files trimmed ', files_trimmed)
153
+
154
+					self.names = [os.path.basename(x) for x in self.globbed]
155
+					self.names = [os.path.splitext(x)[0] for x in self.names]
156
+
157
+					self.menu = self.names
158
+					files_trimmed.insert(0, '..')
159
+					self.menu = files_trimmed		
160
+					if '_blank' in self.menu:
161
+						self.menu.remove('_blank')
162
+					u.draw_header(o)
163
+					
164
+					self.draw_footer(o)
165
+					self.draw_main(o)
166
+					o.update_display(0)			
167
+
168
+				else:
169
+					o.mconf['default_song'] = self.menu[self.cur_el]
170
+					o.save_config()
171
+					o.load_song()
172
+
173
+	def draw_main(self, o):
174
+		al = []
175
+		ypos = 30
176
+
177
+
178
+		print('cur el ', self.cur_el)
179
+		if self.cur_el > (len(self.menu) - 1):
180
+			self.cur_el = 0
181
+		if self.cur_el == 0:
182
+			_iter = 0
183
+			while _iter < 4:
184
+				if _iter < (len(self.menu)):
185
+					al.append(self.menu[_iter])
186
+				
187
+				_iter += 1
188
+
189
+
190
+		
191
+		# print('cur el ', self.cur_el)
192
+		# if self.cur_el == 0:
193
+		# 	_iter = 0
194
+		# 	while len(al) < 4:
195
+		# 		al.append(self.menu[_iter])
196
+		# 		_iter += 1
197
+		elif self.cur_el == 1:
198
+			al.append(self.menu[self.cur_el - 1])
199
+			al.append(self.menu[self.cur_el])
200
+			al.append(self.menu[self.cur_el + 1])
201
+			al.append(self.menu[self.cur_el + 2])
202
+		elif self.cur_el == (len(self.menu) - 2):
203
+			al.append(self.menu[self.cur_el - 2])
204
+			al.append(self.menu[self.cur_el - 1])
205
+			al.append(self.menu[self.cur_el])
206
+			al.append(self.menu[self.cur_el + 1])
207
+		elif self.cur_el == (len(self.menu) - 1):
208
+			al.append(self.menu[self.cur_el - 3])
209
+			al.append(self.menu[self.cur_el - 2])
210
+			al.append(self.menu[self.cur_el - 1])
211
+			al.append(self.menu[self.cur_el])
212
+		else:
213
+			al.append(self.menu[self.cur_el - 1])
214
+			al.append(self.menu[self.cur_el])
215
+			al.append(self.menu[self.cur_el + 1])
216
+			al.append(self.menu[self.cur_el + 2])
217
+		_iter = 0 
218
+		for i in al:
219
+			
220
+			if i == self.menu[self.cur_el]:
221
+			#if _iter == self.cur_el:
222
+				if os.path.isdir(o.song_dir + i):
223
+					i += "/"
224
+				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.light_grey)
225
+				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.blue)
226
+			else:
227
+				if os.path.isdir(o.song_dir + i):
228
+					i += "/"
229
+				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.blue)
230
+				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.light_grey)
231
+			ypos += 20
232
+			_iter += 1		    
233
+
234
+	def draw_footer(self, o):
235
+		_iter = 0
236
+		width = o.width / 4
237
+		xpos = 0
238
+		yposa = 135 - 25
239
+		yposb = 135
240
+		opts = ["Up", "Down", "Esc", "Open"]
241
+		while _iter < 4:
242
+			o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.blue)
243
+			
244
+			if o.keyState[_iter] == 1:
245
+				o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.light_grey)
246
+				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.blue)
247
+			else:
248
+				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
249
+			
250
+			xpos += width
251
+			_iter += 1
252
+		
253
+
254
+	def ReceiveMessage(self, message):
255
+		o = self.FSM.owner 
256
+		u.play_seq(o, message)
257
+		
258
+	def Exit(self):
259
+		self.FSM.owner.pub.unregister("beat", self)
260
+

+ 76
- 0
lib/sPing.py View File

@@ -0,0 +1,76 @@
1
+import FSM
2
+import utils as u
3
+import menus as m
4
+import os
5
+#import socket 
6
+#====================================     
7
+
8
+State = type("State", (object,), {})
9
+#====================================     
10
+class State(object):
11
+	def __init__(self, FSM):
12
+		self.FSM = FSM
13
+	def Enter(self):
14
+		pass
15
+	def Execute(self):
16
+		pass
17
+	def Exit(self):
18
+		pass
19
+
20
+
21
+
22
+class Ping(State):
23
+	def __init__(self,FSM):
24
+		super(Ping, self).__init__(FSM)    
25
+		
26
+	def Enter(self):
27
+		o = self.FSM.owner
28
+		o.header_text = "Ping"
29
+		o.pub.register("beat", self)
30
+		self.pinging = self.check_ping()
31
+		self.draw_main(o)
32
+		u.draw_header(o)
33
+		o.update_display(0)
34
+		super(Ping, self).Enter()        
35
+		
36
+	def Execute(self):
37
+		o = self.FSM.owner 
38
+		m.menu1_actions(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_footer(o)
45
+			self.draw_main(o)
46
+			o.update_display(0)
47
+
48
+		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
49
+			u.draw_header(o)
50
+			#self.draw_footer(o)
51
+			self.draw_main(o)
52
+			o.update_display(0)	
53
+			
54
+		
55
+	def draw_main(self, o):
56
+		o.center_block(self.pinging, o.h2, [0, 0, o.width, o.height], o.light_grey)
57
+
58
+	def check_ping(self):
59
+		hostname = "8.8.8.8"
60
+		response = os.system("ping -c 1 " + hostname)
61
+		# and then check the response...
62
+		if response == 0:
63
+			pingstatus = "Network Active "
64
+		else:
65
+			pingstatus = "Network Error "
66
+
67
+		return pingstatus
68
+
69
+	def ReceiveMessage(self, message):
70
+		o = self.FSM.owner 
71
+		u.play_seq(o, message)
72
+
73
+	def Exit(self):
74
+		self.FSM.owner.pub.unregister("beat", self)
75
+
76
+#==================================== 

+ 43
- 0
lib/sReboot.py View File

@@ -0,0 +1,43 @@
1
+import FSM
2
+import utils as u
3
+import menus as m
4
+import os
5
+import pygame
6
+import sys
7
+#====================================     
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
+
21
+
22
+class Reboot(State):
23
+	def __init__(self,FSM):
24
+		super(Reboot, self).__init__(FSM)    
25
+		
26
+	def Enter(self):
27
+		o = self.FSM.owner
28
+		o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)			
29
+		o.center_block("rebooting", o.h2, [0, 0, o.width,o.height], o.light_grey)
30
+		o.update_display(0)
31
+		command = 'bash -c "sleep 5; sudo shutdown -r now"&'
32
+		os.system(command)
33
+		pygame.quit()
34
+		sys.exit()
35
+		super(Reboot, self).Enter()        
36
+		
37
+	def Execute(self):
38
+		pass
39
+		#self.FSM.stateLife += 1
40
+		#os.system('sudo shutdown -r now')
41
+		
42
+	def Exit(self):
43
+		pass

+ 167
- 0
lib/sSelTheme.py View File

@@ -0,0 +1,167 @@
1
+import FSM
2
+import utils as u
3
+import menus as m
4
+import pygame
5
+#from itertools import cycle
6
+import glob
7
+import os
8
+
9
+#====================================     
10
+
11
+State = type("State", (object,), {})
12
+#====================================     
13
+class State(object):
14
+	def __init__(self, FSM):
15
+		self.FSM = FSM
16
+	def Enter(self):
17
+		pass
18
+	def Execute(self):
19
+		pass
20
+	def Exit(self):
21
+		pass
22
+
23
+class SelTheme(State):
24
+	def __init__(self,FSM):
25
+		super(SelTheme, self).__init__(FSM)    
26
+		
27
+	def Enter(self):
28
+		o = self.FSM.owner
29
+		o.header_text = "Select Theme"
30
+		o.pub.register("beat", self)
31
+		self.cur_el = 0
32
+		self.globbed = glob.glob('/home/pi/zpc_ct/user/themes/*.thm')
33
+		self.globbed.sort()
34
+		self.names = [os.path.basename(x) for x in self.globbed]
35
+		self.names = [os.path.splitext(x)[0] for x in self.names]
36
+		if o.mconf['theme'] in self.names:
37
+			_id = self.names.index(o.mconf['theme'])
38
+			self.cur_el = _id
39
+			#print('found theme ', _id)
40
+		else:
41
+			print('nope ', o.mconf['theme'], ' - ', self.globbed)
42
+		#self.theme = ConfigObj("/home/pi/zpc_ct/themes/" + self.mconf['theme'])
43
+		#print(os.path.splitext(x)[0])
44
+		self.menu = self.names
45
+
46
+		#self.cur_el = 0
47
+		print('theme menu is ', self.menu)
48
+
49
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
50
+			pass
51
+		else:
52
+			u.draw_header(o)
53
+			self.draw_main(o)			
54
+			
55
+			o.update_display(0)
56
+		super(SelTheme, self).Enter()    
57
+
58
+	def Execute(self):
59
+		o = self.FSM.owner 
60
+		m.menu1_actions(self, o)
61
+		if o.keyState[16] == 1:
62
+			m.draw_menu1(o)
63
+			o.update_display(0)
64
+		elif o.keyState[16] == 4:
65
+			u.draw_header(o)
66
+			self.draw_footer(o)
67
+			self.draw_main(o)
68
+			o.update_display(0)
69
+
70
+		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
71
+			u.draw_header(o)
72
+			self.draw_footer(o)
73
+			self.draw_main(o)
74
+			o.update_display(0)	
75
+			print('draw butt')				
76
+
77
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
78
+			pass
79
+		else:
80
+			if o.keyState[0] == 1:
81
+				if self.cur_el > 0:
82
+					self.cur_el -= 1
83
+					o.mconf['theme'] = self.menu[self.cur_el]					
84
+					o.save_config()
85
+					o.load_config()
86
+					o.apply_theme()
87
+					print('cur el down is ', self.cur_el)
88
+
89
+					#o.applyTheme
90
+			if o.keyState[1] == 1:
91
+				if self.cur_el < (len(self.menu) - 1):
92
+					self.cur_el += 1
93
+					o.mconf['theme'] = self.menu[self.cur_el]					
94
+					o.save_config()
95
+					o.load_config()
96
+					o.apply_theme()
97
+					print('cur el up is ', self.cur_el)
98
+					print('loading theme ', self.menu[self.cur_el], '-- ', o.mconf['theme'])
99
+			if o.keyState[3] == 1:
100
+				m.util_command(self, o, self.menu[self.cur_el])
101
+
102
+	def draw_main(self, o):
103
+		al = []
104
+		ypos = 30
105
+		if self.cur_el == 0:
106
+			_iter = 0
107
+			while len(al) < 4:
108
+				al.append(self.menu[_iter])
109
+				_iter += 1
110
+		elif self.cur_el == 1:
111
+			al.append(self.menu[self.cur_el - 1])
112
+			al.append(self.menu[self.cur_el])
113
+			al.append(self.menu[self.cur_el + 1])
114
+			al.append(self.menu[self.cur_el + 2])
115
+		elif self.cur_el == (len(self.menu) - 2):
116
+			al.append(self.menu[self.cur_el - 2])
117
+			al.append(self.menu[self.cur_el - 1])
118
+			al.append(self.menu[self.cur_el])
119
+			al.append(self.menu[self.cur_el + 1])
120
+		elif self.cur_el == (len(self.menu) - 1):
121
+			al.append(self.menu[self.cur_el - 3])
122
+			al.append(self.menu[self.cur_el - 2])
123
+			al.append(self.menu[self.cur_el - 1])
124
+			al.append(self.menu[self.cur_el])
125
+		else:
126
+			al.append(self.menu[self.cur_el - 1])
127
+			al.append(self.menu[self.cur_el])
128
+			al.append(self.menu[self.cur_el + 1])
129
+			al.append(self.menu[self.cur_el + 2])
130
+		_iter = 0 
131
+		for i in al:
132
+			if i == self.menu[self.cur_el]:
133
+			#if _iter == self.cur_el:
134
+				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.light_grey)
135
+				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.blue)
136
+			else:
137
+				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.blue)
138
+				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.light_grey)
139
+			ypos += 20
140
+			_iter += 1		    
141
+
142
+	def draw_footer(self, o):
143
+		_iter = 0
144
+		width = o.width / 4
145
+		xpos = 0
146
+		yposa = 135 - 25
147
+		yposb = 135
148
+		opts = ["Up", "Down", "", ""]
149
+		while _iter < 4:
150
+			o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.blue)
151
+			
152
+			if o.keyState[_iter] == 1:
153
+				o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.light_grey)
154
+				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.blue)
155
+			else:
156
+				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
157
+			
158
+			xpos += width
159
+			_iter += 1
160
+		
161
+
162
+	def ReceiveMessage(self, message):
163
+		o = self.FSM.owner 
164
+		u.play_seq(o, message)
165
+		
166
+	def Exit(self):
167
+		self.FSM.owner.pub.unregister("beat", self)

+ 224
- 0
lib/sSelectFolder.py View File

@@ -0,0 +1,224 @@
1
+import FSM
2
+import utils as u
3
+import menus as m
4
+import pygame
5
+from itertools import cycle
6
+import glob
7
+import os
8
+
9
+#====================================     
10
+
11
+State = type("State", (object,), {})
12
+#====================================     
13
+class State(object):
14
+	def __init__(self, FSM):
15
+		self.FSM = FSM
16
+	def Enter(self):
17
+		pass
18
+	def Execute(self):
19
+		pass
20
+	def Exit(self):
21
+		pass
22
+
23
+class SelectFolder(State):
24
+	def __init__(self,FSM):
25
+		super(SelectFolder, self).__init__(FSM)    
26
+		
27
+	def Enter(self):
28
+		o = self.FSM.owner
29
+		o.header_text = "Select Folder"
30
+		o.pub.register("beat", self)
31
+		self.cur_el = 0
32
+		
33
+		files = u.get_files(o.song_dir, '.zzz')
34
+		files_trimmed = [os.path.basename(x) for x in files]
35
+		files_trimmed = [os.path.splitext(x)[0] for x in files_trimmed]
36
+		print('files trimmed ', files_trimmed)
37
+		files_trimmed.insert(0, '..')
38
+		self.menu = files_trimmed
39
+		if '_blank' in self.menu:
40
+			self.menu.remove('_blank')
41
+
42
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
43
+			pass
44
+		else:
45
+			u.draw_header(o)
46
+			self.draw_main(o)			
47
+			
48
+			o.update_display(0)
49
+		super(SelectFolder, self).Enter()    
50
+
51
+	def Execute(self):
52
+
53
+		#print('doing select folder')
54
+		o = self.FSM.owner 
55
+		#u.draw_header(o)
56
+		#o.update_display(0)
57
+		m.menu1_actions(self, o)
58
+		if o.keyState[16] == 1:
59
+			m.draw_menu1(o)
60
+			o.update_display(0)
61
+		elif o.keyState[16] == 4:
62
+			u.draw_header(o)
63
+			self.draw_footer(o)
64
+			self.draw_main(o)
65
+			o.update_display(0)
66
+
67
+		if o.keyState[17] == 4:
68
+			u.draw_header(o)
69
+			self.draw_footer(o)
70
+			self.draw_main(o)
71
+			o.update_display(0)
72
+
73
+		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
74
+			u.draw_header(o)
75
+			self.draw_footer(o)
76
+			self.draw_main(o)
77
+			o.update_display(0)	
78
+			
79
+
80
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
81
+
82
+			pass
83
+		else:
84
+			if o.keyState[0] == 1:
85
+				if self.cur_el > 0:
86
+					self.cur_el -= 1
87
+					print('cur el down is ', self.cur_el)
88
+
89
+			if o.keyState[1] == 1:
90
+				if self.cur_el < (len(self.menu) - 1):
91
+					self.cur_el += 1
92
+					print('cur el up is ', self.cur_el)
93
+
94
+			if o.keyState[2] == 1:
95
+				print('old song dir is ', o.song_dir)
96
+				print('new song dir is ', self.menu[self.cur_el])
97
+				self.FSM.ToTransition('toEnterText')
98
+
99
+			if o.keyState[3] == 1:
100
+				if self.menu[self.cur_el] == '..':
101
+					print('move up dir')
102
+					if o.song_dir == o.base_song_dir:
103
+						pass
104
+					else:
105
+						print('old song dir ', o.song_dir)
106
+						o.song_dir = os.path.dirname(os.path.dirname(o.song_dir))
107
+						o.song_dir += '/'
108
+						print('new song dir ', o.song_dir)
109
+						files = u.get_files(o.song_dir, '.zzz')
110
+						files_trimmed = [os.path.basename(x) for x in files]
111
+						files_trimmed = [os.path.splitext(x)[0] for x in files_trimmed]
112
+						print('files trimmed ', files_trimmed)
113
+						files_trimmed.insert(0, '..')
114
+						self.menu = files_trimmed
115
+						if '_blank' in self.menu:
116
+							self.menu.remove('_blank')
117
+						u.draw_header(o)
118
+						
119
+						self.draw_footer(o)
120
+						self.draw_main(o)
121
+						o.update_display(0)			
122
+
123
+				elif os.path.isdir(o.song_dir + self.menu[self.cur_el]):
124
+					o.song_dir += self.menu[self.cur_el] + '/'
125
+					print('new song dir is ', o.song_dir)
126
+					
127
+					files = u.get_files(o.song_dir, '.zzz')
128
+					files_trimmed = [os.path.basename(x) for x in files]
129
+					files_trimmed = [os.path.splitext(x)[0] for x in files_trimmed]
130
+					print('files trimmed ', files_trimmed)
131
+					files_trimmed.insert(0, '..')
132
+					self.menu = files_trimmed
133
+					if '_blank' in self.menu:
134
+						self.menu.remove('_blank')
135
+					u.draw_header(o)
136
+					
137
+					self.draw_footer(o)
138
+					self.draw_main(o)
139
+					o.update_display(0)			
140
+
141
+				else:
142
+					pass
143
+					#o.mconf['default_song'] = self.menu[self.cur_el]
144
+					#o.save_config()
145
+					#o.load_song()
146
+
147
+	def draw_main(self, o):
148
+		al = []
149
+		ypos = 30
150
+		print('cur el ', self.cur_el)
151
+		if self.cur_el > (len(self.menu) - 1):
152
+			self.cur_el = 0
153
+		if self.cur_el == 0:
154
+			_iter = 0
155
+			while _iter < 4:
156
+				if _iter < (len(self.menu)):
157
+					al.append(self.menu[_iter])
158
+				
159
+				_iter += 1
160
+		elif self.cur_el == 1:
161
+			al.append(self.menu[self.cur_el - 1])
162
+			al.append(self.menu[self.cur_el])
163
+			al.append(self.menu[self.cur_el + 1])
164
+			al.append(self.menu[self.cur_el + 2])
165
+		elif self.cur_el == (len(self.menu) - 2):
166
+			al.append(self.menu[self.cur_el - 2])
167
+			al.append(self.menu[self.cur_el - 1])
168
+			al.append(self.menu[self.cur_el])
169
+			al.append(self.menu[self.cur_el + 1])
170
+		elif self.cur_el == (len(self.menu) - 1):
171
+			al.append(self.menu[self.cur_el - 3])
172
+			al.append(self.menu[self.cur_el - 2])
173
+			al.append(self.menu[self.cur_el - 1])
174
+			al.append(self.menu[self.cur_el])
175
+		else:
176
+			al.append(self.menu[self.cur_el - 1])
177
+			al.append(self.menu[self.cur_el])
178
+			al.append(self.menu[self.cur_el + 1])
179
+			al.append(self.menu[self.cur_el + 2])
180
+		_iter = 0 
181
+		for i in al:
182
+			
183
+			if i == self.menu[self.cur_el]:
184
+			#if _iter == self.cur_el:
185
+				if os.path.isdir(o.song_dir + i):
186
+					i += "/"
187
+				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.light_grey)
188
+				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.blue)
189
+			else:
190
+				if os.path.isdir(o.song_dir + i):
191
+					i += "/"
192
+				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.blue)
193
+				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.light_grey)
194
+			ypos += 20
195
+			_iter += 1		    
196
+
197
+	def draw_footer(self, o):
198
+		_iter = 0
199
+		width = o.width / 4
200
+		xpos = 0
201
+		yposa = 135 - 25
202
+		yposb = 135
203
+		opts = ["Up", "Down", "Use", "Open"]
204
+		while _iter < 4:
205
+			o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.blue)
206
+			
207
+			if o.keyState[_iter] == 1:
208
+				o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.light_grey)
209
+				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.blue)
210
+			else:
211
+				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
212
+			
213
+			xpos += width
214
+			_iter += 1
215
+		
216
+
217
+	def ReceiveMessage(self, message):
218
+		o = self.FSM.owner 
219
+		u.play_seq(o, message)
220
+		
221
+	def Exit(self):
222
+		print('why the fuck are we leaving')
223
+		self.FSM.owner.pub.unregister("beat", self)
224
+

+ 158
- 0
lib/sSelectPattern.py View File

@@ -0,0 +1,158 @@
1
+import FSM
2
+import utils as u
3
+import menus as m
4
+#====================================     
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
+#==================================== 
19
+			
20
+class SelectPattern(State):
21
+	def __init__(self,FSM):
22
+		super(SelectPattern, self).__init__(FSM)    
23
+		
24
+	def Enter(self):
25
+		self.FSM.stateLife = 1
26
+		o = self.FSM.owner 
27
+		o.header_text = "Select Pattern"
28
+		o.pub.register("beat", self)
29
+		self.cur_playing = 0
30
+		self.active_patterns = []
31
+		self.get_active_patterns(o)
32
+
33
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
34
+			pass
35
+		else:
36
+			u.draw_header(o)
37
+			self.draw_square()
38
+			u.text_box1(o, "Pat", str(o.ePattern))
39
+			u.text_box4(o, "Bank", str(o.pat_bank))
40
+			o.update_display(0)
41
+		
42
+		super(SelectPattern, self).Enter()        
43
+		
44
+	def Execute(self):
45
+		o = self.FSM.owner 
46
+		m.menu1_actions(self, o)
47
+		m.menu2_actions_pattern(self, o)
48
+		if o.keyState[16] == 1:
49
+			m.draw_menu1(o)
50
+			o.update_display(0)
51
+		elif o.keyState[16] == 4:
52
+			u.draw_header(o)
53
+			self.draw_square()
54
+			u.text_box1(o, "Pat", str(o.ePattern))
55
+			u.text_box4(o, "Bank", str(o.pat_bank))
56
+			o.update_display(0)
57
+
58
+		if o.keyState[17] == 1:
59
+			m.draw_menu2_pattern(o)
60
+			o.update_display(0)
61
+		elif o.keyState[17] == 4:
62
+			u.draw_header(o)
63
+			self.get_active_patterns(o)
64
+			self.draw_square()
65
+			u.text_box1(o, "Pat", str(o.ePattern))
66
+			u.text_box4(o, "Bank", str(o.pat_bank))
67
+			
68
+			o.update_display(0)
69
+
70
+
71
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
72
+			pass
73
+		else:
74
+			_id = 0
75
+			for k in o.keyState:
76
+				if _id > 15:
77
+					pass
78
+				else:
79
+					if k == 1:
80
+						o.ePattern = (o.pat_bank * 16) +_id 
81
+
82
+						u.draw_header(o)
83
+						self.draw_square()
84
+						
85
+						u.text_box1(o, "Pat", str(o.ePattern))
86
+						u.text_box4(o, "Bank", str(o.pat_bank))
87
+						o.update_display(0)
88
+						
89
+
90
+				_id += 1        
91
+
92
+	def ReceiveMessage(self, message):
93
+		o = self.FSM.owner
94
+		u.play_seq(o, message) 
95
+		
96
+		if message[0] != self.cur_playing:
97
+			#print('playing ', message)
98
+			self.cur_playing = message[0]
99
+			if o.keyState[16] > 0 or o.keyState[17] > 0:
100
+				pass
101
+			else:
102
+				u.draw_header(o)
103
+				self.draw_square()
104
+				u.text_box1(o, "Pat", str(o.ePattern))
105
+				u.text_box4(o, "Bank", str(o.pat_bank))
106
+				o.update_display(0)
107
+
108
+	def draw_square(self):
109
+		o = self.FSM.owner 
110
+		size = 22
111
+		og_x = (o.width / 2) - (size * 2)
112
+		o_x = og_x
113
+		o_y = 127
114
+		_id = 0
115
+		for n in o.soundSlots[o.eSound].notes[o.ePattern]:
116
+			if (_id + (o.pat_bank * 16)) == o.ePattern:
117
+				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.olive, width=1)
118
+			elif (_id + (o.pat_bank * 16)) == self.cur_playing:
119
+				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.light_grey, width=1)
120
+			elif self.active_patterns[_id] == 1:
121
+				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.blue, width=1)
122
+			else:
123
+				o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.dark_grey, width=1)
124
+			o_x = o_x + size
125
+			_id += 1
126
+			if _id % 4 == 0:
127
+				o_y -= size
128
+				o_x = og_x          
129
+
130
+	def get_active_patterns(self, o):
131
+		#for n in o.soundSlots[o.eSound]
132
+		self.active_patterns = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
133
+		pat_iter = o.pat_bank * 16
134
+		_iter = 0
135
+		#print('is this note on? ', o.soundSlots[0].notes[0][0][0])
136
+
137
+
138
+		while pat_iter < ((o.pat_bank * 16) + 16):
139
+			
140
+			for s in o.soundSlots:
141
+				#print('checking soundSlot ', s.id)
142
+				pat_used = 0
143
+				for p in s.notes[pat_iter]:
144
+					if self.active_patterns[_iter] == 1:
145
+						break
146
+					if p[0] == 1:
147
+						#pat_used = 1
148
+						self.active_patterns[_iter] = 1
149
+						#print('found ', pat_iter, ' -- ', p[0])
150
+						break
151
+				#self.active_patterns.append(pat_used)
152
+			pat_iter += 1
153
+			_iter += 1
154
+	
155
+		#print('active patterns ', self.active_patterns)
156
+
157
+	def Exit(self):
158
+		self.FSM.owner.pub.unregister("beat", self)

+ 92
- 0
lib/sSelectSound.py View File

@@ -0,0 +1,92 @@
1
+import FSM
2
+import utils as u
3
+import menus as m
4
+#====================================     
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 SelectSound(State):
19
+	def __init__(self,FSM):
20
+		super(SelectSound, self).__init__(FSM)    
21
+		
22
+	def Enter(self):
23
+		self.FSM.stateLife = 1
24
+		o = self.FSM.owner 
25
+		o.header_text = "SelSou"
26
+		o.pub.register("beat", self)
27
+		u.draw_header(o)
28
+		self.draw_square()
29
+		o.update_display(0)
30
+		super(SelectSound, self).Enter()        
31
+		
32
+	def Execute(self):
33
+		o = self.FSM.owner 
34
+		if o.keyState[16] == 1:
35
+			m.draw_menu1(o)
36
+			o.update_display(0)
37
+		elif o.keyState[16] == 4:
38
+			u.draw_header(o)
39
+			self.draw_square()
40
+			o.update_display(0)
41
+
42
+		if o.keyState[16] == 2:
43
+			if o.keyState[0] == 1:
44
+				self.FSM.ToTransition('toMain')
45
+		else:
46
+			_id = 0
47
+			for k in o.keyState:
48
+				if _id > 15:
49
+					pass
50
+				else:
51
+					if k == 1:
52
+						o.eSound = _id
53
+						o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
54
+						o.draw.text((0, 0), "SelSou", font=o.h1, fill=o.light_blue)
55
+						o.draw.text((20, 60), str(o.eSound), font=o.h2, fill=o.light_grey)
56
+						self.draw_square()
57
+						o.update_display(0)
58
+						self.FSM.owner.soundSlots[_id].play()
59
+						#print('now editing sound ', _id)    
60
+				_id += 1        
61
+
62
+	def ReceiveMessage(self, message):
63
+		_id = 0
64
+		o = self.FSM.owner 
65
+		o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=(0, 0, 0))
66
+		o.draw.text((0, 0), "SelSou", font=o.h1, fill="#FFFFFF")
67
+		o.draw.text((0, 20), str(o.eSound), font=o.h2, fill="#FFFFFF")
68
+		o.update_display(0)
69
+		u.play_seq(o, message)
70
+
71
+	def draw_square(self):
72
+		o = self.FSM.owner 
73
+		size = 32
74
+		og_x = 110
75
+		o_x = og_x
76
+		o_y = 0
77
+		_id = 0
78
+	
79
+		for n in o.soundSlots[o.eSound].notes[o.ePattern]:
80
+			if _id == o.eSound:
81
+				o.draw.rectangle((o_x, o_y, o_x + size, o_y + size), outline=0, fill=o.light_grey)
82
+			else:
83
+				o.draw.rectangle((o_x, o_y, o_x + size, o_y + size), outline=0, fill=o.dark_grey)
84
+			o_x = o_x + size
85
+			_id += 1
86
+			if _id % 4 == 0:
87
+				o_y += size
88
+				o_x = og_x
89
+
90
+		
91
+	def Exit(self):
92
+		self.FSM.owner.pub.unregister("beat", self)

+ 46
- 0
lib/sShutdown.py View File

@@ -0,0 +1,46 @@
1
+import FSM
2
+import utils as u
3
+import menus as m
4
+import os
5
+import pygame
6
+import sys
7
+
8
+#====================================     
9
+
10
+State = type("State", (object,), {})
11
+#====================================     
12
+class State(object):
13
+	def __init__(self, FSM):
14
+		self.FSM = FSM
15
+	def Enter(self):
16
+		pass
17
+	def Execute(self):
18
+		pass
19
+	def Exit(self):
20
+		pass
21
+
22
+class Shutdown(State):
23
+	def __init__(self,FSM):
24
+		super(Shutdown, self).__init__(FSM)    
25
+		
26
+	def Enter(self):
27
+		o = self.FSM.owner
28
+		o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)			
29
+		o.center_block("shutting down", o.h2, [0, 0, o.width,o.height - 20], o.light_grey)
30
+		o.center_block("(unplug in 20s)", o.h2, [0, 10, o.width,o.height+10], o.light_grey)
31
+		o.center_block("thank you for playing", o.h2, [0, 30, o.width,o.height+30], o.light_grey)
32
+		o.update_display(0)
33
+		command = 'bash -c "sleep 5; sudo shutdown -h now"&'
34
+		os.system(command)
35
+		pygame.quit()
36
+		sys.exit()
37
+		super(Shutdown, self).Enter()        
38
+		
39
+	def Execute(self):
40
+		pass
41
+		#self.FSM.stateLife += 1
42
+		#os.system('sudo shutdown -r now')
43
+		
44
+	def Exit(self):
45
+		pass
46
+

+ 146
- 0
lib/sUtil.py View File

@@ -0,0 +1,146 @@
1
+import FSM
2
+import utils as u
3
+import menus as m
4
+#====================================     
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 Util(State):
19
+	def __init__(self,FSM):
20
+		super(Util, self).__init__(FSM)    
21
+		
22
+	def Enter(self):
23
+		o = self.FSM.owner 
24
+		o.header_text = "Utilities"
25
+		o.pub.register("beat", self)
26
+		self.menu = ["Clock", "Balls", "Defender", "Calculator", "Exit", "Shutdown", "Reboot", "Theme", "Ping", "Wifi", "Update", "About"]
27
+		self.cur_el = 0
28
+
29
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
30
+			pass
31
+		else:
32
+			u.draw_header(o)
33
+			self.draw_footer(o)
34
+			self.draw_main(o)
35
+			o.update_display(0)
36
+
37
+		
38
+		super(Util, self).Enter()        
39
+		
40
+	def Execute(self):
41
+		o = self.FSM.owner 
42
+		m.menu1_actions(self, o)
43
+		if o.keyState[16] == 1:
44
+			m.draw_menu1(o)
45
+			o.update_display(0)
46
+		elif o.keyState[16] == 4:
47
+			u.draw_header(o)
48
+			self.draw_footer(o)
49
+			self.draw_main(o)
50
+			o.update_display(0)
51
+
52
+		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
53
+			u.draw_header(o)
54
+			self.draw_footer(o)
55
+			self.draw_main(o)
56
+			o.update_display(0)	
57
+			print('draw butt')				
58
+
59
+		if o.keyState[16] > 0 or o.keyState[17] > 0:
60
+			pass
61
+		else:
62
+			if o.keyState[0] == 1:
63
+				if self.cur_el > 0:
64
+					self.cur_el -= 1
65
+					print('cur el down is ', self.cur_el)
66
+			if o.keyState[1] == 1:
67
+				if self.cur_el < (len(self.menu) - 1):
68
+					self.cur_el += 1
69
+					print('cur el up is ', self.cur_el)
70
+			
71
+			if o.keyState[3] == 1:
72
+				m.util_command(self, o, self.menu[self.cur_el])
73
+		
74
+	def ReceiveMessage(self, message):
75
+		_id = 0
76
+		o = self.FSM.owner 
77
+		u.play_seq(o, message)
78
+		# if o.keyState[16] > 0 or o.keyState[17] > 0:
79
+		# 	pass
80
+		# else:
81
+		# 	u.draw_header(o)           		
82
+		# o.update_display(0)
83
+
84
+	def draw_main(self, o):
85
+		al = []
86
+		ypos = 30
87
+		if self.cur_el == 0:
88
+			_iter = 0
89
+			while len(al) < 4:
90
+				al.append(self.menu[_iter])
91
+				_iter += 1
92
+		elif self.cur_el == 1:
93
+			al.append(self.menu[self.cur_el - 1])
94
+			al.append(self.menu[self.cur_el])
95
+			al.append(self.menu[self.cur_el + 1])
96
+			al.append(self.menu[self.cur_el + 2])
97
+		elif self.cur_el == (len(self.menu) - 2):
98
+			al.append(self.menu[self.cur_el - 2])
99
+			al.append(self.menu[self.cur_el - 1])
100
+			al.append(self.menu[self.cur_el])
101
+			al.append(self.menu[self.cur_el + 1])
102
+		elif self.cur_el == (len(self.menu) - 1):
103
+			al.append(self.menu[self.cur_el - 3])
104
+			al.append(self.menu[self.cur_el - 2])
105
+			al.append(self.menu[self.cur_el - 1])
106
+			al.append(self.menu[self.cur_el])
107
+		else:
108
+			al.append(self.menu[self.cur_el - 1])
109
+			al.append(self.menu[self.cur_el])
110
+			al.append(self.menu[self.cur_el + 1])
111
+			al.append(self.menu[self.cur_el + 2])
112
+		_iter = 0 
113
+		for i in al:
114
+			if i == self.menu[self.cur_el]:
115
+			#if _iter == self.cur_el:
116
+				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.light_grey)
117
+				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.blue)
118
+			else:
119
+				o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.blue)
120
+				o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.light_grey)
121
+			ypos += 20
122
+			_iter += 1
123
+
124
+	def draw_footer(self, o):
125
+		_iter = 0
126
+		width = o.width / 4
127
+		xpos = 0
128
+		yposa = 135 - 25
129
+		yposb = 135
130
+		opts = ["Up", "Down", "", "OK"]
131
+		while _iter < 4:
132
+			o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.blue)
133
+			
134
+			if o.keyState[_iter] == 1:
135
+				o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.light_grey)
136
+				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.blue)
137
+			else:
138
+				o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
139
+			
140
+			xpos += width
141
+			_iter += 1
142
+
143
+	def Exit(self):
144
+		self.FSM.owner.pub.unregister("beat", self)        
145
+
146
+

+ 85
- 0
lib/sWifi.py View File

@@ -0,0 +1,85 @@
1
+import FSM
2
+import utils as u
3
+import menus as m
4
+import os
5
+import socket 
6
+#====================================     
7
+
8
+State = type("State", (object,), {})
9
+#====================================     
10
+class State(object):
11
+	def __init__(self, FSM):
12
+		self.FSM = FSM
13
+	def Enter(self):
14
+		pass
15
+	def Execute(self):
16
+		pass
17
+	def Exit(self):
18
+		pass
19
+
20
+
21
+
22
+class Wifi(State):
23
+	def __init__(self,FSM):
24
+		super(Wifi, self).__init__(FSM)    
25
+		
26
+	def Enter(self):
27
+		o = self.FSM.owner
28
+		
29
+		o.header_text = "Wifi"
30
+		o.pub.register("beat", self)
31
+		
32
+		self.ipad = self.extract_ip()
33
+		self.ssid = os.popen("sudo iwgetid -r").read()
34
+		o.center_block(self.ipad, o.h2, [0, 0, o.width,o.height], o.light_grey)
35
+
36
+		u.draw_header(o)
37
+		self.draw_main(o)
38
+		o.update_display(0)
39
+		super(Wifi, self).Enter()        
40
+		
41
+	def Execute(self):
42
+		o = self.FSM.owner 
43
+		m.menu1_actions(self, o)
44
+		if o.keyState[16] == 1:
45
+			m.draw_menu1(o)
46
+			o.update_display(0)
47
+		elif o.keyState[16] == 4:
48
+			u.draw_header(o)
49
+			#self.draw_footer(o)
50
+			self.draw_main(o)
51
+			o.update_display(0)
52
+
53
+		if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
54
+			u.draw_header(o)
55
+			#self.draw_footer(o)
56
+			self.draw_main(o)
57
+			o.update_display(0)	
58
+			
59
+		
60
+	def draw_main(self, o):
61
+		o.center_block(self.ipad, o.h2, [0, 0, o.width, o.height], o.light_grey)
62
+		o.center_block(self.ssid, o.h2, [0, 40, o.width, o.height+40], o.light_grey)
63
+
64
+
65
+	def extract_ip(self):
66
+		st = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
67
+		try:       
68
+			#st.connect(('10.255.255.255', 1))
69
+			st.connect(("8.8.8.8", 80))
70
+			IP = st.getsockname()[0]
71
+		except Exception:
72
+			IP = '127.0.0.1'
73
+		finally:
74
+			st.close()
75
+		return IP
76
+	#print(extract_ip())		
77
+
78
+	def ReceiveMessage(self, message):
79
+		o = self.FSM.owner 
80
+		u.play_seq(o, message)
81
+
82
+	def Exit(self):
83
+		self.FSM.owner.pub.unregister("beat", self)
84
+
85
+#==================================== 

+ 80
- 0
lib/utils.py View File

@@ -1,3 +1,6 @@
1
+import glob
2
+import os
3
+
1 4
 def draw_header(o):
2 5
 	o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
3 6
 	o.center_text(o.header_text, o.h1, o.width, 25, o.light_grey)
@@ -6,6 +9,36 @@ def draw_header(o):
6 9
 def play_seq(o, message):
7 10
 	_id = 0
8 11
 	o.clear_notes_on()
12
+	for s in o.soundSlots:
13
+		if s.notes[message[0]][message[1]][0] == 1:
14
+			if o.erase:
15
+				if _id in o.erase_buf:
16
+					#pass
17
+					s.notes[message[0]][message[1]][0] = 0
18
+					print('erasing')
19
+					#o.undo_buf.append(s.notes[message[0]][message[1]][0])
20
+				else:
21
+					o.notes_on[_id] = 1
22
+					o.soundSlots[_id].play(s.notes[message[0]][message[1]][1])
23
+			elif o.mute:
24
+				if _id in o.mute_buf:
25
+					#pass
26
+					#s.notes[message[0]][message[1]][0] = 0
27
+					print('muting')
28
+					#o.undo_buf.append(s.notes[message[0]][message[1]][0])
29
+				else:
30
+					o.notes_on[_id] = 1
31
+					o.soundSlots[_id].play(s.notes[message[0]][message[1]][1])
32
+			else:
33
+
34
+				o.notes_on[_id] = 1
35
+				o.soundSlots[_id].play(s.notes[message[0]][message[1]][1])
36
+		_id += 1
37
+
38
+def erase_note(o, message, pressed):
39
+	_id = 0
40
+	#o.clear_notes_on()
41
+
9 42
 	for s in o.soundSlots:
10 43
 		if s.notes[message[0]][message[1]][0] == 1:
11 44
 			o.notes_on[_id] = 1
@@ -113,3 +146,50 @@ def breakup_song_text(song):
113 146
 			_iter += 1
114 147
 		line1 = ".." + line1
115 148
 	return [line1, line2, line3, line4]
149
+
150
+def get_folders(path):
151
+	globbed = glob.glob(path + "/*/")
152
+	globbed.sort()
153
+
154
+
155
+		# dirs = os.listdir(o.load_sound_dir)
156
+		# dirs.sort()
157
+		# for i in dirs:
158
+		# 	if os.path.isdir(o.load_sound_dir + i):
159
+		# 		i += "/asdfasdfasf"
160
+		# 		print(i, ' is a directory')
161
+		# 	else:
162
+		# 		print(i, ' is not a directory')
163
+		# print(dirs)
164
+		# return dirs
165
+
166
+
167
+
168
+	return globbed
169
+
170
+def get_files(path, ext):
171
+	path += '/'
172
+	out = []
173
+	files = os.listdir(path)
174
+	files.sort()
175
+	print('from utils ', files)
176
+	for file in files:
177
+	    if os.path.isdir(path + file):
178
+	        out.append(file)
179
+	    else:
180
+	    	pass
181
+
182
+	for file in files:
183
+	    if file.lower().endswith(ext):
184
+	    	print(file, ' does end with ext')
185
+	    	if os.path.isdir(path + file):
186
+	        	#out.append(file)
187
+	        	pass
188
+	    	else:
189
+	    		#pass
190
+	        	out.append(file)
191
+	    else:
192
+	    	print(file, ' does not end with ext')
193
+	    	#pass
194
+
195
+	return out

+ 18
- 19
main.py View File

@@ -162,6 +162,10 @@ class Prog:
162 162
 		self.last_load_sound_id = None
163 163
 		self.odub = False
164 164
 		self.undo_buf = []
165
+		self.erase_buf = []
166
+		self.erase = False
167
+		self.mute_buf = []
168
+		self.mute = False
165 169
 		self.black = "#000000"
166 170
 		self.bg_color = "#336699"
167 171
 		#self.color_a = "#FFFFFF"
@@ -193,7 +197,9 @@ class Prog:
193 197
 		self.mconf = ConfigObj("config.txt")
194 198
 		self.sconf = ConfigObj("/home/pi/zpc_ct/user/songs/" + self.mconf['default_song'])
195 199
 		self.theme = ConfigObj("/home/pi/zpc_ct/user/themes/" + self.mconf['theme'] + ".thm")
196
-		self.load_song_dir = '/home/pi/zpc_ct/user/sounds/'
200
+		self.load_sound_dir = '/home/pi/zpc_ct/user/sounds/'
201
+		self.song_dir = self.mconf['song_dir']
202
+		self.base_song_dir = '/home/pi/zpc_ct/user/songs/'
197 203
 
198 204
 		self.light_grey = self.theme['light_grey']
199 205
 		self.apply_theme()
@@ -342,22 +348,7 @@ class Prog:
342 348
 	def button_repeater(self, state, enables):
343 349
 		if state == 0:
344 350
 			pass
345
-			# _iter = 0
346
-			# for b in self.keyState:
347
-			# 	if _iter in enables:
348
-			# 		if b == 2:
349
-			# 			if self.repeater_states[_iter] == None:
350
-			# 				#self.repeater_states[_iter] = pygame.time.get_ticks()
351
-			# 				pass
352
-			# 			else:
353
-			# 				t = pygame.time.get_ticks() - self.repeater_states[_iter]
354
-			# 				if t > 250:
355
-			# 					#self.repeater_states[_iter] = pygame.time.get_ticks()	
356
-			# 					#b = 0
357
-			# 					print('new tick ', _iter, ' ', b)
358
-
359
-			# 	_iter += 1
360
-			#self.repeater_states
351
+			
361 352
 		elif state == 1:
362 353
 			for i in self.repeater_states:
363 354
 				i = None
@@ -378,6 +369,8 @@ class Prog:
378 369
 		self.songStart = self.curPattern
379 370
 		bpm = (60000 / self.bpm) / 4
380 371
 		pygame.time.set_timer(TIMER, int(bpm))
372
+		GPIO.setup(29, GPIO.OUT)
373
+		GPIO.output(29, GPIO.LOW)
381 374
 		
382 375
 
383 376
 	def stop_playback(self):		
@@ -386,6 +379,8 @@ class Prog:
386 379
 		self.playhead = 0
387 380
 		self.curPattern = self.song[0]
388 381
 		pygame.time.set_timer(TIMER, 0)
382
+		GPIO.setup(29, GPIO.OUT)
383
+		GPIO.output(29, GPIO.HIGH)
389 384
 
390 385
 	def center_text(self, text, font, width, y, color):
391 386
 		w,h = font.getsize(text)
@@ -411,7 +406,8 @@ class Prog:
411 406
 		#self.red = self.theme["red"]
412 407
 
413 408
 	def save_song(self):
414
-		base_dir = "/home/pi/zpc_ct/user/songs/"
409
+		#base_dir = "/home/pi/zpc_ct/user/songs/"
410
+		base_dir = self.song_dir
415 411
 		title = self.sconf['title']
416 412
 		fname = base_dir + self.sconf['title'] + '.sng'
417 413
 		if os.path.exists(fname):
@@ -436,18 +432,21 @@ class Prog:
436 432
 		base_dir = "/home/pi/zpc_ct/"
437 433
 		print('before writing')
438 434
 		print(self.mconf['theme'])
435
+		self.mconf['song_dir'] = self.song_dir
439 436
 		self.mconf.write()
440 437
 
441 438
 	def load_config(self):
442 439
 		base_dir = "/home/pi/zpc_ct/"
443 440
 		self.sconf = ConfigObj(base_dir + 'config.txt')
444 441
 		self.theme = ConfigObj("/home/pi/zpc_ct/user/themes/" + self.mconf['theme'] + ".thm")
442
+		self.song_dir = self.mconf['song_dir']
445 443
 
446 444
 	def load_song(self):
447 445
 		#self.stop_playback()
448 446
 		self.quit_mixer()
449 447
 		self.start_mixer()
450
-		base_dir = "/home/pi/zpc_ct/user/songs/"
448
+		#base_dir = "/home/pi/zpc_ct/user/songs/"
449
+		base_dir = self.song_dir
451 450
 		self.sconf = ConfigObj(base_dir + self.mconf['default_song'] + '.sng')
452 451
 		print(base_dir + self.mconf['default_song'] + '.sng')
453 452
 		self.last_load_sound_id = None

+ 0
- 5
user/songs/Roland_TR-808.sng
File diff suppressed because it is too large
View File


+ 0
- 0
user/songs/other/thing.nope View File


Loading…
Cancel
Save