Added config files
This commit is contained in:
53
config.c
Normal file
53
config.c
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#include <libconfig.h>
|
||||||
|
#include "config.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
config_t cfg;
|
||||||
|
const config_setting_t *setting;
|
||||||
|
|
||||||
|
void cfginit(void) {
|
||||||
|
|
||||||
|
config_init(&cfg);
|
||||||
|
if (!config_read_file(&cfg, "csoundbox.cfg")) {
|
||||||
|
fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
|
||||||
|
config_destroy(&cfg);
|
||||||
|
//return(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void cfgdestroy(void) {
|
||||||
|
//free ram
|
||||||
|
config_destroy(&cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cfgreinit(void) {
|
||||||
|
cfgdestroy();
|
||||||
|
cfginit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char *lookupSounds(char input) {
|
||||||
|
setting = config_lookup(&cfg, "soundmap.sounds");
|
||||||
|
const char *temp;
|
||||||
|
if(setting != NULL) {
|
||||||
|
int count = config_setting_length(setting);
|
||||||
|
int i;
|
||||||
|
|
||||||
|
|
||||||
|
for(i = 0; i < count; ++i) {
|
||||||
|
config_setting_t *sound = config_setting_get_elem(setting, i);
|
||||||
|
|
||||||
|
/* Only output the record if all of the expected fields are present. */
|
||||||
|
const char *key;
|
||||||
|
|
||||||
|
if (config_setting_lookup_string(sound, "key", &key))
|
||||||
|
if (key[0] == input) {
|
||||||
|
config_setting_lookup_string(sound, "path", &temp);
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
|
12
config.h
Normal file
12
config.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
typedef struct {
|
||||||
|
char *beep;
|
||||||
|
char *path[50];
|
||||||
|
char *key[50];
|
||||||
|
} sounds;
|
||||||
|
|
||||||
|
void cfginit(void);
|
||||||
|
void cfgdestroy(void);
|
||||||
|
void cfgreinit(void);
|
||||||
|
const char *lookupSounds(char input);
|
||||||
|
|
||||||
|
|
18
csoundbox.c
18
csoundbox.c
@@ -3,17 +3,31 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "csoundbox.h"
|
#include "csoundbox.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <ncurses.h>
|
||||||
#define BITS 8
|
#define BITS 8
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
cfginit();
|
||||||
|
playSound(lookupSounds('a'));
|
||||||
|
char input;
|
||||||
|
initscr();
|
||||||
|
nonl(); //no newline
|
||||||
|
keypad(stdscr, FALSE); //Disable the F1-12 keypad
|
||||||
|
curs_set(0); //Disable the cursor
|
||||||
|
while ((input = getch()) != 13) {
|
||||||
|
playSound(lookupSounds(input));
|
||||||
|
}
|
||||||
|
|
||||||
|
endwin();
|
||||||
|
cfgdestroy();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void playSound(char *path) {
|
void playSound(const char *path) {
|
||||||
mpg123_handle *mh;
|
mpg123_handle *mh;
|
||||||
unsigned char *buffer;
|
unsigned char *buffer;
|
||||||
size_t buffer_size;
|
size_t buffer_size;
|
||||||
|
8
csoundbox.cfg
Normal file
8
csoundbox.cfg
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
soundmap = {
|
||||||
|
sounds = ( {path = "ballsofsteel.mp3";
|
||||||
|
key = "a"},
|
||||||
|
{path = "neck.mp3";
|
||||||
|
key = "b"}
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
@@ -1,2 +1,2 @@
|
|||||||
|
|
||||||
void playSound(char *path);
|
void playSound(const char *path);
|
||||||
|
4
makefile
4
makefile
@@ -5,9 +5,9 @@ VERSION = 1.0
|
|||||||
CC = cc
|
CC = cc
|
||||||
CFLAGS = -Wall -O3 -DVERSION=\"$(VERSION)\"
|
CFLAGS = -Wall -O3 -DVERSION=\"$(VERSION)\"
|
||||||
#LDFLAGS = -lm -lpthread `gtk-config --cflags` `gtk-config --libs` -lgthread
|
#LDFLAGS = -lm -lpthread `gtk-config --cflags` `gtk-config --libs` -lgthread
|
||||||
LDFLAGS = -lmpg123 -lao
|
LDFLAGS = -lmpg123 -lao -lconfig -lncurses
|
||||||
|
|
||||||
OBJ = csoundbox.o
|
OBJ = csoundbox.o config.o
|
||||||
|
|
||||||
all: $(OBJ)
|
all: $(OBJ)
|
||||||
$(CC) $(CFLAGS) -o csoundbox $(OBJ) $(LDFLAGS)
|
$(CC) $(CFLAGS) -o csoundbox $(OBJ) $(LDFLAGS)
|
||||||
|
Reference in New Issue
Block a user