Commit 650ddc14 authored by Adam Honse's avatar Adam Honse

Remove visual studio project and get the Qt project to build on Windows. ...

Remove visual studio project and get the Qt project to build on Windows.  Remove Arduino sketches, these will be moved elsewhere
parent b50b9831
......@@ -11,7 +11,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = KeyboardVisualizer
TEMPLATE = app
LIBS += -lopenal
#LIBS += -lopenal
DISTFILES +=
......@@ -56,3 +56,29 @@ RESOURCES += \
FORMS += \
KeyboardVisualizerQT/keyboardvisualizer.ui
#-----------------------------------------------
# Windows specific project configuration
#-----------------------------------------------
win32:contains(QMAKE_TARGET.arch, x86_64) {
LIBS += \
-lws2_32 \
-lole32 \
}
win32:contains(QMAKE_TARGET.arch, x86) {
LIBS += \
-lws2_32 \
-lole32 \
}
win32:DEFINES -= \
UNICODE
win32:DEFINES += \
_MBCS \
WIN32 \
_CRT_SECURE_NO_WARNINGS \
_WINSOCK_DEPRECATED_NO_WARNINGS \
WIN32_LEAN_AND_MEAN
......@@ -107,10 +107,10 @@ void Visualizer::InitAudioDeviceList()
isCapture.clear();
//Enumerate default audio output
pMMDeviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pEndpoint);
audio_devices.push_back("Default Loopback Device");
pMMDevices.push_back(pEndpoint);
isCapture.push_back(false);
//pMMDeviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pEndpoint);
//audio_devices.push_back("Default Loopback Device");
//pMMDevices.push_back(pEndpoint);
//isCapture.push_back(false);
//Enumerate audio outputs
pMMDeviceEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &pMMDeviceCollection);
......@@ -360,17 +360,17 @@ void Visualizer::SaveSettings()
}
//Get file path in executable directory
#ifdef WIN32
GetModuleFileName(NULL, filename, 2048);
strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str());
strcat(filename, "\\settings.txt");
#else
char arg1[64];
snprintf(arg1, 64, "/proc/%d/exe", getpid());
readlink(arg1, filename, 1024);
strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str());
strcat(filename, "/settings.txt");
#endif
//#ifdef WIN32
// GetModuleFileName(NULL, filename, 2048);
// strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str());
// strcat(filename, "\\settings.txt");
//#else
// char arg1[64];
// snprintf(arg1, 64, "/proc/%d/exe", getpid());
// readlink(arg1, filename, 1024);
// strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str());
// strcat(filename, "/settings.txt");
//#endif
//Open settings file
outfile.open(filename);
......@@ -762,7 +762,7 @@ void Visualizer::Shutdown()
}
}
void DrawSolidColor(int bright, COLORREF color, vis_pixels *pixels)
void DrawSolidColor(int bright, RGBColor color, vis_pixels *pixels)
{
bright = (int)(bright * (255.0f / 100.0f));
for (int x = 0; x < 256; x++)
......@@ -774,7 +774,7 @@ void DrawSolidColor(int bright, COLORREF color, vis_pixels *pixels)
}
}
void DrawVerticalBars(int bright, COLORREF * colors, int num_colors, vis_pixels *pixels)
void DrawVerticalBars(int bright, RGBColor * colors, int num_colors, vis_pixels *pixels)
{
bright = (int)(bright * (255.0f / 100.0f));
for (int x = 0; x < 256; x++)
......@@ -787,7 +787,7 @@ void DrawVerticalBars(int bright, COLORREF * colors, int num_colors, vis_pixels
}
}
void DrawHorizontalBars(int bright, COLORREF * colors, int num_colors, vis_pixels *pixels)
void DrawHorizontalBars(int bright, RGBColor * colors, int num_colors, vis_pixels *pixels)
{
bright = (int)(bright * (255.0f / 100.0f));
for (int x = 0; x < 256; x++)
......@@ -867,7 +867,7 @@ void DrawSpectrumCycle(int bright, float bkgd_step, vis_pixels *pixels)
{
bright = (int)(bright * (255.0f / 100.0f));
hsv_t hsv2 = { (int)bkgd_step, 255, (unsigned char)bright };
COLORREF color = hsv2rgb(&hsv2);
RGBColor color = hsv2rgb(&hsv2);
for (int x = 0; x < 256; x++)
{
......@@ -880,7 +880,7 @@ void DrawSpectrumCycle(int bright, float bkgd_step, vis_pixels *pixels)
void DrawSinusoidalCycle(int bright, float bkgd_step, vis_pixels *pixels)
{
COLORREF color;
RGBColor color;
bright = (int)(bright * (255.0f / 100.0f));
int red = (int)(127 * (sin(((((int)(((360 / 255.0f)) - bkgd_step) % 360) / 360.0f) * 2 * 3.14f)) + 1));
int grn = (int)(127 * (sin(((((int)(((360 / 255.0f)) - bkgd_step) % 360) / 360.0f) * 2 * 3.14f) - (6.28f / 3)) + 1));
......@@ -940,7 +940,7 @@ void Visualizer::DrawSingleColorForeground(float amplitude, vis_pixels *fg_pixel
}
}
void DrawSingleColorStatic(float amplitude, COLORREF in_color, vis_pixels *out_pixels)
void DrawSingleColorStatic(float amplitude, RGBColor in_color, vis_pixels *out_pixels)
{
if (amplitude >= 1.0f)
{
......@@ -1000,42 +1000,42 @@ void Visualizer::DrawPattern(VISUALIZER_PATTERN pattern, int bright, vis_pixels
case VISUALIZER_PATTERN_STATIC_GREEN_YELLOW_RED:
{
COLORREF colors[] = { 0x0000FF00, 0x0000FFFF, 0x000000FF };
RGBColor colors[] = { 0x0000FF00, 0x0000FFFF, 0x000000FF };
DrawHorizontalBars(bright, colors, 3, pixels);
}
break;
case VISUALIZER_PATTERN_STATIC_GREEN_WHITE_RED:
{
COLORREF colors[] = { 0x0000FF00, 0x00FFFFFF, 0x000000FF };
RGBColor colors[] = { 0x0000FF00, 0x00FFFFFF, 0x000000FF };
DrawHorizontalBars(bright, colors, 3, pixels);
}
break;
case VISUALIZER_PATTERN_STATIC_BLUE_CYAN_WHITE:
{
COLORREF colors[] = { 0x00FF0000, 0x00FFFF00, 0x00FFFFFF };
RGBColor colors[] = { 0x00FF0000, 0x00FFFF00, 0x00FFFFFF };
DrawHorizontalBars(bright, colors, 3, pixels);
}
break;
case VISUALIZER_PATTERN_STATIC_RED_WHITE_BLUE:
{
COLORREF colors[] = { 0x000000FF, 0x00FFFFFF, 0x00FF0000 };
RGBColor colors[] = { 0x000000FF, 0x00FFFFFF, 0x00FF0000 };
DrawHorizontalBars(bright, colors, 3, pixels);
}
break;
case VISUALIZER_PATTERN_STATIC_RAINBOW:
{
COLORREF colors[] = { 0x000000FF, 0x0000FFFF, 0x0000FF00, 0x00FFFF00, 0x00FF0000, 0x00FF00FF };
RGBColor colors[] = { 0x000000FF, 0x0000FFFF, 0x0000FF00, 0x00FFFF00, 0x00FF0000, 0x00FF00FF };
DrawHorizontalBars(bright, colors, 6, pixels);
}
break;
case VISUALIZER_PATTERN_STATIC_RAINBOW_INVERSE:
{
COLORREF colors[] = { 0x00FF00FF, 0x00FF0000, 0x00FFFF00, 0x0000FF00, 0x0000FFFF, 0x000000FF };
RGBColor colors[] = { 0x00FF00FF, 0x00FF0000, 0x00FFFF00, 0x0000FF00, 0x0000FFFF, 0x000000FF };
DrawHorizontalBars(bright, colors, 6, pixels);
}
break;
......@@ -1475,4 +1475,4 @@ void Visualizer::LEDUpdateThread( unsigned int q )
Sleep(delay);
}
}
\ No newline at end of file
}
......@@ -7,9 +7,10 @@
#ifndef VISUALIZER_DEFINES_H
#define VISUALIZER_DEFINES_H
#include "RGBController.h"
#ifdef WIN32
#ifndef _WINDOWS_
#include "..\KeyboardVisualizerVC\stdafx.h"
#endif
#else
//Includes for non-Windows builds
......@@ -136,7 +137,7 @@ const char * const visualizer_single_color_labels[VISUALIZER_NUM_SINGLE_COLOR] =
typedef struct
{
COLORREF pixels[64][256];
RGBColor pixels[64][256];
} vis_pixels;
#endif
......@@ -30,12 +30,17 @@
#define MIN3(a,b,c) MIN((a), MIN((b), (c)))
#define MAX3(a,b,c) MAX((a), MAX((b), (c)))
#define RGBGetRValue(rgb) (rgb & 0x000000FF)
#define RGBGetGValue(rgb) ((rgb >> 8) & 0x000000FF)
#define RGBGetBValue(rgb) ((rgb >> 16) & 0x000000FF)
void rgb2hsv(COLORREF rgb, hsv_t* hsv)
#define ToRGBColor(r, g, b) ((b << 16) | (g << 8) | (r))
void rgb2hsv(unsigned int rgb, hsv_t* hsv)
{
int r = GetRValue(rgb);
int g = GetGValue(rgb);
int b = GetBValue(rgb);
int r = RGBGetRValue(rgb);
int g = RGBGetGValue(rgb);
int b = RGBGetBValue(rgb);
int m = MIN3(r, g, b);
int M = MAX3(r, g, b);
int delta = M - m;
......@@ -69,9 +74,11 @@ void rgb2hsv(COLORREF rgb, hsv_t* hsv)
hsv->value = M;
}
COLORREF hsv2rgb(hsv_t* hsv)
unsigned int hsv2rgb(hsv_t* hsv)
{
BYTE r, g, b;
unsigned char r = 0;
unsigned char g = 0;
unsigned char b = 0;
if (hsv->saturation == 0) {
r = g = b = hsv->value;
......@@ -101,7 +108,7 @@ COLORREF hsv2rgb(hsv_t* hsv)
}
}
return RGB(r, g, b);
return ToRGBColor(r, g, b);
}
......
......@@ -24,21 +24,19 @@
#ifndef HSV_H
#define HSV_H
#include "VisualizerDefines.h"
#define HUE_DEGREE 1
typedef struct hsv_tag hsv_t;
struct hsv_tag {
int hue; /* 0 ... (360*HUE_DEGREE - 1) */
BYTE saturation; /* 0 ... 255 */
BYTE value; /* 0 ... 255 */
unsigned int hue; /* 0 ... (360*HUE_DEGREE - 1) */
unsigned char saturation; /* 0 ... 255 */
unsigned char value; /* 0 ... 255 */
};
void rgb2hsv(COLORREF rgb, hsv_t* hsv);
void rgb2hsv(unsigned int rgb, hsv_t* hsv);
COLORREF hsv2rgb(hsv_t* hsv);
unsigned int hsv2rgb(hsv_t* hsv);
#endif /* HSV_H */
......@@ -3,7 +3,10 @@
#include "KeyboardVisualizerCommon/Visualizer.h"
#include "KeyboardVisualizerCommon/VisualizerDefines.h"
#ifndef WIN32
#include <unistd.h>
#endif
#include <fstream>
#include <iostream>
#include <string>
......@@ -156,7 +159,7 @@ bool parse_command_line(int argc, char *argv[])
char* argument;
char* value;
argument = strtok_r(argv[i], "=", &value);
//argument = strtok_r(argv[i], "=", &value);
if (strcmp(argument, "help") == 0)
{
......@@ -271,7 +274,7 @@ void parse_settings_file(char * filename)
value = (char *)line.c_str();
argument = strtok_r(value, "=", &value);
//argument = strtok_r(value, "=", &value);
parse_argument_string(argument, value);
}
......@@ -289,15 +292,15 @@ int main(int argc, char *argv[])
vis.Initialize();
//Get file path in executable directory
char filename[2048];
//char filename[2048];
//GetModuleFileName(NULL, filename, 2048);
char arg1[64];
snprintf(arg1, 64, "/proc/%d/exe", getpid());
readlink(arg1, filename, 1024);
strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str());
//char arg1[64];
//snprintf(arg1, 64, "/proc/%d/exe", getpid());
//readlink(arg1, filename, 1024);
//strcpy(filename, std::string(filename).substr(0, std::string(filename).find_last_of("\\/")).c_str());
//strcat(filename, "\\settings.txt");
strcat(filename, "/settings.txt");
parse_settings_file(filename);
//strcat(filename, "/settings.txt");
//parse_settings_file(filename);
//Parse Command Line
if (!parse_command_line(argc, argv))
......

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KeyboardVisualizerVC", "KeyboardVisualizerVC\KeyboardVisualizerVC.vcxproj", "{11970D07-B63F-487B-AA02-2EDCAD2F71A0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{11970D07-B63F-487B-AA02-2EDCAD2F71A0}.Debug|x86.ActiveCfg = Debug|Win32
{11970D07-B63F-487B-AA02-2EDCAD2F71A0}.Debug|x86.Build.0 = Debug|Win32
{11970D07-B63F-487B-AA02-2EDCAD2F71A0}.Release|x86.ActiveCfg = Release|Win32
{11970D07-B63F-487B-AA02-2EDCAD2F71A0}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
/*---------------------------------------------------------*\
| Processing Code for Keyboard Visualizer Dialog |
| |
| Adam Honse (calcprogrammer1@gmail.com), 12/11/2016 |
\*---------------------------------------------------------*/
#include "stdafx.h"
#include "KeyboardVisDlg.h"
#include "afxdialogex.h"
#include "resource.h"
#include <process.h>
// KeyboardVisDlg dialog
// tray icon ID
#define ID_SYSTEMTRAY 0x1000
// custom message ID
#define WM_TRAYICON_EVENT (WM_APP + 1)
IMPLEMENT_DYNAMIC(KeyboardVisDlg, CDialogEx)
Visualizer* vis;
boolean startminimized;
boolean firstrun;
NOTIFYICONDATA Tray;
KeyboardVisDlg::KeyboardVisDlg(CWnd* pParent)
: CDialogEx(IDD_KEYBOARD_VISUALIZER_DLG, pParent)
{
startminimized = false;
}
void KeyboardVisDlg::SetVisualizer(Visualizer* v)
{
vis = v;
}
KeyboardVisDlg::~KeyboardVisDlg()
{
}
void KeyboardVisDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BOOL KeyboardVisDlg::OnInitDialog()
{
Tray.cbSize = sizeof(Tray);
Tray.hIcon = (HICON)::LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, LR_SHARED);
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);
char nrml_ofst_str[64];
char nrml_scl_str[64];
char anim_speed_str[64];
char fltr_const_str[64];
snprintf(nrml_ofst_str, 64, "%f", vis->nrml_ofst);
snprintf(nrml_scl_str, 64, "%f", vis->nrml_scl);
snprintf(anim_speed_str, 64, "%f", vis->anim_speed);
snprintf(fltr_const_str, 64, "%f", vis->filter_constant);
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);
SetDlgItemInt(IDC_EDIT_BACKGROUND_TIMEOUT, vis->background_timeout);
SetDlgItemText(IDC_EDIT_ANIM_SPEED, anim_speed_str);
SetDlgItemText(IDC_EDIT_NRML_OFST, nrml_ofst_str);
SetDlgItemText(IDC_EDIT_NRML_SCL, nrml_scl_str);
SetDlgItemText(IDC_EDIT_FILTER_CONSTANT, fltr_const_str);
CComboBox* windowBox = (CComboBox*)GetDlgItem(IDC_COMBO_WINDOW);
windowBox->AddString("None");
windowBox->AddString("Hanning");
windowBox->AddString("Hamming");
windowBox->AddString("Blackman");
windowBox->SetCurSel(vis->window_mode);
CComboBox* bkgdModeBox = (CComboBox*)GetDlgItem(IDC_COMBO_BKGD_MODE);
for (int i = 0; i < VISUALIZER_NUM_PATTERNS; i++)
{
bkgdModeBox->AddString(visualizer_pattern_labels[i]);
}
bkgdModeBox->SetCurSel(vis->bkgd_mode);
CComboBox* frgdModeBox = (CComboBox*)GetDlgItem(IDC_COMBO_FRGD_MODE);
for (int i = 0; i < VISUALIZER_NUM_PATTERNS; i++)
{
frgdModeBox->AddString(visualizer_pattern_labels[i]);
}
frgdModeBox->SetCurSel(vis->frgd_mode);
CComboBox* snglClrModeBox = (CComboBox*)GetDlgItem(IDC_COMBO_SNGL_CLR_MODE);
for (int i = 0; i < VISUALIZER_NUM_SINGLE_COLOR; i++)
{
snglClrModeBox->AddString(visualizer_single_color_labels[i]);
}
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* audioDeviceBox = (CComboBox*)GetDlgItem(IDC_COMBO_AUDIO_DEVICE);
for (int i = 0; i < vis->audio_devices.size(); i++)
{
audioDeviceBox->AddString(vis->audio_devices[i]);
}
audioDeviceBox->SetCurSel(vis->audio_device_idx);
((CButton*)GetDlgItem(IDC_CHECK_REACTIVE_BACKGROUND))->SetCheck(vis->reactive_bkgd);
((CButton*)GetDlgItem(IDC_CHECK_SILENT_BACKGROUND))->SetCheck(vis->silent_bkgd);
timer = SetTimer(1, 25, NULL);
firstrun = true;
return true;
}
void KeyboardVisDlg::StartMinimized(boolean startmin)
{
startminimized = startmin;
}
void KeyboardVisDlg::OnDestroy()
{
vis->Shutdown();
Shell_NotifyIcon(NIM_DELETE, &Tray);
}
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++)
{
if (vis->pixels_out != NULL)
{
pixels_bgr[y][x] = RGB2BGR(vis->pixels_out->pixels[y][x]);
}
}
}
HBITMAP hBitmap = CreateBitmap(256, 64, 1, 32, pixels_bgr);
((CStatic *)GetDlgItem(IDC_IMAGE_VISUALIZATION))->SetBitmap(hBitmap);
DeleteObject(hBitmap);
if (vis->update_ui)
{
char nrml_ofst_str[64];
char nrml_scl_str[64];
char anim_speed_str[64];
char fltr_const_str[64];
snprintf(nrml_ofst_str, 64, "%f", vis->nrml_ofst);
snprintf(nrml_scl_str, 64, "%f", vis->nrml_scl);
snprintf(anim_speed_str, 64, "%f", vis->anim_speed);
snprintf(fltr_const_str, 64, "%f", vis->filter_constant);
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);
SetDlgItemInt(IDC_EDIT_BACKGROUND_TIMEOUT, vis->background_timeout);
SetDlgItemText(IDC_EDIT_ANIM_SPEED, anim_speed_str);
SetDlgItemText(IDC_EDIT_NRML_OFST, nrml_ofst_str);
SetDlgItemText(IDC_EDIT_NRML_SCL, nrml_scl_str);
SetDlgItemText(IDC_EDIT_FILTER_CONSTANT, fltr_const_str);
CComboBox* windowBox = (CComboBox*)GetDlgItem(IDC_COMBO_WINDOW);
windowBox->SetCurSel(vis->window_mode);
CComboBox* bkgdModeBox = (CComboBox*)GetDlgItem(IDC_COMBO_BKGD_MODE);
bkgdModeBox->SetCurSel(vis->bkgd_mode);
CComboBox* frgdModeBox = (CComboBox*)GetDlgItem(IDC_COMBO_FRGD_MODE);
frgdModeBox->SetCurSel(vis->frgd_mode);
CComboBox* snglClrModeBox = (CComboBox*)GetDlgItem(IDC_COMBO_SNGL_CLR_MODE);
snglClrModeBox->SetCurSel(vis->single_color_mode);
CComboBox* avgModeBox = (CComboBox*)GetDlgItem(IDC_COMBO_AVG_MODE);
avgModeBox->SetCurSel(vis->avg_mode);
((CButton*)GetDlgItem(IDC_CHECK_REACTIVE_BACKGROUND))->SetCheck(vis->reactive_bkgd);
((CButton*)GetDlgItem(IDC_CHECK_SILENT_BACKGROUND))->SetCheck(vis->silent_bkgd);
vis->update_ui = false;
}
}
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);
}