Skip to content

Commit c13b85d

Browse files
committed
Soundfont change does not require restart anymore
1 parent bf3c63b commit c13b85d

File tree

2 files changed

+49
-27
lines changed

2 files changed

+49
-27
lines changed

easy_abc.py

+33-18
Original file line numberDiff line numberDiff line change
@@ -2017,13 +2017,13 @@ def OnCancel(self, evt):
20172017
#2014-10-14
20182018
class MyNoteBook(wx.Frame):
20192019
''' Settings Notebook '''
2020-
def __init__(self, settings, statusbar):
2021-
wx.Frame.__init__(self, wx.GetApp().TopWindow, wx.ID_ANY, _("Abc settings"), style=wx.DEFAULT_FRAME_STYLE, name='settingsbook')
2020+
def __init__(self, parent, settings, statusbar):
2021+
wx.Frame.__init__(self, parent, wx.ID_ANY, _("Abc settings"), style=wx.DEFAULT_FRAME_STYLE, name='settingsbook')
20222022
# Add a panel so it looks the correct on all platforms
20232023
p = wx.Panel(self)
20242024
nb = wx.Notebook(p)
20252025
# 1.3.6.4 [SS] 2015-05-26 added statusbar
2026-
abcsettings = AbcFileSettingsFrame(nb, settings, statusbar)
2026+
abcsettings = AbcFileSettingsFrame(nb, settings, statusbar, parent.mc)
20272027
chordpage = MyChordPlayPage(nb, settings)
20282028
self.voicepage = MyVoicePage(nb, settings)
20292029
# 1.3.6.1 [SS] 2015-02-02
@@ -2052,26 +2052,27 @@ def OnPageChanged(self, event):
20522052

20532053
class AbcFileSettingsFrame(wx.Panel):
20542054
# 1.3.6.4 [SS] 2015-05-26 added statusbar
2055-
def __init__(self, parent, settings, statusbar):
2055+
def __init__(self, parent, settings, statusbar, mc):
20562056
wx.Panel.__init__(self, parent)
20572057
self.settings = settings
20582058
self.statusbar = statusbar
2059+
self.mc = mc
20592060
self.SetBackgroundColour(dialog_background_colour)
20602061
border = control_margin
20612062

2062-
PathEntry = namedtuple('PathEntry', 'name display_name tooltip add_default wildcard')
2063+
PathEntry = namedtuple('PathEntry', 'name display_name tooltip add_default wildcard on_change')
20632064

20642065
# 1.3.6.3 [JWDJ] 2015-04-27 replaced TextCtrl with ComboBox for easier switching of versions
20652066
self.needed_path_entries = [
2066-
PathEntry('abcm2ps', _('abcm2ps executable:'), _('This executable is used to display the music'), True, None),
2067-
PathEntry('abc2midi', _('abc2midi executable:'), _('This executable is used to make the midi file'), True, None),
2068-
PathEntry('abc2abc', _('abc2abc executable:'), _('This executable is used to transpose the music'), True, None),
2067+
PathEntry('abcm2ps', _('abcm2ps executable:'), _('This executable is used to display the music'), True, None, None),
2068+
PathEntry('abc2midi', _('abc2midi executable:'), _('This executable is used to make the midi file'), True, None, None),
2069+
PathEntry('abc2abc', _('abc2abc executable:'), _('This executable is used to transpose the music'), True, None, None),
20692070
# 1.3.6.4 [SS] 2015-06-22
2070-
PathEntry('midi2abc', _('midi2abc executable:'), _('This executable is used to disassemble the output midi file'), True, None),
2071-
PathEntry('gs', _('ghostscript executable:'), _('This executable is used to create PDF files'), False, None),
2072-
PathEntry('nwc2xml', _('nwc2xml executable:'), _('For NoteWorthy Composer - Windows only'), False, None),
2073-
PathEntry('midiplayer', _('midiplayer:'), _('Your preferred MIDI player'), False, None),
2074-
PathEntry('soundfont', _('SoundFont:'), _('Your preferred SoundFont (.sf2)'), False, 'SoundFont (*.sf2;*.sf3)|*.sf2;*.sf3')
2071+
PathEntry('midi2abc', _('midi2abc executable:'), _('This executable is used to disassemble the output midi file'), True, None, None),
2072+
PathEntry('gs', _('ghostscript executable:'), _('This executable is used to create PDF files'), False, None, None),
2073+
PathEntry('nwc2xml', _('nwc2xml executable:'), _('For NoteWorthy Composer - Windows only'), False, None, None),
2074+
PathEntry('midiplayer', _('midiplayer:'), _('Your preferred MIDI player'), False, None, self.midiplayer_changed),
2075+
PathEntry('soundfont', _('SoundFont:'), _('Your preferred SoundFont (.sf2)'), False, 'SoundFont (*.sf2;*.sf3)|*.sf2;*.sf3', self.soundfont_changed)
20752076
]
20762077

20772078

@@ -2098,9 +2099,11 @@ def __init__(self, parent, settings, statusbar):
20982099
self.browsebutton_to_control = {}
20992100
self.browsebutton_to_wildcard = {}
21002101
self.control_to_name = {}
2102+
self.afterchanged = {}
21012103
for entry in self.needed_path_entries:
21022104
setting_name = '%s_path' % entry.name
21032105
current_path = self.settings.get(setting_name, '')
2106+
self.afterchanged[setting_name] = entry.on_change
21042107
setting_name_choices = '%s_path_choices' % entry.name
21052108
path_choices = self.settings.get(setting_name_choices, '').split('|')
21062109
path_choices = self.keep_existing_paths(path_choices)
@@ -2201,9 +2204,21 @@ def change_path_for_control(self, control, path):
22012204
self.settings[setting_name_choices] = '|'.join(paths)
22022205
# 1.3.6.4 [SS] 2015-05-26
22032206
self.statusbar.SetStatusText(setting_name + ' was updated to '+ path)
2204-
if setting_name == 'midiplayer_path':
2205-
app = wx.GetApp()
2206-
app.frame.update_play_button() # 1.3.6.3 [JWDJ] 2015-04-21 playbutton enabling centralized
2207+
on_changed = self.afterchanged.get(setting_name)
2208+
if on_changed is not None:
2209+
on_changed(path)
2210+
2211+
def midiplayer_changed(self, path):
2212+
app = wx.GetApp()
2213+
app.frame.update_play_button() # 1.3.6.3 [JWDJ] 2015-04-21 playbutton enabling centralized
2214+
2215+
def soundfont_changed(self, sf2_path):
2216+
try:
2217+
wait = wx.BusyCursor()
2218+
self.mc.set_soundfont(sf2_path) # load another sound font
2219+
del wait
2220+
except:
2221+
pass
22072222

22082223
def On_Chk_IncludeHeader(self, event):
22092224
self.settings['abc_include_file_header'] = self.chkIncludeHeader.GetValue()
@@ -2229,7 +2244,7 @@ def OnRestoreSettings(self, event):
22292244
frame.restore_settings()
22302245
frame.settingsbook.Show(False)
22312246
frame.settingsbook.Destroy()
2232-
frame.settingsbook = MyNoteBook(self.settings, self.statusbar)
2247+
frame.settingsbook = MyNoteBook(self, self.settings, self.statusbar)
22332248
frame.settingsbook.Show()
22342249

22352250
def append_exe(self, path, paths):
@@ -6329,7 +6344,7 @@ def OnAbcSettings(self, evt):
63296344
# 1.3.6.4 [SS] 2015-07-07
63306345
win = wx.FindWindowByName('settingsbook')
63316346
if win is None:
6332-
self.settingsbook = MyNoteBook(self.settings, self.statusbar)
6347+
self.settingsbook = MyNoteBook(self, self.settings, self.statusbar)
63336348
self.settingsbook.Show()
63346349
else:
63356350
self.settingsbook.Iconize(False)

fluidsynthplayer.py

+16-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class FluidSynthPlayer(MidiPlayer):
1515
def __init__(self, sf2_path):
1616
super(FluidSynthPlayer, self).__init__()
17-
self.fs = F.Synth(gain=0.7, bsize=2048) # make a synth
17+
self.fs = F.Synth(gain=1.0, bsize=2048) # make a synth
1818

1919
driver = None
2020
if is_linux:
@@ -26,16 +26,20 @@ def __init__(self, sf2_path):
2626
self.p = F.Player(self.fs) # make a new player
2727
self.duration_in_ticks = 0 # length of midi file
2828
self.pause_time = 0 # time in midi ticks where player stopped
29+
self.pending_soundfont = None
2930

3031
def set_soundfont(self, sf2_path): # load another sound font
31-
self.sf2 = sf2_path
32-
if self.sfid >= 0:
33-
self.fs.sfunload(self.sfid)
34-
self.sfid = self.fs.sfload(sf2_path)
35-
if self.sfid < 0: return 0 # not a sf2 file
36-
self.fs.program_select(0, self.sfid, 0, 0)
37-
self.pause_time = 0 # resume playing at time == 0
38-
return 1
32+
if self.is_playing:
33+
self.pending_soundfont = sf2_path
34+
else:
35+
self.sf2 = sf2_path
36+
if self.sfid >= 0:
37+
self.fs.sfunload(self.sfid)
38+
self.sfid = self.fs.sfload(sf2_path)
39+
if self.sfid < 0:
40+
return 0 # not a sf2 file
41+
self.fs.program_select(0, self.sfid, 0, 0)
42+
return 1
3943

4044
def Load(self, path): # load a midi file
4145
self.reset() # reset the player, empty the playlist
@@ -55,6 +59,9 @@ def reset(self): # the only way to empty the playlist ...
5559
def Play(self):
5660
if self.is_playing:
5761
return
62+
if self.pending_soundfont:
63+
self.set_soundfont(self.pending_soundfont)
64+
self.pending_soundfont = None
5865

5966
self.p.play(self.pause_time)
6067
self.pause_time = 0

0 commit comments

Comments
 (0)