Skip to content

Commit b6ae971

Browse files
committed
Low latency audio, fixed logger block, precompiled headers, etc.
- Added `ForceLowLatencyAudio` command to force audio engine to lowest possible latency on Windows 10 - Fixed logger queue handling blocking threads - Renamed precompiled headers file to precompiled.h - Optimized button handling so that it doesn't have to parse strings every time a input action is processed. - Stopped using standard namespace as a default namespace - Added Dualshock 4 controller custom data example to tablet.cfg
1 parent 0d8cc3e commit b6ae971

77 files changed

Lines changed: 1281 additions & 725 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

TabletDriverGUI/MainWindow.Areas.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,8 +1106,13 @@ private void CanvasArea_MouseWheel(object sender, MouseWheelEventArgs e)
11061106

11071107
double oldWidth = mouseArea.Area.Width;
11081108
double oldHeight = mouseArea.Area.Height;
1109-
mouseArea.Area.Width = Math.Round(oldWidth + delta);
1110-
mouseArea.Area.Height = oldHeight / oldWidth * mouseArea.Area.Width;
1109+
double newWidth = Math.Round(oldWidth + delta);
1110+
double newHeight = oldHeight / oldWidth * newWidth;
1111+
if (delta > 0 || newWidth >= 10 || newHeight >= 10)
1112+
{
1113+
mouseArea.Area.Width = newWidth;
1114+
mouseArea.Area.Height = newHeight;
1115+
}
11111116
LoadSettingsFromConfiguration();
11121117
}
11131118

TabletDriverService/BufferQueue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "stdafx.h"
1+
#include "precompiled.h"
22
#include "BufferQueue.h"
33

44

TabletDriverService/BufferQueue.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ class BufferQueue {
1313
~Item();
1414
};
1515

16-
queue<Item*> queue;
17-
mutex lockQueue;
18-
mutex lockWait;
19-
condition_variable conditionBuffer;
16+
std::queue<Item*> queue;
17+
std::mutex lockQueue;
18+
std::mutex lockWait;
19+
std::condition_variable conditionBuffer;
2020
void Push(void *buffer, int length);
2121
void Pop();
2222
void Clear();

TabletDriverService/Command.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "stdafx.h"
1+
#include "precompiled.h"
22
#include "Command.h"
33

44

@@ -14,7 +14,7 @@ Command::Command() {
1414
callback = NULL;
1515
}
1616

17-
Command::Command(string _name, function<bool(CommandLine*)> _callback) {
17+
Command::Command(std::string _name, std::function<bool(CommandLine*)> _callback) {
1818
this->name = _name;
1919
this->callback = _callback;
2020
}

TabletDriverService/Command.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
class Command {
88
public:
99

10-
string name;
11-
function<bool(CommandLine*)> callback;
10+
std::string name;
11+
std::function<bool(CommandLine*)> callback;
1212

1313
bool Execute(CommandLine *cmd);
1414

1515
Command();
16-
Command(string _name, function<bool(CommandLine*)> _callback);
16+
Command(std::string _name, std::function<bool(CommandLine*)> _callback);
1717
~Command();
1818
};

TabletDriverService/CommandHandler.Auxiliary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "stdafx.h"
1+
#include "precompiled.h"
22
#include "CommandHandler.h"
33

44
#define LOG_MODULE ""

TabletDriverService/CommandHandler.Device.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "stdafx.h"
1+
#include "precompiled.h"
22
#include "CommandHandler.h"
33

44
#define LOG_MODULE ""
@@ -18,7 +18,7 @@ void CommandHandler::CreateDeviceCommands() {
1818

1919
//
2020
if (cmd->valueCount >= 1) {
21-
string guid = cmd->GetString(0, "");
21+
std::string guid = cmd->GetString(0, "");
2222
if (tablet == NULL) {
2323
tablet = new Tablet(guid);
2424
if (tablet->isOpen) {
@@ -73,7 +73,7 @@ void CommandHandler::CreateDeviceCommands() {
7373
USHORT usage = cmd->GetInt(3, 0);
7474
bool isExclusive = false;
7575
for (int i = 4; i < cmd->valueCount; i += 2) {
76-
string parameter = cmd->GetStringLower(i, "");
76+
std::string parameter = cmd->GetStringLower(i, "");
7777
if (parameter == "exclusive") {
7878
isExclusive = cmd->GetBoolean(i + 1, false);
7979
}
@@ -257,8 +257,8 @@ void CommandHandler::CreateDeviceCommands() {
257257
if (cmd->valueCount <= 0) return false;
258258
if (tablet == NULL) return false;
259259

260-
string stringName = cmd->GetStringLower(0, "");
261-
string deviceString;
260+
std::string stringName = cmd->GetStringLower(0, "");
261+
std::string deviceString;
262262

263263
// Manufacturer
264264
if (stringName.compare(0, 3, "man") == 0) {
@@ -307,10 +307,10 @@ void CommandHandler::CreateDeviceCommands() {
307307
// Loop through string ids
308308
for (int stringId = stringIdMin; stringId <= stringIdMax; stringId++) {
309309
try {
310-
string deviceString = tablet->GetDeviceString(stringId);
310+
std::string deviceString = tablet->GetDeviceString(stringId);
311311
LOG_INFO(" String (%d) = '%s'\n", stringId, deviceString.c_str());
312312
}
313-
catch (const exception &e) {
313+
catch (const std::exception &e) {
314314
LOG_ERROR("%s\n", e.what());
315315
break;
316316
}
@@ -341,10 +341,9 @@ void CommandHandler::CreateDeviceCommands() {
341341
if (tablet == NULL) return false;
342342

343343
int stringId = cmd->GetInt(0, 0);
344-
string stringName = cmd->GetStringLower(0, "");
345-
string matchString = cmd->GetString(1, "");
346-
347-
string deviceString = "";
344+
std::string stringName = cmd->GetStringLower(0, "");
345+
std::string matchString = cmd->GetString(1, "");
346+
std::string deviceString = "";
348347

349348
// Manufacturer
350349
if (stringName.compare(0, 3, "man") == 0) {
@@ -366,15 +365,15 @@ void CommandHandler::CreateDeviceCommands() {
366365

367366
// Request device string
368367
else {
369-
stringName = to_string(stringId);
368+
stringName = std::to_string(stringId);
370369
if (stringId == 0) {
371370
LOG_ERROR("Invalid string id!\n");
372371
return false;
373372
}
374373
try {
375374
deviceString = tablet->GetDeviceString(stringId);
376375
}
377-
catch (exception&e) {
376+
catch (std::exception&e) {
378377
LOG_ERROR("%s\n", e.what());
379378
}
380379
}

TabletDriverService/CommandHandler.Filters.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "stdafx.h"
1+
#include "precompiled.h"
22
#include "CommandHandler.h"
33

44
#define LOG_MODULE ""
@@ -23,7 +23,7 @@ void CommandHandler::CreateFilterCommands() {
2323
double latency = cmd->GetDouble(0, tablet->smoothing.GetLatency());
2424
bool onlyWhenButtonsDown = cmd->GetBoolean(1, tablet->smoothing.onlyWhenButtonsDown);
2525

26-
string stringValue = cmd->GetStringLower(0, "");
26+
std::string stringValue = cmd->GetStringLower(0, "");
2727

2828
// Off / False
2929
if (stringValue == "off" || stringValue == "false") {
@@ -169,7 +169,7 @@ void CommandHandler::CreateFilterCommands() {
169169
// Tablet valid?
170170
if (!ExecuteCommand("TabletValid")) return false;
171171

172-
string stringValue = cmd->GetStringLower(0, "");
172+
std::string stringValue = cmd->GetStringLower(0, "");
173173

174174
// Off / False
175175
if (stringValue == "off" || stringValue == "false") {
@@ -247,7 +247,7 @@ void CommandHandler::CreateFilterCommands() {
247247
// Tablet valid?
248248
if (!ExecuteCommand("TabletValid")) return false;
249249

250-
string stringValue = cmd->GetStringLower(0, "");
250+
std::string stringValue = cmd->GetStringLower(0, "");
251251

252252
// Off / False
253253
if (stringValue == "off") {
@@ -374,8 +374,8 @@ void CommandHandler::CreateFilterCommands() {
374374
// Tablet valid?
375375
if (!ExecuteCommand("TabletValid")) return false;
376376

377-
string inputFilepath = cmd->GetString(0, "tester_input.txt");
378-
string outputFilepath = cmd->GetString(1, "tester_output.txt");
377+
std::string inputFilepath = cmd->GetString(0, "tester_input.txt");
378+
std::string outputFilepath = cmd->GetString(1, "tester_output.txt");
379379
TabletFilterAntiSmoothing *filterAntiSmoothing = NULL;
380380
TabletFilterNoiseReduction *filterNoise = NULL;
381381
TabletFilterTester *tester = NULL;

TabletDriverService/CommandHandler.Other.cpp

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "stdafx.h"
1+
#include "precompiled.h"
22
#include "CommandHandler.h"
33

44
#define LOG_MODULE ""
@@ -85,7 +85,7 @@ void CommandHandler::CreateOtherCommands() {
8585
AddAlias("Mode", "OutputMode");
8686
AddCommand(new Command("OutputMode", [&](CommandLine *cmd) {
8787

88-
string mode = cmd->GetStringLower(0, "");
88+
std::string mode = cmd->GetStringLower(0, "");
8989

9090
// Absolute mouse
9191
if (mode.compare(0, 3, "abs") == 0) {
@@ -339,6 +339,29 @@ void CommandHandler::CreateOtherCommands() {
339339
}));
340340

341341

342+
//
343+
// Command: ForceLowLatencyAudio
344+
//
345+
// Forces low latency audio on Windows 10
346+
//
347+
AddCommand(new Command("ForceLowLatencyAudio", [&](CommandLine *cmd) {
348+
if (!ExecuteCommand("TabletValid")) return false;
349+
350+
int result = tabletHandler->inputEmulator.ForceLowLatencyAudio();
351+
if (result > 0) {
352+
LOG_INFO("Low latency audio forced!\n");
353+
}
354+
else if (result == 0) {
355+
LOG_INFO("Low latency audio is already forced!\n");
356+
}
357+
else {
358+
LOG_ERROR("Low latency audio error! Maybe you are not running this on Windows 10?\n");
359+
}
360+
361+
return true;
362+
}));
363+
364+
342365
//
343366
// Command: Debug
344367
//
@@ -359,7 +382,7 @@ void CommandHandler::CreateOtherCommands() {
359382
// Start/stop logging messages to a log file
360383
//
361384
AddCommand(new Command("Log", [&](CommandLine *cmd) {
362-
string logPath = cmd->GetString(0, "log.txt");
385+
std::string logPath = cmd->GetString(0, "log.txt");
363386
if (!cmd->GetBoolean(0, true)) {
364387
logger.CloseLogFile();
365388
LOG_INFO("Log file '%s' closed.\n", logger.logFilename.c_str());
@@ -469,15 +492,15 @@ void CommandHandler::CreateOtherCommands() {
469492

470493
// Pen buttons
471494
for (int i = 0; i < tablet->settings.buttonCount; i++) {
472-
stringIndex += sprintf_s(stringBuffer + stringIndex, maxLength - stringIndex, "'%s' ", tablet->settings.buttonMap[i].c_str());
495+
stringIndex += sprintf_s(stringBuffer + stringIndex, maxLength - stringIndex, "'%s' ", tablet->settings.buttonMap[i].ToString().c_str());
473496
}
474497
LOG_INFO(" Pen button map = %s\n", stringBuffer);
475498

476499
// Aux buttons
477500
if (tablet->settings.auxButtonCount > 0) {
478501
stringIndex = 0;
479502
for (int i = 0; i < tablet->settings.auxButtonCount; i++) {
480-
stringIndex += sprintf_s(stringBuffer + stringIndex, maxLength - stringIndex, "'%s' ", tablet->settings.auxButtonMap[i].c_str());
503+
stringIndex += sprintf_s(stringBuffer + stringIndex, maxLength - stringIndex, "'%s' ", tablet->settings.auxButtonMap[i].ToString().c_str());
481504
}
482505
LOG_INFO(" Aux button map = %s\n", stringBuffer);
483506
}
@@ -486,9 +509,9 @@ void CommandHandler::CreateOtherCommands() {
486509

487510
// Init strings
488511
if (tablet->initStrings.size() > 0) {
489-
string stringIds = "";
512+
std::string stringIds = "";
490513
for (int stringId : tablet->initStrings) {
491-
stringIds += to_string(stringId) + " ";
514+
stringIds += std::to_string(stringId) + " ";
492515
}
493516
LOG_INFO(" Init string ids: %s\n", stringIds.c_str());
494517
}
@@ -620,7 +643,7 @@ void CommandHandler::CreateOtherCommands() {
620643
// Reads commands from a file and stops if tablet is redefined.
621644
//
622645
AddCommand(new Command("Include", [&](CommandLine *cmd) {
623-
string filename = cmd->GetString(0, "");
646+
std::string filename = cmd->GetString(0, "");
624647
if (filename == "") {
625648
LOG_ERROR("Invalid filename '%s'!\n", filename.c_str());
626649
return false;
@@ -646,13 +669,13 @@ void CommandHandler::CreateOtherCommands() {
646669
AddCommand(new Command("ListCommands", [&](CommandLine *cmd) {
647670

648671
LOG_INFO("Commands: \n");
649-
for (pair<string, Command*> cmdPair : commands) {
650-
string commandName = cmdPair.second->name;
651-
string lowerCaseName = commandName;
652-
transform(lowerCaseName.begin(), lowerCaseName.end(), lowerCaseName.begin(), ::tolower);
672+
for (std::pair<std::string, Command*> cmdPair : commands) {
673+
std::string commandName = cmdPair.second->name;
674+
std::string lowerCaseName = commandName;
675+
std::transform(lowerCaseName.begin(), lowerCaseName.end(), lowerCaseName.begin(), ::tolower);
653676

654-
string aliasString = "";
655-
for (pair<string, string> aliasPair : aliases) {
677+
std::string aliasString = "";
678+
for (std::pair<std::string, std::string> aliasPair : aliases) {
656679
if (aliasPair.second == lowerCaseName) {
657680
aliasString += ", " + aliasNames[aliasPair.first];
658681
}
@@ -671,19 +694,19 @@ void CommandHandler::CreateOtherCommands() {
671694
//
672695
AddCommand(new Command("GetCommands", [&](CommandLine *cmd) {
673696

674-
string commandsString = "";
697+
std::string commandsString = "";
675698

676699
LOG_STATUS("COMMANDS_CLEAR 1\n");
677700

678-
for (pair<string, Command*> cmdPair : commands) {
679-
string commandName = cmdPair.second->name;
680-
string lowerCaseName = commandName;
681-
transform(lowerCaseName.begin(), lowerCaseName.end(), lowerCaseName.begin(), ::tolower);
701+
for (std::pair<std::string, Command*> cmdPair : commands) {
702+
std::string commandName = cmdPair.second->name;
703+
std::string lowerCaseName = commandName;
704+
std::transform(lowerCaseName.begin(), lowerCaseName.end(), lowerCaseName.begin(), ::tolower);
682705

683706
commandsString += commandName + " ";
684707

685-
string aliasString = "";
686-
for (pair<string, string> aliasPair : aliases) {
708+
std::string aliasString = "";
709+
for (std::pair<std::string, std::string> aliasPair : aliases) {
687710
if (aliasPair.second == lowerCaseName) {
688711
commandsString += aliasNames[aliasPair.first] + " ";
689712
}
@@ -702,16 +725,16 @@ void CommandHandler::CreateOtherCommands() {
702725
}));
703726

704727
//
705-
// Command: ListKeys
728+
// Command: ListInputs
706729
//
707-
// List all keys
730+
// List all input actions
708731
//
709-
AddCommand(new Command("ListKeys", [&](CommandLine *cmd) {
732+
AddCommand(new Command("ListInputs", [&](CommandLine *cmd) {
710733

711-
LOG_INFO("Keys:\n");
712-
for (string key : tabletHandler->inputEmulator.keys) {
713-
if (tabletHandler->inputEmulator.keyMap.count(key) > 0) {
714-
string name = tabletHandler->inputEmulator.keyMap[key]->name;
734+
LOG_INFO("Input actions:\n");
735+
for (std::string key : tabletHandler->inputEmulator.inputs) {
736+
if (tabletHandler->inputEmulator.inputMap.count(key) > 0) {
737+
std::string name = tabletHandler->inputEmulator.inputMap[key]->description;
715738
LOG_INFO(" % -20s %s\n", key.c_str(), name.c_str());
716739
}
717740
}
@@ -727,12 +750,12 @@ void CommandHandler::CreateOtherCommands() {
727750
//
728751
AddHelp("Help", "...");
729752
AddCommand(new Command("Help", [&](CommandLine *cmd) {
730-
string commandName = cmd->GetStringLower(0, "");
753+
std::string commandName = cmd->GetStringLower(0, "");
731754
if (aliases.count(commandName) > 0) {
732755
commandName = aliases[commandName];
733756
}
734757
if (help.count(commandName)) {
735-
string helpText = help[commandName];
758+
std::string helpText = help[commandName];
736759
LOG_INFO("Help:\n\n%s\n", helpText.c_str());
737760
}
738761
else {

0 commit comments

Comments
 (0)