diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7f0ed07 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +################################################################################ +# This .gitignore file was automatically created by Microsoft(R) Visual Studio. +################################################################################ + +/Debug diff --git a/KeyboardVisualizerVC/AppSettings.cpp b/KeyboardVisualizerVC/AppSettings.cpp new file mode 100644 index 0000000..d4c675e --- /dev/null +++ b/KeyboardVisualizerVC/AppSettings.cpp @@ -0,0 +1,96 @@ +#include +#include +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(); +} \ No newline at end of file diff --git a/KeyboardVisualizerVC/AppSettings.h b/KeyboardVisualizerVC/AppSettings.h new file mode 100644 index 0000000..8746ea4 --- /dev/null +++ b/KeyboardVisualizerVC/AppSettings.h @@ -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; +}; \ No newline at end of file diff --git a/KeyboardVisualizerVC/KeyboardVisDlg.cpp b/KeyboardVisualizerVC/KeyboardVisDlg.cpp index 6eba2f0..9905a13 100644 --- a/KeyboardVisualizerVC/KeyboardVisDlg.cpp +++ b/KeyboardVisualizerVC/KeyboardVisDlg.cpp @@ -24,51 +24,52 @@ boolean startminimized; boolean firstrun; KeyboardVisDlg::KeyboardVisDlg(CWnd* pParent) - : CDialogEx(IDD_RAZER_CHROMA_DLG, pParent) + : CDialogEx(IDD_RAZER_CHROMA_DLG, pParent) { - startminimized = FALSE; + startminimized = FALSE; } -void KeyboardVisDlg::SetVisualizer(Visualizer* v) +void KeyboardVisDlg::SetVisualizer(Visualizer* v) { vis = v; } -KeyboardVisDlg::~KeyboardVisDlg() -{ +KeyboardVisDlg::~KeyboardVisDlg() +{ } -void KeyboardVisDlg::DoDataExchange(CDataExchange* pDX) +void KeyboardVisDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } -BOOL KeyboardVisDlg::OnInitDialog() +BOOL KeyboardVisDlg::OnInitDialog() { - NOTIFYICONDATA Tray; - Tray.cbSize = sizeof(Tray); - Tray.hIcon = (HICON)::LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, LR_SHARED);//LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON)); - Tray.hWnd = GetSafeHwnd(); - strcpy(Tray.szTip, "Keyboard Visualizer"); - Tray.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE; - Tray.uID = ID_SYSTEMTRAY; - Tray.uCallbackMessage = WM_TRAYICON_EVENT; + NOTIFYICONDATA Tray; + Tray.cbSize = sizeof(Tray); + Tray.hIcon = (HICON)::LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, LR_SHARED);//LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON)); + Tray.hWnd = GetSafeHwnd(); + strcpy(Tray.szTip, "Keyboard Visualizer"); + Tray.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE; + Tray.uID = ID_SYSTEMTRAY; + Tray.uCallbackMessage = WM_TRAYICON_EVENT; - Shell_NotifyIcon(NIM_ADD, &Tray); + Shell_NotifyIcon(NIM_ADD, &Tray); - char nrml_ofst_str[64]; - char nrml_scl_str[64]; + char nrml_ofst_str[64]; + char nrml_scl_str[64]; - snprintf(nrml_ofst_str, 64, "%f", vis->nrml_ofst); - snprintf(nrml_scl_str, 64, "%f", vis->nrml_scl); + snprintf(nrml_ofst_str, 64, "%f", vis->nrml_ofst); + snprintf(nrml_scl_str, 64, "%f", vis->nrml_scl); SetDlgItemInt(IDC_EDIT_AMPLITUDE, vis->amplitude); SetDlgItemInt(IDC_EDIT_BACKGROUND_BRIGHTNESS, vis->bkgd_bright); SetDlgItemInt(IDC_EDIT_AVERAGE_SIZE, vis->avg_size); SetDlgItemInt(IDC_EDIT_DECAY, vis->decay); SetDlgItemInt(IDC_EDIT_DELAY, vis->delay); - SetDlgItemText(IDC_EDIT_NRML_OFST, nrml_ofst_str); - SetDlgItemText(IDC_EDIT_NRML_SCL, nrml_scl_str); + SetDlgItemText(IDC_EDIT_NRML_OFST, nrml_ofst_str); + SetDlgItemText(IDC_EDIT_NRML_SCL, nrml_scl_str); + SetDlgItemInt(IDC_EDIT_LEDPOS, vis->ldstrp_pos); CComboBox* windowBox = (CComboBox*)GetDlgItem(IDC_COMBO_WINDOW); windowBox->AddString("None"); @@ -81,129 +82,137 @@ BOOL KeyboardVisDlg::OnInitDialog() bkgdModeBox->AddString("None"); bkgdModeBox->AddString("Original"); bkgdModeBox->AddString("Rainbow"); - bkgdModeBox->AddString("Color Wheel"); - bkgdModeBox->AddString("Follow Foreground"); - bkgdModeBox->AddString("White"); - bkgdModeBox->AddString("Red"); - bkgdModeBox->AddString("Orange"); - bkgdModeBox->AddString("Yellow"); - bkgdModeBox->AddString("Green"); - bkgdModeBox->AddString("Cyan"); - bkgdModeBox->AddString("Blue"); - bkgdModeBox->AddString("Purple"); + bkgdModeBox->AddString("Color Wheel"); + bkgdModeBox->AddString("Follow Foreground"); + bkgdModeBox->AddString("White"); + bkgdModeBox->AddString("Red"); + bkgdModeBox->AddString("Orange"); + bkgdModeBox->AddString("Yellow"); + bkgdModeBox->AddString("Green"); + bkgdModeBox->AddString("Cyan"); + bkgdModeBox->AddString("Blue"); + bkgdModeBox->AddString("Purple"); bkgdModeBox->SetCurSel(vis->bkgd_mode); - CComboBox* frgdModeBox = (CComboBox*)GetDlgItem(IDC_COMBO_FRGD_MODE); - frgdModeBox->AddString("White"); - frgdModeBox->AddString("Red"); - frgdModeBox->AddString("Orange"); - frgdModeBox->AddString("Yellow"); - frgdModeBox->AddString("Green"); - frgdModeBox->AddString("Cyan"); - frgdModeBox->AddString("Blue"); - frgdModeBox->AddString("Purple"); - frgdModeBox->AddString("Green/Yellow/Red"); - frgdModeBox->AddString("Green/White/Red"); - frgdModeBox->AddString("Blue/Cyan/White"); - frgdModeBox->AddString("Red/White/Blue"); - frgdModeBox->AddString("Rainbow"); - frgdModeBox->AddString("Rainbow Inverse"); - frgdModeBox->SetCurSel(vis->frgd_mode); - - CComboBox* snglClrModeBox = (CComboBox*)GetDlgItem(IDC_COMBO_SNGL_CLR_MODE); - snglClrModeBox->AddString("None"); - snglClrModeBox->AddString("Follow Foreground"); - snglClrModeBox->AddString("Follow Background"); - snglClrModeBox->AddString("White"); - snglClrModeBox->AddString("Red"); - snglClrModeBox->AddString("Orange"); - snglClrModeBox->AddString("Yellow"); - snglClrModeBox->AddString("Green"); - snglClrModeBox->AddString("Cyan"); - snglClrModeBox->AddString("Blue"); - snglClrModeBox->AddString("Purple"); - snglClrModeBox->SetCurSel(vis->single_color_mode); - - CComboBox* avgModeBox = (CComboBox*)GetDlgItem(IDC_COMBO_AVG_MODE); - avgModeBox->AddString("Binning"); - avgModeBox->AddString("Low Pass"); - avgModeBox->SetCurSel(vis->avg_mode); + CComboBox* frgdModeBox = (CComboBox*)GetDlgItem(IDC_COMBO_FRGD_MODE); + frgdModeBox->AddString("White"); + frgdModeBox->AddString("Red"); + frgdModeBox->AddString("Orange"); + frgdModeBox->AddString("Yellow"); + frgdModeBox->AddString("Green"); + frgdModeBox->AddString("Cyan"); + frgdModeBox->AddString("Blue"); + frgdModeBox->AddString("Purple"); + frgdModeBox->AddString("Green/Yellow/Red"); + frgdModeBox->AddString("Green/White/Red"); + frgdModeBox->AddString("Blue/Cyan/White"); + frgdModeBox->AddString("Red/White/Blue"); + frgdModeBox->AddString("Rainbow"); + frgdModeBox->AddString("Rainbow Inverse"); + frgdModeBox->SetCurSel(vis->frgd_mode); + + CComboBox* snglClrModeBox = (CComboBox*)GetDlgItem(IDC_COMBO_SNGL_CLR_MODE); + snglClrModeBox->AddString("None"); + snglClrModeBox->AddString("Follow Foreground"); + snglClrModeBox->AddString("Follow Background"); + snglClrModeBox->AddString("White"); + snglClrModeBox->AddString("Red"); + snglClrModeBox->AddString("Orange"); + snglClrModeBox->AddString("Yellow"); + snglClrModeBox->AddString("Green"); + snglClrModeBox->AddString("Cyan"); + snglClrModeBox->AddString("Blue"); + snglClrModeBox->AddString("Purple"); + snglClrModeBox->SetCurSel(vis->single_color_mode); + + CComboBox* avgModeBox = (CComboBox*)GetDlgItem(IDC_COMBO_AVG_MODE); + avgModeBox->AddString("Binning"); + avgModeBox->AddString("Low Pass"); + avgModeBox->SetCurSel(vis->avg_mode); + + CComboBox* frflyModeBox = (CComboBox*)GetDlgItem(IDC_COMBO_FRFLY_MODE); + frflyModeBox->AddString("Bottom-Up"); + frflyModeBox->AddString("Upper-Bottom"); + frflyModeBox->AddString("Single Color"); + frflyModeBox->SetCurSel(vis->fireflymode); + + CComboBox* blckwdModeBox = (CComboBox*)GetDlgItem(IDC_COMBO_BLCKWD_MODE); + blckwdModeBox->AddString("EQ Visualizer"); + blckwdModeBox->AddString("Single Color"); + blckwdModeBox->AddString("Bottom-up"); + blckwdModeBox->AddString("Upper-bottom"); + blckwdModeBox->AddString("Mid-to-Side"); + blckwdModeBox->AddString("Side-to-Mid"); + blckwdModeBox->SetCurSel(vis->blkwdwmode); timer = SetTimer(1, 25, NULL); - firstrun = TRUE; + firstrun = TRUE; return TRUE; } -void KeyboardVisDlg::StartMinimized(boolean startmin) +void KeyboardVisDlg::StartMinimized(boolean startmin) { - startminimized = startmin; + startminimized = startmin; } -void KeyboardVisDlg::OnDestroy() +void KeyboardVisDlg::OnDestroy() { - NOTIFYICONDATA Tray; + NOTIFYICONDATA Tray; - Tray.cbSize = sizeof(Tray); - Tray.hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON)); - Tray.hWnd = GetSafeHwnd(); - strcpy(Tray.szTip, "Keyboard Visualizer"); - Tray.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE; - Tray.uID = ID_SYSTEMTRAY; - Tray.uCallbackMessage = WM_TRAYICON_EVENT; + Tray.cbSize = sizeof(Tray); + Tray.hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON)); + Tray.hWnd = GetSafeHwnd(); + strcpy(Tray.szTip, "Keyboard Visualizer"); + Tray.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE; + Tray.uID = ID_SYSTEMTRAY; + Tray.uCallbackMessage = WM_TRAYICON_EVENT; - Shell_NotifyIcon(NIM_DELETE, &Tray); + Shell_NotifyIcon(NIM_DELETE, &Tray); } -void KeyboardVisDlg::OnTimer(UINT nIDEvent) +void KeyboardVisDlg::OnTimer(UINT nIDEvent) { - if (startminimized && firstrun) - { - firstrun = FALSE; - ShowWindow(SW_HIDE); - } - - COLORREF pixels_bgr[64][256]; - - //CreateBitmap uses BGR color layout, convert from RGB - for (int x = 0; x < 256; x++) - { - for (int y = 0; y < 64; y++) - { - pixels_bgr[y][x] = RGB2BGR(vis->pixels[y][x]); - } - } + if (startminimized && firstrun) { + firstrun = FALSE; + ShowWindow(SW_HIDE); + } + + COLORREF pixels_bgr[64][256]; + + //CreateBitmap uses BGR color layout, convert from RGB + for (int x = 0; x < 256; x++) { + for (int y = 0; y < 64; y++) { + pixels_bgr[y][x] = RGB2BGR(vis->pixels[y][x]); + } + } HBITMAP hBitmap = CreateBitmap(256, 64, 1, 32, pixels_bgr); ((CStatic *)GetDlgItem(IDC_IMAGE_VISUALIZATION))->SetBitmap(hBitmap); DeleteObject(hBitmap); } -LRESULT KeyboardVisDlg::OnTrayIconEvent(WPARAM wParam, LPARAM lParam) +LRESULT KeyboardVisDlg::OnTrayIconEvent(WPARAM wParam, LPARAM lParam) { - if ((UINT)wParam != ID_SYSTEMTRAY) - return ERROR_SUCCESS; - - switch ((UINT)lParam) - { - case WM_LBUTTONUP: - { - if (IsWindowVisible()) - { - KillTimer(timer); - ShowWindow(SW_HIDE); - } - else - { - ShowWindow(SW_SHOW); - timer = SetTimer(1, 25, NULL); - } - break; - } - } - - return ERROR_SUCCESS; + if ((UINT)wParam != ID_SYSTEMTRAY) + return ERROR_SUCCESS; + + switch ((UINT)lParam) { + case WM_LBUTTONUP: + { + if (IsWindowVisible()) { + KillTimer(timer); + ShowWindow(SW_HIDE); + } else { + ShowWindow(SW_SHOW); + timer = SetTimer(1, 25, NULL); + } + break; + } + } + + return ERROR_SUCCESS; } BEGIN_MESSAGE_MAP(KeyboardVisDlg, CDialogEx) @@ -219,82 +228,149 @@ BEGIN_MESSAGE_MAP(KeyboardVisDlg, CDialogEx) ON_WM_DESTROY() ON_MESSAGE(WM_TRAYICON_EVENT, OnTrayIconEvent) ON_CBN_SELCHANGE(IDC_COMBO_AVG_MODE, &KeyboardVisDlg::OnCbnSelchangeComboAvgMode) - ON_CBN_SELCHANGE(IDC_COMBO_SNGL_CLR_MODE, &KeyboardVisDlg::OnCbnSelchangeComboSnglClrMode) + ON_CBN_SELCHANGE(IDC_COMBO_SNGL_CLR_MODE, &KeyboardVisDlg::OnCbnSelchangeComboSnglClrMode) + ON_CBN_SELCHANGE(IDC_COMBO_FRFLY_MODE, &KeyboardVisDlg::OnCbnSelchangeComboFireflyMode) + ON_CBN_SELCHANGE(IDC_COMBO_BLCKWD_MODE, &KeyboardVisDlg::OnCbnSelchangeComboBlackwidowMode) ON_EN_CHANGE(IDC_EDIT_NRML_OFST, &KeyboardVisDlg::OnEnChangedEditNrmlOfst) ON_EN_CHANGE(IDC_EDIT_NRML_SCL, &KeyboardVisDlg::OnEnChangedEditNrmlScl) + ON_EN_CHANGE(IDC_EDIT_LEDPOS, &KeyboardVisDlg::OnEnChangeEditLEDPos) + ON_BN_CLICKED(IDC_SAVE_BTN, &KeyboardVisDlg::OnBnSaveClicked) END_MESSAGE_MAP() -void KeyboardVisDlg::OnEnChangeEditAmplitude() +void KeyboardVisDlg::OnEnChangeEditAmplitude() { - vis->amplitude = GetDlgItemInt(IDC_EDIT_AMPLITUDE, 0, 0); + int selected = GetDlgItemInt(IDC_EDIT_AMPLITUDE, 0, 0); + vis->amplitude = selected; + vis->appsettings.amplitude = selected; } -void KeyboardVisDlg::OnEnChangeEditBackgroundBrightness() +void KeyboardVisDlg::OnEnChangeEditBackgroundBrightness() { - vis->bkgd_bright = (int)((GetDlgItemInt(IDC_EDIT_BACKGROUND_BRIGHTNESS, 0, 0) / 100.0f) * 255.0f); + int selected = (int)((GetDlgItemInt(IDC_EDIT_BACKGROUND_BRIGHTNESS, 0, 0) / 100.0f) * 255.0f); + vis->bkgd_bright = selected; + vis->appsettings.bkgd_bright = selected; } -void KeyboardVisDlg::OnCbnSelchangeComboWindow() +void KeyboardVisDlg::OnCbnSelchangeComboWindow() { - vis->window_mode = ((CComboBox*)GetDlgItem(IDC_COMBO_WINDOW))->GetCurSel(); + int selected = ((CComboBox*)GetDlgItem(IDC_COMBO_WINDOW))->GetCurSel(); + vis->window_mode = selected; + vis->appsettings.window_mode = selected; } -void KeyboardVisDlg::OnEnChangeEditAverageSize() +void KeyboardVisDlg::OnEnChangeEditAverageSize() { - vis->avg_size = (int)GetDlgItemInt(IDC_EDIT_AVERAGE_SIZE, 0, 0); + int selected = (int)GetDlgItemInt(IDC_EDIT_AVERAGE_SIZE, 0, 0); + vis->avg_size = selected; + vis->appsettings.avg_size = selected; } -void KeyboardVisDlg::OnCbnSelchangeComboBkgdMode() +void KeyboardVisDlg::OnCbnSelchangeComboBkgdMode() { - vis->bkgd_mode = ((CComboBox*)GetDlgItem(IDC_COMBO_BKGD_MODE))->GetCurSel(); + int selected = ((CComboBox*)GetDlgItem(IDC_COMBO_BKGD_MODE))->GetCurSel(); + vis->bkgd_mode = selected; + vis->appsettings.bkgd_mode = selected; } -void KeyboardVisDlg::OnEnChangeEditDecay() +void KeyboardVisDlg::OnEnChangeEditDecay() { - vis->decay = (int)GetDlgItemInt(IDC_EDIT_DECAY, 0, 0); + int selected = (int)GetDlgItemInt(IDC_EDIT_DECAY, 0, 0); + vis->decay = selected; + vis->appsettings.decay = selected; } -void KeyboardVisDlg::OnEnChangeEditDelay() +void KeyboardVisDlg::OnEnChangeEditDelay() { - vis->delay = (int)GetDlgItemInt(IDC_EDIT_DELAY, 0, 0); + int selected = (int)GetDlgItemInt(IDC_EDIT_DELAY, 0, 0); + vis->delay = selected; + vis->appsettings.delay = selected; } -void KeyboardVisDlg::OnCbnSelchangeComboFrgdMode() +void KeyboardVisDlg::OnCbnSelchangeComboFrgdMode() { - vis->frgd_mode = ((CComboBox*)GetDlgItem(IDC_COMBO_FRGD_MODE))->GetCurSel(); + int selected = ((CComboBox*)GetDlgItem(IDC_COMBO_FRGD_MODE))->GetCurSel(); + vis->frgd_mode = selected; + vis->appsettings.frgd_mode = selected; } -void KeyboardVisDlg::OnCbnSelchangeComboAvgMode() +void KeyboardVisDlg::OnCbnSelchangeComboAvgMode() { - vis->avg_mode = ((CComboBox*)GetDlgItem(IDC_COMBO_AVG_MODE))->GetCurSel(); + int selected = ((CComboBox*)GetDlgItem(IDC_COMBO_AVG_MODE))->GetCurSel(); + vis->avg_mode = selected; + vis->appsettings.avg_mode = selected; } -void KeyboardVisDlg::OnCbnSelchangeComboSnglClrMode() +void KeyboardVisDlg::OnCbnSelchangeComboFireflyMode() +{ + int selected = ((CComboBox*)GetDlgItem(IDC_COMBO_FRFLY_MODE))->GetCurSel(); + vis->fireflymode = selected; + vis->appsettings.fireflymode = selected; + vis->rkb.updatedSettings(&vis->appsettings); +} + + +void KeyboardVisDlg::OnCbnSelchangeComboBlackwidowMode() +{ + int selected = ((CComboBox*)GetDlgItem(IDC_COMBO_BLCKWD_MODE))->GetCurSel(); + vis->blkwdwmode = selected; + vis->appsettings.blkwdwmode = selected; + vis->rkb.updatedSettings(&vis->appsettings); +} + + +void KeyboardVisDlg::OnCbnSelchangeComboSnglClrMode() +{ + int selected = ((CComboBox*)GetDlgItem(IDC_COMBO_SNGL_CLR_MODE))->GetCurSel(); + vis->single_color_mode = selected; + vis->appsettings.single_color_mode = selected; +} + +void KeyboardVisDlg::OnEnChangedEditNrmlOfst() +{ + char val[64]; + GetDlgItemText(IDC_EDIT_NRML_OFST, (LPTSTR)&val, 64); + vis->nrml_ofst = strtod(val, NULL); + vis->appsettings.nrml_ofst = strtod(val, NULL); + vis->SetNormalization(vis->nrml_ofst, vis->nrml_scl); +} + +void KeyboardVisDlg::OnEnChangedEditNrmlScl() { - vis->single_color_mode = ((CComboBox*)GetDlgItem(IDC_COMBO_SNGL_CLR_MODE))->GetCurSel(); + char val[64]; + GetDlgItemText(IDC_EDIT_NRML_SCL, (LPTSTR)&val, 64); + vis->nrml_scl = strtod(val, NULL); + vis->appsettings.nrml_scl = strtod(val, NULL); + vis->SetNormalization(vis->nrml_ofst, vis->nrml_scl); } -void KeyboardVisDlg::OnEnChangedEditNrmlOfst() +void KeyboardVisDlg::OnEnChangeEditLEDPos() { - char val[64]; - GetDlgItemText(IDC_EDIT_NRML_OFST, (LPTSTR)&val, 64); - vis->nrml_ofst = strtod(val, NULL); - vis->SetNormalization(vis->nrml_ofst, vis->nrml_scl); + bool changed = false; + int temp = (int)GetDlgItemInt(IDC_EDIT_LEDPOS, 0, 0); + if (temp > 255) { + temp = 255; + changed = true; + } else if (temp < 0) { + temp = 0; + changed = true; + } + + if (changed) + SetDlgItemInt(IDC_EDIT_LEDPOS, temp, 0); + vis->ldstrp_pos = temp; + vis->appsettings.ldstrp_pos = temp; } -void KeyboardVisDlg::OnEnChangedEditNrmlScl() +void KeyboardVisDlg::OnBnSaveClicked() { - char val[64]; - GetDlgItemText(IDC_EDIT_NRML_SCL, (LPTSTR)&val, 64); - vis->nrml_scl = strtod(val, NULL); - vis->SetNormalization(vis->nrml_ofst, vis->nrml_scl); + vis->saveAppSettings(); } \ No newline at end of file diff --git a/KeyboardVisualizerVC/KeyboardVisDlg.h b/KeyboardVisualizerVC/KeyboardVisDlg.h index 3ed0e75..38f6450 100644 --- a/KeyboardVisualizerVC/KeyboardVisDlg.h +++ b/KeyboardVisualizerVC/KeyboardVisDlg.h @@ -41,9 +41,13 @@ class KeyboardVisDlg : public CDialogEx afx_msg void OnCbnSelchangeComboBkgdMode(); afx_msg void OnEnChangeEditDecay(); afx_msg void OnEnChangeEditDelay(); - afx_msg void OnCbnSelchangeComboFrgdMode(); - afx_msg void OnCbnSelchangeComboAvgMode(); - afx_msg void OnCbnSelchangeComboSnglClrMode(); - afx_msg void OnEnChangedEditNrmlOfst(); - afx_msg void OnEnChangedEditNrmlScl(); + afx_msg void OnCbnSelchangeComboFrgdMode(); + afx_msg void OnCbnSelchangeComboAvgMode(); + afx_msg void OnCbnSelchangeComboSnglClrMode(); + afx_msg void OnEnChangedEditNrmlOfst(); + afx_msg void OnEnChangedEditNrmlScl(); + afx_msg void OnBnSaveClicked(); + afx_msg void OnEnChangeEditLEDPos(); + afx_msg void OnCbnSelchangeComboFireflyMode(); + afx_msg void OnCbnSelchangeComboBlackwidowMode(); }; diff --git a/KeyboardVisualizerVC/KeyboardVisualizerVC.vcxproj b/KeyboardVisualizerVC/KeyboardVisualizerVC.vcxproj index 4f345ca..ef5e8de 100644 --- a/KeyboardVisualizerVC/KeyboardVisualizerVC.vcxproj +++ b/KeyboardVisualizerVC/KeyboardVisualizerVC.vcxproj @@ -172,6 +172,7 @@ + @@ -184,6 +185,7 @@ + diff --git a/KeyboardVisualizerVC/RazerChroma.cpp b/KeyboardVisualizerVC/RazerChroma.cpp index a2bbe52..b6a6dfd 100644 --- a/KeyboardVisualizerVC/RazerChroma.cpp +++ b/KeyboardVisualizerVC/RazerChroma.cpp @@ -1,7 +1,10 @@ #include "RazerChroma.h" - +#include "Visualizer.h" #include +//Settings +AppSettings appset; + //Index lists for BlackWidow int BlackWidowXIndex[22]; int BlackWidowYIndex[6]; @@ -33,7 +36,6 @@ RazerChroma::RazerChroma() { } - RazerChroma::~RazerChroma() { if (hModule) @@ -46,6 +48,10 @@ RazerChroma::~RazerChroma() } } +void RazerChroma::updatedSettings(AppSettings *settings) { + appset = *settings; +} + void RazerChroma::Initialize() { @@ -200,16 +206,67 @@ bool RazerChroma::SetLEDs(COLORREF pixels[64][256]) //Blackwidow Chroma ChromaSDK::Keyboard::CUSTOM_EFFECT_TYPE BlackWidowEffect; - for (int x = 0; x < 22; x++) - { - for (int y = 0; y < 6; y++) - { - BlackWidowEffect.Color[y][x] = (pixels[BlackWidowYIndex[y]][BlackWidowXIndex[x]] & 0x00FFFFFF); - } - } - - //Set Razer "Three Headed Snake" logo to the background color of the 11th column - BlackWidowEffect.Color[0][20] = pixels[3][11 * (256 / 22)]; + switch (appset.blkwdwmode) { + case 0: + // Normal visualizer mode + for (int x = 0; x < 22; x++) { + for (int y = 0; y < 6; y++) { + BlackWidowEffect.Color[y][x] = (pixels[BlackWidowYIndex[y]][BlackWidowXIndex[x]] & 0x00FFFFFF); + } + } + + //Set Razer "Three Headed Snake" logo to the background color of the 11th column + BlackWidowEffect.Color[0][20] = pixels[3][11 * (256 / 22)]; + break; + case 1: + // Single color mode + for (int x = 0; x < 22; x++) { + for (int y = 0; y < 6; y++) { + BlackWidowEffect.Color[y][x] = (pixels[3][0] & 0x00FFFFFF); + } + } + BlackWidowEffect.Color[0][20] = pixels[3][0]; + break; + case 2: + // Bottom Up color mode + for (int x = 0; x < 22; x++) { + for (int y = 0; y < 6; y++) { + BlackWidowEffect.Color[y][x] = (pixels[0][FireflyIndex[y]] & 0x00FFFFFF); + } + } + BlackWidowEffect.Color[0][20] = pixels[3][0]; + break; + case 3: + // Upper Bottom color mode + for (int x = 0; x < 22; x++) { + for (int y = 0; y < 6; y++) { + BlackWidowEffect.Color[y][x] = (pixels[0][FireflyIndex[y + 9]] & 0x00FFFFFF); + } + } + BlackWidowEffect.Color[0][20] = pixels[3][0]; + break; + case 4: + // Mid to side color mode + for (int x = 0; x < 22; x++) { + for (int y = 0; y < 6; y++) { + BlackWidowEffect.Color[y][x] = (pixels[0][BlackWidowXIndex[x + 1]] & 0x00FFFFFF); + } + } + BlackWidowEffect.Color[0][20] = pixels[3][0]; + break; + case 5: + // Side to mid color mode + for (int x = 0; x < 22; x++) { + for (int y = 0; y < 6; y++) { + if (x <= 11) + BlackWidowEffect.Color[y][x] = (pixels[0][BlackWidowXIndex[x + 1 + 11]] & 0x00FFFFFF); + else if (x > 11) + BlackWidowEffect.Color[y][x] = (pixels[0][BlackWidowXIndex[x + 2 - 11]] & 0x00FFFFFF); + } + } + BlackWidowEffect.Color[0][20] = pixels[3][0]; + break; + } CreateEffect(ChromaSDK::BLACKWIDOW_CHROMA, ChromaSDK::CHROMA_CUSTOM, &BlackWidowEffect, NULL); @@ -251,10 +308,29 @@ bool RazerChroma::SetLEDs(COLORREF pixels[64][256]) //Firefly Chroma ChromaSDK::Mousepad::CUSTOM_EFFECT_TYPE FireflyEffect = {}; - for (int x = 0; x < 15; x++) - { - FireflyEffect.Color[x] = pixels[0][FireflyIndex[x]]; - } + switch (appset.fireflymode) { + case 0: + // Normal bottom-up led strip mode + for (int x = 0; x < 15; x++) + FireflyEffect.Color[x] = pixels[0][FireflyIndex[x]]; + break; + case 1: + // Normal upper-bottom led strip mode + for (int x = 0; x < 15; x++) { + if (x == 7) + FireflyEffect.Color[x] = pixels[0][20]; + else if (x < 7) + FireflyEffect.Color[x] = pixels[0][FireflyIndex[x + 8]]; + else + FireflyEffect.Color[x] = pixels[0][FireflyIndex[x - 8]]; + } + break; + case 2: + // Single color mode + for (int x = 0; x < 15; x++) + FireflyEffect.Color[x] = pixels[3][0]; + break; + } CreateEffect(ChromaSDK::FIREFLY_CHROMA, ChromaSDK::CHROMA_CUSTOM, &FireflyEffect, NULL); diff --git a/KeyboardVisualizerVC/RazerChroma.h b/KeyboardVisualizerVC/RazerChroma.h index 2ce5b17..ac954ce 100644 --- a/KeyboardVisualizerVC/RazerChroma.h +++ b/KeyboardVisualizerVC/RazerChroma.h @@ -5,6 +5,7 @@ #include "RzChromaSDKDefines.h" #include "RzChromaSDKTypes.h" #include "RzErrors.h" +#include "AppSettings.h" using namespace ChromaSDK::Keyboard; @@ -25,10 +26,12 @@ class RazerChroma { public: RazerChroma(); + RazerChroma(AppSettings*); ~RazerChroma(); void Initialize(); bool SetLEDs(COLORREF pixels[64][256]); + void updatedSettings(AppSettings*); private: HMODULE hModule = NULL; diff --git a/KeyboardVisualizerVC/Resource.aps b/KeyboardVisualizerVC/Resource.aps new file mode 100644 index 0000000..940148b Binary files /dev/null and b/KeyboardVisualizerVC/Resource.aps differ diff --git a/KeyboardVisualizerVC/Resource.rc b/KeyboardVisualizerVC/Resource.rc index b8b634a..5a5f46e 100644 Binary files a/KeyboardVisualizerVC/Resource.rc and b/KeyboardVisualizerVC/Resource.rc differ diff --git a/KeyboardVisualizerVC/Visualizer.cpp b/KeyboardVisualizerVC/Visualizer.cpp index 83decc1..3c5d35a 100644 --- a/KeyboardVisualizerVC/Visualizer.cpp +++ b/KeyboardVisualizerVC/Visualizer.cpp @@ -1,8 +1,4 @@ #include "Visualizer.h" -#include "RazerChroma.h" -#include "CorsairKeyboard.h" -#include "MSIKeyboard.h" -#include "LEDStrip.h" //WASAPI includes #include @@ -12,12 +8,6 @@ #include #include -RazerChroma rkb; -CorsairKeyboard ckb; -MSIKeyboard mkb; -std::vector str; -std::vector xmas; - //WASAPI objects IMMDeviceEnumerator *pMMDeviceEnumerator; IMMDevice *pMMDevice; @@ -91,33 +81,49 @@ void Visualizer::Initialize() pAudioClient->GetService(__uuidof(IAudioCaptureClient), (void**)&pAudioCaptureClient); pAudioClient->Start(); + + initializeAppSettings(); - rkb.Initialize(); + rkb.Initialize(); ckb.Initialize(); mkb.Initialize(); - 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; - single_color_mode = 1; + //Passing settings + rkb.updatedSettings(&appsettings); hanning(win_hanning, 256); hamming(win_hamming, 256); blackman(win_blackman, 256); - nrml_ofst = 0.04f; - nrml_scl = 0.5f; - SetNormalization(nrml_ofst, nrml_scl); } +void Visualizer::saveAppSettings() { + appsettings.saveSettings(); +} + +void Visualizer::initializeAppSettings() { + appsettings.loadSettings(); + + rememberSettingsOnExit = appsettings.rememberSettingsOnExit; + amplitude = appsettings.amplitude; + avg_mode = appsettings.avg_mode; + avg_size = appsettings.avg_size; + bkgd_step = appsettings.bkgd_step; + bkgd_bright = appsettings.bkgd_bright; + bkgd_mode = appsettings.bkgd_mode; + delay = appsettings.delay; + window_mode = appsettings.window_mode; + decay = appsettings.decay; + frgd_mode = appsettings.frgd_mode; + single_color_mode = appsettings.single_color_mode; + ldstrp_pos = appsettings.ldstrp_pos; + fireflymode = appsettings.fireflymode; + blkwdwmode = appsettings.blkwdwmode; + nrml_ofst = appsettings.nrml_ofst; + nrml_scl = appsettings.nrml_scl; +} + void Visualizer::SetNormalization(float offset, float scale) { for (int i = 0; i < 256; i++) @@ -655,18 +661,19 @@ void Visualizer::VisThread() } } + //Draw LED Strip if (y < 2) { if (x < 128) { - if ((fft[5] - 0.05f) >((1 / 128.0f)*(127-x))) + if ((fft[ldstrp_pos] - 0.05f) >((1 / 128.0f)*(127-x))) { pixels[y][x] = GetAmplitudeColor(x, 128, 255); } } else { - if ((fft[5] - 0.05f) >((1 / 128.0f)*((x-128)))) + if ((fft[ldstrp_pos] - 0.05f) >((1 / 128.0f)*((x-128)))) { pixels[y][x] = GetAmplitudeColor(127-(x-128), 128, 255); } @@ -676,7 +683,7 @@ void Visualizer::VisThread() //Draw brightness based visualizer for single LED devices if (y == 3) { - float brightness = fft[5] * 255; + float brightness = fft[ldstrp_pos] * 255; switch (single_color_mode) { //None @@ -737,6 +744,8 @@ void Visualizer::VisThread() } } + drawLEDStripLine(); + //Increment background step bkgd_step++; @@ -744,6 +753,12 @@ void Visualizer::VisThread() } } +void Visualizer::drawLEDStripLine() { + for (int y = 3; y < 64; y++) { + pixels[y][ldstrp_pos] = RGB(255, 0, 0); + } +} + void Visualizer::RazerChromaUpdateThread() { while (rkb.SetLEDs(pixels)) diff --git a/KeyboardVisualizerVC/Visualizer.h b/KeyboardVisualizerVC/Visualizer.h index 63f41d5..9d40b2c 100644 --- a/KeyboardVisualizerVC/Visualizer.h +++ b/KeyboardVisualizerVC/Visualizer.h @@ -4,6 +4,11 @@ #include #include "chuck_fft.h" #include "hsv.h" +#include "AppSettings.h" +#include "RazerChroma.h" +#include "CorsairKeyboard.h" +#include "LEDStrip.h" +#include "MSIKeyboard.h" #include #include @@ -22,6 +27,13 @@ class Visualizer //Visualizer Thread void VisThread(); + //for visibility + RazerChroma rkb; + CorsairKeyboard ckb; + MSIKeyboard mkb; + std::vector str; + std::vector xmas; + //Keyboard Update Thread void RazerChromaUpdateThread(); void CorsairKeyboardUpdateThread(); @@ -41,6 +53,11 @@ class Visualizer //Compute normalization line void SetNormalization(float offset, float scale); + //Visualizer settings + AppSettings appsettings; + void initializeAppSettings(); + void saveAppSettings(); + //Calculated FFT float fft[256]; @@ -69,6 +86,17 @@ class Visualizer //Foreground Variables int frgd_mode; + //Settings + bool rememberSettingsOnExit; + + //LED Strip offset position and indicator fucntion + int ldstrp_pos; + void drawLEDStripLine(); + + //Device specific display mode + int fireflymode; + int blkwdwmode; + private: //Background Step int bkgd_step; diff --git a/KeyboardVisualizerVC/resource.h b/KeyboardVisualizerVC/resource.h index fc46d52..0190c9a 100644 Binary files a/KeyboardVisualizerVC/resource.h and b/KeyboardVisualizerVC/resource.h differ diff --git a/KeyboardVisualizerVC/settings.txt b/KeyboardVisualizerVC/settings.txt new file mode 100644 index 0000000..ba929df --- /dev/null +++ b/KeyboardVisualizerVC/settings.txt @@ -0,0 +1,17 @@ +1 +150 +0 +6 +0 +160 +0 +25 +1 +90 +8 +10 +0.04 +0.5 +1 +2 +2 diff --git a/README.md b/README.md index fcf4ef2..8c187a0 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ https://drive.google.com/folderview?id=0B1Fq0HEJolPtWDNsNV93NVl5Vms&usp=sharing * Razer Chroma Keyboards - - BlackWidow Chroma (spectrograph) + - BlackWidow Chroma (spectrograph, single color, bar, reverse bar, mid-to-side bar, side-to-mid bar) - BlackWidow Chroma Tournament Edition (spectrograph) - DeathStalker Chroma (horizontal bar) @@ -31,7 +31,7 @@ https://drive.google.com/folderview?id=0B1Fq0HEJolPtWDNsNV93NVl5Vms&usp=sharing - Kraken 7.1 Chroma (single color) Mouse Mats - - Firefly (bar) + - Firefly (single color, bar, reverse bar) * Corsair RGB