diff options
Diffstat (limited to 'Alc/midi')
-rw-r--r-- | Alc/midi/sf2load.c | 80 |
1 files changed, 38 insertions, 42 deletions
diff --git a/Alc/midi/sf2load.c b/Alc/midi/sf2load.c index 29a487f6..0975d2a4 100644 --- a/Alc/midi/sf2load.c +++ b/Alc/midi/sf2load.c @@ -343,16 +343,15 @@ static GenModList GenModList_clone(const GenModList *self) static void GenModList_insertGen(GenModList *self, const Generator *gen, ALboolean ispreset) { - Generator *i = VECTOR_ITER_BEGIN(self->gens); - Generator *end = VECTOR_ITER_END(self->gens); - for(;i != end;i++) + Generator *i; +#define MATCH_GENERATOR(i) ((i)->mGenerator == gen->mGenerator) + VECTOR_FIND_IF(i, Generator, self->gens, MATCH_GENERATOR); + if(i != VECTOR_ITER_END(self->gens)) { - if(i->mGenerator == gen->mGenerator) - { - i->mAmount = gen->mAmount; - return; - } + i->mAmount = gen->mAmount; + return; } +#undef MATCH_GENERATOR if(ispreset && (gen->mGenerator == 0 || gen->mGenerator == 1 || gen->mGenerator == 2 || @@ -370,26 +369,25 @@ static void GenModList_insertGen(GenModList *self, const Generator *gen, ALboole } static void GenModList_accumGen(GenModList *self, const Generator *gen) { - Generator *i = VECTOR_ITER_BEGIN(self->gens); - Generator *end = VECTOR_ITER_END(self->gens); - for(;i != end;i++) + Generator *i; +#define MATCH_GENERATOR(i) ((i)->mGenerator == gen->mGenerator) + VECTOR_FIND_IF(i, Generator, self->gens, MATCH_GENERATOR); + if(i != VECTOR_ITER_END(self->gens)) { - if(i->mGenerator == gen->mGenerator) + if(gen->mGenerator == 43 || gen->mGenerator == 44) { - if(gen->mGenerator == 43 || gen->mGenerator == 44) - { - /* Range generators accumulate by taking the intersection of - * the two ranges. - */ - ALushort low = maxu(i->mAmount&0x00ff, gen->mAmount&0x00ff); - ALushort high = minu(i->mAmount&0xff00, gen->mAmount&0xff00); - i->mAmount = low | high; - } - else - i->mAmount += gen->mAmount; - return; + /* Range generators accumulate by taking the intersection of the + * two ranges. + */ + ALushort low = maxu(i->mAmount&0x00ff, gen->mAmount&0x00ff); + ALushort high = minu(i->mAmount&0xff00, gen->mAmount&0xff00); + i->mAmount = low | high; } + else + i->mAmount += gen->mAmount; + return; } +#undef MATCH_GENERATOR if(VECTOR_PUSH_BACK(self->gens, *gen) == AL_FALSE) { @@ -402,17 +400,16 @@ static void GenModList_accumGen(GenModList *self, const Generator *gen) static void GenModList_insertMod(GenModList *self, const Modulator *mod) { - Modulator *i = VECTOR_ITER_BEGIN(self->mods); - Modulator *end = VECTOR_ITER_END(self->mods); - for(;i != end;i++) + Modulator *i; +#define MATCH_MODULATOR(i) ((i)->mDstOp == mod->mDstOp && (i)->mSrcOp == mod->mSrcOp && \ + (i)->mAmtSrcOp == mod->mAmtSrcOp && (i)->mTransOp == mod->mTransOp) + VECTOR_FIND_IF(i, Modulator, self->mods, MATCH_MODULATOR); + if(i != VECTOR_ITER_END(self->mods)) { - if(i->mDstOp == mod->mDstOp && i->mSrcOp == mod->mSrcOp && - i->mAmtSrcOp == mod->mAmtSrcOp && i->mTransOp == mod->mTransOp) - { - i->mAmount = mod->mAmount; - return; - } + i->mAmount = mod->mAmount; + return; } +#undef MATCH_MODULATOR if(VECTOR_PUSH_BACK(self->mods, *mod) == AL_FALSE) { @@ -422,17 +419,16 @@ static void GenModList_insertMod(GenModList *self, const Modulator *mod) } static void GenModList_accumMod(GenModList *self, const Modulator *mod) { - Modulator *i = VECTOR_ITER_BEGIN(self->mods); - Modulator *end = VECTOR_ITER_END(self->mods); - for(;i != end;i++) + Modulator *i; +#define MATCH_MODULATOR(i) ((i)->mDstOp == mod->mDstOp && (i)->mSrcOp == mod->mSrcOp && \ + (i)->mAmtSrcOp == mod->mAmtSrcOp && (i)->mTransOp == mod->mTransOp) + VECTOR_FIND_IF(i, Modulator, self->mods, MATCH_MODULATOR); + if(i != VECTOR_ITER_END(self->mods)) { - if(i->mDstOp == mod->mDstOp && i->mSrcOp == mod->mSrcOp && - i->mAmtSrcOp == mod->mAmtSrcOp && i->mTransOp == mod->mTransOp) - { - i->mAmount += mod->mAmount; - return; - } + i->mAmount += mod->mAmount; + return; } +#undef MATCH_MODULATOR if(VECTOR_PUSH_BACK(self->mods, *mod) == AL_FALSE) { |