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

MIDI4lights: Give beginTimer callbacks the anonymous function expression form #12048

Merged
merged 1 commit into from
Oct 17, 2023

Conversation

geraldog
Copy link
Contributor

@geraldog geraldog commented Oct 1, 2023

Merged PR #11953 "fix(controllers): engine.beginTimer(ms, string) would evaluate the code immediately instead of after ms" requires anonymous functions expressions instead of string literals.

This should solve #12042

@ronso0 ronso0 changed the title Give beginTimer callbacks the anonymous function expression form MIDI4lights: Give beginTimer callbacks the anonymous function expression form Oct 1, 2023
@Swiftb0y
Copy link
Member

Swiftb0y commented Oct 1, 2023

#11953 should've fixed this exact issue already though. If #11953 works correctly, this PR would just be noop. Do you think #11953 is broken?

@geraldog
Copy link
Contributor Author

geraldog commented Oct 1, 2023

Hi @Swiftb0y and sorry for bringing you out of your time off.

I tested again and again with real fixture to make sure we understand better the problem and save some face. Still, it seems I need to test even more but let me explain.

I use a modified midi_for_light.vuMeter to interact with AudioPathType::Stem I have created in my fourstems_padj_2023 branch.

Without the proposed fix, here's the warning I get when I engage my Programmable AutoDJ with Stems capabilities:

controller.midithroughport0:warning [Controller] "passed a string to 'engine.beginTimer', please pass a function instead!"

And it doesn't work properly. I specifically lose the on-beat information!

@geraldog
Copy link
Contributor Author

geraldog commented Oct 2, 2023

@Swiftb0y as not to waste your precious time I reproduced #12042 with Vanilla Mixxx (no weird customizations). I had a hunch the author of #12042 was using AutoDJ too like me, and lo and behold if you don't touch the crossfader but instead rely on AutoDJ to do crossfading to the next song for you, the bug happens and I get the same warning as with the strange customizations.

EDIT: I was able to reproduce the bug multiple times now, and sometimes I happen to lose Deck 1 instead of the opposite. I'm still not sure what exactly triggers the bug, I would bet on some timing issue, and I'm putting no pressure to merge this as is. It definitely deserves more investigation.

@Swiftb0y
Copy link
Member

Swiftb0y commented Oct 2, 2023

Without the proposed fix, here's the warning I get when I engage my Programmable AutoDJ with Stems capabilities:

Right, thats a warning that the mapping needs some update love. This PR fixes that warning, but the behavior should be identical due to #11953

I have no doubt that you are experiencing the issue you're describing (I have never looked into the midi4lights script myself so I'm not the right person for this anyways). The thing I don't understand is how this PR is supposed to fix #12042. Since as I said, the behavior should I identical (assuming #11953 works as intended).

So, are you confident that this PR actually fixes #12042? I'm unfortunately not able to confirm for myself.

@Swiftb0y
Copy link
Member

Swiftb0y commented Oct 2, 2023

I appreciate it highly btw that you are so understanding of my personal resource constraints. Thank you.

@geraldog
Copy link
Contributor Author

geraldog commented Oct 2, 2023

I have no doubt that you are experiencing the issue you're describing (I have never looked into the midi4lights script myself so I'm not the right person for this anyways). The thing I don't understand is how this PR is supposed to fix #12042. Since as I said, the behavior should I identical (assuming #11953 works as intended).

So, are you confident that this PR actually fixes #12042? I'm unfortunately not able to confirm for myself.

No, I'm not confident at all. We need the author of #12042 to test the proposed fix, see if it solves his bug too.

Copy link
Member

@Holzhaus Holzhaus left a comment

Choose a reason for hiding this comment

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

Thanks. Please check if we can pass the function directly instead of wrapping it in an anonymous function.

res/controllers/Midi_for_light-scripts.js Outdated Show resolved Hide resolved
res/controllers/Midi_for_light-scripts.js Outdated Show resolved Hide resolved
res/controllers/Midi_for_light-scripts.js Outdated Show resolved Hide resolved
@geraldog
Copy link
Contributor Author

geraldog commented Oct 3, 2023

Yes Jan it works normally by passing the function directly, except for the functions which need arguments of course, which I kept as anonymous function expressions.

@Holzhaus
Copy link
Member

Holzhaus commented Oct 3, 2023

Yes Jan it works normally by passing the function directly, except for the functions which need arguments of course, which I kept as anonymous function expressions.

Good 👍

I think you didn't push your changes yet though.

Alternatively, use the anonymous function expressions for callbacks
with arguments.
@geraldog geraldog force-pushed the midi_for_lights_javascript_anonymous branch from b64cb33 to 8fafbd1 Compare October 4, 2023 20:52
Copy link
Member

@Holzhaus Holzhaus left a comment

Choose a reason for hiding this comment

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

Code changes look good to make and make sense, even if they don't fix #12042 (the changes should make no difference, but I didn't test).

@geraldog it would be great if you could apply the proposed fixes from eslint to fix the pre-commit CI failure, too.

@geraldog
Copy link
Contributor Author

geraldog commented Oct 4, 2023

Hi Jan, thanks for the review by the way, and thank you @ronso0 for updating with the correct title, my bad.

Code changes look good to make and make sense, even if they don't fix #12042 (the changes should make no difference, but I didn't test).

The changes do make a difference Jan, they don't go through that code path that Niko fixed inside src/controllers/scripting/legacy/controllerscriptinterfacelegacy.cpp in #11953. Namely:

int ControllerScriptInterfaceLegacy::beginTimer(
        int intervalMillis, QJSValue timerCallback, bool oneShot) {
    if (timerCallback.isString()) {
        m_pScriptEngineLegacy->logOrThrowError(
                QStringLiteral("passed a string to 'engine.beginTimer', please "
                               "pass a function instead!"));
        // wrap the code in a function to make the evaluation lazy.
        // otherwise the code would be evaluated immediately instead of after
        // the timer which is obviously undesired and could also cause
        // issues when used recursively.
        timerCallback = m_pScriptEngineLegacy->jsEngine()->evaluate(
                QStringLiteral("()=>%1").arg(timerCallback.toString()));
    } else if (!timerCallback.isCallable()) {

@geraldog it would be great if you could apply the proposed fixes from eslint to fix the pre-commit CI failure, too.

I will look into it Jan, and I don't want to be rude that's why I held back on this comment I'm about to make.

Niko said the script needs more love, but I consider this an understatement. Quite frankly that script looks like one of my hacks, amazing but kind-of constructed in a rush, if you know what I mean.

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.

welp, lgtm, eslint failure is expected. Still very likely won't solve #12042

@Swiftb0y Swiftb0y merged commit bc776e0 into mixxxdj:2.4 Oct 17, 2023
12 of 13 checks passed
@geraldog
Copy link
Contributor Author

Thanks @Swiftb0y

@geraldog geraldog deleted the midi_for_lights_javascript_anonymous branch October 29, 2023 03:21
@ronso0 ronso0 mentioned this pull request Jan 9, 2024
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