Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modernize ControllerManager #13627

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

Swiftb0y
Copy link
Member

@Swiftb0y Swiftb0y commented Sep 4, 2024

And a little bit of the surrounding code. This is what I have so far, though the multithreading code could use a little larger restructuring. based on (outdated) #13622.

* move equality comparision closer to type definition.
* remove trailing null-entry in support array
* modernize allowlist search
* replace magic (unnamed) values with proper constants
* use idiomatic array iteration
* explicitly initialize all members
* use unique_ptr for owning pointers
* use std::algorithm where applicable
* use compile-time literals where possible
@@ -120,10 +118,13 @@ QList<Controller*> HidEnumerator::queryDevices() {
continue;
}

HidController* newDevice = new HidController(std::move(deviceInfo));
m_devices.push_back(newDevice);
m_devices.push_back(std::make_unique<HidController>(std::move(deviceInfo)));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not that independent of my changes, this is currently broken when querying devices multiple times because we don't clear the list from the previous query... Not sure if I should fix that here because its not feasible to test nor do I have enough non-keyboard/-mice HID devices here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should fix it anyway. Main is still in alpha stage.

Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments of #13627 apply here as well. Can you adopt them?

@Swiftb0y
Copy link
Member Author

Swiftb0y commented Sep 9, 2024

some comments of #13627 apply here as well. Can you adopt them?

I assume you mean #13622? Yes, I will rebase on that once everyone is happy.

Copy link
Member

@acolombier acolombier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall! One request tho, could you make sure that updated pointer variables are prefixed with p... to help with readability?

One mild concerned is around BULK, not directly related to your change: Interface also appears to be relevant on Linux, and not using them leads to dmesg warnings, so I'm wondering if would be worth removing the preprocessor around this. If you're keen to give it a try, I'm happy to test it with my devices to confirm it works as expected!

@Swiftb0y
Copy link
Member Author

Swiftb0y commented Sep 9, 2024

Will look into both. Thanks for taking a look @acolombier

This fixes a (hypothetical) issue which could cause duplicate
HID and Bulk devices to be created when querying for devices
multiple times. This has not not happened yet because devices
so far have only been queried once on startup.
@Swiftb0y Swiftb0y force-pushed the refactor/modernize-controllermanager branch 4 times, most recently from 208692b to b8567ae Compare September 10, 2024 20:53
@Swiftb0y Swiftb0y force-pushed the refactor/modernize-controllermanager branch 4 times, most recently from 4fca48b to 2925eee Compare September 11, 2024 12:33
@Swiftb0y Swiftb0y force-pushed the refactor/modernize-controllermanager branch 2 times, most recently from 4762ae4 to 840e4a5 Compare September 16, 2024 12:21
@@ -1,13 +1,15 @@
#include "controllers/midi/portmidienumerator.h"

#include <portmidi.h>
#include <qlatin1stringview.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this used for? Looks like it doesn't exist on MacOS

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, yeah clangd tries its best to add the relevant includes but its gets it wrong and I don't notice it. I'll remove and force push (and look into disabling that for certain headers).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member Author

@Swiftb0y Swiftb0y Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi in case any1 else stumbles over this, see https://clangd.llvm.org/guides/include-cleaner#adjusting-behavior and use IgnoreHeaders: q.*\.h until QTBUG-124159 is fixed.

@Swiftb0y Swiftb0y force-pushed the refactor/modernize-controllermanager branch from 840e4a5 to 3d5b851 Compare September 16, 2024 21:18
@Swiftb0y Swiftb0y force-pushed the refactor/modernize-controllermanager branch from 3d5b851 to 6b0c83f Compare September 17, 2024 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants