def play_question(self):
     score = self.m_P.m_question_score
     countin = self.m_P.m_globals.get('countin')
     countin = self.m_P.m_questions[self.m_P._idx].get('countin', countin)
     if countin:
         score = elems.Score.concat2(countin.get_score(self.m_P, as_name='countin'), score)
     tracks = mpd.score_to_tracks(score)
     tracks[0].prepend_bpm(*self.m_P.get_tempo())
     soundcard.synth.play_track(*tracks)
Example #2
0
 def play_question(self):
     score = self.m_P.m_question_score
     countin = self.m_P.m_globals.get('countin')
     countin = self.m_P.m_questions[self.m_P._idx].get('countin', countin)
     if countin:
         score = elems.Score.concat2(countin.get_score(self.m_P, as_name='countin'), score)
     tracks = mpd.score_to_tracks(score)
     tracks[0].prepend_bpm(*self.m_P.get_tempo())
     soundcard.synth.play_track(*tracks)
 def play(self, rhythm):
     """
     rhythm is a string. Example: 'c4 c8 c8 c4'
     """
     # FIXME can we use lessonfile.Rhythm insted of this?
     score = mpd.parser.parse_to_score_object(rhythm)
     track = mpd.score_to_tracks(score)[0]
     track.prepend_bpm(self.get_int("bpm"))
     track.prepend_volume(cfg.get_int('config/preferred_instrument_volume'))
     soundcard.synth.play_track(track)
Example #4
0
 def play(self, rhythm):
     """
     rhythm is a string. Example: 'c4 c8 c8 c4'
     """
     # FIXME can we use lessonfile.Rhythm insted of this?
     score = mpd.parser.parse_to_score_object(rhythm)
     track = mpd.score_to_tracks(score)[0]
     track.prepend_bpm(self.get_int("bpm"))
     track.prepend_volume(cfg.get_int('config/preferred_instrument_volume'))
     soundcard.synth.play_track(track)
Example #5
0
 def test_midigen_tie(self):
     n1 = Note.new_from_string("c4")
     n2 = Note.new_from_string("c4")
     n3 = Note.new_from_string("c4")
     n4 = Note.new_from_string("d4")
     self.score.voice11.append(n1)
     self.score.voice11.append(n2)
     self.score.voice11.append(n3)
     self.score.voice11.append(n4)
     self.score.voice11.tie([n1, n2, n3])
     t = mpd.score_to_tracks(self.score)
     self.assertEqual(t[0].str_repr(), "n48 d3/4 o48 n50 d1/4 o50")
Example #6
0
def play_music(music, tempo, patch, volume, start=None, end=None):
    if isinstance(tempo, int):
        bpm = tempo
        nl = 4
    else:
        bpm, nl = tempo
    score = mpd.parser.parse_to_score_object(music)
    tracklist = mpd.score_to_tracks(score, start, end)
    tracklist[0].prepend_bpm(bpm, nl)
    [track.prepend_patch(patch) for track in tracklist]
    [track.prepend_volume(volume) for track in tracklist]
    soundcard.synth.play_track(*tracklist)
Example #7
0
 def test_midigen_tie(self):
     n1 = Note.new_from_string("c4")
     n2 = Note.new_from_string("c4")
     n3 = Note.new_from_string("c4")
     n4 = Note.new_from_string("d4")
     self.score.voice11.append(n1)
     self.score.voice11.append(n2)
     self.score.voice11.append(n3)
     self.score.voice11.append(n4)
     self.score.voice11.tie([n1, n2, n3])
     t = mpd.score_to_tracks(self.score)
     self.assertEqual(t[0].str_repr(), "n48 d3/4 o48 n50 d1/4 o50")
 def play_question(self):
     # We can only create countin for questions that are generated using
     # the mpd module
     music = self.m_P.get_question()['music']
     if isinstance(music, lessonfile.MpdParsable):
         score = self.m_P.get_score('music')
         countin = self.m_P.m_globals.get('countin')
         countin = self.m_P.get_question().get('countin', countin)
         if countin:
             score = elems.Score.concat2(countin.get_score(self.m_P, as_name='countin'), score)
         tracks = mpd.score_to_tracks(score)
         tracks[0].prepend_bpm(*self.m_P.get_tempo())
         soundcard.synth.play_track(*tracks)
     else:
         self.m_P.play_question()
 def play_question(self):
     # We can only create countin for questions that are generated using
     # the mpd module
     music = self.m_P.get_question()['music']
     if isinstance(music, lessonfile.MpdParsable):
         score = self.m_P.get_score('music')
         countin = self.m_P.m_globals.get('countin')
         countin = self.m_P.get_question().get('countin', countin)
         if countin:
             score = elems.Score.concat2(countin.get_score(self.m_P, as_name='countin'), score)
         tracks = mpd.score_to_tracks(score)
         tracks[0].prepend_bpm(*self.m_P.get_tempo())
         soundcard.synth.play_track(*tracks)
     else:
         self.m_P.play_question()
Example #10
0
    def play_question(self):
        cadence = self.m_cadence['music'][:]
        p = mpd.MusicalPitch.new_from_notename("c'") + self.m_tone
        if self.get_bool('random_tonic'):
            cadence = cadence.replace(
                "\\staff", "\\staff\\transpose %s" %
                self.m_transpose.get_octave_notename())
            p.transpose_by_musicalpitch(self.m_transpose)
        m = mpd.parse_to_score_object(cadence)
        # Here we assume that we can check the first voice of the first
        # staff when finding the timepos and the duration of the last
        # tone in the cadence. But it is ok to have more staffs or voices
        # in the cadence, as long as the first assumption is true.
        staff = m.add_staff()
        voice = staff.add_voice()
        if 'tone_instrument' in self.m_cadence:
            try:
                instr = soundcard.find_midi_instrument_number(
                    self.m_cadence.get("tone_instrument"))
            except KeyError:
                logging.warning("WARNING: Bad MIDI instrument name in «%s»" %
                                self.m_P.m_filename)
                instr = cfg.get_int("config/preferred_instrument")
        else:
            instr = cfg.get_int("config/preferred_instrument")

        if self.get_bool('tone_in_cadence'):
            timepos = m.m_staffs[0].get_timeposes()[-1]
            last_len = m.m_staffs[0].m_voices[0].m_length - timepos
        else:
            timepos = m.m_staffs[0].m_voices[0].m_length
            last_len = mpd.Rat(1, 4)
        voice.set_elem([elems.Note(p, elems.Duration.new_from_rat(last_len))],
                       timepos)
        tr = mpd.score_to_tracks(m)
        t = self.m_cadence.get('tempo', (60, 4))
        tr[0].prepend_bpm(t[0], t[1])
        tr[-1].prepend_patch(instr)
        soundcard.synth.play_track(*tr)
Example #11
0
    def play_question(self):
        cadence = self.m_cadence['music'][:]
        p = mpd.MusicalPitch.new_from_notename("c'") + self.m_tone
        if self.get_bool('random_tonic'):
            cadence = cadence.replace("\\staff", "\\staff\\transpose %s" % self.m_transpose.get_octave_notename())
            p.transpose_by_musicalpitch(self.m_transpose)
        m = mpd.parse_to_score_object(cadence)
        # Here we assume that we can check the first voice of the first
        # staff when finding the timepos and the duration of the last
        # tone in the cadence. But it is ok to have more staffs or voices
        # in the cadence, as long as the first assumption is true.
        staff = m.add_staff()
        voice = staff.add_voice()
        if 'tone_instrument' in self.m_cadence:
            try:
                instr = soundcard.find_midi_instrument_number(
                    self.m_cadence.get("tone_instrument"))
            except KeyError:
                logging.warning("WARNING: Bad MIDI instrument name in «%s»"
                                % self.m_P.m_filename)
                instr = cfg.get_int("config/preferred_instrument")
        else:
            instr = cfg.get_int("config/preferred_instrument")

        if self.get_bool('tone_in_cadence'):
            timepos = m.m_staffs[0].get_timeposes()[-1]
            last_len = m.m_staffs[0].m_voices[0].m_length - timepos
        else:
            timepos = m.m_staffs[0].m_voices[0].m_length
            last_len = mpd.Rat(1, 4)
        voice.set_elem([elems.Note(p, elems.Duration.new_from_rat(last_len))],
                       timepos)
        tr = mpd.score_to_tracks(m)
        t = self.m_cadence.get('tempo', (60, 4))
        tr[0].prepend_bpm(t[0], t[1])
        tr[-1].prepend_patch(instr)
        soundcard.synth.play_track(*tr)
Example #12
0
 def test_midigen_rest(self):
     self.score.voice11.append(Note.new_from_string("c4"))
     self.score.voice11.append(Rest(Duration.new_from_string("4")))
     self.score.voice11.append(Note.new_from_string("c4"))
     t = mpd.score_to_tracks(self.score)
     self.assertEqual(t[0].str_repr(), "n48 d1/4 o48 d1/4 n48 d1/4 o48")
Example #13
0
 def test_midigen_rest(self):
     self.score.voice11.append(Note.new_from_string("c4"))
     self.score.voice11.append(Rest(Duration.new_from_string("4")))
     self.score.voice11.append(Note.new_from_string("c4"))
     t = mpd.score_to_tracks(self.score)
     self.assertEqual(t[0].str_repr(), "n48 d1/4 o48 d1/4 n48 d1/4 o48")