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

simplify ControllerEngine::connectControl #656

Closed
wants to merge 2 commits into from

Conversation

Be-ing
Copy link
Contributor

@Be-ing Be-ing commented Jul 20, 2015

also make debugging and error messages more descriptive

This fixes https://bugs.launchpad.net/mixxx/+bug/1458264:
engine.connectionControl(group, control, function, true) connects control to a function rather than removes connection)

I tried writing a test to demonstrate the above bug but couldn't get the test to fail (on a branch without this commit of course). I did see that the bug was there because the test output showed the connection being made twice, but the logic of the test did not fail when this happened.

…nnectControl

also make debugging and error messages more descriptive
This fixes https://bugs.launchpad.net/mixxx/+bug/1458264 ('engine.connectionControl(group, control, function, true) connects control to a function rather than removes connection')
@Be-ing
Copy link
Contributor Author

Be-ing commented Jul 20, 2015

I noticed that the tests use a syntax that is not documented on the wiki (http://mixxx.org/wiki/doku.php/midi_scripting#automatic_reactions_to_changes_in_mixxx ):

        "    connection = engine.connectControl('[Test]', 'potmeter', \n"
        "                            'testConnectDisconnectControlCallback');\n"

and

        "    connection.disconnect();\n"

As far as I can tell by grepping for '.disconnect(' in the source, only one mapping, the one for the Denon MC6000Mk2, users this convention and only on one line. Why is this available if it is not documented? Should the tests be modified to reflect the documentation, that is using engine.connectControl with true as the last argument? Should this feature be removed to simply controllerengine.cpp? Or should the wiki be updated to mention this? I think this feature is confusing because the wiki says connectControl should return true or false.

QScriptValue function;
ControllerEngineConnection conn;
conn.key = ConfigKey(group, name);
conn.ce = this;
Copy link
Member

Choose a reason for hiding this comment

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

can you rename this to something more significant like "conn.parent = this" or similar.

@daschuer
Copy link
Member

Thank you for the patch.
You are right, the disconnect() function is somehow redundant. It is a bit faster but requires storing the connection inside the script. In any case it is not recommend to use connect and reconnect in time critical loops since connect and reconnect is a locking inside QT.
What is the use case for disconnect a CO?

@Be-ing
Copy link
Contributor Author

Be-ing commented Jul 20, 2015

What is the use case for disconnect a CO?

Do you mean the disconnect() function specifically or disconnecting a CO from a script function in general? Disconnecting COs is essential for deck toggle buttons and programming different layers.

@daschuer
Copy link
Member

I have not analyses what bad can happed due to the Qt locking. But in any case our connect and disconnect functions are not light weight. A a common dispatcher callback that calls the active deck callbacks would be a better solution.

We should offer a library that includes a deck toggle layer that does not require connect and disconnect.
But that is an other story.

For now I think we should keep disconnect and update the doku since this will keep the API unchanged.

@Be-ing
Copy link
Contributor Author

Be-ing commented Jul 20, 2015

In any case it is not recommend to use connect and reconnect in time critical loops since connect and reconnect is a locking inside QT.

I can't think of a use case that would require (dis)connecting controls in a time critical loop, but it would be good to make a note of that on the wiki.

We should offer a library that includes a deck toggle layer that does not require connect and disconnect.

Yes, and I think the whole mapping system could really use an overhaul.

But that is an other story

Agreed.

For now I think we should keep disconnect and update the doku since this will keep the API unchanged.

I would rather remove this almost unused and confusingly redundant functionality than document it.
@uklotzde , what is your opinion on that?

@daschuer
Copy link
Member

IMHO the original bug should be fixed in 1.12. The current approach from this PR suits to this.
Keeping disconnect hidden is also Ok for 1.12

There should nothing against streamline this issue for master.

Thoughts?

@Be-ing
Copy link
Contributor Author

Be-ing commented Jul 20, 2015

This bug is not critical, it only affects script writers, and it is trivial to work around. I think the best fix for it is reorganizing the connectControl function, but I am also concerned that this could introduce regressions.

@uklotzde
Copy link
Contributor

The invocation of ".disconnect(" you found in my MC6000MK2 script is a
function of a custom type that I've defined for convenience. The function
DenonMC6000MK2.Control.prototype.disconnect simply calls
engine.connectControl(..., true) internally.

On 07/20/2015 08:54 AM, Be-ing wrote:

In any case it is not recommend to use connect and reconnect in time
critical loops since connect and reconnect is a locking inside QT.

I can't think of a use case that would require (dis)connecting controls in
a time critical loop, but it would be good to make a note of that on the wiki.

We should offer a library that includes a deck toggle layer that does
not require connect and disconnect.

Yes, and I think the whole mapping system could really use an overhaul.

But that is an other story
Agreed.

For now I think we should keep disconnect and update the doku since
this will keep the API unchanged.

I would rather remove this almost entirely unused and confusingly
redundant functionality than document it.
@uklotzde https://github.com/uklotzde , what is your opinion on that?


Reply to this email directly or view it on GitHub
#656 (comment).

@Be-ing
Copy link
Contributor Author

Be-ing commented Jul 20, 2015

Well then, I'm definitely in favor of removing the .disconnect() function and changing the tests to test the method that is actually documented on the wiki and used by scripts.

@Be-ing
Copy link
Contributor Author

Be-ing commented Jul 20, 2015

@pwhelan , care to comment?

@Be-ing
Copy link
Contributor Author

Be-ing commented Jul 20, 2015

https://github.com/Be-ing/mixxx/blob/script_disconnect_control/src/controllers/controllerengine.cpp#L813

I'm not clear about the purpose of this clause. When would the callback be a QObject? Should this clause be removed?

@Be-ing Be-ing changed the title organize ControllerEngine::connectControl and ControllerEngine::disconnectControl simplify ControllerEngine::connectControl Jul 20, 2015
@daschuer
Copy link
Member

Will be OK for me. Do we have conclusion about the target branch?

@daschuer
Copy link
Member

I'm not clear about the purpose of this clause ...

This should be a short cut to re-connect a stored "conn" object.
If you change the return value to boolean, this condition is useless.

simplify ControllerEngine::connectControl
improve debug messages in ControllerEngine::connectControl
consolidate ControllerEngine::disconnectControl into ControllerEngine::connectControl
remove ControllerEngine::disconnect
@Be-ing
Copy link
Contributor Author

Be-ing commented Jul 20, 2015

Will be OK for me. Do we have conclusion about the target branch?

Now that it isn't overcomplicated and I understand what it's doing, I'd be more comfortable merging it into 1.12.

With that functionality removed, the tests need to be updated before this is merged.

@pwhelan
Copy link
Contributor

pwhelan commented Jul 21, 2015

@Be-ing I don't understand your question at all.

@pwhelan
Copy link
Contributor

pwhelan commented Jul 21, 2015

Well then, I'm definitely in favor of removing the .disconnect()

I'm not really in favor of removing this. I actually use it quite a bit. I would be willing to document it on the wiki.

@Be-ing
Copy link
Contributor Author

Be-ing commented Jul 21, 2015

@pwhelan , how do you use it? In what script? What is the advantage of using it rather than connectControl(..., true)? Why should this duplicate functionality be supported?

@daschuer
Copy link
Member

@Be-ing: would you mind to prepare a 1.12 branch, that fixes the issue, but keeps the API?
This way we do not break existing mappings in the wild.

@pwhelan
Copy link
Contributor

pwhelan commented Dec 1, 2015

@Be-ing one huge advantage is that the context of the disconnect is clear, ie: in case there are multiple "callbacks" on the same CO with the same name.

@Be-ing
Copy link
Contributor Author

Be-ing commented Apr 11, 2016

I've started a new branch to present the undocumented functionality in connectControl() in a cleaner way.

@Be-ing
Copy link
Contributor Author

Be-ing commented Mar 15, 2017

@pwhelan

@Be-ing one huge advantage is that the context of the disconnect is clear, ie: in case there are multiple "callbacks" on the same CO with the same name.

Actually that was not the case. Calling the disconnect method on these objects would disconnect all the callbacks connected to that ControlObject sharing the same callback function, even if the this object for the connections was different. I fixed this in #1218.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants