import FSM import utils as u import menus as m import pygame #==================================== 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 Main(State): def __init__(self,FSM): super(Main, self).__init__(FSM) def Enter(self): print('hello main') self.FSM.owner.pub.register("beat", self) self.FSM.stateLife = 1 o = self.FSM.owner o.header_text = "Sound Select" 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.curPattern)) u.text_box2(o, "BPM", str(o.bpm)) u.text_box4(o, "Bank", str(o.note_bank)) u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch)) o.update_display(0) self.recording = True self.record_queue = [] self.undo_queue = [] o.erase = False o.erase_queue = [] o.mute = False o.mute_queue = [] super(Main, self).Enter() def Execute(self): o = self.FSM.owner m.menu1_actions(self, o) m.menu2_actions_sample(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.curPattern)) u.text_box2(o, "BPM", str(o.bpm)) u.text_box4(o, "Bank", str(o.note_bank)) u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch)) o.button_repeater(1, []) o.update_display(0) if o.keyState[17] == 1: m.draw_menu2_sample(o) o.update_display(0) elif o.keyState[17] == 4: u.draw_header(o) self.draw_square() u.text_box1(o, "Pat", str(o.curPattern)) u.text_box2(o, "BPM", str(o.bpm)) u.text_box4(o, "Bank", str(o.note_bank)) u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch)) o.update_display(0) _id = 0 for k in o.keyState: if _id > 15: pass else: if o.keyState[16] > 0 or o.keyState[17] > 0: pass else: note = _id + o.note_bank * 16 if k == 1: self.record_queue = pygame.time.get_ticks() if not o.erase and not o.mute and o.prev: o.soundSlots[note].play(o.note_vol) o.eSound = note u.draw_header(o) #u.text_box1(o, "SVol", str(o.slots[o.eSound].volume)) u.text_box1(o, "Pat", str(o.curPattern)) u.text_box2(o, "BPM", str(o.bpm)) u.text_box4(o, "Bank", str(o.note_bank)) u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch)) self.draw_square() o.update_display(0) if o.erase: o.erase_buf.append(note) if o.mute: o.mute_buf.append(note) if k == 3: if note in o.erase_buf: o.erase_buf.remove(note) if note in o.mute_buf: o.mute_buf.remove(note) _id += 1 def ReceiveMessage(self, message): o = self.FSM.owner if o.erase == True: u.play_seq(o, message) else: 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, "Pat", str(o.curPattern)) u.text_box2(o, "BPM", str(o.bpm)) u.text_box4(o, "Bank", str(o.note_bank)) u.text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch)) o.update_display(0) if self.record_queue != []: cur_time = pygame.time.get_ticks() note_pos = (cur_time - self.record_queue) - (o.half_bpm / 2) if o.odub == True: if note_pos > (o.half_bpm): _note = 0 if message[1] == 0: _note = 15 else: _note = message[1] - 1 if o.soundSlots[o.eSound].notes[message[0]][_note][0] != 1: o.soundSlots[o.eSound].notes[message[0]][_note][0] = 1 o.soundSlots[o.eSound].notes[message[0]][_note][1] = o.note_vol o.undo_buf.append([o.eSound, message[0], _note]) else: if o.soundSlots[o.eSound].notes[message[0]][message[1]][0] != 1: o.soundSlots[o.eSound].notes[message[0]][message[1]][0] = 1 o.soundSlots[o.eSound].notes[message[0]][message[1]][1] = o.note_vol o.undo_buf.append([o.eSound, message[0], message[1]]) self.record_queue = [] 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 = o.note_bank * 16 while _id < ((o.note_bank * 16) + 16): if _id == o.eSound: o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.light_grey, width=1) elif o.notes_on[_id] == 1: o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.grey, width=1) elif self.has_sample(o, _id) == False: o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.dark_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 has_sample(self, o, slot): if o.soundSlots[slot].file != None: return True else: return False def Exit(self): self.FSM.owner.pub.unregister("beat", self)