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
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
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'")
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", "")
def f(combobox): cfg.set_int("%s/%s" % (exname, name), combobox.get_active())
from solfege import testlib import solfege.i18n solfege.i18n.setup(".") from solfege import lessonfile lessonfile.infocache = lessonfile.InfoCache() import solfege.statistics solfege.db = solfege.statistics.DB(None) import tempfile lessonfile.MusicBaseClass.temp_dir = tempfile.mkdtemp(prefix="solfege-") from solfege import cfg cfg.initialise("default.config", None, "") cfg.set_int('config/preferred_instrument', 0) cfg.set_int('config/lowest_instrument', 1) cfg.set_int('config/middle_instrument', 2) cfg.set_int('config/highest_instrument', 3) cfg.set_int('config/lowest_instrument_volume', 121) cfg.set_int('config/middle_instrument_volume', 122) cfg.set_int('config/highest_instrument_volume', 123) cfg.set_bool('config/override_default_instrument', False) cfg.set_bool('testing/may_play_sound', False) if os.path.exists(testlib.outdir): shutil.rmtree(testlib.outdir) os.mkdir(testlib.outdir) from solfege import soundcard from solfege.osutils import *
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"), verbose_init=self.m_options.verbose_sound_init) except (soundcard.SoundInitException, OSError, ImportError), e:
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'")
# 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), e:
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", "")