diff options
author | Chris Robinson <[email protected]> | 2013-12-27 02:59:50 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2013-12-27 02:59:50 -0800 |
commit | f85d733f9dc569bd6b3f37a0a4b8be7b3c783ad6 (patch) | |
tree | a67fa24599e54bee27a36e14e2cde8bca3348465 /Alc | |
parent | 2b772a5607c2147d68eb8e45b04b2f381ec6c0ad (diff) |
Add a method to set and get soundfonts
The main purpose of this is to select soundfonts for playback, eventually,
instead of the existing method that takes a filename.
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/ALc.c | 1 | ||||
-rw-r--r-- | Alc/midi/base.c | 43 | ||||
-rw-r--r-- | Alc/midi/base.h | 7 | ||||
-rw-r--r-- | Alc/midi/dummy.c | 1 | ||||
-rw-r--r-- | Alc/midi/fluidsynth.c | 1 |
5 files changed, 53 insertions, 0 deletions
@@ -304,6 +304,7 @@ static const ALCfunction alcFunctions[] = { DECL(alFontsoundivSOFT), DECL(alGetFontsoundivSOFT), DECL(alMidiSoundfontSOFT), + DECL(alMidiSoundfontsSOFT), DECL(alMidiEventSOFT), DECL(alMidiSysExSOFT), DECL(alMidiPlaySOFT), diff --git a/Alc/midi/base.c b/Alc/midi/base.c index 6449d7fc..8b498680 100644 --- a/Alc/midi/base.c +++ b/Alc/midi/base.c @@ -124,6 +124,9 @@ void MidiSynth_Construct(MidiSynth *self, ALCdevice *device) RWLockInit(&self->Lock); + self->Soundfonts = NULL; + self->NumSoundfonts = 0; + self->Gain = 1.0f; self->State = AL_INITIAL; @@ -137,6 +140,14 @@ void MidiSynth_Construct(MidiSynth *self, ALCdevice *device) void MidiSynth_Destruct(MidiSynth *self) { + ALsizei i; + + for(i = 0;i < self->NumSoundfonts;i++) + DecrementRef(&self->Soundfonts[i]->ref); + free(self->Soundfonts); + self->Soundfonts = NULL; + self->NumSoundfonts = 0; + ResetEvtQueue(&self->EventQueue); } @@ -152,6 +163,38 @@ const char *MidiSynth_getFontName(const MidiSynth* UNUSED(self), const char *fil return filename; } +ALenum MidiSynth_selectSoundfonts(MidiSynth *self, ALCdevice *device, ALsizei count, const ALuint *ids) +{ + ALsoundfont **sfonts; + ALsizei i; + + if(self->State != AL_INITIAL && self->State != AL_STOPPED) + return AL_INVALID_OPERATION; + + sfonts = calloc(1, count * sizeof(sfonts[0])); + if(!sfonts) return AL_OUT_OF_MEMORY; + + for(i = 0;i < count;i++) + { + if(!(sfonts[i]=LookupSfont(device, ids[i]))) + { + free(sfonts); + return AL_INVALID_VALUE; + } + } + + for(i = 0;i < count;i++) + IncrementRef(&sfonts[i]->ref); + sfonts = ExchangePtr((XchgPtr*)&self->Soundfonts, sfonts); + count = ExchangeInt(&self->NumSoundfonts, count); + + for(i = 0;i < count;i++) + DecrementRef(&sfonts[i]->ref); + free(sfonts); + + return AL_NO_ERROR; +} + extern inline void MidiSynth_setGain(MidiSynth *self, ALfloat gain); extern inline ALfloat MidiSynth_getGain(const MidiSynth *self); extern inline void MidiSynth_setState(MidiSynth *self, ALenum state); diff --git a/Alc/midi/base.h b/Alc/midi/base.h index 4f10b89b..d038eebc 100644 --- a/Alc/midi/base.h +++ b/Alc/midi/base.h @@ -27,6 +27,9 @@ typedef struct MidiSynth { */ RWLock Lock; + struct ALsoundfont **Soundfonts; + ALsizei NumSoundfonts; + volatile ALfloat Gain; volatile ALenum State; @@ -36,6 +39,7 @@ typedef struct MidiSynth { void MidiSynth_Construct(MidiSynth *self, ALCdevice *device); void MidiSynth_Destruct(MidiSynth *self); const char *MidiSynth_getFontName(const MidiSynth *self, const char *filename); +ALenum MidiSynth_selectSoundfonts(MidiSynth *self, ALCdevice *device, 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); } @@ -60,6 +64,7 @@ struct MidiSynthVtable { ALboolean (*const isSoundfont)(MidiSynth *self, const char *filename); ALenum (*const loadSoundfont)(MidiSynth *self, const char *filename); + ALenum (*const selectSoundfonts)(MidiSynth *self, ALCdevice *device, ALsizei count, const ALuint *ids); void (*const setGain)(MidiSynth *self, ALfloat gain); void (*const setState)(MidiSynth *self, ALenum state); @@ -77,6 +82,7 @@ struct MidiSynthVtable { DECLARE_THUNK(T, MidiSynth, void, Destruct) \ DECLARE_THUNK1(T, MidiSynth, ALboolean, isSoundfont, const char*) \ DECLARE_THUNK1(T, MidiSynth, ALenum, loadSoundfont, const char*) \ +DECLARE_THUNK3(T, MidiSynth, ALenum, selectSoundfonts, ALCdevice*, ALsizei, const ALuint*) \ DECLARE_THUNK1(T, MidiSynth, void, setGain, ALfloat) \ DECLARE_THUNK1(T, MidiSynth, void, setState, ALenum) \ DECLARE_THUNK(T, MidiSynth, void, stop) \ @@ -90,6 +96,7 @@ static const struct MidiSynthVtable T##_MidiSynth_vtable = { \ \ T##_MidiSynth_isSoundfont, \ T##_MidiSynth_loadSoundfont, \ + T##_MidiSynth_selectSoundfonts, \ T##_MidiSynth_setGain, \ T##_MidiSynth_setState, \ T##_MidiSynth_stop, \ diff --git a/Alc/midi/dummy.c b/Alc/midi/dummy.c index 4e53270e..3b72b63f 100644 --- a/Alc/midi/dummy.c +++ b/Alc/midi/dummy.c @@ -22,6 +22,7 @@ static void DSynth_Construct(DSynth *self, ALCdevice *device); static DECLARE_FORWARD(DSynth, MidiSynth, void, Destruct) static ALboolean DSynth_isSoundfont(DSynth *self, const char *filename); static ALenum DSynth_loadSoundfont(DSynth *self, const char *filename); +static DECLARE_FORWARD3(DSynth, MidiSynth, ALenum, selectSoundfonts, ALCdevice*, 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 7461cc4e..55526238 100644 --- a/Alc/midi/fluidsynth.c +++ b/Alc/midi/fluidsynth.c @@ -42,6 +42,7 @@ static void FSynth_Destruct(FSynth *self); static ALboolean FSynth_init(FSynth *self, ALCdevice *device); static ALboolean FSynth_isSoundfont(FSynth *self, const char *filename); static ALenum FSynth_loadSoundfont(FSynth *self, const char *filename); +static DECLARE_FORWARD3(FSynth, MidiSynth, ALenum, selectSoundfonts, ALCdevice*, ALsizei, const ALuint*) static void FSynth_setGain(FSynth *self, ALfloat gain); static void FSynth_setState(FSynth *self, ALenum state); static void FSynth_stop(FSynth *self); |