diff options
author | Chris Robinson <[email protected]> | 2014-01-03 22:58:51 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-01-03 22:58:51 -0800 |
commit | 13066bbf87c871d848df22c660b17db435561618 (patch) | |
tree | 464a6fec9314aad12800edd8e297024a09f4cb7d /Alc/midi/base.c | |
parent | 42a67731c411775fe9de5d3a05edfd10205cc70f (diff) |
Allow selecting the default soundfont using ID 0
Diffstat (limited to 'Alc/midi/base.c')
-rw-r--r-- | Alc/midi/base.c | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/Alc/midi/base.c b/Alc/midi/base.c index f6a9b5c7..9e778a45 100644 --- a/Alc/midi/base.c +++ b/Alc/midi/base.c @@ -24,6 +24,9 @@ #define SYSEX_EVENT (0xF0) +static size_t read_file(ALvoid *buf, size_t bytes, ALvoid *ptr); + + void InitEvtQueue(EvtQueue *queue) { queue->events = NULL; @@ -151,8 +154,43 @@ void MidiSynth_Destruct(MidiSynth *self) ResetEvtQueue(&self->EventQueue); } -ALenum MidiSynth_selectSoundfonts(MidiSynth *self, ALCdevice *device, ALsizei count, const ALuint *ids) +ALsoundfont *MidiSynth_getDefSoundfont(ALCcontext *context) { + ALCdevice *device = context->Device; + const char *fname; + + if(device->DefaultSfont) + return device->DefaultSfont; + + device->DefaultSfont = calloc(1, sizeof(device->DefaultSfont[0])); + ALsoundfont_Construct(device->DefaultSfont); + + fname = getenv("ALSOFT_SOUNDFONT"); + if((fname && fname[0]) || ConfigValueStr("midi", "soundfont", &fname)) + { + FILE *f; + + f = fopen(fname, "rb"); + if(f == NULL) + ERR("Failed to open default soundfont %s\n", fname); + else + { + Reader reader; + reader.cb = read_file; + reader.ptr = f; + reader.error = 0; + TRACE("Loading default soundfont %s\n", fname); + loadSf2(&reader, device->DefaultSfont, context); + fclose(f); + } + } + + return device->DefaultSfont; +} + +ALenum MidiSynth_selectSoundfonts(MidiSynth *self, ALCcontext *context, ALsizei count, const ALuint *ids) +{ + ALCdevice *device = context->Device; ALsoundfont **sfonts; ALsizei i; @@ -164,7 +202,9 @@ ALenum MidiSynth_selectSoundfonts(MidiSynth *self, ALCdevice *device, ALsizei co for(i = 0;i < count;i++) { - if(!(sfonts[i]=LookupSfont(device, ids[i]))) + if(ids[i] == 0) + sfonts[i] = MidiSynth_getDefSoundfont(context); + else if(!(sfonts[i]=LookupSfont(device, ids[i]))) { free(sfonts); return AL_INVALID_VALUE; @@ -272,3 +312,9 @@ ALenum MidiSynth_insertSysExEvent(MidiSynth *self, ALuint64 time, const ALbyte * return AL_NO_ERROR; } + + +static size_t read_file(ALvoid *buf, size_t bytes, ALvoid *ptr) +{ + return fread(buf, 1, bytes, (FILE*)ptr); +} |