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

Update controller mappings for Behringer DDM4000 & BCR2000 to 2.5 #14232

Merged
merged 2 commits into from
Jan 29, 2025

Conversation

git-developer
Copy link
Contributor

@git-developer git-developer commented Jan 26, 2025

This PR updates controller mappings for Behringer DDM4000 and BCR2000 to 2.5:

  • Removal of references to lodash
  • Removal of a quirk that was required before Qt6
  • Replacement of var with const / let

Lodash's _.merge() function performing a deep merge has been replaced. Most locations could be refactored to use a shallow merge (Object.assign()). The only actual requirement for a deep merge is in Behringer-Extension-scripts.js (for component container definitions). It is replaced by a custom implementation.

The code was tested against 2.5 using Behringer controllers DDM4000 and BCR2000.

@git-developer git-developer force-pushed the refactor/gh13617 branch 4 times, most recently from d449056 to f937c93 Compare January 26, 2025 15:17
Copy link
Member

@JoergAtGithub JoergAtGithub left a comment

Choose a reason for hiding this comment

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

Replacing the code, that calls code marked as deprecated, is a good thing. But we must not remove the deprecated code for compatibility reasons.
Backward compatibility to existing mapping scripts (this includes non-official mappings by our users) must be guranteed. Therefore please restore the deleted code in common-controller-scripts.js and midi-components-0.0.js.

@git-developer
Copy link
Contributor Author

Thanks for looking into this PR so quickly.

I agree that in general, removal of code without deprecation (warning) is a no-go because it could break existing code. But I think the situation is different here.

The functions I remove here were introduced recently in 2.5. deepMerge() throws runtime errors as soon as it is called (because of a missing missing script. prefix on recursive call). That means it is actually never called. setLayer() was introduced in 2.5 as variant of applyLayer() without dependency on lodash. But applyLayer() was refactored to no longer rely on lodash, so it's no longer necessary.

I'd appreciate if @Swiftb0y and @christophehenry could add their opinion on keeping or removing these two functions. They know about this topic from #14197. I will then change the code accordingly.

@JoergAtGithub JoergAtGithub dismissed their stale review January 26, 2025 15:45

Ok, than it seems indeed to be a special case here.

@git-developer git-developer marked this pull request as ready for review January 26, 2025 16:23
deepMerge(objTarget, objSource);
target.length = 0;
target.push(...Object.values(objTarget));
} else if (isSimpleObject(target) && isSimpleObject(source)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove the isSimpleObject function above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Done.

@Swiftb0y
Copy link
Member

@JoergAtGithub, I agree with the assessment made by @git-developer. setLayer() has only been introduced recently, so the chance that mappings rely on them is very slim. deepMerge() seems to have been broken from the start and we have not received a report on this until now, I think that this is evidence that the number of affected mappings is negligible. Wdyt?

@JoergAtGithub
Copy link
Member

Yes, if we just added it in 2.5.0 and it's not working as intended, then I think it's best to remove it immediately in 2.5.1.

@git-developer
Copy link
Contributor Author

I think it's best to remove it immediately in 2.5.1

I agree, it's just that this PR is currently targeted at main. setLayer() does not exist in 2.5. I can open a second PR against 2.5 and cherry-pick the appliable changes there. Would that be OK?

* @see `GenericMidiController` on component container definition
* @private
*/
const mergeDefinitions = (targetObject, ...sources) => sources.reduce((target, source) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand… You need a deep merging algorithm after all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, 1 of 4 uses of lodash's _.merge() requires a deep merge, the other 3 uses are working with a shallow merge. The scope is within Behringer-Extension-scripts.js only. It is used to merge mapping definitions of the user with defaults from the user and defaults from the mapping. Most mapping definitions simply contain data, but the ShiftButton may also reference a JS object (the target that is shifted by the button). This may cause a circular reference in the mapping description that must be considered in the merge algorithm.

This is the only case I found requiring a deep merge. No commonly used location (like applyLayer()) is affected anymore. Due to the limited scope, verifying the behavior was feasible.

@git-developer git-developer force-pushed the refactor/gh13617 branch 2 times, most recently from d0b2c1a to 83ed303 Compare January 27, 2025 05:34
@git-developer
Copy link
Contributor Author

I removed lodash from the XML file. Now the build fails:

warning [0x56179af74560] ControllerScriptHandlerBase:
"Uncaught exception: file:///home/runner/work/mixxx/mixxx/res/controllers/Behringer-DDM4000-scripts.js:6:
ReferenceError: behringer is not defined

Backtrace: %entry@file:///home/runner/work/mixxx/mixxx/res/controllers/Behringer-DDM4000-scripts.js:6"

The mapping works in 2.5. Does the test setup require special handling when scriptfiles are included?

@Swiftb0y
Copy link
Member

not really. I suspect its because of the change from var to const. Try changing line 6 back to var in the DDM4000 script. Add a // eslint-next-line-disable no-var above in case eslint complains.

@christophehenry
Copy link
Contributor

I would advise that you keep your changes to the Behringer scripts in a separate PR so that this one is kept atomic.

@git-developer
Copy link
Contributor Author

OK, I'll fix the tests and then split the PR.

@git-developer
Copy link
Contributor Author

git-developer commented Jan 28, 2025

This PR is now focused on updating the Behringer mappings to 2.5. Removal of deepMerge() and setLayer() has been moved to #14203 (2.5) and #14251 (main)

@git-developer git-developer changed the title Remove deprecations from controller mappings Update controller mappings for Behringer DDM4000 & BCR2000 to 2.5 Jan 28, 2025
@git-developer
Copy link
Contributor Author

May I ask a related question to @christophehenry: I noticed that Registering MIDI Input Handlers From Javascript was implemented in #12781. Do you know an example where a <script-binding /> element was refactored to Javascript?

The Behringer mappings heavily rely on ComponentsJS and contain hundred of lines of XML (DDM4000 / BCR2000) just to delegate to a single input dispatcher function. It would be great if this could be simplified using JS.

Copy link
Member

@Swiftb0y Swiftb0y left a comment

Choose a reason for hiding this comment

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

Almost LGTM. I assume you have done a smoke test with the DDM or BCR?

res/controllers/Behringer-Extension-scripts.js Outdated Show resolved Hide resolved
@christophehenry
Copy link
Contributor

Do you know an example where a element was refactored to Javascript?

Not yet. I am working on a Denon DN-S3700 controller that will use it at some point. When I'm done, I'll propose for official inclusion.

@git-developer
Copy link
Contributor Author

I assume you have done a smoke test with the DDM or BCR?

Thanks for the reminder. I did, but not after that latest changes. All global objects require var. I changed that accordingly and made a test after the latest change, using both DDM4000 and BCR2000.

Copy link
Member

@Swiftb0y Swiftb0y left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you raising the original issue and adressing it. Thank you also @christophehenry for being so responsive and brainstorming possible solutions as well. Thank you both.

@Swiftb0y Swiftb0y merged commit 98d5892 into mixxxdj:2.5 Jan 29, 2025
13 checks passed
@git-developer git-developer deleted the refactor/gh13617 branch January 30, 2025 05:47
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.

4 participants