Esempio n. 1
0
def nComboBox(exname, name, default, popdown_strings):
    c = Gtk.ComboBoxText()
    for n in popdown_strings:
        c.append_text(n)
    c.m_exname = exname
    c.m_name = name
    val = cfg.get_string("%s/%s=X" % (c.m_exname, c.m_name))
    if val == 'X':
        cfg.set_int("%s/%s" % (exname, name),
            popdown_strings.index(default))
        c.set_active(popdown_strings.index(default))
    else:
        try:
            i = cfg.get_int("%s/%s" % (c.m_exname, c.m_name))
        except ValueError:
            i = 0
            cfg.set_int("%s/%s" % (c.m_exname, c.m_name), 0)
        if i >= len(popdown_strings):
            i = 0
            cfg.set_int("%s/%s" % (c.m_exname, c.m_name), 0)
        c.set_active(cfg.get_int("%s/%s" % (c.m_exname, c.m_name)))
    def f(combobox):
        cfg.set_int("%s/%s" % (exname, name), combobox.get_active())
    c.connect('changed', f)
    return c
Esempio n. 2
0
def nComboBox(exname, name, default, popdown_strings):
    c = gtk.combo_box_new_text()
    for n in popdown_strings:
        c.append_text(n)
    c.m_exname = exname
    c.m_name = name
    val = cfg.get_string("%s/%s=X" % (c.m_exname, c.m_name))
    if val == 'X':
        cfg.set_int("%s/%s" % (exname, name), popdown_strings.index(default))
        c.set_active(popdown_strings.index(default))
    else:
        try:
            i = cfg.get_int("%s/%s" % (c.m_exname, c.m_name))
        except ValueError:
            i = 0
            cfg.set_int("%s/%s" % (c.m_exname, c.m_name), 0)
        if i >= len(popdown_strings):
            i = 0
            cfg.set_int("%s/%s" % (c.m_exname, c.m_name), 0)
        c.set_active(cfg.get_int("%s/%s" % (c.m_exname, c.m_name)))

    def f(combobox):
        cfg.set_int("%s/%s" % (exname, name), combobox.get_active())

    c.connect('changed', f)
    return c
Esempio n. 3
0
 def f(w, start, end, self=self):
     try:
         utils.play_music(self.m_t.m_P.get_music(),
             self.m_t.m_P.get_tempo(),
             cfg.get_int('config/preferred_instrument'),
             cfg.get_int('config/preferred_instrument_volume'),
             start, end)
     except Exception, e:
         if not self.standard_exception_handler(e, soundcard.synth.stop):
             raise
Esempio n. 4
0
 def f(w, start, end, self=self):
     try:
         utils.play_music(
             self.m_t.m_P.get_music(), self.m_t.m_P.get_tempo(),
             cfg.get_int('config/preferred_instrument'),
             cfg.get_int('config/preferred_instrument_volume'), start,
             end)
     except Exception, e:
         if not self.standard_exception_handler(e,
                                                soundcard.synth.stop):
             raise
Esempio n. 5
0
def initialise_alsa_sequencer(port, verbose_init=0):
    """
    This function should only be called if the pyalsa module is available.
    """
    global synth
    from solfege.soundcard import alsa_sequencer
    solfege.mpd.track.set_patch_delay = cfg.get_int("app/set_patch_delay")
    synth = alsa_sequencer.AlsaSequencer(port, verbose_init)
Esempio n. 6
0
def initialise_alsa_sequencer(port, verbose_init=0):
    """
    This function should only be called if the pyalsa module is available.
    """
    global synth
    from solfege.soundcard import alsa_sequencer
    solfege.mpd.track.set_patch_delay = cfg.get_int("app/set_patch_delay")
    synth = alsa_sequencer.AlsaSequencer(port, verbose_init)
 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)
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 10
0
def initialise_devicefile(devicefile, devicenum=0, verbose_init=0):
    global synth
    if devicefile == '/dev/sequencer2' or devicefile == '/dev/music':
        import solfege.soundcard.oss_sequencer2
        synth = solfege.soundcard.oss_sequencer2.OSSSequencer2Synth(devicefile, devicenum,
                                                  verbose_init)
    else:#if devicefile == '/dev/sequencer':
        if devicefile != '/dev/sequencer':
            print "warning: the device file is unknown. Assuming it is /dev/sequencer - compatible"
        import solfege.soundcard.oss_sequencer
        synth = solfege.soundcard.oss_sequencer.OSSSequencerSynth(devicefile, devicenum,
                                                verbose_init)
    solfege.mpd.track.set_patch_delay = cfg.get_int("app/set_patch_delay")
Esempio n. 11
0
def initialise_devicefile(devicefile, devicenum=0, verbose_init=0):
    global synth
    if devicefile == '/dev/sequencer2' or devicefile == '/dev/music':
        import solfege.soundcard.oss_sequencer2
        synth = solfege.soundcard.oss_sequencer2.OSSSequencer2Synth(
            devicefile, devicenum, verbose_init)
    else:  #if devicefile == '/dev/sequencer':
        if devicefile != '/dev/sequencer':
            print "warning: the device file is unknown. Assuming it is /dev/sequencer - compatible"
        import solfege.soundcard.oss_sequencer
        synth = solfege.soundcard.oss_sequencer.OSSSequencerSynth(
            devicefile, devicenum, verbose_init)
    solfege.mpd.track.set_patch_delay = cfg.get_int("app/set_patch_delay")
Esempio n. 12
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)
Esempio n. 13
0
def new_3_tracks():
    if cfg.get_bool('config/override_default_instrument'):
        instr_low = cfg.get_int('config/lowest_instrument')
        instr_low_volume = cfg.get_int('config/lowest_instrument_volume')
        instr_middle = cfg.get_int('config/middle_instrument')
        instr_middle_volume = cfg.get_int('config/middle_instrument_volume')
        instr_high = cfg.get_int('config/highest_instrument')
        instr_high_volume = cfg.get_int('config/highest_instrument_volume')
    else:
        instr_low = instr_middle = instr_high = cfg.get_int('config/preferred_instrument')
        instr_low_volume = instr_middle_volume = instr_high_volume = cfg.get_int('config/preferred_instrument_volume')
    t1 = mpd.Track()
    t1.set_bpm(cfg.get_int('config/default_bpm'))
    t1.set_patch(instr_low)
    t1.set_volume(instr_low_volume)
    t2 = mpd.Track()
    t2.set_patch(instr_middle)
    t2.set_volume(instr_middle_volume)
    t3 = mpd.Track()
    t3.set_patch(instr_high)
    t3.set_volume(instr_high_volume)
    return t1, t2, t3
Esempio n. 14
0
    def new_question(self):
        last = self.m_question
        if not self.get_possible_bpms():
            return self.NO_TEMPOS

        self.m_question = random.choice(self.get_possible_bpms())
        while self.m_question == last and len(self.get_possible_bpms()) > 1:
            self.m_question = random.choice(self.get_possible_bpms())
        self.m_question_track = mpd.PercussionTrack()
        self.m_question_track.set_bpm(self.m_question)
        # Lets play the tempo between 20 and 40 seconds. We cannot let
        # it play a static number of seconds, because then the user can
        # count how many beats and find out how fast it plays.
        for n in range(int(self.m_question / (random.random() * 1.5 + 1.5))):
            self.m_question_track.note(4, cfg.get_int("config/rhythm_perc"))
        self.q_status = self.QSTATUS_NEW
        return self.OK
Esempio n. 15
0
def initialise_external_midiplayer(verbose_init=0):
    global synth
    import solfege.soundcard.midifilesynth
    solfege.mpd.track.set_patch_delay = cfg.get_int("app/set_patch_delay")
    synth = solfege.soundcard.midifilesynth.MidiFileSynth(verbose_init)
Esempio n. 16
0
def check_rcfile():
    """See default.config for rcfileversion values, meanings and
    a description of how to add config variables.
    """
    rcfileversion = 21
    if cfg.get_int("app/rcfileversion") > rcfileversion:
        cfg.drop_user_config()
        return
    if cfg.get_int("app/rcfileversion") <= 1:
        if not "example-files" in cfg.get_string('config/lessoncollections'):
            cfg.set_string(
                'config/lessoncollections', "%s example-files" %
                cfg.get_string('config/lessoncollections'))
    if cfg.get_int("app/rcfileversion") <= 5:
        # This is more complicated that necessary to fix an old
        # error.
        if cfg.get_string("sound/commandline"):
            cfg.del_key("sound/commandline")
    if cfg.get_int("app/rcfileversion") <= 3:
        cfg.set_list("config/lessoncollections",
                     cfg.get_string("config/lessoncollections").split())
    if cfg.get_int("app/rcfileversion") <= 4:
        cfg.del_key("config/web_browser")
    if sys.platform == 'win32':
        if cfg.get_string('sound/wav_player'):
            cfg.del_key('sound/wav_player')
    if cfg.get_int("app/rcfileversion") <= 5:
        cfg.set_string("mainwin/history_back_ak", "<alt>Left")
        cfg.set_string("mainwin/history_forward_ak", "<alt>Right")
        cfg.set_string("mainwin/history_reload_ak", "<ctrl>r")
    if cfg.get_int("app/rcfileversion") <= 6:
        cfg.set_list("config/lessoncollections", ['solfege', 'user'])
    if cfg.get_int("app/rcfileversion") <= 7:
        cfg.set_int("rhythm/countin_perc", 80)
    if cfg.get_int("app/rcfileversion") <= 8:
        cfg.del_key("singinterval/highest_tone")
        cfg.del_key("singinterval/lowest_tone")
        cfg.del_key("melodicinterval/highest_tone")
        cfg.del_key("melodicinterval/lowest_tone")
        cfg.del_key("harmonicinterval/highest_tone")
        cfg.del_key("harmonicinterval/lowest_tone")
    if cfg.get_int("app/rcfileversion") <= 9:
        cfg.del_section("mainwin")
    if cfg.get_int("app/rcfileversion") <= 10:
        cfg.del_section("lessoncollections")
        cfg.del_key("config/lessoncollections")
        for n in cfg.iterate_sections():
            cfg.del_key("%s/lessoncollection" % n)
            cfg.del_key("%s/lessonfile" % n)
    if cfg.get_int("app/rcfileversion") <= 11:
        for s in ('rhythm', 'rhythmtapping2'):
            cfg.del_key("%s/countin_perc" % s)
            cfg.del_key("%s/rhythm_perc" % s)
    if cfg.get_int("app/rcfileversion") <= 12:
        cfg.del_key("sound/card_info")
    if cfg.get_int("app/rcfileversion") <= 13:
        cfg.del_key("config/lowest_instrument_velocity")
        cfg.del_key("config/middle_instrument_velocity")
        cfg.del_key("config/highest_instrument_velocity")
        cfg.del_key("config/preferred_instrument_velocity")
    if cfg.get_int("app/rcfileversion") <= 14:
        # We have to split the midi_to_wav_cmd into two strings, and
        # moving the options to *_options, so that midi_to_wav_cmd only
        # have the name of the binary. This to allow binaries in dirs
        # with spaces.
        for k in ("midi_to_wav", "wav_to_mp3", "wav_to_ogg"):
            v = cfg.get_string("app/%s_cmd" % k).split(" ")
            cfg.set_string("app/%s_cmd" % k, v[0])
            cfg.set_string("app/%s_cmd_options" % k, " ".join(v[1:]))
    if cfg.get_int("app/rcfileversion") <= 15:
        for k in ("midi", "wav", "mp3", "ogg"):
            v = cfg.get_string("sound/%s_player" % k).split(" ")
            cfg.set_string("sound/%s_player" % k, v[0])
            cfg.set_string("sound/%s_player_options" % k, " ".join(v[1:]))
    if cfg.get_int("app/rcfileversion") < 17:
        v = cfg.get_string("app/frontpage").split("/")
        if v[0] == u"exercises" and v[1] != u"standard":
            cfg.set_string("app/frontpage",
                           u"/".join([v[0], u"standard"] + v[1:]))
    if cfg.get_int("app/rcfileversion") < 18:
        cfg.del_key("gui/web_browser_as_help_browser")
    if cfg.get_int("app/rcfileversion") < 19:
        for ex in ('singinterval', 'melodicinterval'):
            if cfg.get_int("%s/maximum_number_of_intervals" % ex) == 10:
                cfg.set_int("%s/maximum_number_of_intervals" % ex, 12)
    if cfg.get_int("app/rcfileversion") < 20:
        cfg.del_key("gui/reserved_vspace")
    if cfg.get_int("app/rcfileversion") < 21:
        for ex in ("melodicinterval", "harmonicinterval"):
            i = cfg.get_int("%s/inputwidget" % ex)
            if i > 0:
                cfg.set_int("%s/inputwidget" % ex, i + 1)

    cfg.set_int("app/rcfileversion", rcfileversion)
    try:
        a = mpd.notename_to_int(cfg.get_string("user/lowest_pitch"))
        b = mpd.notename_to_int(cfg.get_string("user/highest_pitch"))
    except mpd.InvalidNotenameException:
        if cfg.get_string("user/sex") == "male":
            cfg.set_string("user/highest_pitch", "e'")
            cfg.set_string("user/lowest_pitch", "c")
        else:
            cfg.set_string("user/highest_pitch", "e''")
            cfg.set_string("user/lowest_pitch", "c'")
Esempio n. 17
0
def initialise_winsynth(synthnum, verbose_init=0):
    from solfege.soundcard import winsynth
    global synth
    solfege.mpd.track.set_patch_delay = cfg.get_int("app/set_patch_delay")
    synth = winsynth.WinSynth(synthnum, verbose_init)
Esempio n. 18
0
 def play_happy_sound(self):
     utils.play_music(r"\staff\relative c'{c16 e g a}", 180, 8,
            cfg.get_int('config/preferred_instrument_volume'))
Esempio n. 19
0
 def display_music(self, music):
     fontsize = cfg.get_int('config/feta_font_size=20')
     self.g_music_displayer.display(music, fontsize)
Esempio n. 20
0
 def play_sad_sound(self):
     utils.play_music(r"\staff\relative c'{<c,,8 cis>", 80, 58,
            cfg.get_int('config/preferred_instrument_volume'))
Esempio n. 21
0
def new_percussion_track():
    t1 = mpd.PercussionTrack()
    t1.set_bpm(cfg.get_int('config/default_bpm'))
    t1.set_volume(cfg.get_int('config/preferred_instrument_volume'))
    return t1
Esempio n. 22
0
def new_track():
    t1 = mpd.Track()
    t1.set_bpm(cfg.get_int('config/default_bpm'))
    t1.set_volume(cfg.get_int('config/preferred_instrument_volume'))
    t1.set_patch(cfg.get_int('config/preferred_instrument'))
    return t1
Esempio n. 23
0
def initialise_winsynth(synthnum, verbose_init=0):
    from solfege.soundcard import winsynth
    global synth
    solfege.mpd.track.set_patch_delay = cfg.get_int("app/set_patch_delay")
    synth = winsynth.WinSynth(synthnum, verbose_init)
Esempio n. 24
0
 def display_music(self, music):
     fontsize = cfg.get_int('config/feta_font_size=20')
     self.g_music_displayer.display(music, fontsize)
Esempio n. 25
0
             cfg.get_int("sound/synth_number"),
             verbose_init=self.m_options.verbose_sound_init)
     except ImportError, e:
         self.display_sound_init_error_message(e)
         cfg.set_string("sound/type", "fake-synth")
         soundcard.initialise_using_fake_synth(True)
         return
     except RuntimeError, e:
         # We can get here if winmidi.output_devices() in winsynth
         # __init__ returns no devices. Don't know when, but it could
         # happen.
         gu.display_exception_message(e)
         cfg.set_string("sound/type", "fake-synth")
         soundcard.initialise_using_fake_synth(True)
         return
     if cfg.get_int("sound/synth_number") != soundcard.synth.m_devnum:
         solfege.win.display_error_message2(
             _("MIDI setup"),
             _("MIDI Device %(olddev)i not available. Will use device %(newdev)i."
               ) % {
                   'olddev': cfg.get_int("sound/synth_number"),
                   'newdev': soundcard.synth.m_devnum
               })
         cfg.set_int("sound/synth_number", soundcard.synth.m_devnum)
 elif cfg.get_string("sound/type") == "external-midiplayer":
     soundcard.initialise_external_midiplayer(
         verbose_init=self.m_options.verbose_sound_init)
     soundcard.synth.error_report_cb = solfege.win.display_error_message
 elif cfg.get_string("sound/type") == '':
     solfege.win.display_error_message(
         _("You should configure sound from the 'Sound' page "
Esempio n. 26
0
 def setup_sound(self):
     if sys.platform == 'win32' and \
                 cfg.get_string("sound/type") == "sequencer-device":
         # just in case c:\home\.solfegerc is wrong
         cfg.set_string("sound/type", "winsynth")
     if self.m_options.no_sound \
        or cfg.get_string("sound/type") == "fake-synth":
         soundcard.initialise_using_fake_synth(self.m_options.verbose_sound_init)
     elif cfg.get_string("sound/type") == "alsa-sequencer":
         if alsaseq:
             try:
                 clientid, portid = self.get_list("sound/alsa-client-port")
             except ValueError:
                 clientid, portid = (None, None)
             try:
                 soundcard.initialise_alsa_sequencer((clientid, portid),
                         self.m_options.verbose_sound_init)
             except alsaseq.SequencerError as e:
                 logging.debug("initialise_alsa_sequencer failed. Using fake synth.")
                 self.display_sound_init_error_message(e)
                 soundcard.initialise_using_fake_synth(True)
                 return
         else:
             if solfege.splash_win:
                 solfege.splash_win.hide()
             gu.dialog_ok(_("The pyalsa Python module is missing"),
                 solfege.win,
                 _("Solfege was configured to use the Python modules from www.alsa-project.org, but the modules were not found. You must reconfigure sound in the preferences window (Ctrl-F12) or restart Solfege in a way that it finds the modules."))
             soundcard.initialise_using_fake_synth(True)
             if solfege.splash_win:
                 solfege.splash_win.show()
     elif cfg.get_string("sound/type") == "winsynth":
         try:
             soundcard.initialise_winsynth(cfg.get_int("sound/synth_number"),
                   verbose_init=self.m_options.verbose_sound_init)
         except ImportError as e:
             self.display_sound_init_error_message(e)
             cfg.set_string("sound/type", "fake-synth")
             soundcard.initialise_using_fake_synth(True)
             return
         except RuntimeError as e:
             # We can get here if winmidi.output_devices() in winsynth
             # __init__ returns no devices. Don't know when, but it could
             # happen.
             gu.display_exception_message(e)
             cfg.set_string("sound/type", "fake-synth")
             soundcard.initialise_using_fake_synth(True)
             return
         if cfg.get_int("sound/synth_number") != soundcard.synth.m_devnum:
             solfege.win.display_error_message2(_("MIDI setup"), _("MIDI Device %(olddev)i not available. Will use device %(newdev)i.") % {'olddev': cfg.get_int("sound/synth_number"), 'newdev': soundcard.synth.m_devnum})
             cfg.set_int("sound/synth_number", soundcard.synth.m_devnum)
     elif cfg.get_string("sound/type") == "external-midiplayer":
         soundcard.initialise_external_midiplayer(
                 verbose_init=self.m_options.verbose_sound_init)
         soundcard.synth.error_report_cb = solfege.win.display_error_message
     elif cfg.get_string("sound/type") == '':
         solfege.win.display_error_message(
             _("You should configure sound from the 'Sound' page "
               "of the preferences window."))
     elif cfg.get_string("sound/type") == "sequencer-device":
         try:
             soundcard.initialise_devicefile(
                          cfg.get_string("sound/device_file"),
                          cfg.get_int("sound/synth_number"),
                          verbose_init=self.m_options.verbose_sound_init)
         except (soundcard.SoundInitException, OSError, ImportError) as e:
             self.m_sound_init_exception = e
             soundcard.initialise_using_fake_synth(True)
     if cfg.get_string("programs/csound") == "AUTODETECT":
         for p in osutils.find_csound_executables():
             cfg.set_string("programs/csound", p)
             break
         else:
             # If not csound binary was found, then we set the string empty.
             # This means that autodetection will only happen the first time
             # you run the program. But later will newly installed binaries
             # be shown in the combo box of the preferences window.
             cfg.set_string("programs/csound", "")
     if cfg.get_string("programs/mma") == "AUTODETECT":
         for p in osutils.find_mma_executables(cfg.get_list("app/win32_ignore_drives")):
             cfg.set_string("programs/mma", p)
             break
         else:
             cfg.set_string("programs/mma", "")
Esempio n. 27
0
class SolfegeApp(cfg.ConfigUtils):
    def __init__(self, options):
        """
        options -- command line options parsed by optparse
        """
        cfg.ConfigUtils.__init__(self, 'solfege-app')
        lessonfile.MusicBaseClass.temp_dir = tempfile.mkdtemp(
            prefix="solfege-")
        os.environ['SOLFEGETEMPDIR'] = lessonfile.MusicBaseClass.temp_dir
        # test_mode is when we are running a test from the Tests menu
        self.m_test_mode = False
        self.m_options = options
        self.m_teachers = {}
        self.m_running_exercise = None
        self.m_sound_init_exception = None
        #
        self.m_userman_language = "C"
        for lang in i18n.langs():
            if os.path.isdir(os.path.join('help', lang)):
                self.m_userman_language = lang
                break

    def setup_sound(self):
        if sys.platform == 'win32' and \
                    cfg.get_string("sound/type") == "sequencer-device":
            # just in case c:\home\.solfegerc is wrong
            cfg.set_string("sound/type", "winsynth")
        if self.m_options.no_sound \
           or cfg.get_string("sound/type") == "fake-synth":
            soundcard.initialise_using_fake_synth(
                self.m_options.verbose_sound_init)
        elif cfg.get_string("sound/type") == "alsa-sequencer":
            if alsaseq:
                try:
                    clientid, portid = self.get_list("sound/alsa-client-port")
                except ValueError:
                    clientid, portid = (None, None)
                try:
                    soundcard.initialise_alsa_sequencer(
                        (clientid, portid), self.m_options.verbose_sound_init)
                except alsaseq.SequencerError, e:
                    logging.debug(
                        "initialise_alsa_sequencer failed. Using fake synth.")
                    self.display_sound_init_error_message(e)
                    soundcard.initialise_using_fake_synth(True)
                    return
            else:
                if solfege.splash_win:
                    solfege.splash_win.hide()
                gu.dialog_ok(
                    _("The pyalsa Python module is missing"), solfege.win,
                    _("Solfege was configured to use the Python modules from www.alsa-project.org, but the modules were not found. You must reconfigure sound in the preferences window (Ctrl-F12) or restart Solfege in a way that it finds the modules."
                      ))
                soundcard.initialise_using_fake_synth(True)
                if solfege.splash_win:
                    solfege.splash_win.show()
        elif cfg.get_string("sound/type") == "winsynth":
            try:
                soundcard.initialise_winsynth(
                    cfg.get_int("sound/synth_number"),
                    verbose_init=self.m_options.verbose_sound_init)
            except ImportError, e:
                self.display_sound_init_error_message(e)
                cfg.set_string("sound/type", "fake-synth")
                soundcard.initialise_using_fake_synth(True)
                return
Esempio n. 28
0
def initialise_external_midiplayer(verbose_init=0):
    global synth
    import solfege.soundcard.midifilesynth
    solfege.mpd.track.set_patch_delay = cfg.get_int("app/set_patch_delay")
    synth = solfege.soundcard.midifilesynth.MidiFileSynth(verbose_init)
Esempio n. 29
0
         soundcard.initialise_winsynth(cfg.get_int("sound/synth_number"),
               verbose_init=self.m_options.verbose_sound_init)
     except ImportError, e:
         self.display_sound_init_error_message(e)
         cfg.set_string("sound/type", "fake-synth")
         soundcard.initialise_using_fake_synth(True)
         return
     except RuntimeError, e:
         # We can get here if winmidi.output_devices() in winsynth
         # __init__ returns no devices. Don't know when, but it could
         # happen.
         gu.display_exception_message(e)
         cfg.set_string("sound/type", "fake-synth")
         soundcard.initialise_using_fake_synth(True)
         return
     if cfg.get_int("sound/synth_number") != soundcard.synth.m_devnum:
         solfege.win.display_error_message2(_("MIDI setup"), _("MIDI Device %(olddev)i not available. Will use device %(newdev)i.") % {'olddev': cfg.get_int("sound/synth_number"), 'newdev': soundcard.synth.m_devnum})
         cfg.set_int("sound/synth_number", soundcard.synth.m_devnum)
 elif cfg.get_string("sound/type") == "external-midiplayer":
     soundcard.initialise_external_midiplayer(
             verbose_init=self.m_options.verbose_sound_init)
     soundcard.synth.error_report_cb = solfege.win.display_error_message
 elif cfg.get_string("sound/type") == '':
     solfege.win.display_error_message(
         _("You should configure sound from the 'Sound' page "
           "of the preferences window."))
 elif cfg.get_string("sound/type") == "sequencer-device":
     try:
         soundcard.initialise_devicefile(
                      cfg.get_string("sound/device_file"),
                      cfg.get_int("sound/synth_number"),
Esempio n. 30
0
def check_rcfile():
    """See default.config for rcfileversion values, meanings and
    a description of how to add config variables.
    """
    rcfileversion = 21
    if cfg.get_int("app/rcfileversion") > rcfileversion:
        cfg.drop_user_config()
        return
    if cfg.get_int("app/rcfileversion") <= 1:
        if not "example-files" in cfg.get_string('config/lessoncollections'):
            cfg.set_string('config/lessoncollections',
                "%s example-files" % cfg.get_string('config/lessoncollections'))
    if cfg.get_int("app/rcfileversion") <= 5:
        # This is more complicated that necessary to fix an old
        # error.
        if cfg.get_string("sound/commandline"):
            cfg.del_key("sound/commandline")
    if cfg.get_int("app/rcfileversion") <= 3:
        cfg.set_list("config/lessoncollections",
            cfg.get_string("config/lessoncollections").split())
    if cfg.get_int("app/rcfileversion") <= 4:
        cfg.del_key("config/web_browser")
    if sys.platform == 'win32':
        if cfg.get_string('sound/wav_player'):
            cfg.del_key('sound/wav_player')
    if cfg.get_int("app/rcfileversion") <= 5:
        cfg.set_string("mainwin/history_back_ak", "<alt>Left")
        cfg.set_string("mainwin/history_forward_ak", "<alt>Right")
        cfg.set_string("mainwin/history_reload_ak", "<ctrl>r")
    if cfg.get_int("app/rcfileversion") <= 6:
        cfg.set_list("config/lessoncollections", ['solfege', 'user'])
    if cfg.get_int("app/rcfileversion") <= 7:
        cfg.set_int("rhythm/countin_perc", 80)
    if cfg.get_int("app/rcfileversion") <= 8:
        cfg.del_key("singinterval/highest_tone")
        cfg.del_key("singinterval/lowest_tone")
        cfg.del_key("melodicinterval/highest_tone")
        cfg.del_key("melodicinterval/lowest_tone")
        cfg.del_key("harmonicinterval/highest_tone")
        cfg.del_key("harmonicinterval/lowest_tone")
    if cfg.get_int("app/rcfileversion") <= 9:
        cfg.del_section("mainwin")
    if cfg.get_int("app/rcfileversion") <= 10:
        cfg.del_section("lessoncollections")
        cfg.del_key("config/lessoncollections")
        for n in cfg.iterate_sections():
            cfg.del_key("%s/lessoncollection" % n)
            cfg.del_key("%s/lessonfile" % n)
    if cfg.get_int("app/rcfileversion") <= 11:
        for s in ('rhythm', 'rhythmtapping2'):
            cfg.del_key("%s/countin_perc" % s)
            cfg.del_key("%s/rhythm_perc" % s)
    if cfg.get_int("app/rcfileversion") <= 12:
        cfg.del_key("sound/card_info")
    if cfg.get_int("app/rcfileversion") <= 13:
        cfg.del_key("config/lowest_instrument_velocity")
        cfg.del_key("config/middle_instrument_velocity")
        cfg.del_key("config/highest_instrument_velocity")
        cfg.del_key("config/preferred_instrument_velocity")
    if cfg.get_int("app/rcfileversion") <= 14:
        # We have to split the midi_to_wav_cmd into two strings, and
        # moving the options to *_options, so that midi_to_wav_cmd only
        # have the name of the binary. This to allow binaries in dirs
        # with spaces.
        for k in ("midi_to_wav", "wav_to_mp3", "wav_to_ogg"):
            v = cfg.get_string("app/%s_cmd" % k).split(" ")
            cfg.set_string("app/%s_cmd" % k, v[0])
            cfg.set_string("app/%s_cmd_options" % k, " ".join(v[1:]))
    if cfg.get_int("app/rcfileversion") <= 15:
        for k in ("midi", "wav", "mp3", "ogg"):
            v = cfg.get_string("sound/%s_player" % k).split(" ")
            cfg.set_string("sound/%s_player" % k, v[0])
            cfg.set_string("sound/%s_player_options" % k,
                " ".join(v[1:]))
    if cfg.get_int("app/rcfileversion") < 17:
        v = cfg.get_string("app/frontpage").split("/")
        if v[0] == "exercises" and v[1] != "standard":
            cfg.set_string("app/frontpage",
                           "/".join([v[0], "standard"] + v[1:]))
    if cfg.get_int("app/rcfileversion") < 18:
        cfg.del_key("gui/web_browser_as_help_browser")
    if cfg.get_int("app/rcfileversion") < 19:
        for ex in ('singinterval', 'melodicinterval'):
            if cfg.get_int("%s/maximum_number_of_intervals" % ex) == 10:
                cfg.set_int("%s/maximum_number_of_intervals" % ex, 12)
    if cfg.get_int("app/rcfileversion") < 20:
        cfg.del_key("gui/reserved_vspace")
    if cfg.get_int("app/rcfileversion") < 21:
        for ex in ("melodicinterval", "harmonicinterval"):
            i = cfg.get_int("%s/inputwidget" % ex)
            if i > 0:
                cfg.set_int("%s/inputwidget" % ex, i + 1)

    cfg.set_int("app/rcfileversion", rcfileversion)
    try:
        a = mpd.notename_to_int(cfg.get_string("user/lowest_pitch"))
        b = mpd.notename_to_int(cfg.get_string("user/highest_pitch"))
    except mpd.InvalidNotenameException:
        if cfg.get_string("user/sex") == "male":
            cfg.set_string("user/highest_pitch", "e'")
            cfg.set_string("user/lowest_pitch", "c")
        else:
            cfg.set_string("user/highest_pitch", "e''")
            cfg.set_string("user/lowest_pitch", "c'")
Esempio n. 31
0
 def setup_sound(self):
     if sys.platform == 'win32' and \
                 cfg.get_string("sound/type") == "sequencer-device":
         # just in case c:\home\.solfegerc is wrong
         cfg.set_string("sound/type", "winsynth")
     if self.m_options.no_sound \
        or cfg.get_string("sound/type") == "fake-synth":
         soundcard.initialise_using_fake_synth(
             self.m_options.verbose_sound_init)
     elif cfg.get_string("sound/type") == "alsa-sequencer":
         if alsaseq:
             try:
                 clientid, portid = self.get_list("sound/alsa-client-port")
             except ValueError:
                 clientid, portid = (None, None)
             try:
                 soundcard.initialise_alsa_sequencer(
                     (clientid, portid), self.m_options.verbose_sound_init)
             except alsaseq.SequencerError as e:
                 logging.debug(
                     "initialise_alsa_sequencer failed. Using fake synth.")
                 self.display_sound_init_error_message(e)
                 soundcard.initialise_using_fake_synth(True)
                 return
         else:
             if solfege.splash_win:
                 solfege.splash_win.hide()
             gu.dialog_ok(
                 _("The pyalsa Python module is missing"), solfege.win,
                 _("Solfege was configured to use the Python modules from www.alsa-project.org, but the modules were not found. You must reconfigure sound in the preferences window (Ctrl-F12) or restart Solfege in a way that it finds the modules."
                   ))
             soundcard.initialise_using_fake_synth(True)
             if solfege.splash_win:
                 solfege.splash_win.show()
     elif cfg.get_string("sound/type") == "winsynth":
         try:
             soundcard.initialise_winsynth(
                 cfg.get_int("sound/synth_number"),
                 verbose_init=self.m_options.verbose_sound_init)
         except ImportError as e:
             self.display_sound_init_error_message(e)
             cfg.set_string("sound/type", "fake-synth")
             soundcard.initialise_using_fake_synth(True)
             return
         except RuntimeError as e:
             # We can get here if winmidi.output_devices() in winsynth
             # __init__ returns no devices. Don't know when, but it could
             # happen.
             gu.display_exception_message(e)
             cfg.set_string("sound/type", "fake-synth")
             soundcard.initialise_using_fake_synth(True)
             return
         if cfg.get_int("sound/synth_number") != soundcard.synth.m_devnum:
             solfege.win.display_error_message2(
                 _("MIDI setup"),
                 _("MIDI Device %(olddev)i not available. Will use device %(newdev)i."
                   ) % {
                       'olddev': cfg.get_int("sound/synth_number"),
                       'newdev': soundcard.synth.m_devnum
                   })
             cfg.set_int("sound/synth_number", soundcard.synth.m_devnum)
     elif cfg.get_string("sound/type") == "external-midiplayer":
         soundcard.initialise_external_midiplayer(
             verbose_init=self.m_options.verbose_sound_init)
         soundcard.synth.error_report_cb = solfege.win.display_error_message
     elif cfg.get_string("sound/type") == '':
         solfege.win.display_error_message(
             _("You should configure sound from the 'Sound' page "
               "of the preferences window."))
     elif cfg.get_string("sound/type") == "sequencer-device":
         try:
             soundcard.initialise_devicefile(
                 cfg.get_string("sound/device_file"),
                 cfg.get_int("sound/synth_number"),
                 verbose_init=self.m_options.verbose_sound_init)
         except (soundcard.SoundInitException, OSError, ImportError) as e:
             self.m_sound_init_exception = e
             soundcard.initialise_using_fake_synth(True)
     if cfg.get_string("programs/csound") == "AUTODETECT":
         for p in osutils.find_csound_executables():
             cfg.set_string("programs/csound", p)
             break
         else:
             # If not csound binary was found, then we set the string empty.
             # This means that autodetection will only happen the first time
             # you run the program. But later will newly installed binaries
             # be shown in the combo box of the preferences window.
             cfg.set_string("programs/csound", "")
     if cfg.get_string("programs/mma") == "AUTODETECT":
         for p in osutils.find_mma_executables(
                 cfg.get_list("app/win32_ignore_drives")):
             cfg.set_string("programs/mma", p)
             break
         else:
             cfg.set_string("programs/mma", "")