Init commit

This commit is contained in:
Han Dai 2020-02-27 11:09:45 -05:00
commit 7c49f99c4c
6 changed files with 964 additions and 0 deletions

353
.gitignore vendored Normal file
View File

@ -0,0 +1,353 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*[.json, .xml, .info]
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/

31
MIDI.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29613.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MIDI", "MIDI\MIDI.vcxproj", "{031B0E12-342D-4114-9C72-12994AAF92A0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{031B0E12-342D-4114-9C72-12994AAF92A0}.Debug|x64.ActiveCfg = Debug|x64
{031B0E12-342D-4114-9C72-12994AAF92A0}.Debug|x64.Build.0 = Debug|x64
{031B0E12-342D-4114-9C72-12994AAF92A0}.Debug|x86.ActiveCfg = Debug|Win32
{031B0E12-342D-4114-9C72-12994AAF92A0}.Debug|x86.Build.0 = Debug|Win32
{031B0E12-342D-4114-9C72-12994AAF92A0}.Release|x64.ActiveCfg = Release|x64
{031B0E12-342D-4114-9C72-12994AAF92A0}.Release|x64.Build.0 = Release|x64
{031B0E12-342D-4114-9C72-12994AAF92A0}.Release|x86.ActiveCfg = Release|Win32
{031B0E12-342D-4114-9C72-12994AAF92A0}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5037088F-BC04-4EB7-952C-D428C1971CC7}
EndGlobalSection
EndGlobal

345
MIDI/MIDI.cpp Normal file
View File

@ -0,0 +1,345 @@
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <mmdeviceapi.h>
#include <endpointvolume.h>
#include <WinHttp.h>
#include <gdiplus.h>
#include <time.h>
void CALLBACK MidiInProc(HMIDIIN, UINT, DWORD, DWORD, DWORD);
void ChangeVolume(double);
void HttpPut(wchar_t*, wchar_t*, LPSTR);
void KeyboardPress(int);
void AugustLock(int);
void UpdateIcon(int, int, int);
DWORD WINAPI resetIcon(void*);
int knobsVal[8];
NOTIFYICONDATA notifyIcon;
HWND hWnd;
ULONG_PTR gdiplusToken;
HICON hIcon;
clock_t time1;
bool windowVisibility = false;
bool needResetIcon = false;
void main(void) {
MIDIINCAPS midiInCap;
HMIDIIN inHandle;
int numOfDevs;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
hWnd = FindWindow(L"ConsoleWindowClass", NULL);
ShowWindow(hWnd, windowVisibility);
notifyIcon.cbSize = sizeof(notifyIcon);
notifyIcon.hWnd = hWnd;
wcscpy_s(notifyIcon.szTip, L"MIDI Control");
notifyIcon.uCallbackMessage = WM_LBUTTONDOWN;
notifyIcon.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
notifyIcon.uID = 1;
Shell_NotifyIcon(NIM_ADD, &notifyIcon);
for (int i = 0; i < 8; i++) knobsVal[i] = -1;
numOfDevs = midiInGetNumDevs();
for (int i = 0; i < numOfDevs; i++)
if (!midiInGetDevCaps(i, &midiInCap, sizeof(MIDIINCAPS)))
wprintf(L"Device ID #%u: %s\n", i, midiInCap.szPname);
if (midiInOpen(&inHandle, 0, (DWORD_PTR)MidiInProc, 0, CALLBACK_FUNCTION))
printf("Err Opening MIDI Device\n");
midiInStart(inHandle);
UpdateIcon(-1, 1, 1);
while (_getch() != VK_ESCAPE);
Shell_NotifyIcon(NIM_DELETE, &notifyIcon);
midiInStop(inHandle);
midiInClose(inHandle);
}
DWORD WINAPI resetIcon(void* data) {
time1 = clock();
if (!needResetIcon) {
needResetIcon = true;
while (clock() - time1 < 1000);
UpdateIcon(-1, 1, 1);
needResetIcon = false;
}
return 0;
}
void UpdateIcon(int type, int num, int value) {
wchar_t tmp[50];
wchar_t types[10] = L"✸⬔";
Gdiplus::Bitmap bitmapText(256, 256);
Gdiplus::Graphics g(&bitmapText);
g.Clear(Gdiplus::Color(0, 0, 0, 0));
if (type == -1) {
Gdiplus::Font font1(L"Arial Black", 96);
Gdiplus::PointF origin1(-32, -32);
Gdiplus::SolidBrush brush1(Gdiplus::Color(0xFFe6b2c6));
swprintf(tmp, 50, L"MI");
g.DrawString(tmp, wcslen(tmp), &font1, origin1, &brush1);
Gdiplus::Font font2(L"Arial Black", 96);
Gdiplus::PointF origin2(32, 96);
Gdiplus::SolidBrush brush2(Gdiplus::Color(0xFFfef6fb));
swprintf(tmp, 50, L"DI");
g.DrawString(tmp, wcslen(tmp), &font2, origin2, &brush2);
} else {
// Icon
Gdiplus::Font font1(L"Arial Black", 88);
Gdiplus::PointF origin1(-36, -32);
Gdiplus::SolidBrush brush1(Gdiplus::Color(0xFFfef6fb));
swprintf(tmp, 50, L"%c", types[type]);
g.DrawString(tmp, wcslen(tmp), &font1, origin1, &brush1);
// num
Gdiplus::Font font2(L"Arial Black", 88);
Gdiplus::PointF origin2(70, -32);
Gdiplus::SolidBrush brush2(Gdiplus::Color(0xFFfef6fb));
swprintf(tmp, 50, L"%X", num);
g.DrawString(tmp, wcslen(tmp), &font2, origin2, &brush2);
// value
Gdiplus::Font font3(L"Arial Black", 100);
Gdiplus::PointF origin3(-32, 96);
Gdiplus::SolidBrush brush3(Gdiplus::Color(0xFFe6b2c6));
swprintf(tmp, 50, L"%d", value);
g.DrawString(tmp, wcslen(tmp), &font3, origin3, &brush3);
CreateThread(NULL, 0, resetIcon, NULL, 0, NULL);
}
bitmapText.GetHICON(&notifyIcon.hIcon);
Shell_NotifyIcon(NIM_MODIFY, &notifyIcon);
}
void CALLBACK MidiInProc(HMIDIIN hMidiIn, UINT wMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
{
switch (wMsg) {
case MIM_DATA:
printf("wMsg=MIM_DATA, dwInstance=%08x, dwParam1=%08x, dwParam2=%08x\n", dwInstance, dwParam1, dwParam2);
char buffer[50];
/* Knobs */
if (!(dwParam1 & 0xFF ^ 0xB0)) {
UpdateIcon(0, dwParam1 >> 8 & 0xFF, dwParam1 >> 16 & 0xFF);
/* Knob 1: PC Volume */
if (!(dwParam1 >> 8 & 0xFF ^ 0x01)) {
ChangeVolume((double)(dwParam1 >> 16 & 0xFF) / 127);
/* Knob 2: Bedroom Lights & Lightstrip Brightness */
} else if (!(dwParam1 >> 8 & 0xFF ^ 0x02)) {
snprintf(buffer, 50, "{\"on\": %s, \"bri\": %d}", (dwParam1 >> 16 & 0xFF) ? "true" : "false", (dwParam1 >> 16 & 0xFF) * 2);
if (!((dwParam1 >> 16 & 0xFF) % 8)) HttpPut((wchar_t*)L"censored.localhost", (wchar_t*)L"/api/censored/groups/2/action", (LPSTR)buffer);
/* Knob 3: Bedroom Lights & Lightstrip Hue */
} else if (!(dwParam1 >> 8 & 0xFF ^ 0x03)) {
snprintf(buffer, 50, "{\"on\": true, \"hue\": %d}", (dwParam1 >> 16 & 0xFF) * 516);
if (!((dwParam1 >> 16 & 0xFF) % 8)) HttpPut((wchar_t*)L"censored.localhost", (wchar_t*)L"/api/censored/groups/2/action", (LPSTR)buffer);
/* Knob 4: Bedroom Lights & Lightstrip Saturation */
} else if (!(dwParam1 >> 8 & 0xFF ^ 0x04)) {
snprintf(buffer, 50, "{\"on\": true, \"sat\": %d}", (dwParam1 >> 16 & 0xFF) * 2);
if (!((dwParam1 >> 16 & 0xFF) % 8)) HttpPut((wchar_t*)L"censored.localhost", (wchar_t*)L"/api/censored/groups/2/action", (LPSTR)buffer);
/* Knob 5: Press Z - Video Rewind */
} else if (!(dwParam1 >> 8 & 0xFF ^ 0x05)) {
if (knobsVal[4] != -1 && knobsVal[4] > dwParam1 >> 16 & 0xFF) KeyboardPress(0x5A);
knobsVal[4] = dwParam1 >> 16 & 0xFF;
/* Knob 6: Press X - Video Advance */
} else if (!(dwParam1 >> 8 & 0xFF ^ 0x06)) {
if (knobsVal[5] != -1 && knobsVal[5] < dwParam1 >> 16 & 0xFF) KeyboardPress(0x58);
knobsVal[5] = dwParam1 >> 16 & 0xFF;
}
/* Pads & Keys */
} else if (!(dwParam1 & 0xFF ^ 0x90)) {
UpdateIcon(1, dwParam1 >> 8 & 0xFF, dwParam1 >> 16 & 0xFF);
/* Bedroom Light Switch */
if (!(dwParam1 >> 8 & 0xFF ^ 0x30)) {
if ((dwParam1 >> 16 & 0xFF) != 0x00) { // ignore key off msg
snprintf(buffer, 50, "{\"on\": %s}", ((dwParam1 >> 16 & 0xFF) > 0x10) ? "true" : "false"); // fast press = on, slow press = off
HttpPut((wchar_t*)L"censored.localhost", (wchar_t*)L"/api/censored/groups/1/action", (LPSTR)buffer);
}
/* Light Strip Switch */
} else if (!(dwParam1 >> 8 & 0xFF ^ 0x32)) {
if ((dwParam1 >> 16 & 0xFF) != 0x00) { // ignore key off msg
snprintf(buffer, 50, "{\"on\": %s}", ((dwParam1 >> 16 & 0xFF) > 0x10) ? "true" : "false"); // fast press = on, slow press = off
HttpPut((wchar_t*)L"censored.localhost", (wchar_t*)L"/api/censored/groups/3/action", (LPSTR)buffer);
}
/* Bathroom Light Switch */
} else if (!(dwParam1 >> 8 & 0xFF ^ 0x34)) {
if ((dwParam1 >> 16 & 0xFF) != 0x00) { // ignore key off msg
snprintf(buffer, 50, "{\"on\": %s}", ((dwParam1 >> 16 & 0xFF) > 0x10) ? "true" : "false"); // fast press = on, slow press = off
HttpPut((wchar_t*)L"censored.localhost", (wchar_t*)L"/api/censored/groups/10/action", (LPSTR)buffer);
}
/* August Lock */
} else if (!(dwParam1 >> 8 & 0xFF ^ 0x35)) {
if ((dwParam1 >> 16 & 0xFF) != 0x00) { // ignore key off msg
if ((dwParam1 >> 16 & 0xFF) > 0x10) AugustLock(0); else AugustLock(1); // fast press = unlock, slow press = lock
}
/* Toggle Window */
} else if (!(dwParam1 >> 8 & 0xFF ^ 0x24)) {
if ((dwParam1 >> 16 & 0xFF) != 0x00) { // ignore key off msg
windowVisibility = !windowVisibility;
ShowWindow(hWnd, windowVisibility);
}
}
}
break;
default:
break;
}
}
void ChangeVolume(double volume)
{
IMMDeviceEnumerator* deviceEnumerator = NULL;
IMMDevice* defaultDevice = NULL;
IAudioEndpointVolume* endpointVolume = NULL;
CoInitialize(NULL);
CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID*)&deviceEnumerator);
deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice);
deviceEnumerator->Release();
deviceEnumerator = NULL;
defaultDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, NULL, (LPVOID*)&endpointVolume);
defaultDevice->Release();
defaultDevice = NULL;
endpointVolume->SetMasterVolumeLevelScalar((float)volume, NULL);
endpointVolume->Release();
CoUninitialize();
}
void HttpPut(wchar_t* host, wchar_t* path, LPSTR body) {
DWORD dwSize = 0;
DWORD dwDownloaded = 0;
LPSTR pszOutBuffer;
BOOL bResults = FALSE;
HINTERNET hSession = NULL, hConnect = NULL, hRequest = NULL;
hSession = WinHttpOpen(L"WinHTTP Example/1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
if (hSession) hConnect = WinHttpConnect(hSession, host, INTERNET_DEFAULT_HTTP_PORT, 0);
if (hConnect) hRequest = WinHttpOpenRequest(hConnect, L"PUT", path, NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, NULL);
if (hRequest) bResults = WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, body, strlen(body), strlen(body), 0);
if (bResults) bResults = WinHttpReceiveResponse(hRequest, NULL);
if (bResults) {
do {
// Check for available data.
dwSize = 0;
if (!WinHttpQueryDataAvailable(hRequest, &dwSize))
printf("Error %u in WinHttpQueryDataAvailable.\n", GetLastError());
// Allocate space for the buffer.
pszOutBuffer = new char[dwSize + 1];
if (!pszOutBuffer){
printf("Out of memory\n");
dwSize = 0;
} else {
// Read the data.
ZeroMemory(pszOutBuffer, dwSize + 1);
if (!WinHttpReadData(hRequest, (LPVOID)pszOutBuffer,
dwSize, &dwDownloaded))
printf("Error %u in WinHttpReadData.\n", GetLastError());
else
// printf("%s", pszOutBuffer);
// Free the memory allocated to the buffer.
delete[] pszOutBuffer;
}
}while (dwSize > 0);
}
// Report any errors.
if (!bResults)
printf("Error %d has occurred.\n", GetLastError());
// Close any open handles.
if (hRequest) WinHttpCloseHandle(hRequest);
if (hConnect) WinHttpCloseHandle(hConnect);
if (hSession) WinHttpCloseHandle(hSession);
}
void AugustLock(int lock) {
DWORD dwSize = 0;
DWORD dwDownloaded = 0;
LPSTR pszOutBuffer;
BOOL bResults = FALSE;
HINTERNET hSession = NULL, hConnect = NULL, hRequest = NULL;
hSession = WinHttpOpen(L"WinHTTP Example/1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
if (hSession) hConnect = WinHttpConnect(hSession, L"api-production.august.com", INTERNET_DEFAULT_HTTPS_PORT, 0);
if (hConnect) hRequest = WinHttpOpenRequest(hConnect, L"PUT", (lock) ? L"/remoteoperate/censored/lock" : L"/remoteoperate/censored/unlock", NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_SECURE);
if (hRequest) bResults = WinHttpAddRequestHeaders(hRequest, L"x-august-api-key:79fd0eb6-381d-4adf-95a0-47721289d1d9", (ULONG)-1L, WINHTTP_ADDREQ_FLAG_ADD);
if (hRequest) bResults = WinHttpAddRequestHeaders(hRequest, L"Content-Type:application/json", (ULONG)-1L, WINHTTP_ADDREQ_FLAG_ADD);
if (hRequest) bResults = WinHttpAddRequestHeaders(hRequest, L"x-august-access-token:censored", (ULONG)-1L, WINHTTP_ADDREQ_FLAG_ADD);
if (hRequest) bResults = WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0);
if (bResults) bResults = WinHttpReceiveResponse(hRequest, NULL);
if (bResults) {
do {
// Check for available data.
dwSize = 0;
if (!WinHttpQueryDataAvailable(hRequest, &dwSize))
printf("Error %u in WinHttpQueryDataAvailable.\n", GetLastError());
// Allocate space for the buffer.
pszOutBuffer = new char[dwSize + 1];
if (!pszOutBuffer) {
printf("Out of memory\n");
dwSize = 0;
}
else {
// Read the data.
ZeroMemory(pszOutBuffer, dwSize + 1);
if (!WinHttpReadData(hRequest, (LPVOID)pszOutBuffer,
dwSize, &dwDownloaded))
printf("Error %u in WinHttpReadData.\n", GetLastError());
else
// printf("%s", pszOutBuffer);
// Free the memory allocated to the buffer.
delete[] pszOutBuffer;
}
} while (dwSize > 0);
}
// Report any errors.
if (!bResults)
printf("Error %d has occurred.\n", GetLastError());
// Close any open handles.
if (hRequest) WinHttpCloseHandle(hRequest);
if (hConnect) WinHttpCloseHandle(hConnect);
if (hSession) WinHttpCloseHandle(hSession);
}
void KeyboardPress(int key) {
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 0;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = key; // Key
ip.ki.dwFlags = 0;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
SendInput(1, &ip, sizeof(INPUT));
}

156
MIDI/MIDI.vcxproj Normal file
View File

@ -0,0 +1,156 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{031B0E12-342D-4114-9C72-12994AAF92A0}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>MIDI</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>gdiplus.lib;Winhttp.lib;Winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="MIDI.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

18
MIDI/MIDI.vcxproj.filters Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="MIDI.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

61
MIDI/Resource.rc Normal file
View File

@ -0,0 +1,61 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED