From db3d7283df6ba6010b4b99ebdb224dfe8d52edd7 Mon Sep 17 00:00:00 2001 From: tth Date: Sun, 3 Nov 2019 18:58:21 +0100 Subject: [PATCH] dernier commit avant travaux... --- .gitignore | 2 +- Makefile | 13 +++++ audio/playfile.c | 10 ++-- audio/t.c | 42 +++++++++----- files/Makefile | 5 +- files/ffuncs.h | 13 ----- files/samples.list | 1 + files/smpllist.c | 139 +++++++++++++++++++++++++++++++++++++++++++++ files/smpllist.h | 12 ++++ files/t.c | 118 ++++---------------------------------- main.c | 59 +++++++++++++++++++ nclooper.h | 18 ++++++ ui/ncfuncs.c | 13 ++++- ui/ncfuncs.h | 3 + ui/t.c | 20 +++++-- 15 files changed, 321 insertions(+), 147 deletions(-) create mode 100644 Makefile create mode 100644 files/smpllist.c create mode 100644 files/smpllist.h create mode 100644 main.c create mode 100644 nclooper.h diff --git a/.gitignore b/.gitignore index 36722de..030295b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,8 @@ audio/t audio/*.wav +nclooper ui/t - files/t diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ae44a08 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +CC = gcc +CCOPT = -Wall -g -DDEBUG_LEVEL=1 + +OBJS = ui/ncfuncs.o files/smpllist.o files/ffuncs.o +LIBS = -lcurses + +main.o: main.c nclooper.h Makefile + $(CC) ${CCOPT} -c $< + + +nclooper: main.o ${OBJS} Makefile + $(CC) ${CCOPT} $< ${OBJS} ${LIBS} -o $@ + diff --git a/audio/playfile.c b/audio/playfile.c index adbcaad..97b991f 100644 --- a/audio/playfile.c +++ b/audio/playfile.c @@ -47,11 +47,11 @@ if (NULL==sndf) buffer = calloc(T_BUFF_WAVES, sizeof(short)*2); -#if DEBUG_LEVEL -fprintf(stderr, "samplerate : %d\n", sfinfo.samplerate); -fprintf(stderr, "frames : %ld\n", sfinfo.frames); -fprintf(stderr, "seekable : %d\n", sfinfo.seekable); -#endif +if (verbosity) { + fprintf(stderr, "samplerate : %d\n", sfinfo.samplerate); + fprintf(stderr, "frames : %ld\n", sfinfo.frames); + fprintf(stderr, "seekable : %d\n", sfinfo.seekable); + } for (pass=0; pass %p\n", device); + +switch (k) { + case 0: + foo = blast_this_file(fname, device, 1); + fprintf(stderr, "blast file -> %d\n", foo); + break; + + case 1: + foo = play_some_stuff(device, 0); + fprintf(stderr, "play stuff -> %d\n", foo); + break; + } + +foo = close_ao_output(device); +fprintf(stderr, "AO close -> %d\n", foo); + +return 0; +} +/* --------------------------------------------------------------------- */ int main(int argc, char *argv[]) { -int foo; -ao_device *device; int opt; - while ((opt = getopt(argc, argv, "hv")) != -1) { switch(opt) { case 'h': help(0); break; @@ -38,18 +61,7 @@ while ((opt = getopt(argc, argv, "hv")) != -1) { fprintf(stderr, "argc = %d, optind = %d\n", argc, optind); #endif -device = init_ao_output(44100); -fprintf(stderr, "AO init -> %p\n", device); - -foo = play_some_stuff(device, 0); -fprintf(stderr, "play stuff -> %d\n", foo); - -foo = blast_this_file("AK14V-ORDRES.wav", device, 3); -fprintf(stderr, "blast file -> %d\n", foo); - -foo = close_ao_output(device); -fprintf(stderr, "AO close -> %d\n", foo); - +envoyer_du_son("AK14V-ORDRES.wav", 0); return 0; } diff --git a/files/Makefile b/files/Makefile index 3d9e2ee..86ba461 100644 --- a/files/Makefile +++ b/files/Makefile @@ -4,8 +4,11 @@ CCOPT = -Wall -g -DDEBUG_LEVEL=1 ffuncs.o: ffuncs.c ffuncs.h Makefile $(CC) ${CCOPT} -c $< +smpllist.o: smpllist.c smpllist.h ffuncs.h Makefile + $(CC) ${CCOPT} -c $< + LIBS = -OBJS = ffuncs.o +OBJS = ffuncs.o smpllist.o t: t.c ${OBJS} Makefile $(CC) ${CCOPT} $< ${OBJS} ${LIBS} -o $@ diff --git a/files/ffuncs.h b/files/ffuncs.h index a652c71..523bc2d 100644 --- a/files/ffuncs.h +++ b/files/ffuncs.h @@ -2,19 +2,6 @@ * various file functions */ -/* --------------------------------------------------------------------- */ - -/* two arbitrary magic number */ -#define SZ_TEXT 20 -#define SZ_PATH 400 - -typedef struct { - char key; - int flags; - char text[SZ_TEXT+1]; - char path[SZ_PATH+1]; - } SampleRef; - /* --------------------------------------------------------------------- */ diff --git a/files/samples.list b/files/samples.list index 9b3da60..27c0096 100644 --- a/files/samples.list +++ b/files/samples.list @@ -1,3 +1,4 @@ a | bla bla | ../AK14V-ORDRES.wav z |znare|znare.wav B | plop ! | ../AK14V-ORDRES.wav +c | classic | foo.wav diff --git a/files/smpllist.c b/files/smpllist.c new file mode 100644 index 0000000..65514cc --- /dev/null +++ b/files/smpllist.c @@ -0,0 +1,139 @@ + +#include +#include +#include +#include + +#include "../nclooper.h" + +#include "ffuncs.h" +#include "smpllist.h" + +/* --------------------------------------------------------------------- */ +extern int verbosity; +/* --------------------------------------------------------------------- */ +void affiche_un_sample(SampleRef *sref, int options) +{ +printf("%c %02X [%-20s] %s\n", sref->key, sref->flags, sref->text, + sref->path); +} +/* --------------------------------------------------------------------- */ + +int decode_la_ligne(char *line, SampleRef *sref) +{ +char *ptr, *cp; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( '%s' %p )\n", __func__, line, sref); +// dump(line); +#endif + +/* + * ON THE WAY TO PARSING HELL + */ +ptr = strtok(line, "|"); +if (NULL==ptr) { + fprintf(stderr, "fubarized\n"); + return -1; + } +cp = ltrim(rtrim(ptr)); +if (verbosity) fprintf(stderr, "key [%s]\n", cp); +if ( ! isalpha(*cp)) { + fprintf(stderr, "invalid key 0x%02x\n", *cp); + return -2; + } +sref->key = toupper(*cp); + +ptr = strtok(NULL, "|"); +if (NULL==ptr) { + fprintf(stderr, "line to short\n"); + return -3; + } +cp = ltrim(rtrim(ptr)); +if (verbosity) fprintf(stderr, "text [%s]\n", cp); +if (strlen(cp) > SZ_TEXT) { + fprintf(stderr, "text too long\n"); + return -4; + } +strcpy(sref->text, cp); + +ptr = strtok(NULL, "|"); +if (NULL==ptr) { + fprintf(stderr, "line to short\n"); + return -6; + } +cp = ltrim(rtrim(ptr)); +if (verbosity) fprintf(stderr, "path [%s]\n", cp); +if (strlen(ptr) > SZ_PATH) { + fprintf(stderr, "path too long\n"); + return -5; + } +strcpy(sref->path, cp); + +return 0; +} + +/* --------------------------------------------------------------------- */ +#define T_LINE 500 + +int lecture_liste_des_samples(char *fname, SampleRef *samples) +{ +FILE *fp; +char line[T_LINE+1]; +int ln; /* line number */ +int foo, bar, idx; +SampleRef sample; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( '%s' )\n", __func__, fname); +#endif + +/* + * first step : clean the current list + */ + +for (foo=0; foo<26; foo++) { + memset(samples+foo, 0, sizeof(SampleRef)); + } + + +if (NULL==(fp=fopen(fname, "r"))) { + perror(fname); + exit(1); + } + +ln = 1; +while (NULL != fgets(line, T_LINE, fp)) { + + /* degommer l'eventuel \n */ + bar = strlen(line); + if (0==bar) { + fprintf(stderr,"line %d very short\n", ln); + continue; + } + bar--; /* backspace one char */ + if ('\n' == line[bar]) line[bar]='\0'; + + memset(&sample, 0, sizeof(SampleRef)); + foo = decode_la_ligne(line, &sample); +#if DEBUG_LEVEL + fprintf(stderr, "decode la ligne -> %d\n\n", foo); +#endif + if (!foo) { + affiche_un_sample(&sample, 0); + idx = tolower(sample.key) - 'a'; + if (idx<0 || idx>25) { + /* serious bug here */ + break; + } + memcpy(samples+idx, &sample, sizeof(SampleRef)); + } + + ln++; + } + +fclose(fp); + +return -1; +} +/* --------------------------------------------------------------------- */ diff --git a/files/smpllist.h b/files/smpllist.h new file mode 100644 index 0000000..37612d4 --- /dev/null +++ b/files/smpllist.h @@ -0,0 +1,12 @@ + + +/* --------------------------------------------------------------------- */ + + +void affiche_un_sample(SampleRef *sref, int options); + +int decode_la_ligne(char *line, SampleRef *sref); +int lecture_liste_des_samples(char *fname, SampleRef *array); + + + diff --git a/files/t.c b/files/t.c index 5d62d7b..daf4aba 100644 --- a/files/t.c +++ b/files/t.c @@ -8,116 +8,16 @@ #include #include +#include "../nclooper.h" +#include "smpllist.h" #include "ffuncs.h" /* --------------------------------------------------------------------- */ int verbosity; -/* --------------------------------------------------------------------- */ -void affiche_un_sample(SampleRef *sref) -{ -printf("%c %02X [%-20s] %s\n", sref->key, sref->flags, sref->text, - sref->path); -} -/* --------------------------------------------------------------------- */ -static int decode_la_ligne(char *line, SampleRef *sref) -{ -char *ptr, *cp; +SampleRef the_samples[26]; -#if DEBUG_LEVEL -fprintf(stderr, ">>> %s ( '%s' %p )\n", __func__, line, sref); -// dump(line); -#endif - -/* - * ON THE WAY TO PARSING HELL - */ -ptr = strtok(line, "|"); -cp = ltrim(rtrim(ptr)); -if (verbosity) fprintf(stderr, "key [%s]\n", cp); -if ( ! isalpha(*cp)) { - fprintf(stderr, "invalid key 0x%02x\n", *cp); - return -2; - } -sref->key = toupper(*cp); - -ptr = strtok(NULL, "|"); -if (NULL==ptr) { - fprintf(stderr, "line to short\n"); - return -3; - } -cp = ltrim(rtrim(ptr)); -if (verbosity) fprintf(stderr, "text [%s]\n", cp); -if (strlen(cp) > SZ_TEXT) { - fprintf(stderr, "text too long\n"); - return -4; - } -strcpy(sref->text, cp); - -ptr = strtok(NULL, "|"); -if (NULL==ptr) { - fprintf(stderr, "line to short\n"); - return -6; - } -cp = ltrim(rtrim(ptr)); -if (verbosity) fprintf(stderr, "path [%s]\n", cp); -if (strlen(ptr) > SZ_PATH) { - fprintf(stderr, "path too long\n"); - return -5; - } -strcpy(sref->path, cp); - -return 0; -} -/* --------------------------------------------------------------------- */ -#define T_LINE 300 - -int essai_lecture_liste(char *fname) -{ -FILE *fp; -char line[T_LINE+1]; -int ln; /* line number */ -int foo, bar; -SampleRef sample; - -#if DEBUG_LEVEL -fprintf(stderr, ">>> %s ( '%s' )\n", __func__, fname); -#endif - -if (NULL==(fp=fopen(fname, "r"))) { - perror(fname); - exit(1); - } - -ln = 1; -while (NULL != fgets(line, T_LINE, fp)) { - - // fprintf(stderr, "%3d = %s", ln, line); - - /* degommer l'eventuel \n */ - bar = strlen(line); - if (0==bar) { - fprintf(stderr,"line %d very short\n", ln); - continue; - } - bar--; /* backspace one char */ - if ('\n' == line[bar]) line[bar]='\0'; - - memset(&sample, 0, sizeof(SampleRef)); - foo = decode_la_ligne(line, &sample); -#if DEBUG_LEVEL - fprintf(stderr, "decode la ligne -> %d\n\n", foo); -#endif - affiche_un_sample(&sample); - - ln++; - } - -fclose(fp); - -return -1; -} /* --------------------------------------------------------------------- */ void help(int k) { @@ -132,10 +32,11 @@ int foo; int opt; char *listname = "samples.list"; -while ((opt = getopt(argc, argv, "hv")) != -1) { +while ((opt = getopt(argc, argv, "hl:v")) != -1) { switch(opt) { case 'h': help(0); break; case 'v': verbosity++; break; + case 'l': listname = optarg; break; } } @@ -143,8 +44,13 @@ while ((opt = getopt(argc, argv, "hv")) != -1) { fprintf(stderr, "argc = %d, optind = %d\n", argc, optind); #endif -foo = essai_lecture_liste(listname); -fprintf(stderr,"essai lecture '%s' -> %d\n", listname, foo); +foo = lecture_liste_des_samples(listname, the_samples); +fprintf(stderr,"retour lecture liste '%s' -> %d\n", listname, foo); + +for (foo=0; foo<26; foo++) { + printf("%3d %02x %s\n", foo, the_samples[foo].key, + the_samples[foo].text); + } return 0; } diff --git a/main.c b/main.c new file mode 100644 index 0000000..2314f51 --- /dev/null +++ b/main.c @@ -0,0 +1,59 @@ +/* + * NcLooper test des fonctions fichier (???) + */ + +#include +#include +#include +#include +#include + +#include "nclooper.h" +// #include "files/smpllist.h" +// #include "files/ffuncs.h" + +/* --------------------------------------------------------------------- */ + +int verbosity; + +SampleRef the_samples[26]; + +/* --------------------------------------------------------------------- */ +void help(int k) +{ +puts("NcLooper : version pas finie..."); +exit(0); +} +/* --------------------------------------------------------------------- */ + +int main(int argc, char *argv[]) +{ +int foo; +int opt; +char *listname = "samples.list"; + +while ((opt = getopt(argc, argv, "hl:v")) != -1) { + switch(opt) { + case 'h': help(0); break; + case 'v': verbosity++; break; + case 'l': listname = optarg; break; + } + } + +#if DEBUG_LEVEL +fprintf(stderr, "argc = %d, optind = %d\n", argc, optind); +#endif + + +foo = lecture_liste_des_samples(listname, the_samples); +fprintf(stderr,"retour lecture liste '%s' -> %d\n", listname, foo); + +for (foo=0; foo<26; foo++) { + printf("%3d %02x %s\n", foo, the_samples[foo].key, + the_samples[foo].text); + } + +return 0; +} +/* --------------------------------------------------------------------- */ + diff --git a/nclooper.h b/nclooper.h new file mode 100644 index 0000000..bb76ab4 --- /dev/null +++ b/nclooper.h @@ -0,0 +1,18 @@ +/* + * NcLooper + */ + + +/* two arbitrary magic number */ +#define SZ_TEXT 20 +#define SZ_PATH 400 + +typedef struct { + char key; + int flags; + char text[SZ_TEXT+1]; + char path[SZ_PATH+1]; + } SampleRef; + +#include "files/smpllist.h" +#include "files/ffuncs.h" diff --git a/ui/ncfuncs.c b/ui/ncfuncs.c index ad75b1a..927f605 100644 --- a/ui/ncfuncs.c +++ b/ui/ncfuncs.c @@ -3,7 +3,7 @@ */ -#include +#include "ncfuncs.h" /* --------------------------------------------------------------------- */ int init_ecran(char *txt) @@ -11,7 +11,7 @@ int init_ecran(char *txt) initscr(); standout(); -border('o', 'o', 'o', 'o', 'X', 'X', 'X', 'X'); +// border('o', 'o', 'o', 'o', 'X', 'X', 'X', 'X'); standend(); mvaddstr(1, 5, txt); refresh(); @@ -27,3 +27,12 @@ endwin(); return 0; } /* --------------------------------------------------------------------- */ +int idx2position(int idx, int *prow, int *pcol) +{ + +*prow = 6 + (idx % 13); +*pcol = 4 + (40*(idx/13)); + +return 0; +} +/* --------------------------------------------------------------------- */ diff --git a/ui/ncfuncs.h b/ui/ncfuncs.h index aec054b..45f0d6d 100644 --- a/ui/ncfuncs.h +++ b/ui/ncfuncs.h @@ -2,7 +2,10 @@ * NcLooper--- interface curses, fonctions de base */ +#include int init_ecran(char *txt); int fin_ecran(void); +int idx2position(int idx, int *prow, int *pcol); + diff --git a/ui/t.c b/ui/t.c index 9f2fe3a..4ef52bb 100644 --- a/ui/t.c +++ b/ui/t.c @@ -6,24 +6,26 @@ #include #include +#include "../nclooper.h" #include "ncfuncs.h" /* --------------------------------------------------------------------- */ + int verbosity; /* --------------------------------------------------------------------- */ void help(int k) { -puts("plop..."); +puts("test des fonctions de l'interface utilisateur"); exit(0); } /* --------------------------------------------------------------------- */ int main(int argc, char *argv[]) { -int foo; +int foo, idx; int opt; - +int row, col; while ((opt = getopt(argc, argv, "hv")) != -1) { switch(opt) { @@ -37,9 +39,19 @@ fprintf(stderr, "argc = %d, optind = %d\n", argc, optind); #endif foo = init_ecran("* NcLooper *"); -sleep(2); +for (idx=0; idx<26; idx++) { + foo = idx2position(idx, &row, &col); + standout(); + mvaddch(row, col, '<'); + mvaddch(row, col+1, 'A' + idx); + mvaddch(row, col+2, '>'); + standend(); + mvaddstr(row, col+5, "bla bla bla..."); + } + refresh(); +sleep(3); fin_ecran();