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

fix(controllers): restore legacy passing of HID data in plain array #11470

Merged
merged 1 commit into from
May 8, 2023

Conversation

Swiftb0y
Copy link
Member

Fixes #11461, alternative to #11463

@Swiftb0y
Copy link
Member Author

I don't have a HID controller to test, so it would be nice if someone with the affected hardware could fix it.
Likely affected mappings:

  • HID Keyboard.hid.xml.example
  • HID Trackpad.hid.xml.example
  • Pioneer CDJ HID.hid.xml
  • EKS Otus.hid.xml
  • Nintendo Wiimote.hid.xml
  • Sony SixxAxis.hid.xml
  • Traktor Kontrol F1.hid.xml
  • Traktor Kontrol S2 Mk2.hid.xml
  • Traktor Kontrol S3.hid.xml
  • Traktor Kontrol S4 MK2.hid.xml
  • Traktor Kontrol S2 MK3.hid.xml
  • Traktor Kontrol S2 Mk1.hid.xml

@JoergAtGithub
Copy link
Member

I fully agree, that this is the right place to fix this! Thank you for providing this fix!
I haven't tried it yet. I hope it has no performance impact.

@Swiftb0y
Copy link
Member Author

Thank you. I don't think so. from what I can tell, these code parts are not particularly hot. Still, I'd really prefer if someone could test this before merging.

@mccowanm
Copy link

confirm commit works against last pull on 2.4 for a NITrakKontrolS2MK3 tyvm!

@Swiftb0y
Copy link
Member Author

Thank you for testing. I'm still waiting on a review by @JoergAtGithub or someone else. Maybe @ywwg? Thanks.

@JoergAtGithub
Copy link
Member

I will test it tonight!

@Swiftb0y
Copy link
Member Author

Swiftb0y commented Apr 27, 2023

friendly ping @JoergAtGithub. If you don't have the time or resources to test this, you could probably also just merge this since it was already confirmed to be working.

@JoergAtGithub
Copy link
Member

I will check this out this weekend - promised!

Comment on lines +16 to +29
* @param {number[] | ArrayBuffer | TypedArray} bufferLike Object that can be represented as a sequence of bytes
* @returns {DataView} dataview over the bufferLike object
*/
const createDataView = function(bufferLike) {
return new DataView((() => {
if (Array.isArray(bufferLike)) {
return new Uint8ClampedArray(bufferLike).buffer;
} else if (ArrayBuffer.isView(bufferLike)) {
return bufferLike.buffer;
} else {
return bufferLike;
}
})());
};
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @param {number[] | ArrayBuffer | TypedArray} bufferLike Object that can be represented as a sequence of bytes
* @returns {DataView} dataview over the bufferLike object
*/
const createDataView = function(bufferLike) {
return new DataView((() => {
if (Array.isArray(bufferLike)) {
return new Uint8ClampedArray(bufferLike).buffer;
} else if (ArrayBuffer.isView(bufferLike)) {
return bufferLike.buffer;
} else {
return bufferLike;
}
})());
};
* @param {Uint8Array | number[] | ArrayBuffer} bufferLike Object that can be represented as a sequence of bytes
* @returns {DataView} dataview over the bufferLike object
*/
const createDataView = function(bufferLike) {
if (bufferLike.constructor === Uint8Array) {
return new DataView(bufferLike.buffer);
} else if (Array.isArray(bufferLike)) {
return new DataView(new Uint8ClampedArray(bufferLike).buffer);
} else {
return new DataView(bufferLike);
}
};

Copy link
Member

Choose a reason for hiding this comment

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

I noticed a performance impact by your implementation. I played a bit with the code and this is faster. I guess because the bufferLike is in nearly all cases a Uint8Array.
I don't think there is a need to support any other TypedArray type.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think there is a need to support any other TypedArray type.

I disagree, and I don't think it would be difficult to support it.
The improvement from performance is likely just the change in ordering of the if cases, can you experiement whether there is a significant difference when you change bufferLike.constructor === Uint8Array back to ArrayBuffer.isView(bufferLike) in your suggestion? Also I doubt the IIFE is make any difference either because it should just be inlined by the JIT.

Copy link
Member

Choose a reason for hiding this comment

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

Thee IIFE is removed for better code readabilty and I also doubt it affects the performance. I will benchmark your suggestions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thee IIFE is removed for better code readabilty

I guess this is certainly something to argue about, but I think the IIFE improves readability because it DRY's up the code. If I see the same code repeated in all branches, it usually creates suspicion for me that this could be the source of a bug from mindlessly copy-pasting code. But that is certainly controversial.

@JoergAtGithub
Copy link
Member

I tested this under various conditions on Windows 7 and Windows 11 and it always worked. There is a slight performance degrations but this is not so clear to measure. Therefore this is Ok for me, further performance improvements can be done in Follow-Up PRs if needed.
Thank you!

@JoergAtGithub JoergAtGithub merged commit 5b5af37 into mixxxdj:2.4 May 8, 2023
@Swiftb0y Swiftb0y deleted the fix/gh11461 branch May 8, 2023 20:20
@Swiftb0y
Copy link
Member Author

Swiftb0y commented May 8, 2023

Thank you for the review. 👍

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.

None yet

3 participants