karlstav / cava

Cross-platform Audio Visualizer
MIT License
4.22k stars 232 forks source link

Config file #43

Closed karlstav closed 9 years ago

karlstav commented 9 years ago

The config file will in INI format:

#CONFIG FILE
paramter1=value1
;parameter2=value2

Suggested parameters:

Please make suggestions for other parameters.

Other considerations:

@CelestialWalrus has volunteered to do the initial work. Feel free to modify or reject any of my suggestions.

ghost commented 9 years ago

Library: https://github.com/ndevilla/iniparser

File path: ~/.config/cava/config

Example file:

[general]
mode=normal
framerate=60
sensitivity=100
bars=63

[input]
method=fifo
source=/tmp/mpd.fifo

[output]
method=terminal

[color]
background=white
foreground=blue

[smoothing]
integral=1
monstercat=1
gravity=0.66

[eq]
; naming of keys doesn't matter
1=0.5
2=0.6
3=0.7
4=0.3
5=0.2

Should there be a possibility to save adjusted parameters real time back in to the config file?(nice to have)

EDIT: iniparser is able to write stuff

ghost commented 9 years ago

So I'm using the iniparser library (instead of inih) in my fork: https://github.com/CelestialWalrus/cava

karlstav commented 9 years ago

looks very nice, there should be some explaining as what the different parameters do and what the range/options are.

Also i will have to make cava ready for frequency cutoff parameters and eq setting. Or you can decide range and whats supposed to be "normal/max/min" first then I will implement the functionalities when the rest is complete.

ghost commented 9 years ago

@karlstav I'll make a pull request, I've got the first four sections to work.

anko commented 9 years ago

The environment variable $XDG_CONFIG_HOME is a standard location for configuration files:

$XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.

If we'll have only one config file, just make it $XDG_CONFIG_HOME/cava?

ghost commented 9 years ago

The environment variable $XDG_CONFIG_HOME is a standard location for configuration files

I don't know how to check for it...

This segfaults:

// config: location
char *configDirectory = "%s/cava/";
char *configFile = "config.ini";
char configPath[255];
char *coPa = configPath;
char *xdghome = getenv("XDG_CONFIG_HOME");
size_t xdghomelength = strlen(xdghome);
if (xdghomelength == 0) {
    char *home = getenv("HOME");
    size_t homelength = strlen(home);
    if (homelength == 0) {
        printf("No HOME found, exiting...");
        exit(EXIT_FAILURE);
    }
    strcpy(&coPa, home);
    strcat(&coPa, "/.config");
}

// config: create empty file
snprintf(configPath, sizeof(configPath), configDirectory, configPath);
mkdir(configPath, 0777);
strcat(configPath, configFile);
FILE *fp = fopen(configPath, "ab+");
printf(xdghome);
exit(EXIT_FAILURE);
fclose(fp);

I'm a Java/JavaScript dev with no C experience.

C is such a shitty language. No strings, wth!?

anko commented 9 years ago

@CelestialWalrus

I suspect strlen is segfaulting if getenv returns NULL. Do you have $XDG_CONFIG_HOME set?

bspwm's analogous code might help.

ghost commented 9 years ago

@anko: thanks. I'll add [smoothing] section and push it.

EDIT: Pushed, working on eq now.

ghost commented 9 years ago

@karlstav the eq works like that smooth array. I'll explain it later.

karlstav commented 9 years ago

@CelestialWalrus wow this is really promising, looks like you have gotten a lot of things done already.

The EQ gives no output if it is below 1, but maybe you changed how it worked after you made the example values.

The ini file is also empty when it is created. I think the best way to do it is to populate it with all default values but commented. Like etc/pulse/client.conf. Also i think that the .ini extension is a bit "windowsy", use .conf instead.

A couple of things on the implementation:

The EQ could be done before the main loop (in the weigh signal to frequencies process) to save CPU. Or could it? I'm not sure how you do it. But the process before the main loop creates bars numbers of constants and multiples them with the signal and is already a kind of "static" EQ. So if it can be placed here I think it would make sense.

The integral filter would also be nice to adjust (not just turn on of). The default value there now is 0.7, tuning this up towards 1.0 creates more smooth experience tuning it down will make it faster, but less smooth. Also cava will segfault without the if (f[o] < 1)f[o] = 1;check that is know at the end of this filter, as it gets a divided by zero error in the drawing. Just move the check to its own for loop. (or will this consume more CPU?)

Can the monstercat filter also be adjustable? Not just on/off?

Anyway verry nice work!

ghost commented 9 years ago

The EQ gives no output if it is below 1, but maybe you changed how it worked after you made the example values.

EDIT: Should work now.

[eq]
1=0
2=1
3=0
4=1
5=0

3_138

[eq]
1=2
2=2
3=1
4=1
5=0.5

3_139

Also i think that the .ini extension is a bit "windowsy", use .conf instead.

Changed to PATH/config [no extension].

The EQ could be done before the main loop (in the weigh signal to frequencies process) to save CPU.

EDIT: Done.

The integral filter would also be nice to adjust (not just turn on of).

EDIT: Done.

Can the monstercat filter also be adjustable? Not just on/off?

EDIT: Done.

ghost commented 9 years ago

@karlstav I've documented the config file. https://github.com/CelestialWalrus/cava/blob/modules/README.md (it's at the end).

ghost commented 9 years ago

Smoothing after eq looks better, but less precise.

[1,0,1,0,1]

3_141

karlstav commented 9 years ago

OK, i think we should go for smoothing after eq then.

regarding the readme. I think it would be best to explain the functions of the config in comments within the config file. The readme is getting pretty long...

ghost commented 9 years ago

@karlstav I don't know how to store the file inside the executable. (as a string?)

anko commented 9 years ago

@CelestialWalrus As a string would work—but why? Could distribute an example config file with the program, and have make install copy it into the right location, if it doesn't yet exist.

(Sorry for doing lots of talking and little work. I hope I'm more useful than annoying.)

karlstav commented 9 years ago

Here is how I whould imagine the config file:

## Configuration file for CAVA. Default values are commented out.  Use either ; or # for commenting.

[general]
; mode = normal # defines smoothing mode, can be normal, scientific or waves.
; framerate = 60 # Default: 60. Accepts only non-negative values.
; sensitivity = 100 #  is sensitivity %. Accepts only non-negative values.
; bars = 0 # defines the amount of bars. 0 sets it to auto (25 + fill up leftover space). 

[input]
; method = alsa # supported input methods are 'alsa' or 'fifo'.
; source = hw:1,1 # ALSA device or FIFO path.

[output]
; method = terminal # may be terminal or circle.

[color]
# supported colors are: red, green, yellow, magenta, cyan, white, blue, black.
; background = black
; foreground = cyan

[smoothing]
; integral = 0.7 # multiplier for the integral smoothing calculations. Higher values means smoother, but less precise. 0 to disable.
; monstercat = 1 # disables or enables the so-called "Monstercat smoothing". Default: 1. Set to 0 to disable. 
; gravity = 1 # Set gravity multiplier for "drop off". Higher values means smoother, but less precise. Accepts only non-negative values. Set to 0 to disable "drop off".

[eq]
# This one is tricky. You can have as much keys as you want. More keys = more precision. Look at readme.md on github for further explanations and examples.
; 1 = 1 # base
; 2 = 1
; 3 = 1
; 4 = 1
; 5 = 1 # treble

Come to think of it, setting the number of bars is retarted, I should set the bar width instead and then fill up terminal. Maybe number of bars as overieable option...

@CelestialWalrus give me a heads up when you are done in your end. Then I will pull your version and do some adjustments from my end. There are a few things that are needed to make all the customization work ok.

ghost commented 9 years ago

@karlstav I'm done for now, you can pull it.

ghost commented 9 years ago

@karlstav could you merge modules into master, please? cava-git AUR package uses master and since modules branch is temporary I'm not changing that.

karlstav commented 9 years ago

@CelestialWalrus done, pushing 0.3.1 out as well.

ghost commented 9 years ago

@karlstav you should mark it as a "release", not a "prerelease" ;-) (release sounds better!)

EDIT: Also, the default for integral should be 1 (user expects that) multiplied by 0.7 (default).

karlstav commented 9 years ago

release does sound better. But I thought that as long as it was 0.x.y it was a prerelease? I'll set it to release anyway, it looks very unusable with the "warning prerelease!" tag.

About the integral, having a total multiply factor of more then or equal to 1 will eventually cause all the bars to raise to maximum and stay there.So the plan is to limit allowed values to 0 - 0.99. Having the setting multiplied by 0.7 will cause 1/0,7=1,429 to be the maximum allowed value so that is not very intuitive.

ghost commented 9 years ago

@karlstav Well, never thought about that. You should also limit the gravity.

ghost commented 9 years ago

@karlstav BTW.

Come to think of it, setting the number of bars is retarted, I should set the bar width instead and then fill up terminal. Maybe number of bars as overieable option...

I use this option. Maybe bar width OR bar count?

ghost commented 9 years ago

@karlstav I've made a live reload feature. https://github.com/karlstav/cava/pull/47 (& that "ignore" thing)

I'm still trying to figure out how to restart/reload input.

karlstav commented 9 years ago

done for now, thanks to @CelestialWalrus again for spearheading the work on this. Further improvements would be to make it use some kind of system wide parser (separate issue)