forked from cnlohr/colorchord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parameters.h
63 lines (47 loc) · 1.6 KB
/
parameters.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef _PARAMETERS_H
#define _PARAMETERS_H
#define PARAM_BUFF 128
enum ParamType
{
NONE,
PAFLOAT,
PAINT,
PASTRING, //const char *, cannot set.
PABUFFER,
NUM_PARAMS,
};
typedef void (*ParamCallbackT)( void * v );
struct ParamCallback
{
ParamCallbackT t;
void * v;
struct ParamCallback * next;
};
struct LinkedParameter
{
void * ptr;
struct LinkedParameter * lp;
};
struct Param
{
char orphan; //If this is set, then this is something that was received from a string, but has no claimed interface.
//It will be claimed when RegisterValue is called. NOTE: When orphan is set, it must be a malloc'd string.
enum ParamType t;
int size;
struct LinkedParameter * lp;
struct ParamCallback * callback;
};
//This is the preferred method for getting settings, that way changes will be propogated
void RegisterValue( const char * name, enum ParamType, void * ptr, int size );
void DumpParameters();
//Use these only if you really can't register your value.
float GetParameterF( const char * name, float defa );
int GetParameterI( const char * name, int defa );
const char * GetParameterS( const char * name, const char * defa );
//Format: parameter1=value1;parameter2=value2, OR \n instead of; ... \r's treated as whitespace. Will trip whitespace.
void SetParametersFromString( const char * string );
void AddCallback( const char * name, ParamCallbackT t, void * v );
#define REGISTER_PARAM( parameter_name, type ) \
void Register##parameter_name() __attribute__((constructor)); \
void Register##parameter_name() { RegisterValue( #parameter_name, type, ¶meter_name, sizeof( parameter_name ) ); }
#endif