diff -urN midi_prog-/Makefile midi_prog/Makefile --- midi_prog-/Makefile Wed Apr 1 02:00:00 2015 +++ midi_prog/Makefile Wed Apr 1 03:00:00 2015 @@ -1,6 +1,6 @@ CC = gcc LIB = -lm -lpthread -L../cui -lcui -TARG = prog49 +TARG = prog50 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-/cui_tone.c midi_prog/cui_tone.c --- midi_prog-/cui_tone.c Fri Mar 27 03:00:00 2015 +++ midi_prog/cui_tone.c Wed Apr 1 03:00:00 2015 @@ -4,6 +4,7 @@ #include "cui/button.h" #include "cui/menu.h" #include "cui/num.h" +#include "cui/etext.h" #include "cui/ckbox.h" #include "cui/handler.h" #include "cui/arg.h" @@ -113,6 +114,19 @@ return TRUE; } +static int +save_hdr(cui obj, int evt, int val, void *prm) +{ + /* CUI_EVT_BUTTON */ + + cui etext = (cui)prm; + char *path = cui_etext_str_get(etext); + if(path == NULL || *path == '\0') return TRUE; + + tone_save(path); + return TRUE; +} + void * pth_func(void *arg) { @@ -125,6 +139,7 @@ cui sheet = cui_scpanel_sheet_get(root); cui ch, note, bs_ch, note_i, bs_vco, bs_filt, bs_env; cui bs_lfo_modu, bs_lfo, bs_env_modu, bs_delay; + cui save, path; char *wave_lst[] = { "sin", "saw", "square", "noise", NULL }; char *filt_lst[] = { "OFF", "LPF", "HPF", "BPF", NULL }; @@ -289,6 +304,10 @@ cui_hide(bs_ch); cui_wh_fit(bs_ch); + + save = cui_button_new(sheet, 0, CUI_CHILD_Y2, "save"); + path = cui_etext_new(sheet, CUI_CHILD_X2+2, CUI_CHILD_Y, 20, "tone_file"); + cui_wh_fit(sheet); if(w == 0) cui_w_set(root, sheet->w+2); @@ -297,6 +316,7 @@ cui_bind(ch, CUI_EVT_BUTTON, ch_note_hdr, sheet); cui_bind(note, CUI_EVT_BUTTON, ch_note_hdr, sheet); cui_bind(note_i, CUI_EVT_BUTTON, note_i_hdr, sheet); + cui_bind(save, CUI_EVT_BUTTON, save_hdr, path); cui_handler_call(ch, CUI_EVT_BUTTON, 0); diff -urN midi_prog-/tone.c midi_prog/tone.c --- midi_prog-/tone.c Wed Apr 1 02:00:00 2015 +++ midi_prog/tone.c Wed Apr 1 03:00:00 2015 @@ -466,4 +466,46 @@ return v; } +static void +save_n_data(int n, int usz, void *p, FILE *fp) +{ + if(fwrite(&n, sizeof(n), 1, fp) != 1){ + fprintf(stderr, "error write\n"); + } + if(fwrite(p, usz, n, fp) != n){ + fprintf(stderr, "error write\n"); + } +} + +void +tone_save(char *path) +{ + FILE *fp; + int sz; + + if((fp = fopen(path, "w")) == NULL){ + fprintf(stderr, "Can't open '%s'\n", path); + return; + } + + sz = sizeof(tone_inf[0]); + save_n_data(sizeof(tone_inf)/sz, sz, tone_inf, fp); + + sz = sizeof(tones_lst[0]); + save_n_data(sizeof(tones_lst)/sz, sz, tones_lst, fp); + + sz = sizeof(compo_inf.lst[0]); + save_n_data(compo_inf.n, sz, compo_inf.lst, fp); + + sz = sizeof(compo_inf.arr[0]); + save_n_data(compo_inf.arr_n, sz, compo_inf.arr, fp); + + sz = sizeof(name_inf.lst[0]); + save_n_data(name_inf.n, sz, name_inf.lst, fp); + + save_n_data(name_inf.area_sz, 1, name_inf.area, fp); + + fclose(fp); +} + /* EOF */ diff -urN midi_prog-/tone.h midi_prog/tone.h --- midi_prog-/tone.h Wed Mar 25 00:00:02 2015 +++ midi_prog/tone.h Wed Apr 1 03:00:00 2015 @@ -31,5 +31,6 @@ 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); +void tone_save(char *path); #endif