import FSM import utils as u import menus as m #==================================== 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 EditSoundSequence(State): def __init__(self,FSM): super(EditSoundSequence, self).__init__(FSM) def Enter(self): self.FSM.stateLife = 1 o = self.FSM.owner o.header_text = "Note Edit" o.pub.register("beat", self) self.curPattern = o.ePattern if o.keyState[16] > 0 or o.keyState[17] > 0: pass else: u.draw_header(o) self.draw_square() u.text_box1(o, "Note Vol", str(o.note_vol)) u.text_box3(o, "Pat", str(self.curPattern)) o.update_display(0) super(EditSoundSequence, self).Enter() def Execute(self): o = self.FSM.owner m.menu1_actions(self, o) m.menu2_actions_note(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, "Note Vol", str(o.note_vol)) u.text_box3(o, "Pat", str(self.curPattern)) o.update_display(0) if o.keyState[17] == 1: m.draw_menu2_note(o) o.update_display(0) elif o.keyState[17] == 4: u.draw_header(o) self.draw_square() u.text_box1(o, "Note Vol", str(o.note_vol)) u.text_box3(o, "Pat", str(self.curPattern)) o.update_display(0) if o.keyState[16] > 0 or o.keyState[17] > 0: pass else: _id = 0 for k in self.FSM.owner.keyState: if _id < 16 and k == 1: if o.soundSlots[o.eSound].notes[self.curPattern][_id][0] == 1: #print('turn note off') o.soundSlots[o.eSound].notes[self.curPattern][_id][0] = 0 o.soundSlots[o.eSound].notes[self.curPattern][_id][1] = 0 else: #print('turn note on') o.soundSlots[o.eSound].notes[self.curPattern][_id][0] = 1 o.soundSlots[o.eSound].notes[self.curPattern][_id][1] = o.note_vol u.draw_header(o) self.draw_square() u.text_box1(o, "Note Vol", str(o.note_vol)) u.text_box3(o, "Pat", str(self.curPattern)) o.update_display(0) _id += 1 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[self.curPattern]: if _id == o.playhead and o.playing: if o.curPattern == self.curPattern: o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.olive, width=1) else: o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.pink, width=1) elif n[0] == 1: o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.light_grey, width=1) else: o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.blue, width=1) o_x = o_x + size _id += 1 if _id % 4 == 0: o_y -= size o_x = og_x def ReceiveMessage(self, message): _id = 0 o = self.FSM.owner u.play_seq(o, message) if o.keyState[16] > 0 or o.keyState[17] > 0: pass else: u.draw_header(o) self.draw_square() u.text_box1(o, "Note Vol", str(o.note_vol)) u.text_box3(o, "Pat", str(self.curPattern)) if o.patternFollow: self.curPattern = message[0] else: self.curPattern = o.ePattern #print('message ', message) o.update_display(0) def Exit(self): self.FSM.owner.pub.unregister("beat", self)