From 994c3f00e51b7263d4e24bde81de048584372d49 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 19 Jul 2014 12:42:52 -0700 Subject: Keep existing presets when loading in a new soundfont Note that alLoadSoundfontSOFT doesn't currently allow using a soundfont with existing presets. This is for being able to load and stack multiple soundfonts for the default soundfont. --- Alc/midi/sf2load.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'Alc') diff --git a/Alc/midi/sf2load.c b/Alc/midi/sf2load.c index dd1a4518..4b8fd6a6 100644 --- a/Alc/midi/sf2load.c +++ b/Alc/midi/sf2load.c @@ -1245,9 +1245,11 @@ ALboolean loadSf2(Reader *stream, ALsoundfont *soundfont, ALCcontext *context) if(!ensureFontSanity(&sfont)) goto error; - presets = calloc(1, (sfont.phdr_size-1)*sizeof(presets[0])); + presets = calloc(1, (soundfont->NumPresets+sfont.phdr_size-1)*sizeof(presets[0])); if(!presets) ERROR_GOTO(error, "Error allocating presets\n"); + memcpy(presets, soundfont->Presets, soundfont->NumPresets*sizeof(presets[0])); + presets_size = soundfont->NumPresets; for(i = 0;i < sfont.phdr_size-1;i++) { @@ -1341,7 +1343,7 @@ ALboolean loadSf2(Reader *stream, ALsoundfont *soundfont, ALCcontext *context) GenModList_Destruct(&gzone); } - for(i = 0;i < presets_size;i++) + for(i = soundfont->NumPresets;i < presets_size;i++) IncrementRef(&presets[i]->ref); presets = ExchangePtr((XchgPtr*)&soundfont->Presets, presets); ExchangeInt(&soundfont->NumPresets, presets_size); @@ -1359,7 +1361,7 @@ error: if(presets) { ALCdevice *device = context->Device; - for(i = 0;i < presets_size;i++) + for(i = soundfont->NumPresets;i < presets_size;i++) DeletePreset(device, presets[i]); free(presets); } -- cgit v1.2.3