--- np2/sound/vermouth/midimod.c 2006/12/10 11:14:31 1.8 +++ np2/sound/vermouth/midimod.c 2006/12/16 12:11:07 1.10 @@ -42,7 +42,7 @@ static const OEMCHAR file_timiditycfg[] static const OEMCHAR str_basedir[] = OEMTEXT("${basedir}"); -static void pathadd(MIDIMOD mod, const OEMCHAR *path) { +static void VERMOUTHCL pathadd(MIDIMOD mod, const OEMCHAR *path) { _PATHLIST pl; PATHLIST p; @@ -74,7 +74,7 @@ static void pathadd(MIDIMOD mod, const O } } -static void pathaddex(MIDIMOD mod, const OEMCHAR *path) { +static void VERMOUTHCL pathaddex(MIDIMOD mod, const OEMCHAR *path) { OEMCHAR _path[MAX_PATH]; @@ -89,7 +89,7 @@ static void pathaddex(MIDIMOD mod, const } } -static int cfggetarg(OEMCHAR *str, OEMCHAR *arg[], int maxarg) { +static int VERMOUTHCL cfggetarg(OEMCHAR *str, OEMCHAR *arg[], int maxarg) { int ret; BOOL quot; @@ -141,7 +141,7 @@ cga_done: return(ret); } -static OEMCHAR *seachr(const OEMCHAR *str, OEMCHAR sepa) { +static OEMCHAR *VERMOUTHCL seachr(const OEMCHAR *str, OEMCHAR sepa) { OEMCHAR c; @@ -163,7 +163,7 @@ enum { VAL_SIGN = 2 }; -static BRESULT cfggetval(const OEMCHAR *str, int *val) { +static BRESULT VERMOUTHCL cfggetval(const OEMCHAR *str, int *val) { int ret; int flag; @@ -208,7 +208,8 @@ static BRESULT cfggetval(const OEMCHAR * // ---- -static void settone(MIDIMOD mod, int bank, int argc, OEMCHAR *argv[]) { +static void VERMOUTHCL settone(MIDIMOD mod, int bank, int argc, + OEMCHAR *argv[]) { int val; TONECFG tone; @@ -332,7 +333,7 @@ static void settone(MIDIMOD mod, int ban // ---- -BRESULT cfgfile_getfile(MIDIMOD mod, const OEMCHAR *filename, +BRESULT VERMOUTHCL midimod_getfile(MIDIMOD mod, const OEMCHAR *filename, OEMCHAR *path, int size) { PATHLIST p; @@ -361,7 +362,8 @@ fpgf_exit: return(FAILURE); } -BRESULT cfgfile_load(MIDIMOD mod, const OEMCHAR *filename, int depth) { +static BRESULT VERMOUTHCL cfgfile_load(MIDIMOD mod, const OEMCHAR *filename, + int depth) { TEXTFILEH tfh; OEMCHAR buf[1024]; @@ -375,7 +377,7 @@ BRESULT cfgfile_load(MIDIMOD mod, const bank = -1; if ((depth >= 16) || - (cfgfile_getfile(mod, filename, buf, NELEMENTS(buf)) != SUCCESS)) { + (midimod_getfile(mod, filename, buf, NELEMENTS(buf)) != SUCCESS)) { goto cfl_err; } // TRACEOUT(("open: %s", buf)); @@ -459,7 +461,7 @@ VEXTERN MIDIMOD VEXPORT midimod_create(U ret->tone[1] = ret->tone[0] + 128; ret->tonecfg[0] = (TONECFG)(ret->tone[1] + 128); ret->tonecfg[1] = ret->tonecfg[0] + 128; - ret->pathtbl = listarray_new(sizeof(_PATHLIST), 64); + ret->pathtbl = listarray_new(sizeof(_PATHLIST), 16); pathadd(ret, NULL); pathadd(ret, file_getcd(str_null)); ret->namelist = listarray_new(MAX_NAME, 128); @@ -472,6 +474,7 @@ VEXTERN MIDIMOD VEXPORT midimod_create(U if (r != SUCCESS) { goto mmcre_err2; } + midimod_lock(ret); return(ret); mmcre_err2: @@ -483,27 +486,51 @@ mmcre_err1: return(NULL); } -VEXTERN void VEXPORT midimod_destroy(MIDIMOD hdl) { +void VERMOUTHCL midimod_lock(MIDIMOD hdl) { + + hdl->lockcount++; +} + +void VERMOUTHCL midimod_unlock(MIDIMOD hdl) { UINT r; TONECFG bank; - if (hdl) { - r = 128; - do { - r--; - inst_bankfree(hdl, r); - } while(r > 0); - for (r=2; r<(MIDI_BANKS*2); r++) { - bank = hdl->tonecfg[r]; - if (bank) { - _MFREE(bank); - } + if (!hdl->lockcount) { + return; + } + hdl->lockcount--; + if (hdl->lockcount) { + return; + } + + r = 128; + do { + r--; + inst_bankfree(hdl, r); + } while(r > 0); + for (r=2; r<(MIDI_BANKS*2); r++) { + bank = hdl->tonecfg[r]; + if (bank) { + _MFREE(bank); } - listarray_destroy(hdl->namelist); - listarray_destroy(hdl->pathtbl); - _MFREE(hdl); } + listarray_destroy(hdl->namelist); + listarray_destroy(hdl->pathtbl); + _MFREE(hdl); +} + +VEXTERN void VEXPORT midimod_destroy(MIDIMOD hdl) { + + if (hdl) { + midimod_unlock(hdl); + } +} + +VEXTERN BRESULT VEXPORT midimod_cfgload(MIDIMOD hdl, + const OEMCHAR *filename) { + + return(cfgfile_load(hdl, filename, 0)); } VEXTERN void VEXPORT midimod_loadprogram(MIDIMOD hdl, UINT num) {