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/midi/base.c | |
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/midi/base.c')
-rw-r--r-- | Alc/midi/base.c | 43 |
1 files changed, 43 insertions, 0 deletions
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); |