diff --git a/src/sfloader/fluid_sffile.c b/src/sfloader/fluid_sffile.c index 7326b41d..a4b05569 100644 --- a/src/sfloader/fluid_sffile.c +++ b/src/sfloader/fluid_sffile.c @@ -1146,7 +1146,8 @@ static int load_phdr(SFData *sf, unsigned int size) /* preset bag loader */ static int load_pbag(SFData *sf, int size) { - fluid_list_t *p, *p2; + fluid_list_t *preset_list; + fluid_list_t *zone_list; SFZone *z, *pz = NULL; unsigned short genndx, modndx; unsigned short pgenndx = 0, pmodndx = 0; @@ -1158,14 +1159,14 @@ static int load_pbag(SFData *sf, int size) return FALSE; } - p = sf->preset; + preset_list = sf->preset; - while(p) + while(preset_list) { /* traverse through presets */ - p2 = ((SFPreset *)(p->data))->zone; + zone_list = ((SFPreset *)(preset_list->data))->zone; - while(p2) + while(zone_list) { /* traverse preset's zones */ if((size -= SF_BAG_SIZE) < 0) @@ -1180,7 +1181,7 @@ static int load_pbag(SFData *sf, int size) return FALSE; } - p2->data = z; + zone_list->data = z; z->gen = NULL; /* Init gen and mod before possible failure, */ z->mod = NULL; /* to ensure proper cleanup (fluid_sffile_close) */ READW(sf, genndx); /* possible read failure ^ */ @@ -1220,10 +1221,10 @@ static int load_pbag(SFData *sf, int size) pz = z; /* update previous zone ptr */ pgenndx = genndx; /* update previous zone gen index */ pmodndx = modndx; /* update previous zone mod index */ - p2 = fluid_list_next(p2); + zone_list = fluid_list_next(zone_list); } - p = fluid_list_next(p); + preset_list = fluid_list_next(preset_list); } size -= SF_BAG_SIZE; @@ -1284,22 +1285,24 @@ static int load_pbag(SFData *sf, int size) /* preset modulator loader */ static int load_pmod(SFData *sf, int size) { - fluid_list_t *p, *p2, *p3; + fluid_list_t *preset_list; + fluid_list_t *zone_list; + fluid_list_t *mod_list; SFMod *m; - p = sf->preset; + preset_list = sf->preset; - while(p) + while(preset_list) { /* traverse through all presets */ - p2 = ((SFPreset *)(p->data))->zone; + zone_list = ((SFPreset *)(preset_list->data))->zone; - while(p2) + while(zone_list) { /* traverse this preset's zones */ - p3 = ((SFZone *)(p2->data))->mod; + mod_list = ((SFZone *)(zone_list->data))->mod; - while(p3) + while(mod_list) { /* load zone's modulators */ if((size -= SF_MOD_SIZE) < 0) @@ -1314,19 +1317,19 @@ static int load_pmod(SFData *sf, int size) return FALSE; } - p3->data = m; + mod_list->data = m; READW(sf, m->src); READW(sf, m->dest); READW(sf, m->amount); READW(sf, m->amtsrc); READW(sf, m->trans); - p3 = fluid_list_next(p3); + mod_list = fluid_list_next(mod_list); } - p2 = fluid_list_next(p2); + zone_list = fluid_list_next(zone_list); } - p = fluid_list_next(p); + preset_list = fluid_list_next(preset_list); } /* @@ -1365,35 +1368,39 @@ static int load_pmod(SFData *sf, int size) * ------------------------------------------------------------------- */ static int load_pgen(SFData *sf, int size) { - fluid_list_t *p, *p2, *p3, *dup, **hz = NULL, *start_of_zone_list; + fluid_list_t *dup, **hz = NULL; + fluid_list_t *preset_list; + fluid_list_t *zone_list; + fluid_list_t *gen_list; + fluid_list_t *start_of_zone_list; SFZone *z; SFGen *g; SFGenAmount genval; unsigned short genid; int level, skip, drop, gzone, discarded; - p = sf->preset; + preset_list = sf->preset; - while(p) + while(preset_list) { /* traverse through all presets */ gzone = FALSE; discarded = FALSE; - start_of_zone_list = p2 = ((SFPreset *)(p->data))->zone; + start_of_zone_list = zone_list = ((SFPreset *)(preset_list->data))->zone; - if(p2) + if(zone_list) { - hz = &p2; + hz = &zone_list; } - while(p2) + while(zone_list) { /* traverse preset's zones */ level = 0; - z = (SFZone *)(p2->data); - p3 = z->gen; + z = (SFZone *)(zone_list->data); + gen_list = z->gen; - while(p3) + while(gen_list) { /* load zone's generators */ dup = NULL; @@ -1441,7 +1448,7 @@ static int load_pgen(SFData *sf, int size) /* inst is last gen */ level = 3; READW(sf, genval.uword); - ((SFZone *)(p2->data))->instsamp = FLUID_INT_TO_POINTER(genval.uword + 1); + ((SFZone *)(zone_list->data))->instsamp = FLUID_INT_TO_POINTER(genval.uword + 1); break; /* break out of generator loop */ } else @@ -1471,7 +1478,7 @@ static int load_pgen(SFData *sf, int size) return FALSE; } - p3->data = g; + gen_list->data = g; g->id = genid; } else @@ -1492,18 +1499,18 @@ static int load_pgen(SFData *sf, int size) if(!drop) { - p3 = fluid_list_next(p3); /* next gen */ + gen_list = fluid_list_next(gen_list); /* next gen */ } else { - SLADVREM(z->gen, p3); /* drop place holder */ + SLADVREM(z->gen, gen_list); /* drop place holder */ } } /* generator loop */ if(level == 3) { - SLADVREM(z->gen, p3); /* zone has inst? */ + SLADVREM(z->gen, gen_list); /* zone has inst? */ } else { @@ -1514,29 +1521,29 @@ static int load_pgen(SFData *sf, int size) gzone = TRUE; /* if global zone is not 1st zone, relocate */ - if(*hz != p2) + if(*hz != zone_list) { - void *save = p2->data; + void *save = zone_list->data; FLUID_LOG(FLUID_WARN, "Preset '%s': Global zone is not first zone", - ((SFPreset *)(p->data))->name); - SLADVREM(*hz, p2); + ((SFPreset *)(preset_list->data))->name); + SLADVREM(*hz, zone_list); *hz = fluid_list_prepend(*hz, save); continue; } } else { - p2 = fluid_list_next(p2); /* advance to next zone before deleting the current list element */ + zone_list = fluid_list_next(zone_list); /* advance to next zone before deleting the current list element */ /* previous global zone exists, discard */ FLUID_LOG(FLUID_WARN, "Preset '%s': Discarding invalid global zone", - ((SFPreset *)(p->data))->name); + ((SFPreset *)(preset_list->data))->name); fluid_list_remove(start_of_zone_list, z); delete_zone(z); continue; } } - while(p3) + while(gen_list) { /* Kill any zones following an instrument */ discarded = TRUE; @@ -1548,20 +1555,20 @@ static int load_pgen(SFData *sf, int size) } FSKIP(sf, SF_GEN_SIZE); - SLADVREM(z->gen, p3); + SLADVREM(z->gen, gen_list); } - p2 = fluid_list_next(p2); /* next zone */ + zone_list = fluid_list_next(zone_list); /* next zone */ } if(discarded) { FLUID_LOG(FLUID_WARN, "Preset '%s': Some invalid generators were discarded", - ((SFPreset *)(p->data))->name); + ((SFPreset *)(preset_list->data))->name); } - p = fluid_list_next(p); + preset_list = fluid_list_next(preset_list); } /* in case there isn't a terminal record */ @@ -1588,7 +1595,7 @@ static int load_ihdr(SFData *sf, unsigned int size) { unsigned int i; int i2; - SFInst *p, *pr = NULL; /* ptr to current & previous instrument */ + SFInst *inst, *prev_inst = NULL; /* ptr to current & previous instrument */ unsigned short zndx, pzndx = 0; if(size % SF_IHDR_SIZE || size == 0) /* chunk size is valid? */ @@ -1610,19 +1617,19 @@ static int load_ihdr(SFData *sf, unsigned int size) for(i = 0; i < size; i++) { /* load all instrument headers */ - if((p = FLUID_NEW(SFInst)) == NULL) + if((inst = FLUID_NEW(SFInst)) == NULL) { FLUID_LOG(FLUID_ERR, "Out of memory"); return FALSE; } - sf->inst = fluid_list_append(sf->inst, p); - p->zone = NULL; /* For proper cleanup if fail (fluid_sffile_close) */ - p->idx = i; - READSTR(sf, &p->name); /* Possible read failure ^ */ + sf->inst = fluid_list_append(sf->inst, inst); + inst->zone = NULL; /* For proper cleanup if fail (fluid_sffile_close) */ + inst->idx = i; + READSTR(sf, &inst->name); /* Possible read failure ^ */ READW(sf, zndx); - if(pr) + if(prev_inst) { /* not first instrument? */ if(zndx < pzndx) @@ -1635,7 +1642,7 @@ static int load_ihdr(SFData *sf, unsigned int size) while(i2--) { - pr->zone = fluid_list_prepend(pr->zone, NULL); + prev_inst->zone = fluid_list_prepend(prev_inst->zone, NULL); } } else if(zndx > 0) /* 1st inst, warn if ofs >0 */ @@ -1644,7 +1651,7 @@ static int load_ihdr(SFData *sf, unsigned int size) } pzndx = zndx; - pr = p; /* update instrument ptr */ + prev_inst = inst; /* update instrument ptr */ } FSKIP(sf, 20); @@ -1660,7 +1667,7 @@ static int load_ihdr(SFData *sf, unsigned int size) while(i2--) { - pr->zone = fluid_list_prepend(pr->zone, NULL); + prev_inst->zone = fluid_list_prepend(prev_inst->zone, NULL); } return TRUE; @@ -1669,7 +1676,8 @@ static int load_ihdr(SFData *sf, unsigned int size) /* instrument bag loader */ static int load_ibag(SFData *sf, int size) { - fluid_list_t *p, *p2; + fluid_list_t *inst_list; + fluid_list_t *zone_list; SFZone *z, *pz = NULL; unsigned short genndx, modndx, pgenndx = 0, pmodndx = 0; int i; @@ -1680,14 +1688,14 @@ static int load_ibag(SFData *sf, int size) return FALSE; } - p = sf->inst; + inst_list = sf->inst; - while(p) + while(inst_list) { /* traverse through inst */ - p2 = ((SFInst *)(p->data))->zone; + zone_list = ((SFInst *)(inst_list->data))->zone; - while(p2) + while(zone_list) { /* load this inst's zones */ if((size -= SF_BAG_SIZE) < 0) @@ -1702,7 +1710,7 @@ static int load_ibag(SFData *sf, int size) return FALSE; } - p2->data = z; + zone_list->data = z; z->gen = NULL; /* In case of failure, */ z->mod = NULL; /* fluid_sffile_close can clean up */ READW(sf, genndx); /* READW = possible read failure */ @@ -1742,10 +1750,10 @@ static int load_ibag(SFData *sf, int size) pz = z; /* update previous zone ptr */ pgenndx = genndx; pmodndx = modndx; - p2 = fluid_list_next(p2); + zone_list = fluid_list_next(zone_list); } - p = fluid_list_next(p); + inst_list = fluid_list_next(inst_list); } size -= SF_BAG_SIZE; @@ -1807,22 +1815,24 @@ static int load_ibag(SFData *sf, int size) /* instrument modulator loader */ static int load_imod(SFData *sf, int size) { - fluid_list_t *p, *p2, *p3; + fluid_list_t *inst_list; + fluid_list_t *zone_list; + fluid_list_t *mod_list; SFMod *m; - p = sf->inst; + inst_list = sf->inst; - while(p) + while(inst_list) { /* traverse through all inst */ - p2 = ((SFInst *)(p->data))->zone; + zone_list = ((SFInst *)(inst_list->data))->zone; - while(p2) + while(zone_list) { /* traverse this inst's zones */ - p3 = ((SFZone *)(p2->data))->mod; + mod_list = ((SFZone *)(zone_list->data))->mod; - while(p3) + while(mod_list) { /* load zone's modulators */ if((size -= SF_MOD_SIZE) < 0) @@ -1837,19 +1847,19 @@ static int load_imod(SFData *sf, int size) return FALSE; } - p3->data = m; + mod_list->data = m; READW(sf, m->src); READW(sf, m->dest); READW(sf, m->amount); READW(sf, m->amtsrc); READW(sf, m->trans); - p3 = fluid_list_next(p3); + mod_list = fluid_list_next(mod_list); } - p2 = fluid_list_next(p2); + zone_list = fluid_list_next(zone_list); } - p = fluid_list_next(p); + inst_list = fluid_list_next(inst_list); } /* @@ -1877,35 +1887,39 @@ static int load_imod(SFData *sf, int size) /* load instrument generators (see load_pgen for loading rules) */ static int load_igen(SFData *sf, int size) { - fluid_list_t *p, *p2, *p3, *dup, **hz = NULL, *start_of_zone_list; + fluid_list_t *dup, **hz = NULL; + fluid_list_t *inst_list; + fluid_list_t *zone_list; + fluid_list_t *gen_list; + fluid_list_t *start_of_zone_list; SFZone *z; SFGen *g; SFGenAmount genval; unsigned short genid; int level, skip, drop, gzone, discarded; - p = sf->inst; + inst_list = sf->inst; - while(p) + while(inst_list) { /* traverse through all instruments */ gzone = FALSE; discarded = FALSE; - start_of_zone_list = p2 = ((SFInst *)(p->data))->zone; + start_of_zone_list = zone_list = ((SFInst *)(inst_list->data))->zone; - if(p2) + if(zone_list) { - hz = &p2; + hz = &zone_list; } - while(p2) + while(zone_list) { /* traverse this instrument's zones */ level = 0; - z = (SFZone *)(p2->data); - p3 = z->gen; + z = (SFZone *)(zone_list->data); + gen_list = z->gen; - while(p3) + while(gen_list) { /* load zone's generators */ dup = NULL; @@ -1953,7 +1967,7 @@ static int load_igen(SFData *sf, int size) /* sample is last gen */ level = 3; READW(sf, genval.uword); - ((SFZone *)(p2->data))->instsamp = FLUID_INT_TO_POINTER(genval.uword + 1); + ((SFZone *)(zone_list->data))->instsamp = FLUID_INT_TO_POINTER(genval.uword + 1); break; /* break out of generator loop */ } else @@ -1983,7 +1997,7 @@ static int load_igen(SFData *sf, int size) return FALSE; } - p3->data = g; + gen_list->data = g; g->id = genid; } else @@ -2004,18 +2018,18 @@ static int load_igen(SFData *sf, int size) if(!drop) { - p3 = fluid_list_next(p3); /* next gen */ + gen_list = fluid_list_next(gen_list); /* next gen */ } else { - SLADVREM(z->gen, p3); + SLADVREM(z->gen, gen_list); } } /* generator loop */ if(level == 3) { - SLADVREM(z->gen, p3); /* zone has sample? */ + SLADVREM(z->gen, gen_list); /* zone has sample? */ } else { @@ -2025,29 +2039,29 @@ static int load_igen(SFData *sf, int size) gzone = TRUE; /* if global zone is not 1st zone, relocate */ - if(*hz != p2) + if(*hz != zone_list) { - void *save = p2->data; + void *save = zone_list->data; FLUID_LOG(FLUID_WARN, "Instrument '%s': Global zone is not first zone", - ((SFPreset *)(p->data))->name); - SLADVREM(*hz, p2); + ((SFPreset *)(inst_list->data))->name); + SLADVREM(*hz, zone_list); *hz = fluid_list_prepend(*hz, save); continue; } } else { - p2 = fluid_list_next(p2); /* advance to next zone before deleting the current list element */ + zone_list = fluid_list_next(zone_list); /* advance to next zone before deleting the current list element */ /* previous global zone exists, discard */ FLUID_LOG(FLUID_WARN, "Instrument '%s': Discarding invalid global zone", - ((SFInst *)(p->data))->name); + ((SFInst *)(inst_list->data))->name); fluid_list_remove(start_of_zone_list, z); delete_zone(z); continue; } } - while(p3) + while(gen_list) { /* Kill any zones following a sample */ discarded = TRUE; @@ -2059,20 +2073,20 @@ static int load_igen(SFData *sf, int size) } FSKIP(sf, SF_GEN_SIZE); - SLADVREM(z->gen, p3); + SLADVREM(z->gen, gen_list); } - p2 = fluid_list_next(p2); /* next zone */ + zone_list = fluid_list_next(zone_list); /* next zone */ } if(discarded) { FLUID_LOG(FLUID_WARN, "Instrument '%s': Some invalid generators were discarded", - ((SFInst *)(p->data))->name); + ((SFInst *)(inst_list->data))->name); } - p = fluid_list_next(p); + inst_list = fluid_list_next(inst_list); } /* for those non-terminal record cases, grr! */ @@ -2146,7 +2160,9 @@ static int load_shdr(SFData *sf, unsigned int size) /* "fixup" (inst # -> inst ptr) instrument references in preset list */ static int fixup_pgen(SFData *sf) { - fluid_list_t *p, *p2, *p3; + fluid_list_t *p; + fluid_list_t *zone_list; + fluid_list_t *inst_list; SFZone *z; int i; @@ -2154,33 +2170,33 @@ static int fixup_pgen(SFData *sf) while(p) { - p2 = ((SFPreset *)(p->data))->zone; + zone_list = ((SFPreset *)(p->data))->zone; - while(p2) + while(zone_list) { /* traverse this preset's zones */ - z = (SFZone *)(p2->data); + z = (SFZone *)(zone_list->data); if((i = FLUID_POINTER_TO_INT(z->instsamp))) { /* load instrument # */ - p3 = fluid_list_nth(sf->inst, i - 1); + inst_list = fluid_list_nth(sf->inst, i - 1); - if(!p3) + if(!inst_list) { FLUID_LOG(FLUID_ERR, "Preset %03d %03d: Invalid instrument reference", ((SFPreset *)(p->data))->bank, ((SFPreset *)(p->data))->prenum); return FALSE; } - z->instsamp = p3; + z->instsamp = inst_list; } else { z->instsamp = NULL; } - p2 = fluid_list_next(p2); + zone_list = fluid_list_next(zone_list); } p = fluid_list_next(p); @@ -2192,7 +2208,9 @@ static int fixup_pgen(SFData *sf) /* "fixup" (sample # -> sample ptr) sample references in instrument list */ static int fixup_igen(SFData *sf) { - fluid_list_t *p, *p2, *p3; + fluid_list_t *p; + fluid_list_t *zone_list; + fluid_list_t *inst_list; SFZone *z; int i; @@ -2200,29 +2218,29 @@ static int fixup_igen(SFData *sf) while(p) { - p2 = ((SFInst *)(p->data))->zone; + zone_list = ((SFInst *)(p->data))->zone; - while(p2) + while(zone_list) { /* traverse instrument's zones */ - z = (SFZone *)(p2->data); + z = (SFZone *)(zone_list->data); if((i = FLUID_POINTER_TO_INT(z->instsamp))) { /* load sample # */ - p3 = fluid_list_nth(sf->sample, i - 1); + inst_list = fluid_list_nth(sf->sample, i - 1); - if(!p3) + if(!inst_list) { FLUID_LOG(FLUID_ERR, "Instrument '%s': Invalid sample reference", ((SFInst *)(p->data))->name); return FALSE; } - z->instsamp = p3; + z->instsamp = inst_list; } - p2 = fluid_list_next(p2); + zone_list = fluid_list_next(zone_list); } p = fluid_list_next(p);