Esempio n. 1
0
 def get_question(self):
     """
     Return a string that can be used to display the intervals.
     """
     score = elems.Score()
     staff = score.add_staff()
     staff.set_property(solfege.mpd.Rat(0, 1), 'hide-barline', True)
     staff.set_property(solfege.mpd.Rat(0, 1), 'hide-timesignature', True)
     score.voice11.append(
         elems.Note(self.m_tonika, solfege.mpd.Duration(4, 0)))
     last = self.m_tonika
     tones = [last]
     for i in self.m_question:
         n = mpd.Interval()
         n.set_from_int(i)
         last = last + n
         if abs(last.m_accidental_i) > 1:
             last.normalize_double_accidental()
         tones.append(last)
         score.voice11.append(elems.Note(last, solfege.mpd.Duration(4, 0)))
     score.m_staffs[0].set_clef(
         solfege.mpd.select_clef(" ".join(
             [x.get_octave_notename() for x in tones])),
         solfege.mpd.Rat(0, 1))
     return score
Esempio n. 2
0
 def show_intervals(self, widget=None):
     tv = [
         self.get_string('first_interval_type'),
         self.get_string('last_interval_type')
     ]
     clefs = {}
     music = {}
     for x in range(2):
         music[x] = self.m_t.m_tonikas[x].get_octave_notename() + " " \
             + (self.m_t.m_tonikas[x] + mpd.Interval().set_from_int(self.m_t.m_intervals[x])).get_octave_notename()
         clefs[x] = mpd.select_clef(music[x])
         if tv[x] == 'harmonic':
             music[x] = "< %s >" % music[x]
     m = r"\staff{ \clef %s %s |" % (clefs[0], music[0])
     if clefs[0] != clefs[1]:
         m = m + r"\clef %s " % clefs[1]
     m = m + music[1]
     self.g_music_displayer.display(
         m, self.get_int('config/feta_font_size=20'))
Esempio n. 3
0
 def answered_correctly(self):
     """
     Return true if the question is answered correctly.
     """
     if self.m_answered_quality:
         q = self.m_answered_quality
     else:
         assert len(self.m_P.header.interval_quality) == 1
         q = self.m_P.header.interval_quality[0]
     if self.m_answered_number:
         n = self.m_answered_number
     else:
         assert len(self.m_P.header.interval_number) == 1
         n = self.m_P.header.interval_number[0]
     try:
         i = mpd.Interval("%s%s" % (q, n))
     except mpd.interval.InvalidIntervalnameException:
         return False
     return i == self.m_interval
Esempio n. 4
0
 def click_on_interval(self, mouse_button, interval, midi_int):
     """The key bindings are also directed here.
     """
     if mouse_button == 3 and not solfege.app.m_test_mode \
             and self.get_int('number_of_intervals') == 1:
         if not self.m_t.m_tonika:
             return
         i = mpd.Interval()
         if (not midi_int  # buttons interface does not set midi_int. And
                 # since it assumes all intervals go up, we have
                 # to check and set the direction.
                 and self.m_t.m_question[0] < 0):
             i.set_from_int(-interval)
         else:
             i.set_from_int(interval)
         n = self.m_t.m_tonika + i
         track = utils.new_track()
         track.note(4, self.m_t.m_tonika.semitone_pitch())
         track.note(4, n.semitone_pitch())
         soundcard.synth.play_track(track)
         return
     if mouse_button not in (1, self.keyboard_accel):
         return
     if solfege.app.m_test_mode and self.m_t.q_status == self.QSTATUS_NO:
         self.g_flashbar.flash(_("Click 'Start test' to begin."))
         return
     if solfege.app.m_test_mode:
         self.g_new.hide()
     if self.m_t.q_status == self.QSTATUS_NO:
         self.g_flashbar.flash(_("Click 'New interval' to begin."))
         return
     if midi_int:
         # midi_int is only set when we use some of the instrument widgets,
         # not when we use the buttons interface.
         utils.play_note(4, midi_int)
     if self.m_t.q_status == self.QSTATUS_GIVE_UP:
         return
     if self.m_t.q_status == self.QSTATUS_SOLVED:
         self.g_flashbar.flash(
             _("You have already identified this interval"))
         return
     if not (mpd.interval.min_interval < interval <=
             mpd.interval.max_interval):
         self.g_flashbar.flash(
             _("Ignoring intervals greater than double octave."))
         self.g_input.forget_last_tone()
         return
     self.m_answer.append(interval)
     d = self.m_t.m_question[len(self.m_answer) - 1]
     md = d / abs(d)
     if self.g_input.know_directions():
         md = 1
     if not self.msg:
         self.msg = utils.int_to_intervalname(interval * md, 1, 1) + "+ ..."
     else:
         self.msg = self.msg[:-4]
         self.msg = self.msg + utils.int_to_intervalname(
             interval * md, 1, 1) + "+ ..."
     self.g_flashbar.push(self.msg)
     if len(self.m_answer) == self.m_number_of_intervals_in_question:
         if self.m_t.guess_answer(self.m_answer,
                                  self.g_input.know_directions()):
             self.g_flashbar.clear()
             self.g_flashbar.flash(_("Correct"))
             self.std_buttons_answer_correct()
         else:
             self.g_flashbar.clear()
             self.g_flashbar.flash(_("Wrong"))
             if self.get_bool(
                     "config/auto_repeat_question_if_wrong_answer"):
                 self.m_t.play_question()
             self.std_buttons_answer_wrong()
         self.m_answer = []
         self.g_input.set_first_note(self.m_t.m_tonika)
         self.msg = ""
     if solfege.app.m_test_mode and self.m_t.m_P.is_test_complete():
         self.do_test_complete()
         return