123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- import FSM
- import utils as u
- import menus as m
- from itertools import cycle
- #====================================
-
- State = type("State", (object,), {})
- #====================================
- class State(object):
- def __init__(self, FSM):
- self.FSM = FSM
- def Enter(self):
- pass
- def Execute(self):
- pass
- def Exit(self):
- pass
-
- #====================================
-
- class SelectPattern(State):
- def __init__(self,FSM):
- super(SelectPattern, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- o = self.FSM.owner
- o.header_text = "Select Pattern"
- o.pub.register("beat", self)
- self.cur_playing = 0
- self.active_patterns = []
- self.get_active_patterns(o)
- o.pat_buf = o.song
- self.new_song = []
-
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- u.draw_header(o)
- self.draw_square()
- u.text_box1(o, "Pat", str(o.ePattern))
- u.text_box4(o, "Bank", str(o.pat_bank))
- o.update_display(0)
-
- super(SelectPattern, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
- m.menu1_actions(self, o)
- m.menu2_actions_pattern(self, o)
- if o.keyState[16] == 1:
- m.draw_menu1(o)
- o.update_display(0)
- elif o.keyState[16] == 4:
- u.draw_header(o)
- self.draw_square()
- u.text_box1(o, "Pat", str(o.ePattern))
- u.text_box4(o, "Bank", str(o.pat_bank))
- o.update_display(0)
-
- if o.keyState[17] == 1:
- m.draw_menu2_pattern(o)
- o.update_display(0)
- elif o.keyState[17] == 4:
- u.draw_header(o)
- self.get_active_patterns(o)
- self.draw_square()
- u.text_box1(o, "Pat", str(o.ePattern))
- u.text_box4(o, "Bank", str(o.pat_bank))
- o.update_display(0)
-
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- _id = 0
- for k in o.keyState:
- if _id > 15:
- pass
- else:
- if k == 1:
- if o.pat_perf:
- this = o.ePattern = (o.pat_bank * 16) +_id
- #print('we should play ', this)
- o.song = [this]
- o.songCycle = cycle(o.song)
- o.songStart = this
- if not o.playing:
-
-
- o.start_playback()
- u.play_seq(o, [o.curPattern, 0])
- o.ePattern = (o.pat_bank * 16) +_id
-
- u.draw_header(o)
- self.draw_square()
-
- u.text_box1(o, "Pat", str(o.ePattern))
- u.text_box4(o, "Bank", str(o.pat_bank))
- o.update_display(0)
- _id += 1
-
- def ReceiveMessage(self, message):
- o = self.FSM.owner
- u.play_seq(o, message)
-
- if message[0] != self.cur_playing:
- self.cur_playing = message[0]
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- u.draw_header(o)
- self.draw_square()
- u.text_box1(o, "Pat", str(o.ePattern))
- u.text_box4(o, "Bank", str(o.pat_bank))
- o.update_display(0)
- # if o.pat_odub:
- # print('add to record queue ', o.song[0])
- # else:
- # print('not recording')
- #print(message)
- if o.pat_odub:
- if message[1] == 0:
- if len(o.song) > 0:
- #print('adding to rec', o.song[0])
- o.song_in.append(o.song[0])
- #print('adding to song_in ', o.song_in)
-
- def draw_square(self):
- o = self.FSM.owner
- size = 22
- og_x = (o.width / 2) - (size * 2)
- o_x = og_x
- o_y = 127
- _id = 0
- for n in o.soundSlots[o.eSound].notes[o.ePattern]:
- if (_id + (o.pat_bank * 16)) == o.ePattern:
- o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.olive, width=1)
- elif (_id + (o.pat_bank * 16)) == self.cur_playing:
- o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.light_grey, width=1)
- elif self.active_patterns[_id] == 1:
- o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.blue, width=1)
- else:
- o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.dark_grey, width=1)
- o_x = o_x + size
- _id += 1
- if _id % 4 == 0:
- o_y -= size
- o_x = og_x
-
- def get_active_patterns(self, o):
- self.active_patterns = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
- pat_iter = o.pat_bank * 16
- _iter = 0
- while pat_iter < ((o.pat_bank * 16) + 16):
- for s in o.soundSlots:
- pat_used = 0
- for p in s.notes[pat_iter]:
- if self.active_patterns[_iter] == 1:
- break
- if p[0] == 1:
- self.active_patterns[_iter] = 1
- break
- pat_iter += 1
- _iter += 1
-
- def Exit(self):
- o = self.FSM.owner
- o.pub.unregister("beat", self)
- # if len(o.song) < 1 and len(o.pat_buf) > 0:
- # o.song = o.pat_buf
- # o.pat_buf = []
- o.pat_perf = False
-
- o.song = o.pat_buf
- o.pat_buf = []
- o.songCycle = cycle(o.song)
- o.songStart = o.song[0]
- #print('song is ', o.song)
|