diff options
-rw-r--r-- | Alc/midi/base.c | 50 | ||||
-rw-r--r-- | Alc/midi/base.h | 7 | ||||
-rw-r--r-- | Alc/midi/dummy.c | 2 | ||||
-rw-r--r-- | Alc/midi/fluidsynth.c | 10 | ||||
-rw-r--r-- | OpenAL32/alMidi.c | 2 |
5 files changed, 59 insertions, 12 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); +} diff --git a/Alc/midi/base.h b/Alc/midi/base.h index e9245887..72e83b7d 100644 --- a/Alc/midi/base.h +++ b/Alc/midi/base.h @@ -52,7 +52,8 @@ typedef struct MidiSynth { void MidiSynth_Construct(MidiSynth *self, ALCdevice *device); void MidiSynth_Destruct(MidiSynth *self); -ALenum MidiSynth_selectSoundfonts(MidiSynth *self, ALCdevice *device, ALsizei count, const ALuint *ids); +struct ALsoundfont *MidiSynth_getDefSoundfont(ALCcontext *context); +ALenum MidiSynth_selectSoundfonts(MidiSynth *self, ALCcontext *context, ALsizei count, const ALuint *ids); inline void MidiSynth_setGain(MidiSynth *self, ALfloat gain) { self->Gain = gain; } inline ALfloat MidiSynth_getGain(const MidiSynth *self) { return self->Gain; } inline void MidiSynth_setState(MidiSynth *self, ALenum state) { ExchangeInt(&self->State, state); } @@ -75,7 +76,7 @@ ALenum MidiSynth_insertSysExEvent(MidiSynth *self, ALuint64 time, const ALbyte * struct MidiSynthVtable { void (*const Destruct)(MidiSynth *self); - ALenum (*const selectSoundfonts)(MidiSynth *self, ALCdevice *device, ALsizei count, const ALuint *ids); + ALenum (*const selectSoundfonts)(MidiSynth *self, ALCcontext *context, ALsizei count, const ALuint *ids); void (*const setGain)(MidiSynth *self, ALfloat gain); void (*const setState)(MidiSynth *self, ALenum state); @@ -91,7 +92,7 @@ struct MidiSynthVtable { #define DEFINE_MIDISYNTH_VTABLE(T) \ DECLARE_THUNK(T, MidiSynth, void, Destruct) \ -DECLARE_THUNK3(T, MidiSynth, ALenum, selectSoundfonts, ALCdevice*, ALsizei, const ALuint*) \ +DECLARE_THUNK3(T, MidiSynth, ALenum, selectSoundfonts, ALCcontext*, ALsizei, const ALuint*) \ DECLARE_THUNK1(T, MidiSynth, void, setGain, ALfloat) \ DECLARE_THUNK1(T, MidiSynth, void, setState, ALenum) \ DECLARE_THUNK(T, MidiSynth, void, stop) \ diff --git a/Alc/midi/dummy.c b/Alc/midi/dummy.c index 760aed74..71c03efb 100644 --- a/Alc/midi/dummy.c +++ b/Alc/midi/dummy.c @@ -20,7 +20,7 @@ typedef struct DSynth { static void DSynth_Construct(DSynth *self, ALCdevice *device); static DECLARE_FORWARD(DSynth, MidiSynth, void, Destruct) -static DECLARE_FORWARD3(DSynth, MidiSynth, ALenum, selectSoundfonts, ALCdevice*, ALsizei, const ALuint*) +static DECLARE_FORWARD3(DSynth, MidiSynth, ALenum, selectSoundfonts, ALCcontext*, ALsizei, const ALuint*) static DECLARE_FORWARD1(DSynth, MidiSynth, void, setGain, ALfloat) static DECLARE_FORWARD1(DSynth, MidiSynth, void, setState, ALenum) static DECLARE_FORWARD(DSynth, MidiSynth, void, stop) diff --git a/Alc/midi/fluidsynth.c b/Alc/midi/fluidsynth.c index f5074d6d..234de07e 100644 --- a/Alc/midi/fluidsynth.c +++ b/Alc/midi/fluidsynth.c @@ -341,7 +341,7 @@ typedef struct FSynth { static void FSynth_Construct(FSynth *self, ALCdevice *device); static void FSynth_Destruct(FSynth *self); static ALboolean FSynth_init(FSynth *self, ALCdevice *device); -static ALenum FSynth_selectSoundfonts(FSynth *self, ALCdevice *device, ALsizei count, const ALuint *ids); +static ALenum FSynth_selectSoundfonts(FSynth *self, ALCcontext *context, ALsizei count, const ALuint *ids); static void FSynth_setGain(FSynth *self, ALfloat gain); static void FSynth_setState(FSynth *self, ALenum state); static void FSynth_stop(FSynth *self); @@ -438,19 +438,19 @@ static fluid_sfont_t *FSynth_loadSfont(fluid_sfloader_t *loader, const char *fil return STATIC_CAST(fluid_sfont_t, sfont); } -static ALenum FSynth_selectSoundfonts(FSynth *self, ALCdevice *device, ALsizei count, const ALuint *ids) +static ALenum FSynth_selectSoundfonts(FSynth *self, ALCcontext *context, ALsizei count, const ALuint *ids) { int *fontid; ALenum ret; ALsizei i; - ret = MidiSynth_selectSoundfonts(STATIC_CAST(MidiSynth, self), device, count, ids); + ret = MidiSynth_selectSoundfonts(STATIC_CAST(MidiSynth, self), context, count, ids); if(ret != AL_NO_ERROR) return ret; - ALCdevice_Lock(device); + ALCdevice_Lock(context->Device); for(i = 0;i < 16;i++) fluid_synth_all_sounds_off(self->Synth, i); - ALCdevice_Unlock(device); + ALCdevice_Unlock(context->Device); fontid = malloc(count * sizeof(fontid[0])); if(fontid) diff --git a/OpenAL32/alMidi.c b/OpenAL32/alMidi.c index 9b0309bf..257a9481 100644 --- a/OpenAL32/alMidi.c +++ b/OpenAL32/alMidi.c @@ -51,7 +51,7 @@ AL_API void AL_APIENTRY alMidiSoundfontvSOFT(ALsizei count, const ALuint *ids) alSetError(context, AL_INVALID_OPERATION); else { - err = V(synth,selectSoundfonts)(device, count, ids); + err = V(synth,selectSoundfonts)(context, count, ids); if(err != AL_NO_ERROR) alSetError(context, err); } |