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

Don't override XML mapping when using makeInputHandler #13089

Merged
merged 1 commit into from
May 1, 2024

Conversation

christophehenry
Copy link
Contributor

Follow up of #12781. This PR is designed to prevent overriting an existing XML mapping when when using makeInputHandler.

@@ -631,6 +631,12 @@ QJSValue MidiController::makeInputHandler(int status, int midino, const QJSValue
return QJSValue();
}

if (m_pMapping->getInputMappings().contains(status)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This just check if an existing mapping exists. Should it perform a more thourough search to check if existing binding is an XML type?

Copy link
Member

Choose a reason for hiding this comment

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

I'd argue yes. I think its valid that JS would like to bind different handlers to the same message. It's also possible in the XML manually, so the limitation for pure JS seems arbitrary.

Copy link
Member

Choose a reason for hiding this comment

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

Before, all bindings are from XML right? So the question is regarding to allow a second js binding. Is that your point? Do we have a use case for it? I think in such cases you could just put both features onto one callback.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder why midino is not relevant here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh that's a mistake. Fixed.

@@ -631,6 +631,12 @@ QJSValue MidiController::makeInputHandler(int status, int midino, const QJSValue
return QJSValue();
}

if (m_pMapping->getInputMappings().contains(status)) {
qDebug(m_logBase).nospace() << "Ignoring anonymous JS function for status "
<< status << " because a previous binding exists";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here, I just log a message. I was thinking maybe also log the script line. getScriptEngine()->throwJSError() indicates a line in the script. Is there a similar method to just log a warning?

Copy link
Member

Choose a reason for hiding this comment

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

not that I'd know of. I think its easy enough to identify if you also include the midino in the warning. Alternatively consider using ControllerScriptEngineBase::logOrThrowError.

Copy link
Member

Choose a reason for hiding this comment

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

My guess is:
getScriptEngine()->currentStackFrame->lineNumber()

Copy link
Member

@Swiftb0y Swiftb0y Apr 11, 2024

Choose a reason for hiding this comment

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

that doesn't exist / is private, or at least it seems to be undocumented. where is this from?

Copy link
Member

Choose a reason for hiding this comment

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

I have skimmed through the Qt source.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't find getScriptEngine()->currentStackFrame.

@christophehenry
Copy link
Contributor Author

I didn't write any tests here. Should I?

@daschuer
Copy link
Member

I didn't write any tests here. Should I?

At least don't spend to much time on that. ;-)

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.

Thank you. Here some comments.

@@ -631,6 +631,12 @@ QJSValue MidiController::makeInputHandler(int status, int midino, const QJSValue
return QJSValue();
}

if (m_pMapping->getInputMappings().contains(status)) {
Copy link
Member

Choose a reason for hiding this comment

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

Before, all bindings are from XML right? So the question is regarding to allow a second js binding. Is that your point? Do we have a use case for it? I think in such cases you could just put both features onto one callback.

@@ -631,6 +631,12 @@ QJSValue MidiController::makeInputHandler(int status, int midino, const QJSValue
return QJSValue();
}

if (m_pMapping->getInputMappings().contains(status)) {
qDebug(m_logBase).nospace() << "Ignoring anonymous JS function for status "
<< status << " because a previous binding exists";
Copy link
Member

Choose a reason for hiding this comment

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

My guess is:
getScriptEngine()->currentStackFrame->lineNumber()

@@ -631,6 +631,12 @@ QJSValue MidiController::makeInputHandler(int status, int midino, const QJSValue
return QJSValue();
}

if (m_pMapping->getInputMappings().contains(status)) {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder why midino is not relevant here?

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.

sorry, forgot to submit my review earlier

@@ -631,6 +631,12 @@ QJSValue MidiController::makeInputHandler(int status, int midino, const QJSValue
return QJSValue();
}

if (m_pMapping->getInputMappings().contains(status)) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd argue yes. I think its valid that JS would like to bind different handlers to the same message. It's also possible in the XML manually, so the limitation for pure JS seems arbitrary.

@@ -631,6 +631,12 @@ QJSValue MidiController::makeInputHandler(int status, int midino, const QJSValue
return QJSValue();
}

if (m_pMapping->getInputMappings().contains(status)) {
qDebug(m_logBase).nospace() << "Ignoring anonymous JS function for status "
<< status << " because a previous binding exists";
Copy link
Member

Choose a reason for hiding this comment

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

not that I'd know of. I think its easy enough to identify if you also include the midino in the warning. Alternatively consider using ControllerScriptEngineBase::logOrThrowError.

@christophehenry
Copy link
Contributor Author

I wonder why midino is not relevant here?

You're right. That's fixed.

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 otherwise

src/controllers/midi/midicontroller.cpp Show resolved Hide resolved
Comment on lines 641 to 645
qCWarning(m_logBase) << QString(
"Ignoring anonymous JS function for status=%1,midino=%2 "
"because a previous XML binding exists")
.arg(status)
.arg(midino);
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
qCWarning(m_logBase) << QString(
"Ignoring anonymous JS function for status=%1,midino=%2 "
"because a previous XML binding exists")
.arg(status)
.arg(midino);
qCWarning(m_logBase) << QStringLiteral(
"Ignoring anonymous JS function for status=%1,midino=%2 "
"because a previous XML binding exists")
.arg(status, midino);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Erf, no, that works only for objects that can be casted to QString. When used with (status, midino), C++ select this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do:

Suggested change
qCWarning(m_logBase) << QString(
"Ignoring anonymous JS function for status=%1,midino=%2 "
"because a previous XML binding exists")
.arg(status)
.arg(midino);
qCWarning(m_logBase) << QString(
"Ignoring anonymous JS function for status=%1,midino=%2 "
"because a previous XML binding exists")
.arg(QString::number(status), QString::number(midino));

Copy link
Member

Choose a reason for hiding this comment

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

whoops, good point. yeah, then the double arg is probably fine. suboptimal Qt Api. Still, please wrap the string literal in a QStringLiteral

Copy link
Contributor 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

@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. wdyt @daschuer

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.

LGTM, Thank you.

@daschuer daschuer merged commit 6170466 into mixxxdj:main May 1, 2024
13 checks passed
@christophehenry christophehenry deleted the dont-override-XML-mapping branch May 29, 2024 08:02
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