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