summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Schürmann <daschuer@mixxx.org>2020-11-13 20:55:14 +0100
committerGitHub <noreply@github.com>2020-11-13 20:55:14 +0100
commit3a9048073bf045c40ae015d61634bf6248540ce2 (patch)
tree309a55c1202cce71c5c792d70f8bb0cc8dfb3568 /src
parent1c9f6aceee3ac0b28aa36f43be031c843a705af8 (diff)
parenta57bf767cc7db138cc92f01c9b74eb081335a235 (diff)
Merge pull request #3297 from uklotzde/controller_renaming
Controller devices: Use inclusive naming
Diffstat (limited to 'src')
-rw-r--r--src/controllers/hid/hidblacklist.h21
-rw-r--r--src/controllers/hid/hiddenylist.h17
-rw-r--r--src/controllers/hid/hidenumerator.cpp93
-rw-r--r--src/controllers/midi/portmidienumerator.cpp118
4 files changed, 133 insertions, 116 deletions
diff --git a/src/controllers/hid/hidblacklist.h b/src/controllers/hid/hidblacklist.h
deleted file mode 100644
index 48d5083987..0000000000
--- a/src/controllers/hid/hidblacklist.h
+++ /dev/null
@@ -1,21 +0,0 @@
-// Blacklisted HID devices
-
-#ifndef HIDBLACKLIST_H
-#define HIDBLACKLIST_H
-
-typedef struct hid_blacklist {
- unsigned short vendor_id;
- unsigned short product_id;
- unsigned short usage_page;
- unsigned short usage;
- int interface_number;
-} hid_blacklist_t;
-
-hid_blacklist_t hid_blacklisted[] = {
- {0x5ac, 0x253, 0xff00, 0x1, -1}, // Apple laptop chassis
- {0x5ac, 0x8242, 0xc, 0x1, -1}, // Apple IR Remote Controller
- {0x1157, 0x300, 0x1, 0x2, -1}, // EKS Otus mouse pad (OS/X,windows)
- {0x1157, 0x300, 0x0, 0x0, 0x3}, // EKS Otus mouse pad (linux)
-};
-
-#endif
diff --git a/src/controllers/hid/hiddenylist.h b/src/controllers/hid/hiddenylist.h
new file mode 100644
index 0000000000..1a1fdb05b1
--- /dev/null
+++ b/src/controllers/hid/hiddenylist.h
@@ -0,0 +1,17 @@
+#pragma once
+
+typedef struct hid_denylist {
+ unsigned short vendor_id;
+ unsigned short product_id;
+ unsigned short usage_page;
+ unsigned short usage;
+ int interface_number;
+} hid_denylist_t;
+
+/// USB HID device that should not be recognized as controllers
+hid_denylist_t hid_denylisted[] = {
+ {0x5ac, 0x253, 0xff00, 0x1, -1}, // Apple laptop chassis
+ {0x5ac, 0x8242, 0xc, 0x1, -1}, // Apple IR Remote Controller
+ {0x1157, 0x300, 0x1, 0x2, -1}, // EKS Otus mouse pad (OS/X,windows)
+ {0x1157, 0x300, 0x0, 0x0, 0x3}, // EKS Otus mouse pad (linux)
+};
diff --git a/src/controllers/hid/hidenumerator.cpp b/src/controllers/hid/hidenumerator.cpp
index 802459f3c0..5a34074368 100644
--- a/src/controllers/hid/hidenumerator.cpp
+++ b/src/controllers/hid/hidenumerator.cpp
@@ -5,61 +5,66 @@
* @brief This class handles discovery and enumeration of DJ controllers that use the USB-HID protocol
*/
+#include "controllers/hid/hidenumerator.h"
+
#include <hidapi.h>
#include "controllers/hid/hidcontroller.h"
-#include "controllers/hid/hidenumerator.h"
-#include "controllers/hid/hidblacklist.h"
+#include "controllers/hid/hiddenylist.h"
-HidEnumerator::HidEnumerator(UserSettingsPointer pConfig)
- : ControllerEnumerator(), m_pConfig(pConfig) {
-}
-
-HidEnumerator::~HidEnumerator() {
- qDebug() << "Deleting HID devices...";
- while (m_devices.size() > 0) {
- delete m_devices.takeLast();
- }
- hid_exit();
-}
+namespace {
-bool isDeviceBlacklisted(struct hid_device_info* cur_dev) {
- bool interface_number_valid = cur_dev->interface_number != -1;
- const int blacklist_len = sizeof(hid_blacklisted)/sizeof(hid_blacklisted[0]);
- for (int bl_index=0;bl_index<blacklist_len;bl_index++) {
- hid_blacklist_t blacklisted = hid_blacklisted[bl_index];
+bool recognizeDevice(const hid_device_info& device_info) {
+ bool interface_number_valid = device_info.interface_number != -1;
+ const int denylist_len = sizeof(hid_denylisted) / sizeof(hid_denylisted[0]);
+ for (int bl_index = 0; bl_index < denylist_len; bl_index++) {
+ hid_denylist_t denylisted = hid_denylisted[bl_index];
// If vendor ids do not match, skip.
- if (cur_dev->vendor_id != blacklisted.vendor_id)
+ if (device_info.vendor_id != denylisted.vendor_id)
continue;
// If product IDs do not match, skip.
- if (cur_dev->product_id != blacklisted.product_id)
+ if (device_info.product_id != denylisted.product_id)
continue;
- // Blacklist entry based on interface number
- if (blacklisted.interface_number != -1) {
+ // Denylist entry based on interface number
+ if (denylisted.interface_number != -1) {
// Skip matching for devices without usage info.
if (!interface_number_valid)
continue;
// If interface number is present and the interface numbers do not
// match, skip.
- if (cur_dev->interface_number != blacklisted.interface_number) {
+ if (device_info.interface_number != denylisted.interface_number) {
continue;
}
}
- // Blacklist entry based on usage_page and usage (both required)
- if (blacklisted.usage_page != 0 && blacklisted.usage != 0) {
+ // Denylist entry based on usage_page and usage (both required)
+ if (denylisted.usage_page != 0 && denylisted.usage != 0) {
// Skip matching for devices with no usage_page/usage info.
- if (cur_dev->usage_page == 0 && cur_dev->usage == 0)
+ if (device_info.usage_page == 0 && device_info.usage == 0)
continue;
// If usage_page is different, skip.
- if (cur_dev->usage_page != blacklisted.usage_page)
+ if (device_info.usage_page != denylisted.usage_page)
continue;
// If usage is different, skip.
- if (cur_dev->usage != blacklisted.usage)
+ if (device_info.usage != denylisted.usage)
continue;
}
- return true;
+ return false;
}
- return false;
+ return true;
+}
+
+} // namespace
+
+HidEnumerator::HidEnumerator(UserSettingsPointer pConfig)
+ : m_pConfig(pConfig) {
+}
+
+HidEnumerator::~HidEnumerator() {
+ qDebug() << "Deleting HID devices...";
+ while (m_devices.size() > 0) {
+ delete m_devices.takeLast();
+ }
+ hid_exit();
}
QList<Controller*> HidEnumerator::queryDevices() {
@@ -69,17 +74,25 @@ QList<Controller*> HidEnumerator::queryDevices() {
devs = hid_enumerate(0x0, 0x0);
for (cur_dev = devs; cur_dev; cur_dev = cur_dev->next) {
- if (isDeviceBlacklisted(cur_dev)) {
+ if (!recognizeDevice(*cur_dev)) {
// OS/X and windows use usage_page/usage not interface_number
- qDebug() << "Blacklisting"
- << HidController::safeDecodeWideString(cur_dev->manufacturer_string, 512)
- << HidController::safeDecodeWideString(cur_dev->product_string, 512)
- << QString("r%1").arg(cur_dev->release_number)
- << "S/N" << HidController::safeDecodeWideString(cur_dev->serial_number, 512)
- << (cur_dev->interface_number == -1 ? QString("Usage Page %1 Usage %2").arg(
- QString::number(cur_dev->usage_page),
- QString::number(cur_dev->usage)) :
- QString("Interface %1").arg(cur_dev->interface_number));
+ qDebug()
+ << "Skipping"
+ << HidController::safeDecodeWideString(
+ cur_dev->manufacturer_string, 512)
+ << HidController::safeDecodeWideString(
+ cur_dev->product_string, 512)
+ << QString("r%1").arg(cur_dev->release_number) << "S/N"
+ << HidController::safeDecodeWideString(
+ cur_dev->serial_number, 512)
+ << (cur_dev->interface_number == -1
+ ? QString("Usage Page %1 Usage %2")
+ .arg(QString::number(
+ cur_dev->usage_page),
+ QString::number(
+ cur_dev->usage))
+ : QString("Interface %1")
+ .arg(cur_dev->interface_number));
continue;
}
diff --git a/src/controllers/midi/portmidienumerator.cpp b/src/controllers/midi/portmidienumerator.cpp
index ba525ddeb7..356c111d37 100644
--- a/src/controllers/midi/portmidienumerator.cpp
+++ b/src/controllers/midi/portmidienumerator.cpp
@@ -13,16 +13,26 @@
#include "controllers/midi/portmidicontroller.h"
#include "util/cmdlineargs.h"
-bool shouldBlacklistDevice(const PmDeviceInfo* device) {
- QString deviceName = device->name;
- // In developer mode we show the MIDI Through Port, otherwise blacklist it
+namespace {
+
+const auto kMidiThroughPortPrefix = QLatin1String("MIDI Through Port");
+
+bool recognizeDevice(const PmDeviceInfo& deviceInfo) {
+ // In developer mode we show the MIDI Through Port, otherwise ignore it
// since it routinely causes trouble.
- return !CmdlineArgs::Instance().getDeveloper() &&
- deviceName.startsWith("Midi Through Port", Qt::CaseInsensitive);
+ return CmdlineArgs::Instance().getDeveloper() ||
+#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
+ !QLatin1String(deviceInfo.name)
+#else
+ !QString::fromLatin1(deviceInfo.name)
+#endif
+ .startsWith(kMidiThroughPortPrefix, Qt::CaseInsensitive);
}
+} // namespace
+
PortMidiEnumerator::PortMidiEnumerator(UserSettingsPointer pConfig)
- : MidiEnumerator(), m_pConfig(pConfig) {
+ : m_pConfig(pConfig) {
PmError err = Pm_Initialize();
// Based on reading the source, it's not possible for this to fail.
if (err != pmNoError) {
@@ -206,74 +216,72 @@ QList<Controller*> PortMidiEnumerator::queryDevices() {
// Build a complete list of output devices for later pairing
for (int i = 0; i < iNumDevices; i++) {
- const PmDeviceInfo* deviceInfo = Pm_GetDeviceInfo(i);
- if (shouldBlacklistDevice(deviceInfo)) {
+ const PmDeviceInfo* pDeviceInfo = Pm_GetDeviceInfo(i);
+ VERIFY_OR_DEBUG_ASSERT(pDeviceInfo) {
continue;
}
- if (deviceInfo->output) {
- qDebug() << " Found output device" << "#" << i << deviceInfo->name;
- QString deviceName = deviceInfo->name;
- unassignedOutputDevices[i] = deviceName;
+ if (!recognizeDevice(*pDeviceInfo) || !pDeviceInfo->output) {
+ continue;
}
+ qDebug() << " Found output device"
+ << "#" << i << pDeviceInfo->name;
+ QString deviceName = pDeviceInfo->name;
+ unassignedOutputDevices[i] = deviceName;
}
// Search for input devices and pair them with output devices if applicable
for (int i = 0; i < iNumDevices; i++) {
- const PmDeviceInfo* deviceInfo = Pm_GetDeviceInfo(i);
- if (shouldBlacklistDevice(deviceInfo)) {
+ const PmDeviceInfo* pDeviceInfo = Pm_GetDeviceInfo(i);
+ VERIFY_OR_DEBUG_ASSERT(pDeviceInfo) {
+ continue;
+ }
+ if (!recognizeDevice(*pDeviceInfo) || !pDeviceInfo->input) {
+ // Is there a use case for output-only devices such as message
+ // displays? Then this condition has to be split and
+ // deviceInfo->output also needs to be checked and handled.
continue;
}
- //If we found an input device
- if (deviceInfo->input) {
- qDebug() << " Found input device" << "#" << i << deviceInfo->name;
- inputDeviceInfo = deviceInfo;
- inputDevIndex = i;
+ qDebug() << " Found input device"
+ << "#" << i << pDeviceInfo->name;
+ inputDeviceInfo = pDeviceInfo;
+ inputDevIndex = i;
- //Reset our output device variables before we look for one in case we find none.
- outputDeviceInfo = NULL;
- outputDevIndex = -1;
+ //Reset our output device variables before we look for one in case we find none.
+ outputDeviceInfo = nullptr;
+ outputDevIndex = -1;
- //Search for a corresponding output device
- QMapIterator<int, QString> j(unassignedOutputDevices);
- while (j.hasNext()) {
- j.next();
+ //Search for a corresponding output device
+ QMapIterator<int, QString> j(unassignedOutputDevices);
+ while (j.hasNext()) {
+ j.next();
- QString deviceName = inputDeviceInfo->name;
- QString outputName = QString(j.value());
+ QString deviceName = inputDeviceInfo->name;
+ QString outputName = QString(j.value());
- if (shouldLinkInputToOutput(deviceName, outputName)) {
- outputDevIndex = j.key();
- outputDeviceInfo = Pm_GetDeviceInfo(outputDevIndex);
+ if (shouldLinkInputToOutput(deviceName, outputName)) {
+ outputDevIndex = j.key();
+ outputDeviceInfo = Pm_GetDeviceInfo(outputDevIndex);
- unassignedOutputDevices.remove(outputDevIndex);
+ unassignedOutputDevices.remove(outputDevIndex);
- qDebug() << " Linking to output device #" << outputDevIndex << outputName;
- break;
- }
+ qDebug() << " Linking to output device #" << outputDevIndex << outputName;
+ break;
}
-
- // So at this point, we either have an input-only MIDI device
- // (outputDeviceInfo == NULL) or we've found a matching output MIDI
- // device (outputDeviceInfo != NULL).
-
- //.... so create our (aggregate) MIDI device!
- PortMidiController* currentDevice =
- new PortMidiController(inputDeviceInfo,
- outputDeviceInfo,
- inputDevIndex,
- outputDevIndex,
- m_pConfig);
- m_devices.push_back(currentDevice);
}
- // Is there a use-case for output-only devices (such as message
- // displays?) If so, handle them here.
-
- //else if (deviceInfo->output) {
- // PortMidiController *currentDevice = new PortMidiController(deviceInfo, i);
- // m_devices.push_back((MidiController*)currentDevice);
- //}
+ // So at this point, we either have an input-only MIDI device
+ // (outputDeviceInfo == NULL) or we've found a matching output MIDI
+ // device (outputDeviceInfo != NULL).
+
+ //.... so create our (aggregate) MIDI device!
+ PortMidiController* currentDevice =
+ new PortMidiController(inputDeviceInfo,
+ outputDeviceInfo,
+ inputDevIndex,
+ outputDevIndex,
+ m_pConfig);
+ m_devices.push_back(currentDevice);
}
return m_devices;
}