diff -urN midi_prog-/Makefile midi_prog/Makefile --- midi_prog-/Makefile Mon Apr 28 22:30:00 2014 +++ midi_prog/Makefile Wed Mar 25 00:00:02 2015 @@ -1,6 +1,6 @@ CC = gcc LIB = -lm -lpthread -L../cui -lcui -TARG = prog39 +TARG = prog40 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-/main.c midi_prog/main.c --- midi_prog-/main.c Thu Apr 24 23:00:00 2014 +++ midi_prog/main.c Wed Mar 25 00:00:02 2015 @@ -76,6 +76,7 @@ double tempo_sec; pthread_t pth; + tone_init(); out_init(&otr, ac, av); note_buf_init(); stat_buf_init(); diff -urN midi_prog-/tone.c midi_prog/tone.c --- midi_prog-/tone.c Fri Apr 25 22:00:00 2014 +++ midi_prog/tone.c Wed Mar 25 00:00:02 2015 @@ -4,7 +4,8 @@ #include "stat.h" static struct tone_rec tone_inf[] = { - { /* strings */ + { + "strings", { WAVE_SAW, WAVE_SAW, 12, 0.5, OFF }, { LPF, 3000, 1.5 }, { OFF, }, { 0.15, 0.5, 0.8, 0.5 }, @@ -12,7 +13,8 @@ { OFF, 12, OFF, OFF }, { WAVE_SIN, 4, 0.3 }, { OFF, OFF, OFF, OFF }, { OFF, }, ON, - },{ /* bass */ + },{ + "bass", { WAVE_SAW, WAVE_SQUARE, OFF, 0.5, OFF }, { LPF, 1000, 1.5 }, { OFF, }, { 0.05, 0.2, 0.4, 0.2 }, @@ -20,7 +22,8 @@ { OFF, 60, OFF, OFF }, { WAVE_SIN, 1.5, 0.2 }, { OFF, OFF, OFF, OFF }, { OFF, }, ON, - },{ /* lead */ + },{ + "lead", { WAVE_SQUARE, WAVE_SQUARE, 10, 0.5, OFF }, { LPF, 2000, 4 }, { OFF, }, { 0.01, 0.2, 0.8, 0.3 }, @@ -28,7 +31,8 @@ { OFF, 1, 5, OFF }, { WAVE_SIN, 4, 0.3 }, { OFF, OFF, OFF, OFF }, { ON, 0.2, 0.4}, OFF, - },{ /* SIN */ + },{ + "SIN", { WAVE_SIN, WAVE_SIN, OFF, 0, OFF }, { LPF, 20000, 0.8 }, { OFF, }, { 0, 0.3, 0.2, 0.3 }, @@ -36,9 +40,12 @@ { 25, OFF, OFF, OFF }, { WAVE_SIN, 6, 0.3 }, { OFF, OFF, OFF, OFF }, { OFF, }, OFF, + },{ + NULL, } }, drum_tone_inf[] = { - { /* bass */ + { + "bass drum", { WAVE_SIN, WAVE_NOISE, OFF, 0.4, OFF }, { LPF, 400, 1 }, { OFF, }, { 0.01, 0.18, 0, 0.18 }, @@ -46,7 +53,8 @@ { 100, OFF, 30, OFF }, { WAVE_NOISE, 0, 0.5 }, { OFF, OFF, OFF, OFF }, { OFF, }, OFF, - },{ /* snare */ + },{ + "snare", { WAVE_SQUARE, WAVE_NOISE, OFF, 0.8, ON }, { LPF, 1500, 1.7 }, { OFF, }, { 0, 0.4, 0.3, 0.4 }, @@ -54,7 +62,8 @@ { OFF, OFF, OFF, OFF }, {}, { OFF, OFF, OFF, OFF }, { OFF, }, OFF, - },{ /* tom */ + },{ + "tom", { WAVE_SQUARE, WAVE_NOISE, OFF, 0.5, ON }, { LPF, 800, 2.5 }, { OFF, }, { 0, 0.03, 0.1, 0.4 }, @@ -62,7 +71,8 @@ { OFF, OFF, OFF, OFF }, {}, { 200, OFF, 1200, OFF }, { OFF, }, OFF, - },{ /* hi-hat close */ + },{ + "hi-hat close", { WAVE_SQUARE, WAVE_SQUARE, 700, 0.9, ON }, { LPF, 16000, 2 }, { OFF, }, { 0, 0.15, 0, 0.15 }, @@ -70,7 +80,8 @@ { OFF, OFF, OFF, OFF }, {}, { OFF, OFF, OFF, OFF }, { OFF, }, OFF, - },{ /* hi-hat open */ + },{ + "hi-hat open", { WAVE_SQUARE, WAVE_SQUARE, 700, 0.9, ON }, { LPF, 16000, 2 }, { OFF, }, { 0, 0, 1, 0.35 }, @@ -78,7 +89,8 @@ { OFF, OFF, OFF, OFF }, {}, { OFF, OFF, OFF, OFF }, { OFF, }, OFF, - },{ /* cymbal */ + },{ + "cymbal", { WAVE_NOISE, WAVE_SQUARE, OFF, 0.8, ON }, { LPF, 4000, 2 }, { OFF, }, { 0, 0.01, 0.2, 0.8 }, @@ -86,7 +98,8 @@ { OFF, OFF, OFF, OFF }, {}, { OFF, OFF, 600, OFF }, { OFF, }, OFF, - },{ /* side stick */ + },{ + "side stick", { WAVE_NOISE, WAVE_SQUARE, OFF, 0.2, OFF }, { LPF, 1700, 3 }, { OFF, }, { 0, 0.012, 0.1, 0.7 }, @@ -94,6 +107,8 @@ { OFF, OFF, OFF, OFF }, {}, { OFF, OFF, OFF, OFF }, { OFF, }, OFF, + },{ + NULL, } }; @@ -106,89 +121,116 @@ { PROG_DRUM, 36, /* bass drum1 */ (struct tone_compo_rec []){ - { &drum_tone_inf[0], 28, 1.0 }, { NULL, } + { "bass drum", 28, 1.0, }, { NULL, } } },{ PROG_DRUM, 37, /* side stick */ (struct tone_compo_rec []){ - { &drum_tone_inf[6], 110, 1.0 }, { NULL, } + { "side stick", 110, 1.0 }, { NULL, } } },{ PROG_DRUM, 40, /* electric snare */ (struct tone_compo_rec []){ - { &drum_tone_inf[1], 69, 1.0 }, { NULL, } + { "snare", 69, 1.0 }, { NULL, } } },{ PROG_DRUM, 41, /* low floor tom */ (struct tone_compo_rec []){ - { &drum_tone_inf[2], 50, 1.0 }, { NULL, } + { "tom", 50, 1.0 }, { NULL, } } },{ PROG_DRUM, 42, /* closed hi-hat */ (struct tone_compo_rec []){ - { &drum_tone_inf[3], 115 + 8, 1.0 }, { NULL, } + { "hi-hat close", 115 + 8, 1.0 }, { NULL, } } },{ PROG_DRUM, 46, /* open hi-hat */ (struct tone_compo_rec []){ - { &drum_tone_inf[4], 115 + 8, 1.0 }, { NULL, } + { "hi-hat open", 115 + 8, 1.0 }, { NULL, } } },{ PROG_DRUM, 49, /* crash cymbal 1 */ (struct tone_compo_rec []){ - { &drum_tone_inf[5], 75, 1.0 }, { NULL, } + { "cymbal", 75, 1.0 }, { NULL, } } },{ PROG_DRUM, 57, /* crash cymbal 2 */ (struct tone_compo_rec []){ - { &drum_tone_inf[5], 85, 1.0 }, + { "cymbal", 85, 1.0 }, { NULL, } } },{ 48, -1, /* timpani */ (struct tone_compo_rec []){ - { &tone_inf[0], -1, 1.0 }, { NULL, } + { "strings", -1, 1.0 }, { NULL, } } },{ 50, -1, /* strings ensamble 2 */ (struct tone_compo_rec []){ - { &tone_inf[2], -1, 1.0 }, /* test */ - { &tone_inf[0], -1, 1.0 }, { NULL, } + { "lead", -1, 1.0 }, /* test */ + { "strings", -1, 1.0 }, { NULL, } } },{ 35, -1, /* electric bass (pick) */ (struct tone_compo_rec []){ - { &tone_inf[1], -1, 1.0 }, { NULL, } + { "bass", -1, 1.0 }, { NULL, } } },{ 79, -1, /* whistle */ (struct tone_compo_rec []){ - { &tone_inf[2], -1, 1.0 }, { NULL, } + { "lead", -1, 1.0 }, { NULL, } } },{ 81, -1, /* lead 1 (square) */ (struct tone_compo_rec []){ - { &tone_inf[2], -1, 1.0 }, { NULL, } + { "lead", -1, 1.0 }, { NULL, } } },{ 87, -1, /* lead 7 (fifths) */ (struct tone_compo_rec []){ - { &tone_inf[2], -1, 1.0 }, { NULL, } + { "lead", -1, 1.0 }, { NULL, } } },{ 24, -1, /* tango accordion */ (struct tone_compo_rec []){ - { &tone_inf[3], -1, 1.0 }, { NULL, } + { "SIN", -1, 1.0 }, { NULL, } } },{ 67, -1, /* tenor sax */ (struct tone_compo_rec []){ - { &tone_inf[3], -1, 1.0 }, { NULL, } + { "SIN", -1, 1.0 }, { NULL, } } },{ -1, /* tail */ } }; + +static struct tone_rec * +name_search(char *name) +{ + struct tone_rec *lst[] = { tone_inf, drum_tone_inf, NULL }, + **p, *tone; + + for(p=lst; *p; p++){ + for(tone=*p; tone->name; tone++){ + if(strcmp(name, tone->name) == 0) return tone; + } + } + return NULL; /* not found */ +} + +void +tone_init(void) +{ + struct tone_compo_rec *tone_compo; + 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); + } + } +} #define CH_PROG(ch) ( (ch) == 9 ? 0 : ch_inf[ch].prog ) diff -urN midi_prog-/tone.h midi_prog/tone.h --- midi_prog-/tone.h Sat Jan 25 00:00:00 2014 +++ midi_prog/tone.h Wed Mar 25 00:00:02 2015 @@ -9,6 +9,7 @@ #include "delay.h" struct tone_rec{ + char *name; struct vco_rec vco; struct filter_rec fl1, fl2; struct env_rec env; @@ -21,11 +22,13 @@ }; struct tone_compo_rec{ - struct tone_rec *tone; + char *name; int note; /* -1 : event note */ double rate; + struct tone_rec *tone; }; +void tone_init(void); struct tone_compo_rec *tone_compo_get(int ch, int note, int *ret_n); double tone_out(struct stat_rec *stat, double freq, double env_v);