diff -urN midi_prog-/Makefile midi_prog/Makefile --- midi_prog-/Makefile Tue Mar 31 02:00:00 2015 +++ midi_prog/Makefile Wed Apr 1 02:00:00 2015 @@ -1,6 +1,6 @@ CC = gcc LIB = -lm -lpthread -L../cui -lcui -TARG = prog48 +TARG = prog49 OBJS = main.o vcf.o ch.o delay.o stat.o note.o env.o tone.o filter.o lfo.o modu.o vco.o wave.o out.o rd.o util.o OBJS += cui_tone.o CFLAGS += -Wall -I.. diff -urN midi_prog-/tone.c midi_prog/tone.c --- midi_prog-/tone.c Tue Mar 31 02:00:00 2015 +++ midi_prog/tone.c Wed Apr 1 02:00:00 2015 @@ -41,10 +41,6 @@ { OFF, OFF, OFF, OFF }, { OFF, }, OFF, },{ - NULL, - } -}, drum_tone_inf[] = { - { "bass drum", { WAVE_SIN, WAVE_NOISE, OFF, 0.4, OFF }, { LPF, 400, 1 }, { OFF, }, @@ -294,32 +290,121 @@ } }; +struct name_lst{ + char *name; + int offset; +}; + +static struct{ + int n; + struct name_lst *lst; + int area_sz; + char *area; +} name_inf; + +struct compo_lst{ + struct tone_compo_rec *tone_compo; + int idx; +}; + +static struct{ + int n; + struct compo_lst *lst; + int arr_n; + struct tone_compo_rec *arr; +} compo_inf; + static struct tone_rec * name_search(char *name) { - struct tone_rec *lst[] = { tone_inf, drum_tone_inf, NULL }, - **p, *tone; + struct tone_rec *tone; - for(p=lst; *p; p++){ - for(tone=*p; tone->name; tone++){ - if(strcmp(name, tone->name) == 0) return tone; - } + for(tone=tone_inf; tone->name; tone++){ + if(strcmp(name, tone->name) == 0) return tone; } fprintf(stderr, "not found '%s'\n", name); return NULL; /* not found */ } +static void +name_inf_setup(void) +{ + struct tone_rec *tone; + int i, offset; + + name_inf.n = 0; + name_inf.area_sz = 0; + for(tone=tone_inf; tone->name; tone++){ + name_inf.n++; + name_inf.area_sz += strlen(tone->name) + 1; + } + if((name_inf.lst = malloc(sizeof(struct name_lst) * name_inf.n)) == NULL){ + fprintf(stderr, "No mem"); + exit(1); + } + if((name_inf.area = malloc(name_inf.area_sz)) == NULL){ + fprintf(stderr, "No mem"); + exit(1); + } + offset = 0; + for(tone=tone_inf, i=0; tone->name; tone++, i++){ + name_inf.lst[i].name = tone->name; + name_inf.lst[i].offset = offset; + strcpy(name_inf.area + offset, tone->name); + offset += strlen(tone->name) + 1; + } +} + +static void +compo_inf_setup(void) +{ + struct tone_compo_rec *tone_compo; + int i, idx; + + compo_inf.n = 0; + compo_inf.arr_n = 0; + for(i=0; tones_lst[i].prog >= 0; i++){ + compo_inf.n++; + for(tone_compo=tones_lst[i].tone_compo; tone_compo->name; tone_compo++){ + compo_inf.arr_n++; + } + compo_inf.arr_n++; + } + if((compo_inf.lst = malloc(sizeof(struct compo_lst) * compo_inf.n)) == NULL){ + fprintf(stderr, "No mem"); + exit(1); + } + if((compo_inf.arr = malloc(sizeof(struct tone_compo_rec) * compo_inf.arr_n)) == NULL){ + fprintf(stderr, "No mem"); + exit(1); + } + idx = 0; + for(i=0; tones_lst[i].prog >= 0; i++){ + compo_inf.lst[i].tone_compo = tone_compo = tones_lst[i].tone_compo; + compo_inf.lst[i].idx = idx; + for(; tone_compo->name; tone_compo++){ + memcpy(&compo_inf.arr[idx++], tone_compo, sizeof(*tone_compo)); + } + memcpy(&compo_inf.arr[idx++], tone_compo, sizeof(*tone_compo)); + } +} + void tone_init(void) { struct tone_compo_rec *tone_compo; + struct tone_rec *tone; int i; for(i=0; tones_lst[i].prog >= 0; i++){ for(tone_compo=tones_lst[i].tone_compo; tone_compo->name; tone_compo++){ - tone_compo->tone = name_search(tone_compo->name); + tone_compo->tone = tone = name_search(tone_compo->name); + if(tone) tone_compo->name = tone->name; } } + + name_inf_setup(); + compo_inf_setup(); } #define CH_PROG(ch) ( (ch) == 9 ? 0 : ch_inf[ch].prog )