예제 #1
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, 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()
예제 #2
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, 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()
예제 #3
0
def start_gui(datadir):
    if not options.profile:
        if cfg.get_bool("app/noprofilemanager"):
            options.profile = cfg.get_string("app/last_profile")
        elif do_profiles():
            if solfege.splash_win:
                solfege.splash_win.hide()
            p = ProfileManager(cfg.get_string("app/last_profile"))
            ret = p.run()
            if ret == Gtk.ResponseType.ACCEPT:
                options.profile = p.get_profile()
                cfg.set_string("app/last_profile", "" if not options.profile else options.profile)
            elif ret in (Gtk.ResponseType.CLOSE, Gtk.ResponseType.DELETE_EVENT):
                Gtk.main_quit()
                return
            p.destroy()
            if solfege.splash_win:
                solfege.splash_win.show()

    cfg.set_bool('config/no_random', bool(options.no_random))

    lessonfile.infocache = lessonfile.InfoCache()

    def f(s):
        if solfege.splash_win:
            solfege.splash_win.show_progress(s)
    if solfege.splash_win:
        solfege.splash_win.show_progress(_("Opening statistics database"))
    try:
        solfege.db = statistics.DB(f, profile=options.profile)
    except sqlite3.OperationalError, e:
        solfege.splash_win.hide()
        gu.dialog_ok(_(u"Failed to open the statistics database:\n«%s»") % str(e).decode(sys.getfilesystemencoding(), 'replace'), secondary_text=_("Click OK to exit the program. Then try to quit all other instances of the program, or reboot the computer. You can only run one instance of GNU Solfege at once."))
        sys.exit()
예제 #4
0
 def set_buttons(widget, layout):
     v = layouts[layout][1]
     idx = 0
     it = self.g_idtone_accels.get_iter_first()
     while True:
         self.g_idtone_accels.set_value(it, 1, v[idx])
         cfg.set_string('idtone/tone_%s_ak' % notenames[idx], v[idx])
         it = self.g_idtone_accels.iter_next(it)
         idx += 1
         if not it:
             break
예제 #5
0
 def f(combobox):
     if combobox.get_active() == languages.C_locale_idx:
         lang = "C"
     else:
         lang = languages.languages[combobox.get_active()]
     cfg.set_string('app/lc_messages', lang)
     if sys.platform == 'win32':
         if combobox.get_active():
             winlang.win32_put_langenviron(lang)
         else:
             winlang.win32_put_langenviron(None)
예제 #6
0
 def set_buttons(widget, layout):
     v = layouts[layout][1]
     idx = 0
     it = self.g_interval_accels.get_iter_first()
     while True:
         self.g_interval_accels.set_value(it, 1, v[idx])
         cfg.set_string('interval_input/%s' % intervals[idx], v[idx])
         it = self.g_interval_accels.iter_next(it)
         idx += 1
         if not it:
             break
예제 #7
0
 def set_buttons(widget, layout):
     v = layouts[layout][1]
     idx = 0
     it = self.g_idtone_accels.get_iter_first()
     while True:
         self.g_idtone_accels.set_value(it, 1, v[idx])
         cfg.set_string('idtone/tone_%s_ak' % notenames[idx], v[idx])
         it = self.g_idtone_accels.iter_next(it)
         idx += 1
         if not it:
             break
예제 #8
0
 def f(combobox):
     if combobox.get_active() == languages.C_locale_idx:
         lang = "C"
     else:
         lang = languages.languages[combobox.get_active()]
     cfg.set_string('app/lc_messages', lang)
     if sys.platform == 'win32':
         if combobox.get_active():
             winlang.win32_put_langenviron(lang)
         else:
             winlang.win32_put_langenviron(None)
예제 #9
0
 def set_buttons(widget, layout):
     v = layouts[layout][1]
     idx = 0
     it = self.g_interval_accels.get_iter_first()
     while True:
         self.g_interval_accels.set_value(it, 1, v[idx])
         cfg.set_string('interval_input/%s' % intervals[idx], v[idx])
         it = self.g_interval_accels.iter_next(it)
         idx += 1
         if not it:
             break
예제 #10
0
 def run_startup_profile_manager(self):
     """
     Select a user profile to use. Return its name.
     Quit program if user selects that.
     """
     p = ProfileManager(self, cfg.get_string("app/last_profile"))
     ret = p.run()
     if ret == Gtk.ResponseType.ACCEPT:
         profile = p.get_profile()
         cfg.set_string("app/last_profile", "" if not profile else profile)
         p.destroy()
         return profile
     else:
         self.quit_program()
예제 #11
0
 def acc_ff(renderer, path, accel_key, accel_mods, hw_key):
     is_unique = True
     for interval in intervals:
         if (interval != intervals[int(path)]
             and cfg.get_string('interval_input/%s' % interval) == unichr(accel_key)):
             is_unique = False
             break
     if not is_unique:
         gu.dialog_ok(_(u"The accelerator in use for “%s”. You have to choose another key.") % mpd.Interval.new_from_int(intervals.index(interval)).get_name(), parent=self, msgtype=Gtk.MessageType.ERROR)
         return
     it = self.g_interval_accels.get_iter(path)
     cfg.set_string('interval_input/%s' % intervals[int(path)], unichr(accel_key))
     self.g_interval_accels.set(it, 1, unichr(accel_key))
     return True
예제 #12
0
 def acc_ff(renderer, path, accel_key, accel_mods, hw_key):
     is_unique = True
     for notename in notenames:
         if (notename != notenames[int(path)]
             and cfg.get_string('idtone/tone_%s_ak' % notename) == unichr(accel_key)):
             is_unique = False
             break
     if not is_unique:
         gu.dialog_ok(_(u"The accelerator in use for the tone “%s”. You have to choose another key.") % solfege.mpd.MusicalPitch.new_from_notename(notename).get_user_notename(), parent=self, msgtype=Gtk.MessageType.ERROR)
         return
     it = self.g_idtone_accels.get_iter(path)
     cfg.set_string('idtone/tone_%s_ak' % notenames[int(path)], unichr(accel_key))
     self.g_idtone_accels.set(it, 1, unichr(accel_key))
     return True
예제 #13
0
 def run_startup_profile_manager(self):
     """
     Select a user profile to use. Return its name.
     Quit program if user selects that.
     """
     p = ProfileManager(self, cfg.get_string("app/last_profile"))
     ret = p.run()
     if ret == Gtk.ResponseType.ACCEPT:
         profile = p.get_profile()
         cfg.set_string("app/last_profile", "" if not profile else profile)
         p.destroy()
         return profile
     else:
         self.quit_program()
예제 #14
0
def presetup(app_defaults_filename, system_filename, user_filename):
    if not os.path.exists(filesystem.app_data()):
        os.makedirs(filesystem.app_data())
    if not os.path.exists(filesystem.user_data()):
        os.makedirs(filesystem.user_data())
    try:
        cfg.initialise(app_defaults_filename, system_filename, user_filename)
    except UnicodeDecodeError:
        traceback.print_exc()
        print(file=sys.stderr)
        print("\n".join(
            textwrap.wrap(
                "Your %s file is not properly utf8 encoded. Most likely"
                " it is the path to some external program that contain non-ascii"
                " characters. Please edit or delete the file. Or email it to"
                " [email protected], and he will tell you what the problem is." %
                filesystem.rcfile().encode("ascii", "backslashreplace"))),
              file=sys.stderr)
        print(file=sys.stderr)
        sys.exit("I give up (solfege.py)")
    except cfg.CfgParseException as e:
        i18n.setup(".")
        a, b = os.path.split(user_filename)
        renamed_fn = os.path.join(a, "BAD-" + b)
        m = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL,
                              Gtk.MessageType.ERROR, Gtk.ButtonsType.NONE,
                              _("Parsing %s failed") % filesystem.rcfile())
        m.format_secondary_text(
            str(e) + "\n\n" +
            _("We cannot recover from this, we can rename the corrupt file to %s and then start the program."
              % renamed_fn))
        m.add_buttons("Rename", 10)
        m.add_buttons(Gtk.STOCK_QUIT, 11)
        m.set_default_response(11)
        ret = m.run()
        if ret == 10:
            os.rename(user_filename, renamed_fn)
            m.destroy()
            cfg.initialise(app_defaults_filename, system_filename,
                           user_filename)
        else:
            sys.exit(1)
    # MIGRATION from 2.9.2 to 2.9.3
    if cfg.get_string("app/lc_messages") == 'C (english)':
        cfg.set_string("app/lc_messages", "C")
예제 #15
0
 def open_profile_manager(self, widget=None):
     p = ChangeProfileDialog(self, solfege.app.m_options.profile)
     if p.run() == Gtk.ResponseType.ACCEPT:
         prof = p.get_profile()
     else:
         # The user presses cancel. This will use the same profile as
         # before, but if the user has renamed the active profile, then
         # we need to use the new name.
         prof = p.m_default_profile
     p.destroy()
     solfege.app.reset_exercise()
     solfege.app.m_options.profile = prof
     solfege.db.conn.commit()
     solfege.db.conn.close()
     if prof is None:
         prof = ''
     solfege.db = statistics.DB(None, profile=prof)
     cfg.set_string("app/last_profile", prof)
     self.display_frontpage()
예제 #16
0
 def open_profile_manager(self, widget=None):
     p = ChangeProfileDialog(self, solfege.app.m_options.profile)
     if p.run() == Gtk.ResponseType.ACCEPT:
         prof = p.get_profile()
     else:
         # The user presses cancel. This will use the same profile as
         # before, but if the user has renamed the active profile, then
         # we need to use the new name.
         prof = p.m_default_profile
     p.destroy()
     solfege.app.reset_exercise()
     solfege.app.m_options.profile = prof
     solfege.db.conn.commit()
     solfege.db.conn.close()
     if prof is None:
         prof = ''
     solfege.db = statistics.DB(None, profile=prof)
     cfg.set_string("app/last_profile", prof)
     self.display_frontpage()
예제 #17
0
def start_gui(datadir):
    if not options.profile:
        if cfg.get_bool("app/noprofilemanager"):
            options.profile = cfg.get_string("app/last_profile")
        elif do_profiles():
            if solfege.splash_win:
                solfege.splash_win.hide()
            p = ProfileManager(cfg.get_string("app/last_profile"))
            ret = p.run()
            if ret == Gtk.ResponseType.ACCEPT:
                options.profile = p.get_profile()
                cfg.set_string("app/last_profile",
                               "" if not options.profile else options.profile)
            elif ret in (Gtk.ResponseType.CLOSE,
                         Gtk.ResponseType.DELETE_EVENT):
                Gtk.main_quit()
                return
            p.destroy()
            if solfege.splash_win:
                solfege.splash_win.show()

    cfg.set_bool('config/no_random', bool(options.no_random))

    lessonfile.infocache = lessonfile.InfoCache()

    def f(s):
        if solfege.splash_win:
            solfege.splash_win.show_progress(s)

    if solfege.splash_win:
        solfege.splash_win.show_progress(_("Opening statistics database"))
    try:
        solfege.db = statistics.DB(f, profile=options.profile)
    except sqlite3.OperationalError, e:
        solfege.splash_win.hide()
        gu.dialog_ok(
            _(u"Failed to open the statistics database:\n«%s»") %
            str(e).decode(sys.getfilesystemencoding(), 'replace'),
            secondary_text=
            _("Click OK to exit the program. Then try to quit all other instances of the program, or reboot the computer. You can only run one instance of GNU Solfege at once."
              ))
        sys.exit()
예제 #18
0
 def acc_ff(renderer, path, accel_key, accel_mods, hw_key):
     is_unique = True
     for interval in intervals:
         if (interval != intervals[int(path)] and cfg.get_string(
                 'interval_input/%s' % interval) == unichr(accel_key)):
             is_unique = False
             break
     if not is_unique:
         gu.dialog_ok(_(
             u"The accelerator in use for “%s”. You have to choose another key."
         ) % mpd.Interval.new_from_int(
             intervals.index(interval)).get_name(),
                      parent=self,
                      msgtype=Gtk.MessageType.ERROR)
         return
     it = self.g_interval_accels.get_iter(path)
     cfg.set_string('interval_input/%s' % intervals[int(path)],
                    unichr(accel_key))
     self.g_interval_accels.set(it, 1, unichr(accel_key))
     return True
예제 #19
0
 def acc_ff(renderer, path, accel_key, accel_mods, hw_key):
     is_unique = True
     for notename in notenames:
         if (notename != notenames[int(path)] and cfg.get_string(
                 'idtone/tone_%s_ak' % notename) == unichr(accel_key)):
             is_unique = False
             break
     if not is_unique:
         gu.dialog_ok(_(
             u"The accelerator in use for the tone “%s”. You have to choose another key."
         ) % solfege.mpd.MusicalPitch.new_from_notename(
             notename).get_user_notename(),
                      parent=self,
                      msgtype=Gtk.MessageType.ERROR)
         return
     it = self.g_idtone_accels.get_iter(path)
     cfg.set_string('idtone/tone_%s_ak' % notenames[int(path)],
                    unichr(accel_key))
     self.g_idtone_accels.set(it, 1, unichr(accel_key))
     return True
예제 #20
0
def sComboBox(exname, name, strings):
    liststore = Gtk.ListStore(str)
    for s in strings:
        liststore.append([s])
    g = Gtk.ComboBox.new_with_model_and_entry(liststore)
    g.set_entry_text_column(0)
    g.get_child().set_text(cfg.get_string("%s/%s" % (exname, name)))
    g.connect('changed', lambda w:
            cfg.set_string("%s/%s" % (exname, name),
                           w.get_child().get_text()))
    return g
예제 #21
0
파일: gu.py 프로젝트: PauloJava2016/Solfege
def sComboBox(exname, name, strings):
    liststore = Gtk.ListStore(str)
    for s in strings:
        liststore.append([s])
    g = Gtk.ComboBox.new_with_model_and_entry(liststore)
    g.set_entry_text_column(0)
    g.get_child().set_text(cfg.get_string("%s/%s" % (exname, name)))
    g.connect('changed', lambda w:
            cfg.set_string("%s/%s" % (exname, name),
                           w.get_child().get_text().decode("utf-8")))
    return g
예제 #22
0
def presetup(app_defaults_filename, system_filename, user_filename):
    if not os.path.exists(filesystem.app_data()):
        os.makedirs(filesystem.app_data())
    if not os.path.exists(filesystem.user_data()):
        os.makedirs(filesystem.user_data())
    try:
        cfg.initialise(app_defaults_filename, system_filename, user_filename)
    except UnicodeDecodeError:
        traceback.print_exc()
        print(file=sys.stderr)
        print("\n".join(textwrap.wrap(
              "Your %s file is not properly utf8 encoded. Most likely"
              " it is the path to some external program that contain non-ascii"
              " characters. Please edit or delete the file. Or email it to"
              " [email protected], and he will tell you what the problem is." % filesystem.rcfile().encode("ascii", "backslashreplace"))), file=sys.stderr)
        print(file=sys.stderr)
        sys.exit("I give up (solfege.py)")
    except cfg.CfgParseException as e:
        i18n.setup(".")
        a, b = os.path.split(user_filename)
        renamed_fn = os.path.join(a, "BAD-" + b)
        m = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR,
                Gtk.ButtonsType.NONE,
                _("Parsing %s failed") % filesystem.rcfile())
        m.format_secondary_text(str(e) + "\n\n" + _("We cannot recover from this, we can rename the corrupt file to %s and then start the program." % renamed_fn))
        m.add_buttons("Rename", 10)
        m.add_buttons(Gtk.STOCK_QUIT, 11)
        m.set_default_response(11)
        ret = m.run()
        if ret == 10:
            os.rename(user_filename, renamed_fn)
            m.destroy()
            cfg.initialise(app_defaults_filename, system_filename, user_filename)
        else:
            sys.exit(1)
    # MIGRATION from 2.9.2 to 2.9.3
    if cfg.get_string("app/lc_messages") == 'C (english)':
        cfg.set_string("app/lc_messages", "C")
예제 #23
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'")
예제 #24
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", "")
예제 #25
0
 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
     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
예제 #26
0
 def test_set_str(self):
     cfg.set_string("abc/def", "str string")
     cfg.set_string("abc/ghi", "unicode string ØÆÅ")
     self.assertTrue(isinstance(cfg.get_string("abc/def"), str))
     self.assertTrue(isinstance(cfg.get_string("abc/ghi"), str))
예제 #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
예제 #28
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'")
예제 #29
0
             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
     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:
예제 #30
0
 def test_set_str(self):
     cfg.set_string("abc/def", "str string")
     cfg.set_string("abc/ghi", u"unicode string ØÆÅ")
     self.assert_(isinstance(cfg.get_string("abc/def"), unicode))
     self.assert_(isinstance(cfg.get_string("abc/ghi"), unicode))
예제 #31
0
                " characters. Please edit or delete the file. Or email it to"
                " [email protected], and he will tell you what the problem is." %
                filesystem.rcfile().encode("ascii", "backslashreplace")))
        print >> sys.stderr
        sys.exit("I give up (solfege.py)")
    except cfg.CfgParseException, e:
        i18n.setup(".")
        a, b = os.path.split(user_filename)
        renamed_fn = os.path.join(a, "BAD-" + b)
        m = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL,
                              Gtk.MessageType.ERROR, Gtk.ButtonsType.NONE,
                              _("Parsing %s failed") % filesystem.rcfile())
        m.format_secondary_text(
            str(e) + "\n\n" +
            _("We cannot recover from this, we can rename the corrupt file to %s and then start the program."
              % renamed_fn))
        m.add_buttons("Rename", 10)
        m.add_buttons(Gtk.STOCK_QUIT, 11)
        m.set_default_response(11)
        ret = m.run()
        if ret == 10:
            os.rename(user_filename, renamed_fn)
            m.destroy()
            cfg.initialise(app_defaults_filename, system_filename,
                           user_filename)
        else:
            sys.exit(1)
    # MIGRATION from 2.9.2 to 2.9.3
    if cfg.get_string("app/lc_messages") == 'C (english)':
        cfg.set_string("app/lc_messages", "C")
예제 #32
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", "")
예제 #33
0
if not os.path.exists(filesystem.app_data()):
    os.makedirs(filesystem.app_data())
if not os.path.exists(filesystem.user_data()):
    os.makedirs(filesystem.user_data())

try:
    cfg.initialise("default.config", None, filesystem.rcfile())
except UnicodeDecodeError, e:
    traceback.print_exc()
    print >> sys.stderr
    print >> sys.stderr, "\n".join(textwrap.wrap(
          "Your %s file is not properly utf8 encoded. Most likely"
          " it is the path to some external program that contain non-ascii"
          " characters. Please edit or delete the file. Or email it to"
          " [email protected], and he will tell you what the problem is." % filesystem.rcfile().encode("ascii", "backslashreplace")))
    print >> sys.stderr
    sys.exit("I give up (solfege.py)")


# i18n should be imported very early in program init because it setup
# the _ and _i functions for the whole program.
import solfege.i18n
# MIGRATION from 2.9.2 to 2.9.3
if cfg.get_string("app/lc_messages") == 'C (english)':
    cfg.set_string("app/lc_messages", "C")
solfege.i18n.setup(".", cfg.get_string("app/lc_messages"))

import solfege.startup

solfege.startup.start_app(".")
예제 #34
0
 def on_update_mangle(self,  *v):
     cfg.set_string('user/email', self.g_email.get_text())
     self.g_mangled_email.set_text(utils.mangle_email(self.g_email.get_text()))