Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added visualizer modes for Firefly and Blackwidow Chroma + Settings saving/reloading #41

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################

/Debug
96 changes: 96 additions & 0 deletions KeyboardVisualizerVC/AppSettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#include <fstream>
#include <string>
using namespace std;
using std::string;

#include "AppSettings.h"
string path = "settings.txt";

AppSettings::AppSettings() { }

void AppSettings::defaultSettings() {
rememberSettingsOnExit = true;
amplitude = 100;
avg_mode = 0;
avg_size = 8;
bkgd_step = 0;
bkgd_bright = 10;
bkgd_mode = 0;
delay = 50;
window_mode = 1;
decay = 80;
frgd_mode = 8;
ldstrp_pos = 0;
nrml_ofst = 0.04f;
nrml_scl = 0.5f;
single_color_mode = 1;
fireflymode = 0;
blkwdwmode = 0;
}

void AppSettings::saveSettings() {
ofstream fout(path);
if (fout.is_open()) {
fout
<< rememberSettingsOnExit << endl
<< amplitude << endl
<< avg_mode << endl
<< avg_size << endl
<< bkgd_step << endl
<< bkgd_bright << endl
<< bkgd_mode << endl
<< delay << endl
<< window_mode << endl
<< decay << endl
<< frgd_mode << endl
<< ldstrp_pos << endl
<< nrml_ofst << endl
<< nrml_scl << endl
<< single_color_mode << endl
<< fireflymode << endl
<< blkwdwmode << endl;
fout.close();
}
}

void AppSettings::loadSettings() {
ifstream fin;
try {
fin.open(path);
if (fin.is_open()) {
fin
>> rememberSettingsOnExit
>> amplitude
>> avg_mode
>> avg_size
>> bkgd_step
>> bkgd_bright
>> bkgd_mode
>> delay
>> window_mode
>> decay
>> frgd_mode
>> ldstrp_pos
>> nrml_ofst
>> nrml_scl
>> single_color_mode
>> fireflymode
>> blkwdwmode;
fin.close();
} else {
initSettingsFile();
}
} catch (...) {
defaultSettings();
}
}

void AppSettings::initSettingsFile() {
defaultSettings();
saveSettings();
}

bool is_file_exist(const char *fileName) {
std::ifstream infile(fileName);
return infile.good();
}
44 changes: 44 additions & 0 deletions KeyboardVisualizerVC/AppSettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

class AppSettings {
public:
AppSettings();

//Initialize default settings
void defaultSettings();

//Creates a default settings file if it does not exist
void initSettingsFile();

//Loads settings from file
void loadSettings();

//Saves settings to file
void saveSettings();

//_____ Settings _____//
//Amplitude of input waveform
int amplitude;
int avg_mode;
int avg_size;
int window_mode;
int decay;
int delay;
int ldstrp_pos;
//Background Variables
int bkgd_bright;
int bkgd_mode;
int bkgd_step;
//Single Color Mode
int single_color_mode;
//Normalization Offset and Scale
float nrml_ofst;
float nrml_scl;
//Foreground Variables
int frgd_mode;
//Device specific modes
int fireflymode;
int blkwdwmode;
//App settings
bool rememberSettingsOnExit;
};
Loading