--- np2/sound/vermouth/midimod.c 2003/11/28 08:01:33 1.3 +++ np2/sound/vermouth/midimod.c 2006/12/16 12:11:07 1.10 @@ -3,6 +3,9 @@ #include "dosio.h" #include "textfile.h" #include "midiout.h" +#if defined(SUPPORT_ARC) +#include "arc.h" +#endif #define CFG_MAXAMP 400 @@ -16,29 +19,30 @@ enum { CFG_DRUM }; -static const char str_dir[] = "dir"; -static const char str_source[] = "source"; -static const char str_default[] = "default"; -static const char str_bank[] = "bank"; -static const char str_drumset[] = "drumset"; -static const char *cfgstr[] = {str_dir, str_source, str_default, +static const OEMCHAR str_dir[] = OEMTEXT("dir"); +static const OEMCHAR str_source[] = OEMTEXT("source"); +static const OEMCHAR str_default[] = OEMTEXT("default"); +static const OEMCHAR str_bank[] = OEMTEXT("bank"); +static const OEMCHAR str_drumset[] = OEMTEXT("drumset"); +static const OEMCHAR *cfgstr[] = {str_dir, str_source, str_default, str_bank, str_drumset}; -static const char str_amp[] = "amp"; -static const char str_keep[] = "keep"; -static const char str_note[] = "note"; -static const char str_pan[] = "pan"; -static const char str_strip[] = "strip"; -static const char str_left[] = "left"; -static const char str_center[] = "center"; -static const char str_right[] = "right"; -static const char str_env[] = "env"; -static const char str_loop[] = "loop"; -static const char str_tail[] = "tail"; -static const char file_timiditycfg[] = "timidity.cfg"; +static const OEMCHAR str_amp[] = OEMTEXT("amp"); +static const OEMCHAR str_keep[] = OEMTEXT("keep"); +static const OEMCHAR str_note[] = OEMTEXT("note"); +static const OEMCHAR str_pan[] = OEMTEXT("pan"); +static const OEMCHAR str_strip[] = OEMTEXT("strip"); +static const OEMCHAR str_left[] = OEMTEXT("left"); +static const OEMCHAR str_center[] = OEMTEXT("center"); +static const OEMCHAR str_right[] = OEMTEXT("right"); +static const OEMCHAR str_env[] = OEMTEXT("env"); +static const OEMCHAR str_loop[] = OEMTEXT("loop"); +static const OEMCHAR str_tail[] = OEMTEXT("tail"); +static const OEMCHAR file_timiditycfg[] = OEMTEXT("timidity.cfg"); +static const OEMCHAR str_basedir[] = OEMTEXT("${basedir}"); -static void pathadd(MIDIMOD mod, const char *path) { +static void VERMOUTHCL pathadd(MIDIMOD mod, const OEMCHAR *path) { _PATHLIST pl; PATHLIST p; @@ -46,16 +50,20 @@ static void pathadd(MIDIMOD mod, const c ZeroMemory(&pl, sizeof(pl)); if (path) { pl.path[0] = '\0'; - file_catname(pl.path, path, sizeof(pl.path)); // separator change! + // separator change! + file_catname(pl.path, path, NELEMENTS(pl.path)); if (path[0]) { - file_setseparator(pl.path, sizeof(pl.path)); +#if defined(SUPPORT_ARC) + if (milstr_chr(pl.path, '#') == NULL) +#endif + file_setseparator(pl.path, NELEMENTS(pl.path)); } } pl.next = mod->pathlist; p = pl.next; while(p) { - if (!strcmp(p->path, pl.path)) { + if (!file_cmpname(p->path, pl.path)) { return; } p = p->next; @@ -66,12 +74,27 @@ static void pathadd(MIDIMOD mod, const c } } -static int cfggetarg(char *str, char *arg[], int maxarg) { +static void VERMOUTHCL pathaddex(MIDIMOD mod, const OEMCHAR *path) { + + OEMCHAR _path[MAX_PATH]; + + if (milstr_memcmp(path, str_basedir)) { + pathadd(mod, path); + } + else { + file_cpyname(_path, file_getcd(str_null), NELEMENTS(_path)); + file_cutseparator(_path); + file_catname(_path, path + 10, NELEMENTS(_path)); + pathadd(mod, _path); + } +} + +static int VERMOUTHCL cfggetarg(OEMCHAR *str, OEMCHAR *arg[], int maxarg) { int ret; BOOL quot; - char *p; - BYTE c; + OEMCHAR *p; + OEMCHAR c; ret = 0; while(maxarg--) { @@ -81,7 +104,7 @@ static int cfggetarg(char *str, char *ar if ((c == 0) || (c == 0x23)) { goto cga_done; } - if (c > 0x20) { + if ((c < 0) || (c > 0x20)) { break; } str++; @@ -104,7 +127,7 @@ static int cfggetarg(char *str, char *ar *p = '\0'; goto cga_done; } - else if (c > 0x20) { + else if ((c < 0) || (c > 0x20)) { *p++ = c; } else { @@ -118,9 +141,9 @@ cga_done: return(ret); } -static char *seachr(char *str, char sepa) { +static OEMCHAR *VERMOUTHCL seachr(const OEMCHAR *str, OEMCHAR sepa) { - char c; + OEMCHAR c; while(1) { c = *str; @@ -128,7 +151,7 @@ static char *seachr(char *str, char sepa break; } if (c == sepa) { - return(str); + return((OEMCHAR *)str); } str++; } @@ -140,7 +163,7 @@ enum { VAL_SIGN = 2 }; -static BOOL cfggetval(const char *str, int *val) { +static BRESULT VERMOUTHCL cfggetval(const OEMCHAR *str, int *val) { int ret; int flag; @@ -185,15 +208,16 @@ static BOOL cfggetval(const char *str, i // ---- -static void settone(MIDIMOD mod, int bank, int argc, char *argv[]) { +static void VERMOUTHCL settone(MIDIMOD mod, int bank, int argc, + OEMCHAR *argv[]) { int val; TONECFG tone; - char *name; + OEMCHAR *name; int i; - char *key; - char *data; - BYTE flag; + OEMCHAR *key; + OEMCHAR *data; + UINT8 flag; if ((bank < 0) || (bank >= (MIDI_BANKS * 2)) || (argc < 2) || (cfggetval(argv[0], &val) != SUCCESS) || (val < 0) || (val >= 128)) { @@ -211,7 +235,7 @@ static void settone(MIDIMOD mod, int ban tone += val; name = tone->name; if (name == NULL) { - name = (char *)listarray_append(mod->namelist, NULL); + name = (OEMCHAR *)listarray_append(mod->namelist, NULL); tone->name = name; } if (name) { @@ -227,7 +251,7 @@ static void settone(MIDIMOD mod, int ban } else { // for drums flag |= TONECFG_NOLOOP | TONECFG_NOENV; - tone->note = (BYTE)val; + tone->note = (UINT8)val; } for (i=2; i= 0) && (val < 128)) { - tone->note = (BYTE)val; + tone->note = (UINT8)val; } } else if (!milstr_cmp(key, str_pan)) { @@ -288,7 +312,7 @@ static void settone(MIDIMOD mod, int ban else { continue; } - tone->pan = (BYTE)val; + tone->pan = (UINT8)val; } else if (!milstr_cmp(key, str_strip)) { if (!milstr_cmp(data, str_env)) { @@ -309,8 +333,8 @@ static void settone(MIDIMOD mod, int ban // ---- -BOOL cfgfile_getfile(MIDIMOD mod, const char *filename, - char *path, int size) { +BRESULT VERMOUTHCL midimod_getfile(MIDIMOD mod, const OEMCHAR *filename, + OEMCHAR *path, int size) { PATHLIST p; short attr; @@ -323,7 +347,11 @@ BOOL cfgfile_getfile(MIDIMOD mod, const while(p) { file_cpyname(path, p->path, size); file_catname(path, filename, size); +#if defined(SUPPORT_ARC) + attr = arcex_attr(path); +#else attr = file_attr(path); +#endif if (attr != -1) { return(SUCCESS); } @@ -334,21 +362,22 @@ fpgf_exit: return(FAILURE); } -BOOL cfgfile_load(MIDIMOD mod, const char *filename, int depth) { +static BRESULT VERMOUTHCL cfgfile_load(MIDIMOD mod, const OEMCHAR *filename, + int depth) { TEXTFILEH tfh; - char buf[1024]; + OEMCHAR buf[1024]; int bank; int i; int argc; - char *argv[16]; + OEMCHAR *argv[16]; int val; UINT cfg; bank = -1; if ((depth >= 16) || - (cfgfile_getfile(mod, filename, buf, sizeof(buf)) != SUCCESS)) { + (midimod_getfile(mod, filename, buf, NELEMENTS(buf)) != SUCCESS)) { goto cfl_err; } // TRACEOUT(("open: %s", buf)); @@ -356,13 +385,13 @@ BOOL cfgfile_load(MIDIMOD mod, const cha if (tfh == NULL) { goto cfl_err; } - while(textfile_read(tfh, buf, sizeof(buf)) == SUCCESS) { - argc = cfggetarg(buf, argv, sizeof(argv)/sizeof(char *)); + while(textfile_read(tfh, buf, NELEMENTS(buf)) == SUCCESS) { + argc = cfggetarg(buf, argv, NELEMENTS(argv)); if (argc < 2) { continue; } cfg = 0; - while(cfg < (sizeof(cfgstr)/sizeof(char *))) { + while(cfg < NELEMENTS(cfgstr)) { if (!milstr_cmp(argv[0], cfgstr[cfg])) { break; } @@ -371,7 +400,7 @@ BOOL cfgfile_load(MIDIMOD mod, const cha switch(cfg) { case CFG_DIR: for (i=1; itone[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); @@ -445,39 +474,66 @@ MIDIMOD midimod_create(UINT samprate) { if (r != SUCCESS) { goto mmcre_err2; } + midimod_lock(ret); return(ret); mmcre_err2: + listarray_destroy(ret->namelist); + listarray_destroy(ret->pathtbl); _MFREE(ret); mmcre_err1: return(NULL); } -void midimod_destroy(MIDIMOD hdl) { +void VERMOUTHCL midimod_lock(MIDIMOD hdl) { + + hdl->lockcount++; +} + +void VERMOUTHCL midimod_unlock(MIDIMOD hdl) { UINT r; TONECFG 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); +} + +VEXTERN void VEXPORT midimod_destroy(MIDIMOD hdl) { + 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); - } - } - listarray_destroy(hdl->namelist); - listarray_destroy(hdl->pathtbl); - _MFREE(hdl); + midimod_unlock(hdl); } } -void midimod_loadprogram(MIDIMOD hdl, UINT num) { +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) { UINT bank; @@ -490,7 +546,7 @@ void midimod_loadprogram(MIDIMOD hdl, UI } } -void midimod_loadrhythm(MIDIMOD hdl, UINT num) { +VEXTERN void VEXPORT midimod_loadrhythm(MIDIMOD hdl, UINT num) { UINT bank; @@ -503,7 +559,7 @@ void midimod_loadrhythm(MIDIMOD hdl, UIN } } -void midimod_loadgm(MIDIMOD hdl) { +VEXTERN void VEXPORT midimod_loadgm(MIDIMOD hdl) { if (hdl) { inst_bankload(hdl, 0); @@ -511,7 +567,7 @@ void midimod_loadgm(MIDIMOD hdl) { } } -void midimod_loadall(MIDIMOD hdl) { +VEXTERN void VEXPORT midimod_loadall(MIDIMOD hdl) { UINT b; @@ -522,3 +578,22 @@ void midimod_loadall(MIDIMOD hdl) { } } + +VEXTERN void VEXPORT midimod_loadallex(MIDIMOD hdl, FNMIDIOUTLAEXCB cb, void *userdata) { + + MIDIOUTLAEXPARAM param; + UINT b; + + if (hdl) { + ZeroMemory(¶m, sizeof(param)); + param.userdata = userdata; + for (b=0; b<(MIDI_BANKS*2); b++) { + param.totaltones += inst_gettones(hdl, b); + } + for (b=0; b<(MIDI_BANKS*2); b++) { + param.bank = b; + inst_bankloadex(hdl, b, cb, ¶m); + } + } +} +