Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
 def on_quit(self, qevent):
     """ stop the while loop from running """
     Clock.stop(self)
Ejemplo n.º 3
0
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
        '''