class MainWidget2(BaseWidget): def __init__(self): super(MainWidget2, self).__init__() # create a clock and a tempo map self.clock = Clock() self.tempo_map = SimpleTempoMap(120) # and text to display our status self.label = topleft_label() self.add_widget(self.label) def on_key_down(self, keycode, modifiers): if keycode[1] == 'c': self.clock.toggle() def on_update(self): time = self.clock.get_time() tick = self.tempo_map.time_to_tick(time) bpm = self.tempo_map.get_tempo() self.label.text = 'time:{:.2f}\n'.format(time) self.label.text += tick_str(tick) + '\n' self.label.text += 'bpm:{}\n'.format(bpm) self.label.text += 'c: toggle clock\n'
def __init__(self, norm, sandbox, mixer, client, client_id, block_handler, tempo=60): self.norm = norm self.module_name = 'TempoCursor' self.sandbox = sandbox self.mixer = mixer self.client = client self.cid = client_id self.block_handler = block_handler self.tempo = tempo self.clock = Clock() self.tempo_map = SimpleTempoMap(bpm=self.tempo) self.touch_points = {} self.cursors = AnimGroup() self.sandbox.add(self.cursors) self.gui = CursorGUI(norm, pos=self.norm.nt((20, 300)), beat_callback=self.update_touch_points) self.delete_mode = {}
def __init__(self, other_members, tempo, bars, divs, inst_set): super(Session, self).__init__() self.tempo = tempo self.bars = bars self.divs = divs self.inst_set = inst_set spb = 60. / tempo beats = bars * 4 self.seconds = spb * beats self.clock = Clock() self.temp_map = SimpleTempoMap(bpm=tempo) self.sched = Scheduler(self.clock, self.temp_map) # self.players = players self.IM = InstrumentManager(self.sched) self.add(self.IM) ### NEW CODE ### self.pattern_list = PatternList(self.bars, self.tempo, self.inst_set) self.add(self.pattern_list) track = Track(num_lanes, self.bars, self.tempo) track.position.y = Window.height * 0.025 controller = InstrumentKeyboard(default_keycodes, lock_in_keycode) self.player = Player(controller, track, inst_set) self.player.position.x = Window.width - player_size[0] - 20 self.add(self.player) self.vplayers = [] self.add_band_members(other_members) self.IM.add(self.player.instrument) self.clock.offset = self.seconds - spb self.paused = True self.start()
def __init__(self, evManager, fps): if fps == 0: fps = 100 #100 fps is the maximum timer resolution anyway Clock.__init__(self, fps) self._em = evManager self._em.reg_cb(QuitEvent, self.on_quit)
def __init__(self): super(MainWidget2, self).__init__() # create a clock and a tempo map self.clock = Clock() self.tempo_map = SimpleTempoMap(120) # and text to display our status self.label = topleft_label() self.add_widget(self.label)
def __init__(self): super(MainWidget3, self).__init__() # create a clock and TempoMap self.clock = Clock() self.tempo = SimpleTempoMap(120) # create a Scheduler self.sched = Scheduler(self.clock, self.tempo) # and text to display our status self.label = topleft_label() self.add_widget(self.label) # to see accumulated output: self.output_text = ''
def __init__(self, evManager): self._em = evManager fps = config_get_fps() if fps <= 0 or fps > 100: fps = 100 #100 fps is the maximum timer resolution anyway Clock.__init__(self, fps) # slice = set of frames between 2 logging self.slice_size = config_get_logperiod() * fps # number of frames in the slice self.slice_start_time = time.time() # the first slice starts now self.slice_work_time = 0 # cumulated time worked for a frame slice self.cumul_ucpu_time = 0 # cumulated userland cpu time used since process started self.cumul_kcpu_time = 0 # cumulated kernel cpu time used since process started self.cumul_vcsw = 0 # cumulated voluntary context switches, posix OS only self.cumul_nvcsw = 0 # cumulated involuntary switches, posix OS only
class MainWidget4(BaseWidget): def __init__(self): super(MainWidget4, self).__init__() self.audio = Audio(2) self.synth = Synth('../data/FluidR3_GM.sf2') self.audio.set_generator(self.synth) # create clock, tempo_map, scheduler self.clock = Clock() self.tempo_map = SimpleTempoMap(120) self.sched = Scheduler(self.clock, self.tempo_map) # create the metronome: self.metro = Metronome(self.sched, self.synth) # and text to display our status self.label = topleft_label() self.add_widget(self.label) def on_key_down(self, keycode, modifiers): if keycode[1] == 'c': self.clock.toggle() if keycode[1] == 'm': self.metro.toggle() bpm_adj = lookup(keycode[1], ('up', 'down'), (10, -10)) if bpm_adj: new_tempo = self.tempo_map.get_tempo() + bpm_adj self.tempo_map.set_tempo(new_tempo, self.sched.get_time()) def on_update(self): # scheduler and audio get poked every frame self.sched.on_update() self.audio.on_update() bpm = self.tempo_map.get_tempo() self.label.text = self.sched.now_str() + '\n' self.label.text += 'Metronome:' + ("ON" if self.metro.playing else "OFF") + '\n' self.label.text += 'tempo:{}\n'.format(bpm) self.label.text += 'm: toggle Metronome\n' self.label.text += 'up/down: change speed\n'
def __init__(self): super(MainWidget4, self).__init__() self.audio = Audio(2) self.synth = Synth('../data/FluidR3_GM.sf2') self.audio.set_generator(self.synth) # create clock, tempo_map, scheduler self.clock = Clock() self.tempo_map = SimpleTempoMap(120) self.sched = Scheduler(self.clock, self.tempo_map) # create the metronome: self.metro = Metronome(self.sched, self.synth) # and text to display our status self.label = topleft_label() self.add_widget(self.label)
class MainWidget3(BaseWidget): def __init__(self): super(MainWidget3, self).__init__() # create a clock and TempoMap self.clock = Clock() self.tempo = SimpleTempoMap(120) # create a Scheduler self.sched = Scheduler(self.clock, self.tempo) # and text to display our status self.label = topleft_label() self.add_widget(self.label) # to see accumulated output: self.output_text = '' def on_key_down(self, keycode, modifiers): if keycode[1] == 'c': self.clock.toggle() if keycode[1] == 'a': now = self.sched.get_tick() later = now + (2 * kTicksPerQuarter) self.output_text += "now={}. post at tick={}\n".format(now, later) self.cmd = self.sched.post_at_tick(self._do_it, later, 'hello') if keycode[1] == 'b': self.sched.remove(self.cmd) def _do_it(self, tick, msg): self.output_text += "{} (at {})\n".format(msg, tick) def on_update(self): # scheduler gets called every frame to process events self.sched.on_update() self.label.text = self.sched.now_str() + '\n' self.label.text += 'c: toggle clock\n' self.label.text += 'a: post event\n' self.label.text += 'b: remove event\n' self.label.text += self.output_text
def __init__(self, callback=None): super(DataPlayer, self).__init__() self.sched = Scheduler(Clock(), tempo_map=[(0, 0), (100000000000, 100000000000 / 60 * 480)]) self.beat_len = kTicksPerQuarter self.on_cmd = None self.off_cmd = None self.playing = False self.callback = None self.barData = None
def __init__(self, masterPattern=None, key=None, fileName='testoutput.txt', noteDetector=None, mixer=None, callback=None): super(MainWidget, self).__init__() ''' The main game instance, the pattern and keys are loaded before the screen is initialized ALL graphical components are controlled by the clock (update isnt' run if clock isn't playing) ''' self.mixer = mixer self.pattern, self.patternString = masterPattern self.key = key #Audio self.clock = GameClock() self.gui = KeyboardGui(noteDetector) self.detector = noteDetector self.ticker = Ticker(self.pattern, key, self.clock) self.mixer.add(self.ticker.synth) self.player = Player(self.ticker, self.clock, masterPattern, self.key, noteDetector.updateTargetChord, noteDetector.getActiveNotes, callback) self.ticker.initialize_callbacks(self.player.increment_bar, self.player.catch_passes) self.detector.initializePlayer(self.player) crect = CRectangle(cpos=(Window.width // 2, Window.height // 2), csize=(Window.width, Window.height)) crect.texture = Image('../images/Blackboard.png').texture self.canvas.add(crect) self.canvas.add(self.player) self.canvas.add(self.gui) #midi input state self.info.parent = None # make sure the label widget does not have a parent self.add_widget(self.info) self.switchScreens = callback
class TempoCursorHandler(object): """ Handles the TempoCursor GUI. Also stores and updates all currently active TempoCursors. """ def __init__(self, norm, sandbox, mixer, client, client_id, block_handler, tempo=60): self.norm = norm self.module_name = 'TempoCursor' self.sandbox = sandbox self.mixer = mixer self.client = client self.cid = client_id self.block_handler = block_handler self.tempo = tempo self.clock = Clock() self.tempo_map = SimpleTempoMap(bpm=self.tempo) self.touch_points = {} self.cursors = AnimGroup() self.sandbox.add(self.cursors) self.gui = CursorGUI(norm, pos=self.norm.nt((20, 300)), beat_callback=self.update_touch_points) self.delete_mode = {} def on_touch_down(self, cid, pos): if cid == self.cid: self.gui.on_touch_down(pos) if not self.sandbox.in_bounds(pos): return for cursor in self.cursors.objects: cursor_pos = (cursor.pos[0] - cursor.size[0] / 2, cursor.pos[1] - cursor.size[1] / 2) if in_bounds(pos, cursor_pos, cursor.size): if self.delete_mode[cid]: self.cursors.objects.remove(cursor) self.cursors.remove(cursor) return if self.delete_mode[cid]: return touch_points = self.touch_points[cid] if len(touch_points) == 0: return cursor = TempoCursor(self.norm, pos, self.tempo, self.clock, self.tempo_map, copy.deepcopy(touch_points), self.block_handler) self.cursors.add(cursor) def on_touch_move(self, cid, pos): pass def on_touch_up(self, cid, pos): pass def on_key_down(self, cid, key): if key == 'p': self.clock.toggle() if key == 'v' and cid == self.cid: self.delete_mode[cid] = not self.delete_mode[cid] self.update_server_state(post=True) if key == 'up': self.tempo += 4 self.tempo_map.set_tempo(self.tempo) self.update_server_state(post=True) if key == 'down': self.tempo -= 4 self.tempo_map.set_tempo(self.tempo) self.update_server_state(post=True) def on_update(self): self.cursors.on_update() def update_touch_points(self, touch_points): self.touch_points[self.cid] = touch_points self.update_server_state(post=True) def display_controls(self): cur_time = self.clock.get_time() cur_tick = self.tempo_map.time_to_tick(cur_time) info = 'delete mode: {}\n\n'.format(self.delete_mode[self.cid]) info += 'tempo: {}\n'.format(self.tempo) return info def update_server_state(self, post=False): """Update server state. If post is True, relay this updated state to all clients.""" state = { 'touch_points': self.touch_points, 'delete_mode': self.delete_mode, 'tempo': self.tempo } data = { 'module': self.module_name, 'cid': self.cid, 'state': state, 'post': post } self.client.emit('update_state', data) def update_client_state(self, cid, state): """Update this handler's state.""" if cid != self.cid: # this client already updated its own state self.touch_points = state['touch_points'] self.delete_mode = state['delete_mode'] self.tempo = state['tempo'] def sync_state(self, state): """ Initial sync with the server's copy of module state. """ self.touch_points = state['touch_points'] self.delete_mode = state['delete_mode'] self.tempo = state['tempo'] # after initial sync, add default values for this client self.touch_points[self.cid] = [] self.delete_mode[self.cid] = False # update server with these default values # post=True here because we want all other clients' states to update with this client's # default values. self.update_server_state(post=True)
class Session(GameObject): def __init__(self, other_members, tempo, bars, divs, inst_set): super(Session, self).__init__() self.tempo = tempo self.bars = bars self.divs = divs self.inst_set = inst_set spb = 60. / tempo beats = bars * 4 self.seconds = spb * beats self.clock = Clock() self.temp_map = SimpleTempoMap(bpm=tempo) self.sched = Scheduler(self.clock, self.temp_map) # self.players = players self.IM = InstrumentManager(self.sched) self.add(self.IM) ### NEW CODE ### self.pattern_list = PatternList(self.bars, self.tempo, self.inst_set) self.add(self.pattern_list) track = Track(num_lanes, self.bars, self.tempo) track.position.y = Window.height * 0.025 controller = InstrumentKeyboard(default_keycodes, lock_in_keycode) self.player = Player(controller, track, inst_set) self.player.position.x = Window.width - player_size[0] - 20 self.add(self.player) self.vplayers = [] self.add_band_members(other_members) self.IM.add(self.player.instrument) self.clock.offset = self.seconds - spb self.paused = True self.start() def add_band_members(self, other_members): for other_member in other_members: vcontroller = InstrumentController(16, other_member['id']) vtrack = VirtualTrack(num_lanes, self.bars, self.tempo) vplayer = VirtualPlayer(vcontroller, vtrack) self.vplayers.append(vplayer) self.add(vplayer) def on_key_down(self, event): # if event.keycode[1] == 'enter':on # self.toggle() pass def toggle(self): if self.paused: self.paused = False self.start() else: self.paused = True self.stop() def stop(self): self.clock.stop() def start(self): self.clock.start() def next_player(self, sequence): if self.current_player < self.num_players: self.players[self.current_player].note_sequence = sequence self.players[self.current_player].stop_composing() self.current_player += 1 if self.current_player < self.num_players: self.players[self.current_player].start_composing() def on_lock_in(self, event): self.next_player(event.action['sequence']) def on_update(self): self.sched.on_update() # for player in self.players: now = self.clock.get_time() % self.seconds for vplayer in self.vplayers: vplayer.set_now(now) self.player.set_now(now) self.pattern_list.set_now(self.clock.get_time() % self.seconds)
def start(self): """ start the clock """ log.debug('Clock starts to tick at ' + str(self.fps) + ' fps') Clock.start(self)
def start(self): self.log.debug('Clock starts to tick at ' + str(self.fps) + ' fps') Clock.start(self)
def on_quit(self, qevent): """ stop the while loop from running """ Clock.stop(self)
class MainWidget(BaseWidget): playing = False info = topleft_label() def __init__(self, masterPattern=None, key=None, fileName='testoutput.txt', noteDetector=None, mixer=None, callback=None): super(MainWidget, self).__init__() ''' The main game instance, the pattern and keys are loaded before the screen is initialized ALL graphical components are controlled by the clock (update isnt' run if clock isn't playing) ''' self.mixer = mixer self.pattern, self.patternString = masterPattern self.key = key #Audio self.clock = GameClock() self.gui = KeyboardGui(noteDetector) self.detector = noteDetector self.ticker = Ticker(self.pattern, key, self.clock) self.mixer.add(self.ticker.synth) self.player = Player(self.ticker, self.clock, masterPattern, self.key, noteDetector.updateTargetChord, noteDetector.getActiveNotes, callback) self.ticker.initialize_callbacks(self.player.increment_bar, self.player.catch_passes) self.detector.initializePlayer(self.player) crect = CRectangle(cpos=(Window.width // 2, Window.height // 2), csize=(Window.width, Window.height)) crect.texture = Image('../images/Blackboard.png').texture self.canvas.add(crect) self.canvas.add(self.player) self.canvas.add(self.gui) #midi input state self.info.parent = None # make sure the label widget does not have a parent self.add_widget(self.info) self.switchScreens = callback def on_key_down(self, keycode, modifiers): if keycode[1] == 'p': self.pause_game() elif keycode[1] == 'o': self.play_game() ''' elif keycode[1] == 'c' and self.midiInput is None: self.initialize_controller() # self.playerSynth.start() # else: # self.player.on_input(keycode[1]) ''' def play_game(self): self.clock.start() self.player.play_game() self.playing = True def pause_game(self): self.player.pause_game() self.clock.stop() self.playing = False def on_update(self): if not self.parent: return if self.playing: self.player.on_update() self.gui.on_update() # check for midi input and add onscreen indicator if not self.parent._has_midi_input(): self.info.text = "\n\nNo Keyboard Connected" else: if self.player.scoreCard: self.info.text = "\n\nScore: %d" % self.player.scoreCard.getScore( ) else: self.info.text = "\n\nPress o to Start!" # update personal clock # self.t += kivyClock.frametime '''