Beispiel #1
0
 def hint(self, midi_out):
     seq = (
         melody(self.notes).rhythm(1 / 8)
         + rest(1 / 8)
         + chord(self.notes).rhythm(1 / 4)
     )
     play(midi_out, seq.render(self.root, 120))
Beispiel #2
0
    def blonk(self, asked, answered, midi_out):
        def x(a, b):
            if a != b:
                return chord([self.note(a), self.note(b)])
            else:
                return Note(self.note(a))

        blonk = Sequence([x(a, b) for a, b in zip(asked, answered)])
        play(midi_out, (blonk + rest(0.25)).render(60, 120))
Beispiel #3
0
    def handle_event(self, event):
        "The events we handle directly."
        if is_quit(event):
            self.running = False

        elif is_replay(event):
            self.quiz.current_question.play(self.midi_out, self.quiz.root)

        elif is_replay_with_hint(event):
            self.quiz.current_question.hint(self.midi_out)

        elif is_establish_key(event):
            play(self.midi_out, establish_key)

        elif event.type == QuizUI.NEW_QUESTION:
            self.draw()
            event.question.play(self.midi_out, self.quiz.root)

        elif event.type == QuizUI.CORRECT_ANSWER:
            self.play_and_wait(self.correct_sound)
            self.draw()

        elif event.type == QuizUI.WRONG_ANSWER:
            self.play_and_wait(self.wrong_sound)
            self.draw()
            event.question.play(self.midi_out, self.quiz.root)

        elif event.type == Button.BUTTON_PRESSED:
            # FIXME: this should probably live in the Button itself.
            if event.button.state is ButtonState.WRONG:
                # We get here when the button has already been marked
                # wrong previously.
                event.button.question.play(self.midi_out, self.quiz.root)
            else:
                if self.quiz.check_answer(event.button.question):
                    for b in self.grid.buttons:
                        b.state = ButtonState.ACTIVE
                else:
                    event.button.state = ButtonState.WRONG
                    event.button.draw(update=True)
Beispiel #4
0
def run():

    m = make_melody()

    round = (
        m.transpose(12)
        | (Rest(1) + m)
        | (Rest(2) + m.transpose(-12))
        | (Rest(3) + m.transpose(-24))
    )

    pygame.init()
    pygame.midi.init()

    port = pygame.midi.get_default_output_id()

    midi_out = pygame.midi.Output(port, 0)

    try:
        midi_out.set_instrument(0)
        play(midi_out, round.render(60, 120))
    finally:
        pygame.midi.quit()
Beispiel #5
0
 def play(self, midi_out, root):
     play(midi_out, chord(self.notes).render(root, 120))
Beispiel #6
0
 def play(self, elements, midi_out):
     play(midi_out, melody([self.note(i) for i in elements]).render(60, 60))
Beispiel #7
0
 def establish_key(self, midi_out):
     play(midi_out, melody([0, 12]).render(60, 60))
Beispiel #8
0
 def after_correct(self, midi_out):
     pitches = [self.scale.note(d) for d in range(self.degree, 0, -1)]
     midi = melody(pitches).rhythm(1 / 8) + rest(1 / 4)
     play(midi_out, midi.render(60, 120))
Beispiel #9
0
 def play(self, midi_out):
     play(midi_out, melody((0, self.scale.note(self.degree))).render(60, 120))
Beispiel #10
0
 def play(self, midi_out):
     play(midi_out, self.midi)
Beispiel #11
0
 def hint(self, midi_out):
     second_note = -self.distance if self.ascending else self.distance
     play(midi_out, melody((0, second_note)).render(self.root, speed))