Compare commits
16 Commits
2e538157c5
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
713fe618de | ||
|
|
be1809ec16 | ||
| af5f983a60 | |||
| 4bd4e1c43f | |||
| 10b2f53b85 | |||
| 119a61c0e5 | |||
| db3d7283df | |||
| ec27a42dc1 | |||
| 134f3170f6 | |||
| af13698209 | |||
| 5bb5ae987f | |||
| d721ea674c | |||
| 7ac2bc53e9 | |||
| 759a6450a6 | |||
| ad54bac3f7 | |||
| 1bd06fb67b |
57
.gitignore
vendored
57
.gitignore
vendored
@@ -1,58 +1,13 @@
|
|||||||
# mon machin a moi
|
# mon machin a moi
|
||||||
|
|
||||||
audio/t
|
audio/t
|
||||||
|
audio/*.wav
|
||||||
|
|
||||||
# ---> C
|
nclooper
|
||||||
# Prerequisites
|
ui/t
|
||||||
*.d
|
files/t
|
||||||
|
|
||||||
|
sounds/*
|
||||||
|
|
||||||
# Object files
|
# Object files
|
||||||
*.o
|
*.o
|
||||||
*.ko
|
|
||||||
*.obj
|
|
||||||
*.elf
|
|
||||||
|
|
||||||
# Linker output
|
|
||||||
*.ilk
|
|
||||||
*.map
|
|
||||||
*.exp
|
|
||||||
|
|
||||||
# Precompiled Headers
|
|
||||||
*.gch
|
|
||||||
*.pch
|
|
||||||
|
|
||||||
# Libraries
|
|
||||||
*.lib
|
|
||||||
*.a
|
|
||||||
*.la
|
|
||||||
*.lo
|
|
||||||
|
|
||||||
# Shared objects (inc. Windows DLLs)
|
|
||||||
*.dll
|
|
||||||
*.so
|
|
||||||
*.so.*
|
|
||||||
*.dylib
|
|
||||||
|
|
||||||
# Executables
|
|
||||||
*.exe
|
|
||||||
*.out
|
|
||||||
*.app
|
|
||||||
*.i*86
|
|
||||||
*.x86_64
|
|
||||||
*.hex
|
|
||||||
|
|
||||||
# Debug files
|
|
||||||
*.dSYM/
|
|
||||||
*.su
|
|
||||||
*.idb
|
|
||||||
*.pdb
|
|
||||||
|
|
||||||
# Kernel Module Compile Results
|
|
||||||
*.mod*
|
|
||||||
*.cmd
|
|
||||||
.tmp_versions/
|
|
||||||
modules.order
|
|
||||||
Module.symvers
|
|
||||||
Mkfile.old
|
|
||||||
dkms.conf
|
|
||||||
|
|
||||||
|
|||||||
23
Makefile
Normal file
23
Makefile
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#
|
||||||
|
# NC-LOOPER --- another kluge from tth
|
||||||
|
#
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
CCOPT = -Wall -g -DDEBUG_LEVEL=0
|
||||||
|
|
||||||
|
OBJS = ui/ncfuncs.o files/smpllist.o files/ffuncs.o
|
||||||
|
LIBS = -lcurses
|
||||||
|
|
||||||
|
all: nclooper
|
||||||
|
|
||||||
|
main.o: main.c nclooper.h Makefile
|
||||||
|
$(CC) ${CCOPT} -c $<
|
||||||
|
|
||||||
|
interactive.o: interactive.c nclooper.h Makefile
|
||||||
|
$(CC) ${CCOPT} -c $<
|
||||||
|
|
||||||
|
OBJS += interactive.o
|
||||||
|
|
||||||
|
nclooper: main.o ${OBJS} Makefile
|
||||||
|
$(CC) ${CCOPT} $< ${OBJS} ${LIBS} -o $@
|
||||||
|
|
||||||
16
README.md
16
README.md
@@ -2,9 +2,21 @@
|
|||||||
|
|
||||||
Les scratchmen utilisent des loopers en Flash 11.
|
Les scratchmen utilisent des loopers en Flash 11.
|
||||||
Il est temps qu'ils découvrent une interface ncurses
|
Il est temps qu'ils découvrent une interface ncurses
|
||||||
pilotée au joystick :)
|
pilotable au joystick ou par OSC :)
|
||||||
|
|
||||||
## Prérequis :
|
## Prérequis :
|
||||||
|
|
||||||
libsndfile, libao, libcurses.
|
libsndfile, libao, liblo, libcurses.avec les bons -dev !
|
||||||
|
|
||||||
|
## Compilation :
|
||||||
|
|
||||||
|
Pour le moment, vous êtes laissé à vous-même.
|
||||||
|
|
||||||
|
## Hacking :
|
||||||
|
|
||||||
|
La voie est libre.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,19 @@
|
|||||||
|
#
|
||||||
|
# NC-LOOPER --- another kluge from tth
|
||||||
|
#
|
||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CCOPT = -Wall -g -DDEBUG_LEVEL=1
|
CCOPT = -Wall -g -DDEBUG_LEVEL=0
|
||||||
LIBS = -lao -lsndfile -lm
|
LIBS = -lao -lsndfile -lm
|
||||||
|
|
||||||
ao_output.o: ao_output.c Makefile
|
ao_output.o: ao_output.c Makefile
|
||||||
$(CC) ${CCOPT} -c $<
|
$(CC) ${CCOPT} -c $<
|
||||||
|
|
||||||
t: t.c ao_output.o Makefile
|
playfile.o: playfile.c Makefile
|
||||||
$(CC) ${CCOPT} $< ao_output.o ${LIBS} -o $@
|
$(CC) ${CCOPT} -c $<
|
||||||
|
|
||||||
|
OBJS = ao_output.o playfile.o
|
||||||
|
|
||||||
|
t: t.c ${OBJS} Makefile
|
||||||
|
$(CC) ${CCOPT} $< ${OBJS} ${LIBS} -o $@
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* NcLooper fonctions audio
|
* NcLooper fonctions audio output
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -15,13 +15,14 @@
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
static ao_device *device; /* never alone with a singleton */
|
extern int verbosity;
|
||||||
|
|
||||||
/* --------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------- */
|
||||||
int init_ao_output(int smplrate)
|
ao_device *init_ao_output(int smplrate)
|
||||||
{
|
{
|
||||||
int default_driver;
|
int default_driver;
|
||||||
ao_sample_format format;
|
ao_sample_format format;
|
||||||
|
ao_device *device;
|
||||||
|
|
||||||
#if DEBUG_LEVEL
|
#if DEBUG_LEVEL
|
||||||
fprintf(stderr, ">>> %s ( %d )\n", __func__, smplrate);
|
fprintf(stderr, ">>> %s ( %d )\n", __func__, smplrate);
|
||||||
@@ -43,33 +44,39 @@ format.byte_format = AO_FMT_LITTLE;
|
|||||||
device = ao_open_live(default_driver, &format, NULL);
|
device = ao_open_live(default_driver, &format, NULL);
|
||||||
if (device == NULL) {
|
if (device == NULL) {
|
||||||
fprintf(stderr, "Error opening AO device.\n");
|
fprintf(stderr, "Error opening AO device.\n");
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DEBUG_LEVEL
|
||||||
|
fprintf(stderr, "%s : device at %p\n", __func__, device);
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return device;
|
||||||
}
|
}
|
||||||
/* --------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------- */
|
||||||
int close_ao_output(void)
|
int close_ao_output(ao_device *dev)
|
||||||
{
|
{
|
||||||
|
|
||||||
ao_close(device);
|
if (NULL == dev) {
|
||||||
ao_shutdown();
|
fprintf(stderr, "%s : no output to close\n", __func__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
device = NULL;
|
ao_close(dev);
|
||||||
|
ao_shutdown();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* --------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------- */
|
||||||
int play_some_stuff(int notused)
|
int play_some_stuff(ao_device *dev, int notused)
|
||||||
{
|
{
|
||||||
int i, sample;
|
int i, sample;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
float freq = 440.0;
|
float freq = 440.0;
|
||||||
|
|
||||||
#define NB_SAMPLES 44100
|
#define NB_SAMPLES (44100*2)
|
||||||
|
|
||||||
if (NULL == device) {
|
if (NULL == dev) {
|
||||||
fprintf(stderr, "%s : please call 'init_ao_output' first\n",
|
fprintf(stderr, "%s : please call 'init_ao_output' first\n",
|
||||||
__func__);
|
__func__);
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -85,7 +92,13 @@ for (i = 0; i < NB_SAMPLES; i++) {
|
|||||||
buffer[4*i] = buffer[4*i+2] = sample & 0xff;
|
buffer[4*i] = buffer[4*i+2] = sample & 0xff;
|
||||||
buffer[4*i+1] = buffer[4*i+3] = (sample >> 8) & 0xff;
|
buffer[4*i+1] = buffer[4*i+3] = (sample >> 8) & 0xff;
|
||||||
}
|
}
|
||||||
ao_play(device, buffer, NB_SAMPLES);
|
ao_play(dev, buffer, NB_SAMPLES);
|
||||||
|
|
||||||
|
free(buffer);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
/* generic output */
|
/* generic output */
|
||||||
|
|
||||||
int init_ao_output(int smplrate);
|
ao_device * init_ao_output(int smplrate);
|
||||||
int close_ao_output(void);
|
int close_ao_output(ao_device *dev);
|
||||||
|
|
||||||
|
|
||||||
/* tests functions */
|
/* tests functions */
|
||||||
|
|
||||||
int play_some_stuff(int notused);
|
int play_some_stuff(ao_device *dev, int notused);
|
||||||
|
|||||||
78
audio/playfile.c
Normal file
78
audio/playfile.c
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* NcLooper fonctions audio output
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include <ao/ao.h>
|
||||||
|
#include <sndfile.h>
|
||||||
|
|
||||||
|
#include "ao_output.h"
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
extern int verbosity;
|
||||||
|
|
||||||
|
#define T_BUFF_WAVES (16384*2)
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
int blast_this_file(char *fname, ao_device *dev, int loop)
|
||||||
|
{
|
||||||
|
SNDFILE *sndf;
|
||||||
|
SF_INFO sfinfo;
|
||||||
|
int foo, lus, pass;
|
||||||
|
short *buffer;
|
||||||
|
|
||||||
|
#if DEBUG_LEVEL
|
||||||
|
fprintf(stderr, ">>> %s ( '%s' %p %d )\n", __func__, fname, dev, loop);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
buffer = calloc(T_BUFF_WAVES, sizeof(short)*2);
|
||||||
|
if (NULL == buffer) {
|
||||||
|
fprintf(stderr, "ALLOC FAIL, ABEND in %s\n", __func__);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
sndf = sf_open(fname, SFM_READ, &sfinfo);
|
||||||
|
if (NULL==sndf)
|
||||||
|
{
|
||||||
|
perror("sf_open");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer = calloc(T_BUFF_WAVES, sizeof(short)*2);
|
||||||
|
|
||||||
|
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<loop; pass++) {
|
||||||
|
|
||||||
|
sf_seek(sndf, 0, SEEK_SET);
|
||||||
|
|
||||||
|
while ((lus = sf_read_short(sndf, buffer, T_BUFF_WAVES))) {
|
||||||
|
|
||||||
|
#if DEBUG_LEVEL > 1
|
||||||
|
fprintf(stderr, "%s : %d bytes read\n", fname, lus);
|
||||||
|
#endif
|
||||||
|
ao_play(dev, buffer, lus*2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* do some cleanup */
|
||||||
|
sf_close(sndf);
|
||||||
|
free(buffer);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
3
audio/playfile.h
Normal file
3
audio/playfile.h
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
|
int blast_this_file(char *fname, ao_device *dev, int loop);
|
||||||
58
audio/t.c
58
audio/t.c
@@ -3,27 +3,65 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <ao/ao.h>
|
||||||
|
|
||||||
#include "ao_output.h"
|
#include "ao_output.h"
|
||||||
|
#include "playfile.h"
|
||||||
|
|
||||||
/* --------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
/* --------------------------------------------------------------------- */
|
int verbosity;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
/* --------------------------------------------------------------------- */
|
||||||
|
void help(int k)
|
||||||
{
|
{
|
||||||
int foo;
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
int envoyer_du_son(char *fname, int k)
|
||||||
|
{
|
||||||
|
ao_device *device;
|
||||||
|
int foo;
|
||||||
|
|
||||||
|
device = init_ao_output(44100);
|
||||||
|
if (verbosity) fprintf(stderr, "AO init -> %p\n", device);
|
||||||
|
|
||||||
foo = init_ao_output(44100);
|
switch (k) {
|
||||||
fprintf(stderr, "AO init -> %d\n", foo);
|
case 0:
|
||||||
|
foo = blast_this_file(fname, device, 1);
|
||||||
|
fprintf(stderr, "blast file -> %d\n", foo);
|
||||||
|
break;
|
||||||
|
|
||||||
foo = play_some_stuff(0);
|
case 1:
|
||||||
fprintf(stderr, "play stuff -> %d\n", foo);
|
foo = play_some_stuff(device, 0);
|
||||||
|
fprintf(stderr, "play stuff -> %d\n", foo);
|
||||||
foo = close_ao_output();
|
break;
|
||||||
fprintf(stderr, "AO close -> %d\n", foo);
|
}
|
||||||
|
|
||||||
|
foo = close_ao_output(device);
|
||||||
|
if (verbosity) fprintf(stderr, "AO close -> %d\n", foo);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "hv")) != -1) {
|
||||||
|
switch(opt) {
|
||||||
|
case 'h': help(0); break;
|
||||||
|
case 'v': verbosity++; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DEBUG_LEVEL
|
||||||
|
fprintf(stderr, "argc = %d, optind = %d\n", argc, optind);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
envoyer_du_son("AK14V-ORDRES.wav", 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
37
build.sh
Executable file
37
build.sh
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
function build
|
||||||
|
{
|
||||||
|
echo =================== $1 ====================
|
||||||
|
curdir=${PWD}
|
||||||
|
cd $1
|
||||||
|
make t
|
||||||
|
error=$?
|
||||||
|
cd ${curdir}
|
||||||
|
|
||||||
|
if [ ${error} -ne 0 ]
|
||||||
|
then
|
||||||
|
echo === error on $1 = ${error}
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
build files
|
||||||
|
build ui
|
||||||
|
build audio
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
printf "\n...final...\n"
|
||||||
|
make
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
19
files/Makefile
Normal file
19
files/Makefile
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#
|
||||||
|
# NC-LOOPER --- another kluge from tth
|
||||||
|
#
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
CCOPT = -Wall -g -DDEBUG_LEVEL=0
|
||||||
|
|
||||||
|
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 smpllist.o
|
||||||
|
|
||||||
|
t: t.c ${OBJS} Makefile
|
||||||
|
$(CC) ${CCOPT} $< ${OBJS} ${LIBS} -o $@
|
||||||
|
|
||||||
61
files/ffuncs.c
Normal file
61
files/ffuncs.c
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* various functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "ffuncs.h"
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
extern int verbosity;
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
void dump(unsigned char *ptr)
|
||||||
|
{
|
||||||
|
int foo;
|
||||||
|
|
||||||
|
for (foo=0; foo<24; foo++) fprintf(stderr, "%02x ", ptr[foo]);
|
||||||
|
fputs("\n", stderr);
|
||||||
|
for (foo=0; foo<24; foo++) fprintf(stderr, "%c ",
|
||||||
|
isgraph(ptr[foo])?ptr[foo]:' ');
|
||||||
|
fputs("\n", stderr);
|
||||||
|
|
||||||
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
char *rtrim(char *src)
|
||||||
|
{
|
||||||
|
int foo;
|
||||||
|
|
||||||
|
for (foo=strlen(src)-1; src[foo]==' '|| src[foo]=='\t'; foo--) {
|
||||||
|
src[foo] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
return src;
|
||||||
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
char *ltrim(char *src)
|
||||||
|
{
|
||||||
|
int foo, bar;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
tmp = alloca(strlen(src));
|
||||||
|
|
||||||
|
for (foo=0; src[foo]==' ' || src[foo]=='\t'; foo++);
|
||||||
|
|
||||||
|
bar = 0;
|
||||||
|
while (src[foo]!='\0') {
|
||||||
|
tmp[bar]=src[foo];
|
||||||
|
foo++;
|
||||||
|
bar++;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(src, tmp);
|
||||||
|
|
||||||
|
return src;
|
||||||
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
13
files/ffuncs.h
Normal file
13
files/ffuncs.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* various file functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void dump(unsigned char *ptr);
|
||||||
|
|
||||||
|
char *rtrim(char *src);
|
||||||
|
char *ltrim(char *src);
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
4
files/samples.list
Normal file
4
files/samples.list
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
a | bla bla | ../AK14V-ORDRES.wav
|
||||||
|
z |znare|znare.wav
|
||||||
|
B | plop ! | ../AK14V-ORDRES.wav
|
||||||
|
c | classic | foo.wav
|
||||||
148
files/smpllist.c
Normal file
148
files/smpllist.c
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
void affiche_liste_des_samples(SampleRef samples[])
|
||||||
|
{
|
||||||
|
int foo;
|
||||||
|
|
||||||
|
for (foo=0; foo<26; foo++) {
|
||||||
|
printf("%2d %02x %-30s %s\n", foo, samples[foo].key,
|
||||||
|
samples[foo].text,
|
||||||
|
samples[foo].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 > 1
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
14
files/smpllist.h
Normal file
14
files/smpllist.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
void affiche_un_sample(SampleRef *sref, int options);
|
||||||
|
|
||||||
|
void affiche_liste_des_samples(SampleRef samples[]);
|
||||||
|
|
||||||
|
int decode_la_ligne(char *line, SampleRef *sref);
|
||||||
|
int lecture_liste_des_samples(char *fname, SampleRef *array);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
47
files/t.c
Normal file
47
files/t.c
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* small proggy for testing some functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "ffuncs.h"
|
||||||
|
|
||||||
|
int verbosity = 1;
|
||||||
|
|
||||||
|
int test_of_the_trim_funcs(int foo)
|
||||||
|
{
|
||||||
|
char buffer[200];
|
||||||
|
|
||||||
|
printf(" --- %s ---\n\n", __func__);
|
||||||
|
|
||||||
|
strcpy(buffer, "nothing to trim");
|
||||||
|
dump(buffer, NULL);
|
||||||
|
puts("");
|
||||||
|
|
||||||
|
strcpy(buffer, "trailing spaces ");
|
||||||
|
dump(buffer, NULL);
|
||||||
|
rtrim(buffer);
|
||||||
|
dump(buffer, NULL);
|
||||||
|
puts("");
|
||||||
|
|
||||||
|
strcpy(buffer, " leading spaces");
|
||||||
|
dump(buffer, NULL);
|
||||||
|
ltrim(buffer);
|
||||||
|
dump(buffer, NULL);
|
||||||
|
puts("");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
|
||||||
|
(void)test_of_the_trim_funcs(0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
83
interactive.c
Normal file
83
interactive.c
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* NCLOOPER INTERACTIVE
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "nclooper.h"
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
extern int verbosity;
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
static int la_grande_boucle(SampleRef *psmpl, int notused)
|
||||||
|
{
|
||||||
|
static int curpos = 0;
|
||||||
|
int key;
|
||||||
|
int flag_exit = 0;
|
||||||
|
char line[120];
|
||||||
|
|
||||||
|
#if DEBUG_LEVEL
|
||||||
|
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, psmpl, notused);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
sprintf(line, "curpos %4d", curpos);
|
||||||
|
mvaddstr(1,50, line);
|
||||||
|
|
||||||
|
refresh();
|
||||||
|
|
||||||
|
/* - - - - handle human input, be careful */
|
||||||
|
noecho();
|
||||||
|
key = getch();
|
||||||
|
echo();
|
||||||
|
// sprintf(line, " key %4d", key);
|
||||||
|
// mvaddstr(2,50, line);
|
||||||
|
|
||||||
|
switch(key) {
|
||||||
|
case KEY_UP:
|
||||||
|
if (curpos < 25) curpos++;
|
||||||
|
break;
|
||||||
|
case KEY_DOWN:
|
||||||
|
if (curpos > 0) curpos--;
|
||||||
|
break;
|
||||||
|
} // end of swict
|
||||||
|
|
||||||
|
|
||||||
|
flag_exit = ('X' == key);
|
||||||
|
} while ( ! flag_exit );
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
int enter_interactive(SampleRef *psmpl, int notused)
|
||||||
|
{
|
||||||
|
int foo, row, col;
|
||||||
|
char txt[99];
|
||||||
|
|
||||||
|
#if DEBUG_LEVEL
|
||||||
|
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, psmpl, notused);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
for (foo=0; foo<26; foo++) {
|
||||||
|
idx2position(foo, &row, &col);
|
||||||
|
sprintf(txt, "%3d", foo);
|
||||||
|
mvaddstr(row, col, txt);
|
||||||
|
if (psmpl[foo].key) {
|
||||||
|
standout();
|
||||||
|
mvaddch(row, col+4, psmpl[foo].key);
|
||||||
|
standend();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
refresh();
|
||||||
|
|
||||||
|
foo = la_grande_boucle(psmpl, notused); /* wtf ?
|
||||||
|
notused is used ? */
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
115
main.c
Normal file
115
main.c
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
* NcLooper test des fonctions fichier (???)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <ao/ao.h>
|
||||||
|
|
||||||
|
#include "nclooper.h"
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
int verbosity;
|
||||||
|
|
||||||
|
SampleRef the_samples[26];
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
void help(int k)
|
||||||
|
{
|
||||||
|
puts("NcLooper : version pas finie...");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
/*
|
||||||
|
* all the basic engines are up, we have to fire ncurses
|
||||||
|
*/
|
||||||
|
int introduction(int k)
|
||||||
|
{
|
||||||
|
int foo;
|
||||||
|
ao_device *device;
|
||||||
|
|
||||||
|
#if DEBUG_LEVEL
|
||||||
|
fprintf(stderr, ">>> %s ( %d )\n", __func__, k);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
foo = init_ecran(__func__);
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
/* check the sound subsystem */
|
||||||
|
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
int start_the_engine(int k)
|
||||||
|
{
|
||||||
|
|
||||||
|
#if DEBUG_LEVEL
|
||||||
|
fprintf(stderr, ">>> %s ( %d )\n", __func__, k);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (k) {
|
||||||
|
fprintf(stderr, "%s: k %d is not null ?\n", __func__, k);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
int conclusion(int k)
|
||||||
|
{
|
||||||
|
int foo;
|
||||||
|
|
||||||
|
#if DEBUG_LEVEL
|
||||||
|
fprintf(stderr, ">>> %s ( %d )\n", __func__, k);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
foo = fin_ecran();
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int foo;
|
||||||
|
int opt;
|
||||||
|
int mode = 0;
|
||||||
|
char *listname = "files/samples.list";
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "hl:m:v")) != -1) {
|
||||||
|
switch(opt) {
|
||||||
|
case 'h': help(0); break;
|
||||||
|
case 'l': listname = optarg; break;
|
||||||
|
case 'm': mode = atoi(optarg); break;
|
||||||
|
case 'v': verbosity++; 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);
|
||||||
|
|
||||||
|
foo = start_the_engine(mode);
|
||||||
|
fprintf(stderr,"retour start engine -> %d\n", foo);
|
||||||
|
|
||||||
|
introduction(0);
|
||||||
|
|
||||||
|
foo = enter_interactive(the_samples, 0);
|
||||||
|
#if DEBUG_LEVEL
|
||||||
|
fprintf(stderr, "retour 'enter interactive' -> %d\n", foo);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
conclusion(0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
23
nclooper.h
Normal file
23
nclooper.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* 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"
|
||||||
|
|
||||||
|
#include "ui/ncfuncs.h"
|
||||||
|
|
||||||
|
|
||||||
|
int enter_interactive(SampleRef *, int notused);
|
||||||
17
ui/Makefile
Normal file
17
ui/Makefile
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
# NcLooper : user interface components
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
CCOPT = -Wall -g -DDEBUG_LEVEL=1
|
||||||
|
|
||||||
|
ncfuncs.o: ncfuncs.c ncfuncs.h Makefile
|
||||||
|
$(CC) ${CCOPT} -c $<
|
||||||
|
|
||||||
|
OBJS = ncfuncs.o
|
||||||
|
LIBS = -lcurses
|
||||||
|
|
||||||
|
t: t.c ${OBJS} Makefile
|
||||||
|
$(CC) ${CCOPT} $< ${OBJS} ${LIBS} -o $@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
42
ui/ncfuncs.c
Normal file
42
ui/ncfuncs.c
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* NcLooper--- interface curses, fonctions de base
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <curses.h>
|
||||||
|
|
||||||
|
#include "ncfuncs.h"
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
int init_ecran(const char *txt)
|
||||||
|
{
|
||||||
|
initscr();
|
||||||
|
|
||||||
|
standout();
|
||||||
|
// border('o', 'o', 'o', 'o', 'X', 'X', 'X', 'X');
|
||||||
|
standend();
|
||||||
|
mvaddstr(1, 5, txt);
|
||||||
|
refresh();
|
||||||
|
|
||||||
|
keypad(stdscr, 1);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
int fin_ecran(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
endwin();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
int idx2position(int idx, int *prow, int *pcol)
|
||||||
|
{
|
||||||
|
|
||||||
|
*prow = 6 + (idx % 13);
|
||||||
|
*pcol = 4 + (40*(idx/13));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
11
ui/ncfuncs.h
Normal file
11
ui/ncfuncs.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* NcLooper--- interface curses, fonctions de base
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <curses.h>
|
||||||
|
|
||||||
|
int init_ecran(const char *txt);
|
||||||
|
int fin_ecran(void);
|
||||||
|
|
||||||
|
int idx2position(int idx, int *prow, int *pcol);
|
||||||
|
|
||||||
60
ui/t.c
Normal file
60
ui/t.c
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* NcLooper test des fonctions ncurses
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "../nclooper.h"
|
||||||
|
#include "ncfuncs.h"
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
int verbosity;
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
void help(int k)
|
||||||
|
{
|
||||||
|
puts("test des fonctions de l'interface utilisateur");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int foo, idx;
|
||||||
|
int opt;
|
||||||
|
int row, col;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "hv")) != -1) {
|
||||||
|
switch(opt) {
|
||||||
|
case 'h': help(0); break;
|
||||||
|
case 'v': verbosity++; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DEBUG_LEVEL
|
||||||
|
fprintf(stderr, "argc = %d, optind = %d\n", argc, optind);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
foo = init_ecran("* NcLooper *");
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* --------------------------------------------------------------------- */
|
||||||
Reference in New Issue
Block a user