Skip to content

Commit

Permalink
Added live config file support
Browse files Browse the repository at this point in the history
  • Loading branch information
duckyondiscord committed Jul 27, 2023
1 parent 9c1dd6a commit 1fcaf68
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ I use some snippets of code from [cava](https://github.com/karlstav/cava) and [c
- FreeBSD 13.2
- Arch Linux
- postmarketOS

Probably will work on any other Unix-like OS that has Xorg and supplies the dependencies

# Building
Expand All @@ -39,4 +39,3 @@ The syntax is just regular INI syntax, but it's pretty self-explanatory just fro

- Add support for other audio sources
- More visualizer designs (possibly one similar to [cava](https://github.com/karlstav/cava).)
- Add live configuration(remove the need for a restart of the app after modifying the config).
13 changes: 8 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ XEvent event;
}
return NULL;
}

void draw(sf::RenderWindow* window, int MAX_HEIGHT, int red, int green, int blue, int alpha) { // render stuff :D
int i;

Expand All @@ -110,8 +111,9 @@ void draw(sf::RenderWindow* window, int MAX_HEIGHT, int red, int green, int blue

int main () {

std::string homedir = std::getenv("HOME");
INIReader reader(homedir + "/.config/deskvis.ini"); // Open config file
std::string confFile = std::getenv("HOME");
confFile = confFile + "/.config/deskvis.ini";
INIReader reader(confFile); // Open config file

if(reader.ParseError() < 0) // Check if we can't load/parse the config file
{
Expand All @@ -131,7 +133,7 @@ int main () {
sf::Clock clock;
pthread_t inputThread;
pthread_t eventThread;
int i, thr_id, silence, sleep, XeventThread_id;
int i, thr_id, silence, sleep, eventThread_id;
struct timespec req = { .tv_sec = 0, .tv_nsec = 0 };
struct audio_data audio;
double in[2050];
Expand All @@ -151,8 +153,8 @@ int main () {
audio.audio_out[i] = 0;
}
getPulseDefaultSink((void*)&audio);
thr_id = pthread_create(&inputThread, NULL, input_pulse, (void*)&audio);
XeventThread_id = pthread_create(&eventThread, NULL, handleXEvents, NULL);
thr_id = pthread_create(&inputThread, NULL, input_pulse, (void*)&audio);
eventThread_id = pthread_create(&eventThread, NULL, handleXEvents, NULL);
audio.rate = 48000;

// Main Loop
Expand Down Expand Up @@ -197,6 +199,7 @@ int main () {
}

// Render
INIReader reader(confFile);
draw(&window, MAX_HEIGHT, reader.GetInteger("color", "red", 4), reader.GetInteger("color", "green", 248), reader.GetInteger("color", "blue", 0), reader.GetInteger("color", "alpha", 153));
fps = 1 / clock.restart().asSeconds();
// Handle Events
Expand Down

0 comments on commit 1fcaf68

Please sign in to comment.