| version 1.11, 2006/12/16 22:23:24 | version 1.13, 2011/02/04 00:39:34 | 
| Line 1 | Line 1 | 
| #include        "compiler.h" | #include        "compiler.h" | 
| #include        "strres.h" | #include        "strres.h" | 
| #include        "dosio.h" | #include        "dosio.h" | 
| #include        "textfile.h" | #include        "textfile.h" | 
| #include        "midiout.h" | #include        "midiout.h" | 
| #if defined(SUPPORT_ARC) | #if defined(SUPPORT_ARC) | 
| #include        "arc.h" | #include        "arc.h" | 
| #endif | #endif | 
|  |  | 
|  |  | 
| #define CFG_MAXAMP              400 | #define CFG_MAXAMP              400 | 
| #define MAX_NAME                64 | #define MAX_NAME                64 | 
|  |  | 
| enum { | enum { | 
| CFG_DIR          = 0, | CFG_DIR          = 0, | 
| CFG_SOURCE, | CFG_SOURCE, | 
| CFG_DEFAULT, | CFG_DEFAULT, | 
| CFG_BANK, | CFG_BANK, | 
| CFG_DRUM | CFG_DRUM | 
| }; | }; | 
|  |  | 
| static const OEMCHAR str_dir[] = OEMTEXT("dir"); | static const OEMCHAR str_dir[] = OEMTEXT("dir"); | 
| static const OEMCHAR str_source[] = OEMTEXT("source"); | static const OEMCHAR str_source[] = OEMTEXT("source"); | 
| static const OEMCHAR str_default[] = OEMTEXT("default"); | static const OEMCHAR str_default[] = OEMTEXT("default"); | 
| static const OEMCHAR str_bank[] = OEMTEXT("bank"); | static const OEMCHAR str_bank[] = OEMTEXT("bank"); | 
| static const OEMCHAR str_drumset[] = OEMTEXT("drumset"); | static const OEMCHAR str_drumset[] = OEMTEXT("drumset"); | 
| static const OEMCHAR *cfgstr[] = {str_dir, str_source, str_default, | static const OEMCHAR *cfgstr[] = {str_dir, str_source, str_default, | 
| str_bank, str_drumset}; | str_bank, str_drumset}; | 
|  |  | 
| static const OEMCHAR str_amp[] = OEMTEXT("amp"); | static const OEMCHAR str_amp[] = OEMTEXT("amp"); | 
| static const OEMCHAR str_keep[] = OEMTEXT("keep"); | static const OEMCHAR str_keep[] = OEMTEXT("keep"); | 
| static const OEMCHAR str_note[] = OEMTEXT("note"); | static const OEMCHAR str_note[] = OEMTEXT("note"); | 
| static const OEMCHAR str_pan[] = OEMTEXT("pan"); | static const OEMCHAR str_pan[] = OEMTEXT("pan"); | 
| static const OEMCHAR str_strip[] = OEMTEXT("strip"); | static const OEMCHAR str_strip[] = OEMTEXT("strip"); | 
| static const OEMCHAR str_left[] = OEMTEXT("left"); | static const OEMCHAR str_left[] = OEMTEXT("left"); | 
| static const OEMCHAR str_center[] = OEMTEXT("center"); | static const OEMCHAR str_center[] = OEMTEXT("center"); | 
| static const OEMCHAR str_right[] = OEMTEXT("right"); | static const OEMCHAR str_right[] = OEMTEXT("right"); | 
| static const OEMCHAR str_env[] = OEMTEXT("env"); | static const OEMCHAR str_env[] = OEMTEXT("env"); | 
| static const OEMCHAR str_loop[] = OEMTEXT("loop"); | static const OEMCHAR str_loop[] = OEMTEXT("loop"); | 
| static const OEMCHAR str_tail[] = OEMTEXT("tail"); | static const OEMCHAR str_tail[] = OEMTEXT("tail"); | 
| static const OEMCHAR file_timiditycfg[] = OEMTEXT("timidity.cfg"); | static const OEMCHAR file_timiditycfg[] = OEMTEXT("timidity.cfg"); | 
| static const OEMCHAR str_basedir[] = OEMTEXT("${basedir}"); | static const OEMCHAR str_basedir[] = OEMTEXT("${basedir}"); | 
|  |  | 
|  |  | 
| static void VERMOUTHCL pathadd(MIDIMOD mod, const OEMCHAR *path) { | static void VERMOUTHCL pathadd(MIDIMOD mod, const OEMCHAR *path) { | 
|  |  | 
| _PATHLIST       pl; | _PATHLIST       pl; | 
| PATHLIST        p; | PATHLIST        p; | 
|  |  | 
| ZeroMemory(&pl, sizeof(pl)); | ZeroMemory(&pl, sizeof(pl)); | 
| if (path) { | if (path) { | 
| pl.path[0] = '\0'; | pl.path[0] = '\0'; | 
| // separator change! | // separator change! | 
| file_catname(pl.path, path, NELEMENTS(pl.path)); | file_catname(pl.path, path, NELEMENTS(pl.path)); | 
| if (path[0]) { | if (path[0]) { | 
| #if defined(SUPPORT_ARC) | #if defined(SUPPORT_ARC) | 
| if (milstr_chr(pl.path, '#') == NULL) | if (milstr_chr(pl.path, '#') == NULL) | 
| #endif | #endif | 
| file_setseparator(pl.path, NELEMENTS(pl.path)); | file_setseparator(pl.path, NELEMENTS(pl.path)); | 
| } | } | 
| } | } | 
|  |  | 
| pl.next = mod->pathlist; | pl.next = mod->pathlist; | 
| p = pl.next; | p = pl.next; | 
| while(p) { | while(p) { | 
| if (!file_cmpname(p->path, pl.path)) { | if (!file_cmpname(p->path, pl.path)) { | 
| return; | return; | 
| } | } | 
| p = p->next; | p = p->next; | 
| } | } | 
| p = (PATHLIST)listarray_append(mod->pathtbl, &pl); | p = (PATHLIST)listarray_append(mod->pathtbl, &pl); | 
| if (p) { | if (p) { | 
| mod->pathlist = p; | mod->pathlist = p; | 
| } | } | 
| } | } | 
|  |  | 
| static void VERMOUTHCL pathaddex(MIDIMOD mod, const OEMCHAR *path) { | static void VERMOUTHCL pathaddex(MIDIMOD mod, const OEMCHAR *path) { | 
|  |  | 
| OEMCHAR _path[MAX_PATH]; | OEMCHAR _path[MAX_PATH]; | 
|  |  | 
| if (milstr_memcmp(path, str_basedir)) { | if (milstr_memcmp(path, str_basedir)) { | 
| pathadd(mod, path); | pathadd(mod, path); | 
| } | } | 
| else { | else { | 
| file_cpyname(_path, file_getcd(str_null), NELEMENTS(_path)); | file_cpyname(_path, file_getcd(str_null), NELEMENTS(_path)); | 
| file_cutseparator(_path); | file_cutseparator(_path); | 
| file_catname(_path, path + 10, NELEMENTS(_path)); | file_catname(_path, path + 10, NELEMENTS(_path)); | 
| pathadd(mod, _path); | pathadd(mod, _path); | 
| } | } | 
| } | } | 
|  |  | 
| static int VERMOUTHCL cfggetarg(OEMCHAR *str, OEMCHAR *arg[], int maxarg) { | static int VERMOUTHCL cfggetarg(OEMCHAR *str, OEMCHAR *arg[], int maxarg) { | 
|  |  | 
| int             ret; | int             ret; | 
| BOOL    quot; | BOOL    quot; | 
| OEMCHAR *p; | OEMCHAR *p; | 
| OEMCHAR c; | OEMCHAR c; | 
|  |  | 
| ret = 0; | ret = 0; | 
| while(maxarg--) { | while(maxarg--) { | 
| quot = FALSE; | quot = FALSE; | 
| while(1) { | while(1) { | 
| c = *str; | c = *str; | 
| if ((c == 0) || (c == 0x23)) { | if ((c == 0) || (c == 0x23)) { | 
| goto cga_done; | goto cga_done; | 
| } | } | 
| if ((c < 0) || (c > 0x20)) { | if ((c < 0) || (c > 0x20)) { | 
| break; | break; | 
| } | } | 
| str++; | str++; | 
| } | } | 
| arg[ret++] = str; | arg[ret++] = str; | 
| p = str; | p = str; | 
| while(1) { | while(1) { | 
| c = *str; | c = *str; | 
| if (c == 0) { | if (c == 0) { | 
| break; | break; | 
| } | } | 
| str++; | str++; | 
| if (c == 0x22) { | if (c == 0x22) { | 
| quot = !quot; | quot = !quot; | 
| } | } | 
| else if (quot) { | else if (quot) { | 
| *p++ = c; | *p++ = c; | 
| } | } | 
| else if (c == 0x23) { | else if (c == 0x23) { | 
| *p = '\0'; | *p = '\0'; | 
| goto cga_done; | goto cga_done; | 
| } | } | 
| else if ((c < 0) || (c > 0x20)) { | else if ((c < 0) || (c > 0x20)) { | 
| *p++ = c; | *p++ = c; | 
| } | } | 
| else { | else { | 
| break; | break; | 
| } | } | 
| } | } | 
| *p = '\0'; | *p = '\0'; | 
| } | } | 
|  |  | 
| cga_done: | cga_done: | 
| return(ret); | return(ret); | 
| } | } | 
|  |  | 
| static OEMCHAR *VERMOUTHCL seachr(const OEMCHAR *str, OEMCHAR sepa) { | static OEMCHAR *VERMOUTHCL seachr(const OEMCHAR *str, OEMCHAR sepa) { | 
|  |  | 
| OEMCHAR c; | OEMCHAR c; | 
|  |  | 
| while(1) { | while(1) { | 
| c = *str; | c = *str; | 
| if (c == '\0') { | if (c == '\0') { | 
| break; | break; | 
| } | } | 
| if (c == sepa) { | if (c == sepa) { | 
| return((OEMCHAR *)str); | return((OEMCHAR *)str); | 
| } | } | 
| str++; | str++; | 
| } | } | 
| return(NULL); | return(NULL); | 
| } | } | 
|  |  | 
| enum { | enum { | 
| VAL_EXIST       = 1, | VAL_EXIST       = 1, | 
| VAL_SIGN        = 2 | VAL_SIGN        = 2 | 
| }; | }; | 
|  |  | 
| static BRESULT VERMOUTHCL cfggetval(const OEMCHAR *str, int *val) { | static BRESULT VERMOUTHCL cfggetval(const OEMCHAR *str, int *val) { | 
|  |  | 
| int             ret; | int             ret; | 
| int             flag; | int             flag; | 
| int             c; | int             c; | 
|  |  | 
| ret = 0; | ret = 0; | 
| flag = 0; | flag = 0; | 
| c = *str; | c = *str; | 
| if (c == '+') { | if (c == '+') { | 
| str++; | str++; | 
| } | } | 
| else if (c == '-') { | else if (c == '-') { | 
| str++; | str++; | 
| flag |= VAL_SIGN; | flag |= VAL_SIGN; | 
| } | } | 
| while(1) { | while(1) { | 
| c = *str++; | c = *str++; | 
| c -= '0'; | c -= '0'; | 
| if ((unsigned)c < 10) { | if ((unsigned)c < 10) { | 
| ret *= 10; | ret *= 10; | 
| ret += c; | ret += c; | 
| flag |= VAL_EXIST; | flag |= VAL_EXIST; | 
| } | } | 
| else { | else { | 
| break; | break; | 
| } | } | 
| } | } | 
| if (flag & VAL_EXIST) { | if (flag & VAL_EXIST) { | 
| if (flag & VAL_SIGN) { | if (flag & VAL_SIGN) { | 
| ret *= -1; | ret *= -1; | 
| } | } | 
| if (val) { | if (val) { | 
| *val = ret; | *val = ret; | 
| } | } | 
| return(SUCCESS); | return(SUCCESS); | 
| } | } | 
| else { | else { | 
| return(FAILURE); | return(FAILURE); | 
| } | } | 
| } | } | 
|  |  | 
|  |  | 
| // ---- | // ---- | 
|  |  | 
| static void VERMOUTHCL settone(MIDIMOD mod, int bank, int argc, | static void VERMOUTHCL settone(MIDIMOD mod, int bank, int argc, | 
| OEMCHAR *argv[]) { | OEMCHAR *argv[]) { | 
|  |  | 
| int             val; | int             val; | 
| TONECFG tone; | TONECFG tone; | 
| OEMCHAR *name; | OEMCHAR *name; | 
| int             i; | int             i; | 
| OEMCHAR *key; | OEMCHAR *key; | 
| OEMCHAR *data; | OEMCHAR *data; | 
| UINT8   flag; | UINT8   flag; | 
|  |  | 
| if ((bank < 0) || (bank >= (MIDI_BANKS * 2)) || (argc < 2) || | if ((bank < 0) || (bank >= (MIDI_BANKS * 2)) || (argc < 2) || | 
| (cfggetval(argv[0], &val) != SUCCESS) || (val < 0) || (val >= 128)) { | (cfggetval(argv[0], &val) != SUCCESS) || (val < 0) || (val >= 128)) { | 
| return; | return; | 
| } | } | 
| tone = mod->tonecfg[bank]; | tone = mod->tonecfg[bank]; | 
| if (tone == NULL) { | if (tone == NULL) { | 
| tone = (TONECFG)_MALLOC(sizeof(_TONECFG) * 128, "tone cfg"); | tone = (TONECFG)_MALLOC(sizeof(_TONECFG) * 128, "tone cfg"); | 
| if (tone == NULL) { | if (tone == NULL) { | 
| return; | return; | 
| } | } | 
| mod->tonecfg[bank] = tone; | mod->tonecfg[bank] = tone; | 
| ZeroMemory(tone, sizeof(_TONECFG) * 128); | ZeroMemory(tone, sizeof(_TONECFG) * 128); | 
| } | } | 
| tone += val; | tone += val; | 
| name = tone->name; | name = tone->name; | 
| if (name == NULL) { | if (name == NULL) { | 
| name = (OEMCHAR *)listarray_append(mod->namelist, NULL); | name = (OEMCHAR *)listarray_append(mod->namelist, NULL); | 
| tone->name = name; | tone->name = name; | 
| } | } | 
| if (name) { | if (name) { | 
| name[0] = '\0'; | name[0] = '\0'; | 
| file_catname(name, argv[1], MAX_NAME);          // separator change! | file_catname(name, argv[1], MAX_NAME);          // separator change! | 
| } | } | 
| flag = TONECFG_EXIST; | flag = TONECFG_EXIST; | 
| tone->amp = TONECFG_AUTOAMP; | tone->amp = TONECFG_AUTOAMP; | 
| tone->pan = TONECFG_VARIABLE; | tone->pan = TONECFG_VARIABLE; | 
|  |  | 
| if (!(bank & 1)) {                                      // for tone | if (!(bank & 1)) {                                      // for tone | 
| tone->note = TONECFG_VARIABLE; | tone->note = TONECFG_VARIABLE; | 
| } | } | 
| else {                                                          // for drums | else {                                                          // for drums | 
| flag |= TONECFG_NOLOOP | TONECFG_NOENV; | flag |= TONECFG_NOLOOP | TONECFG_NOENV; | 
| tone->note = (UINT8)val; | tone->note = (UINT8)val; | 
| } | } | 
|  |  | 
| for (i=2; i<argc; i++) { | for (i=2; i<argc; i++) { | 
| key = argv[i]; | key = argv[i]; | 
| data = seachr(key, '='); | data = seachr(key, '='); | 
| if (data == NULL) { | if (data == NULL) { | 
| continue; | continue; | 
| } | } | 
| *data++ = '\0'; | *data++ = '\0'; | 
| if (!milstr_cmp(key, str_amp)) { | if (!milstr_cmp(key, str_amp)) { | 
| if (cfggetval(data, &val) == SUCCESS) { | if (cfggetval(data, &val) == SUCCESS) { | 
| if (val < 0) { | if (val < 0) { | 
| val = 0; | val = 0; | 
| } | } | 
| else if (val > CFG_MAXAMP) { | else if (val > CFG_MAXAMP) { | 
| val = CFG_MAXAMP; | val = CFG_MAXAMP; | 
| } | } | 
| tone->amp = val; | tone->amp = val; | 
| } | } | 
| } | } | 
| else if (!milstr_cmp(key, str_keep)) { | else if (!milstr_cmp(key, str_keep)) { | 
| if (!milstr_cmp(data, str_env)) { | if (!milstr_cmp(data, str_env)) { | 
| flag &= ~TONECFG_NOENV; | flag &= ~TONECFG_NOENV; | 
| flag |= TONECFG_KEEPENV; | flag |= TONECFG_KEEPENV; | 
| } | } | 
| else if (!milstr_cmp(data, str_loop)) { | else if (!milstr_cmp(data, str_loop)) { | 
| flag &= ~TONECFG_NOLOOP; | flag &= ~TONECFG_NOLOOP; | 
| } | } | 
| } | } | 
| else if (!milstr_cmp(key, str_note)) { | else if (!milstr_cmp(key, str_note)) { | 
| if ((cfggetval(data, &val) == SUCCESS) && | if ((cfggetval(data, &val) == SUCCESS) && | 
| (val >= 0) && (val < 128)) { | (val >= 0) && (val < 128)) { | 
| tone->note = (UINT8)val; | tone->note = (UINT8)val; | 
| } | } | 
| } | } | 
| else if (!milstr_cmp(key, str_pan)) { | else if (!milstr_cmp(key, str_pan)) { | 
| if (!milstr_cmp(data, str_left)) { | if (!milstr_cmp(data, str_left)) { | 
| val = 0; | val = 0; | 
| } | } | 
| else if (!milstr_cmp(data, str_center)) { | else if (!milstr_cmp(data, str_center)) { | 
| val = 64; | val = 64; | 
| } | } | 
| else if (!milstr_cmp(data, str_right)) { | else if (!milstr_cmp(data, str_right)) { | 
| val = 127; | val = 127; | 
| } | } | 
| else if (cfggetval(data, &val) == SUCCESS) { | else if (cfggetval(data, &val) == SUCCESS) { | 
| if (val < -100) { | if (val < -100) { | 
| val = -100; | val = -100; | 
| } | } | 
| else if (val > 100) { | else if (val > 100) { | 
| val = 100; | val = 100; | 
| } | } | 
| val = val + 100; | val = val + 100; | 
| val *= 127; | val *= 127; | 
| val += 100; | val += 100; | 
| val /= 200; | val /= 200; | 
| } | } | 
| else { | else { | 
| continue; | continue; | 
| } | } | 
| tone->pan = (UINT8)val; | tone->pan = (UINT8)val; | 
| } | } | 
| else if (!milstr_cmp(key, str_strip)) { | else if (!milstr_cmp(key, str_strip)) { | 
| if (!milstr_cmp(data, str_env)) { | if (!milstr_cmp(data, str_env)) { | 
| flag &= ~TONECFG_KEEPENV; | flag &= ~TONECFG_KEEPENV; | 
| flag |= TONECFG_NOENV; | flag |= TONECFG_NOENV; | 
| } | } | 
| else if (!milstr_cmp(data, str_loop)) { | else if (!milstr_cmp(data, str_loop)) { | 
| flag |= TONECFG_NOLOOP; | flag |= TONECFG_NOLOOP; | 
| } | } | 
| else if (!milstr_cmp(data, str_tail)) { | else if (!milstr_cmp(data, str_tail)) { | 
| flag |= TONECFG_NOTAIL; | flag |= TONECFG_NOTAIL; | 
| } | } | 
| } | } | 
| } | } | 
| tone->flag = flag; | tone->flag = flag; | 
| } | } | 
|  |  | 
|  |  | 
| // ---- | // ---- | 
|  |  | 
| BRESULT VERMOUTHCL midimod_getfile(MIDIMOD mod, const OEMCHAR *filename, | BRESULT VERMOUTHCL midimod_getfile(MIDIMOD mod, const OEMCHAR *filename, | 
| OEMCHAR *path, int size) { | OEMCHAR *path, int size) { | 
|  |  | 
| PATHLIST        p; | PATHLIST        p; | 
| short           attr; | short           attr; | 
|  |  | 
| if ((filename == NULL) || (filename[0] == '\0') || | if ((filename == NULL) || (filename[0] == '\0') || | 
| (path == NULL) || (size == 0)) { | (path == NULL) || (size == 0)) { | 
| goto fpgf_exit; | goto fpgf_exit; | 
| } | } | 
| p = mod->pathlist; | p = mod->pathlist; | 
| while(p) { | while(p) { | 
| file_cpyname(path, p->path, size); | file_cpyname(path, p->path, size); | 
| file_catname(path, filename, size); | file_catname(path, filename, size); | 
| #if defined(SUPPORT_ARC) | #if defined(SUPPORT_ARC) | 
| attr = arcex_attr(path); | attr = arcex_attr(path); | 
| #else | #else | 
| attr = file_attr(path); | attr = file_attr(path); | 
| #endif | #endif | 
| if (attr != -1) { | if (attr != -1) { | 
| return(SUCCESS); | return(SUCCESS); | 
| } | } | 
| p = p->next; | p = p->next; | 
| } | } | 
|  |  | 
| fpgf_exit: | fpgf_exit: | 
| return(FAILURE); | return(FAILURE); | 
| } | } | 
|  |  | 
| static BRESULT VERMOUTHCL cfgfile_load(MIDIMOD mod, const OEMCHAR *filename, | static BRESULT VERMOUTHCL cfgfile_load(MIDIMOD mod, const OEMCHAR *filename, | 
| int depth) { | int depth) { | 
|  |  | 
| TEXTFILEH       tfh; | TEXTFILEH       tfh; | 
| OEMCHAR         buf[1024]; | OEMCHAR         buf[1024]; | 
| int                     bank; | int                     bank; | 
| int                     i; | int                     i; | 
| int                     argc; | int                     argc; | 
| OEMCHAR         *argv[16]; | OEMCHAR         *argv[16]; | 
| int                     val; | int                     val; | 
| UINT            cfg; | UINT            cfg; | 
|  |  | 
| bank = -1; | bank = -1; | 
|  |  | 
| if ((depth >= 16) || | if ((depth >= 16) || | 
| (midimod_getfile(mod, filename, buf, NELEMENTS(buf)) != SUCCESS)) { | (midimod_getfile(mod, filename, buf, NELEMENTS(buf)) != SUCCESS)) { | 
| goto cfl_err; | goto cfl_err; | 
| } | } | 
| //      TRACEOUT(("open: %s", buf)); | // TRACEOUT(("open: %s", buf)); | 
| tfh = textfile_open(buf, 0x1000); | tfh = textfile_open(buf, 0x1000); | 
| if (tfh == NULL) { | if (tfh == NULL) { | 
| goto cfl_err; | goto cfl_err; | 
| } | } | 
| while(textfile_read(tfh, buf, NELEMENTS(buf)) == SUCCESS) { | while(textfile_read(tfh, buf, NELEMENTS(buf)) == SUCCESS) { | 
| argc = cfggetarg(buf, argv, NELEMENTS(argv)); | argc = cfggetarg(buf, argv, NELEMENTS(argv)); | 
| if (argc < 2) { | if (argc < 2) { | 
| continue; | continue; | 
| } | } | 
| cfg = 0; | cfg = 0; | 
| while(cfg < NELEMENTS(cfgstr)) { | while(cfg < NELEMENTS(cfgstr)) { | 
| if (!milstr_cmp(argv[0], cfgstr[cfg])) { | if (!milstr_cmp(argv[0], cfgstr[cfg])) { | 
| break; | break; | 
| } | } | 
| cfg++; | cfg++; | 
| } | } | 
| switch(cfg) { | switch(cfg) { | 
| case CFG_DIR: | case CFG_DIR: | 
| for (i=1; i<argc; i++) { | for (i=1; i<argc; i++) { | 
| pathaddex(mod, argv[i]); | pathaddex(mod, argv[i]); | 
| } | } | 
| break; | break; | 
|  |  | 
| case CFG_SOURCE: | case CFG_SOURCE: | 
| for (i=1; i<argc; i++) { | for (i=1; i<argc; i++) { | 
| depth++; | depth++; | 
| cfgfile_load(mod, argv[i], depth); | cfgfile_load(mod, argv[i], depth); | 
| depth--; | depth--; | 
| } | } | 
| break; | break; | 
|  |  | 
| case CFG_DEFAULT: | case CFG_DEFAULT: | 
| break; | break; | 
|  |  | 
| case CFG_BANK: | case CFG_BANK: | 
| case CFG_DRUM: | case CFG_DRUM: | 
| if ((cfggetval(argv[1], &val) == SUCCESS) && | if ((cfggetval(argv[1], &val) == SUCCESS) && | 
| (val >= 0) && (val < 128)) { | (val >= 0) && (val < 128)) { | 
| val <<= 1; | val <<= 1; | 
| if (cfg == CFG_DRUM) { | if (cfg == CFG_DRUM) { | 
| val++; | val++; | 
| } | } | 
| bank = val; | bank = val; | 
| } | } | 
| break; | break; | 
|  |  | 
| default: | default: | 
| settone(mod, bank, argc, argv); | settone(mod, bank, argc, argv); | 
| break; | break; | 
| } | } | 
| } | } | 
| textfile_close(tfh); | textfile_close(tfh); | 
| return(SUCCESS); | return(SUCCESS); | 
|  |  | 
| cfl_err: | cfl_err: | 
| return(FAILURE); | return(FAILURE); | 
| } | } | 
|  |  | 
|  |  | 
| // ---- | // ---- | 
|  |  | 
| VEXTERN MIDIMOD VEXPORT midimod_create(UINT samprate) { | VEXTERN MIDIMOD VEXPORT midimod_create(UINT samprate) { | 
|  |  | 
| UINT    size; | UINT    size; | 
| MIDIMOD ret; | MIDIMOD ret; | 
| BRESULT r; | BRESULT r; | 
|  |  | 
| size = sizeof(_MIDIMOD); | size = sizeof(_MIDIMOD); | 
| size += sizeof(INSTRUMENT) * 128 * 2; | size += sizeof(INSTRUMENT) * 128 * 2; | 
| size += sizeof(_TONECFG) * 128 * 2; | size += sizeof(_TONECFG) * 128 * 2; | 
| ret = (MIDIMOD)_MALLOC(size, "MIDIMOD"); | ret = (MIDIMOD)_MALLOC(size, "MIDIMOD"); | 
| if (ret == NULL) { | if (ret == NULL) { | 
| goto mmcre_err1; | goto mmcre_err1; | 
| } | } | 
| ZeroMemory(ret, size); | ZeroMemory(ret, size); | 
| ret->samprate = samprate; | ret->samprate = samprate; | 
| ret->tone[0] = (INSTRUMENT *)(ret + 1); | ret->tone[0] = (INSTRUMENT *)(ret + 1); | 
| ret->tone[1] = ret->tone[0] + 128; | ret->tone[1] = ret->tone[0] + 128; | 
| ret->tonecfg[0] = (TONECFG)(ret->tone[1] + 128); | ret->tonecfg[0] = (TONECFG)(ret->tone[1] + 128); | 
| ret->tonecfg[1] = ret->tonecfg[0] + 128; | ret->tonecfg[1] = ret->tonecfg[0] + 128; | 
| ret->pathtbl = listarray_new(sizeof(_PATHLIST), 16); | ret->pathtbl = listarray_new(sizeof(_PATHLIST), 16); | 
| pathadd(ret, NULL); | pathadd(ret, NULL); | 
| pathadd(ret, file_getcd(str_null)); | pathadd(ret, file_getcd(str_null)); | 
| ret->namelist = listarray_new(MAX_NAME, 128); | ret->namelist = listarray_new(MAX_NAME, 128); | 
| r = cfgfile_load(ret, file_timiditycfg, 0); | r = cfgfile_load(ret, file_timiditycfg, 0); | 
| #if defined(TIMIDITY_CFGFILE) | #if defined(TIMIDITY_CFGFILE) | 
| if (r != SUCCESS) { | if (r != SUCCESS) { | 
| r = cfgfile_load(ret, TIMIDITY_CFGFILE, 0); | r = cfgfile_load(ret, TIMIDITY_CFGFILE, 0); | 
| } | } | 
| #endif | #endif | 
| if (r != SUCCESS) { | if (r != SUCCESS) { | 
| goto mmcre_err2; | goto mmcre_err2; | 
| } | } | 
| midimod_lock(ret); | midimod_lock(ret); | 
| return(ret); | return(ret); | 
|  |  | 
| mmcre_err2: | mmcre_err2: | 
| listarray_destroy(ret->namelist); | listarray_destroy(ret->namelist); | 
| listarray_destroy(ret->pathtbl); | listarray_destroy(ret->pathtbl); | 
| _MFREE(ret); | _MFREE(ret); | 
|  |  | 
| mmcre_err1: | mmcre_err1: | 
| return(NULL); | return(NULL); | 
| } | } | 
|  |  | 
| void VERMOUTHCL midimod_lock(MIDIMOD mod) { | void VERMOUTHCL midimod_lock(MIDIMOD mod) { | 
|  |  | 
| mod->lockcount++; | mod->lockcount++; | 
| } | } | 
|  |  | 
| void VERMOUTHCL midimod_unlock(MIDIMOD mod) { | void VERMOUTHCL midimod_unlock(MIDIMOD mod) { | 
|  |  | 
| UINT    r; | UINT    r; | 
| TONECFG bank; | TONECFG bank; | 
|  |  | 
| if (!mod->lockcount) { | if (!mod->lockcount) { | 
| return; | return; | 
| } | } | 
| mod->lockcount--; | mod->lockcount--; | 
| if (mod->lockcount) { | if (mod->lockcount) { | 
| return; | return; | 
| } | } | 
|  |  | 
| r = 128; | r = 128; | 
| do { | do { | 
| r--; | r--; | 
| inst_bankfree(mod, r); | inst_bankfree(mod, r); | 
| } while(r > 0); | } while(r > 0); | 
| for (r=2; r<(MIDI_BANKS*2); r++) { | for (r=2; r<(MIDI_BANKS*2); r++) { | 
| bank = mod->tonecfg[r]; | bank = mod->tonecfg[r]; | 
| if (bank) { | if (bank) { | 
| _MFREE(bank); | _MFREE(bank); | 
| } | } | 
| } | } | 
| listarray_destroy(mod->namelist); | listarray_destroy(mod->namelist); | 
| listarray_destroy(mod->pathtbl); | listarray_destroy(mod->pathtbl); | 
| _MFREE(mod); | _MFREE(mod); | 
| } | } | 
|  |  | 
| VEXTERN void VEXPORT midimod_destroy(MIDIMOD mod) { | VEXTERN void VEXPORT midimod_destroy(MIDIMOD mod) { | 
|  |  | 
| if (mod) { | if (mod) { | 
| midimod_unlock(mod); | midimod_unlock(mod); | 
| } | } | 
| } | } | 
|  |  | 
| VEXTERN BRESULT VEXPORT midimod_cfgload(MIDIMOD mod, | VEXTERN BRESULT VEXPORT midimod_cfgload(MIDIMOD mod, | 
| const OEMCHAR *filename) { | const OEMCHAR *filename) { | 
|  |  | 
| return(cfgfile_load(mod, filename, 0)); | return(cfgfile_load(mod, filename, 0)); | 
| } | } | 
|  |  | 
| VEXTERN void VEXPORT midimod_loadprogram(MIDIMOD mod, UINT num) { | VEXTERN void VEXPORT midimod_loadprogram(MIDIMOD mod, UINT num) { | 
|  |  | 
| UINT    bank; | UINT    bank; | 
|  |  | 
| if (mod != NULL) { | if (mod != NULL) { | 
| bank = (num >> 8) & 0x7f; | bank = (num >> 8) & 0x7f; | 
| num &= 0x7f; | num &= 0x7f; | 
| if (inst_singleload(mod, bank << 1, num) != MIDIOUT_SUCCESS) { | if (inst_singleload(mod, bank << 1, num) != MIDIOUT_SUCCESS) { | 
| inst_singleload(mod, 0, num); | inst_singleload(mod, 0, num); | 
| } | } | 
| } | } | 
| } | } | 
|  |  | 
| VEXTERN void VEXPORT midimod_loadrhythm(MIDIMOD mod, UINT num) { | VEXTERN void VEXPORT midimod_loadrhythm(MIDIMOD mod, UINT num) { | 
|  |  | 
| UINT    bank; | UINT    bank; | 
|  |  | 
| if (mod != NULL) { | if (mod != NULL) { | 
| bank = (num >> 8) & 0x7f; | bank = (num >> 8) & 0x7f; | 
| num &= 0x7f; | num &= 0x7f; | 
| if (inst_singleload(mod, (bank << 1) + 1, num) != MIDIOUT_SUCCESS) { | if (inst_singleload(mod, (bank << 1) + 1, num) != MIDIOUT_SUCCESS) { | 
| inst_singleload(mod, 1, num); | inst_singleload(mod, 1, num); | 
| } | } | 
| } | } | 
| } | } | 
|  |  | 
| VEXTERN void VEXPORT midimod_loadgm(MIDIMOD mod) { | VEXTERN void VEXPORT midimod_loadgm(MIDIMOD mod) { | 
|  |  | 
| if (mod) { | if (mod) { | 
| inst_bankload(mod, 0); | inst_bankload(mod, 0); | 
| inst_bankload(mod, 1); | inst_bankload(mod, 1); | 
| } | } | 
| } | } | 
|  |  | 
| VEXTERN void VEXPORT midimod_loadall(MIDIMOD mod) { | VEXTERN void VEXPORT midimod_loadall(MIDIMOD mod) { | 
|  |  | 
| UINT    b; | UINT    b; | 
|  |  | 
| if (mod) { | if (mod) { | 
| for (b=0; b<(MIDI_BANKS*2); b++) { | for (b=0; b<(MIDI_BANKS*2); b++) { | 
| inst_bankload(mod, b); | inst_bankload(mod, b); | 
| } | } | 
| } | } | 
| } | } | 
|  |  | 
|  |  | 
| VEXTERN void VEXPORT midimod_loadallex(MIDIMOD mod, FNMIDIOUTLAEXCB cb, | VEXTERN int VEXPORT midimod_loadallex(MIDIMOD mod, FNMIDIOUTLAEXCB cb, | 
| void *userdata) { | void *userdata) { | 
|  |  | 
| MIDIOUTLAEXPARAM param; | int                                     result; | 
| UINT    b; | MIDIOUTLAEXPARAM        param; | 
|  | UINT                            b; | 
| if (mod) { |  | 
| ZeroMemory(¶m, sizeof(param)); | result = MIDIOUT_SUCCESS; | 
| param.userdata = userdata; | if (mod) { | 
| for (b=0; b<(MIDI_BANKS*2); b++) { | ZeroMemory(¶m, sizeof(param)); | 
| param.totaltones += inst_gettones(mod, b); | param.userdata = userdata; | 
| } | for (b=0; b<(MIDI_BANKS*2); b++) { | 
| for (b=0; b<(MIDI_BANKS*2); b++) { | param.totaltones += inst_gettones(mod, b); | 
| param.bank = b; | } | 
| inst_bankloadex(mod, b, cb, ¶m); | for (b=0; b<(MIDI_BANKS*2); b++) { | 
| } | param.bank = b; | 
| } | result = inst_bankloadex(mod, b, cb, ¶m); | 
| } | if (result != MIDIOUT_SUCCESS) | 
|  | { | 
|  | break; | 
|  | } | 
|  | } | 
|  | } | 
|  | return result; | 
|  | } | 
|  |  |