Skip to content

Commit b4b436e

Browse files
committed
Faster startup
Loading of selected soundfont is postponed until first play
1 parent c13b85d commit b4b436e

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ build
5959
dist
6060
.vscode
6161
*.spec
62-
*.sf2
6362
*.pdb
6463
.vscode/settings.json
6564
.vscode/launch.json

easy_abc.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -2214,9 +2214,10 @@ def midiplayer_changed(self, path):
22142214

22152215
def soundfont_changed(self, sf2_path):
22162216
try:
2217-
wait = wx.BusyCursor()
2218-
self.mc.set_soundfont(sf2_path) # load another sound font
2219-
del wait
2217+
if os.path.exists(sf2_path):
2218+
wait = wx.BusyCursor()
2219+
self.mc.set_soundfont(sf2_path) # load another sound font
2220+
del wait
22202221
except:
22212222
pass
22222223

@@ -3904,8 +3905,12 @@ def __init__(self, parent, ID, app_dir, settings, options):
39043905
self.uses_fluidsynth = False
39053906
if fluidsynth_available and soundfont_path and os.path.exists(soundfont_path):
39063907
try:
3907-
self.mc = FluidSynthPlayer(soundfont_path)
3908+
init_soundfont_path = os.path.join(application_path, 'sound', 'example.sf2')
3909+
if not os.path.exists(init_soundfont_path):
3910+
init_soundfont_path = soundfont_path
3911+
self.mc = FluidSynthPlayer(init_soundfont_path)
39083912
self.uses_fluidsynth = True
3913+
self.mc.set_soundfont(soundfont_path, load_on_play=True)
39093914
except Exception as e:
39103915
error_msg = traceback.format_exc()
39113916
self.mc = None
@@ -6343,7 +6348,7 @@ def OnMidiSettings(self, evt):
63436348
def OnAbcSettings(self, evt):
63446349
# 1.3.6.4 [SS] 2015-07-07
63456350
win = wx.FindWindowByName('settingsbook')
6346-
if win is None:
6351+
if win is None or not self.settingsbook:
63476352
self.settingsbook = MyNoteBook(self, self.settings, self.statusbar)
63486353
self.settingsbook.Show()
63496354
else:

fluidsynthplayer.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@ def __init__(self, sf2_path):
2121
driver = 'pulseaudio'
2222

2323
self.fs.start(driver) # set default output driver and start clock
24+
self.soundfont_path = sf2_path
2425
self.sfid = self.fs.sfload(sf2_path)
2526
self.fs.program_select(0, self.sfid, 0, 0)
2627
self.p = F.Player(self.fs) # make a new player
2728
self.duration_in_ticks = 0 # length of midi file
2829
self.pause_time = 0 # time in midi ticks where player stopped
2930
self.pending_soundfont = None
3031

31-
def set_soundfont(self, sf2_path): # load another sound font
32-
if self.is_playing:
32+
def set_soundfont(self, sf2_path, load_on_play=False): # load another sound font
33+
if self.is_playing or load_on_play:
3334
self.pending_soundfont = sf2_path
3435
else:
35-
self.sf2 = sf2_path
36+
self.soundfont_path = sf2_path
3637
if self.sfid >= 0:
3738
self.fs.sfunload(self.sfid)
3839
self.sfid = self.fs.sfload(sf2_path)
@@ -46,7 +47,6 @@ def Load(self, path): # load a midi file
4647
self.pause_time = 0 # resume playing at time == 0
4748
if os.path.exists(path):
4849
success = self.p.add(path) # add file to playlist
49-
self.p.play()
5050
self.OnAfterLoad.fire()
5151
return True
5252
return False
@@ -60,7 +60,8 @@ def Play(self):
6060
if self.is_playing:
6161
return
6262
if self.pending_soundfont:
63-
self.set_soundfont(self.pending_soundfont)
63+
if self.pending_soundfont != self.soundfont_path and os.path.exists(self.pending_soundfont):
64+
self.set_soundfont(self.pending_soundfont)
6465
self.pending_soundfont = None
6566

6667
self.p.play(self.pause_time)

sound/example.sf2

3.49 KB
Binary file not shown.

0 commit comments

Comments
 (0)