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 NamedControl 'name' String convertion #4761

Merged

Conversation

patrickdupuis
Copy link
Contributor

Purpose and Motivation

A NamedControl's name is converted from a Symbol to a String in cases where the .init function is called (when res == nil). I stumbled upon this while testing #3814. This issue should be fixed before that PR gets merged.

I'm not sure how to demonstrate the issue using current develop, but it may be simple enough to understand just by looking at the changes. Some unused variables were removed (ctlName, ctl, & selector), and name stays a Symbol throughout the .init function.

Types of changes

  • Bug fix

To-do list

  • Code is tested
  • All tests are passing
  • Updated documentation
  • This PR is ready for review

@patrickdupuis patrickdupuis added bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs. comp: class library SC class library labels Feb 8, 2020
@patrickdupuis patrickdupuis changed the title avoid converting name to String Fix NamedControl 'name' String convertion Feb 8, 2020
Copy link
Contributor

@jamshark70 jamshark70 left a comment

Choose a reason for hiding this comment

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

I see nothing wrong with this. I worried a bit about ctlName but it really is unused! So, yes, simplify.

I'm just baffled how the IdentityDictionary lookup ever worked before...

@patrickdupuis
Copy link
Contributor Author

Well name gets converted back to a Symbol later on when a ControlName is created. That's probably why it all works.

@joshpar joshpar self-assigned this Feb 9, 2020
name = name.asString;
if(name[1] == $_) { prefix = name[0]; ctlName = name[2..] } { ctlName = name };
str = name.asString;
if(str[1] == $_) { prefix = str[0] };
};
Copy link
Member

Choose a reason for hiding this comment

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

Not removing the prefix from the ctlName might result in some ambiguity. Just make sure to ckeck whether something like \t_trig.kr and trig.tr don't interfere in a bad way...

Copy link
Contributor

Choose a reason for hiding this comment

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

Not removing the prefix from the ctlName might result in some ambiguity. Just make sure to ckeck whether something like \t_trig.kr and trig.tr don't interfere in a bad way...

I had the same question, but... in the currently released version, ctlName is assigned in this block and then never used.

https://github.com/supercollider/supercollider/blob/develop/SCClassLibrary/Common/Control/GraphBuilder.sc#L123

Here, there are exactly 3 occurrences of ctlName: once to declare it, and twice in the if where it's assigned, and then... nothing.

So ctlName is cruft, and deleting the variable entirely is correct.

@jamshark70
Copy link
Contributor

Well name gets converted back to a Symbol later on when a ControlName is created. That's probably why it all works.

It's moot because you're fixing it, but...

		name = name.asSymbol;

		this.initDict;
		res = currentControls.at(name);

Dictionary lookup by symbol, ok. Then, if a previously created control is not found:

			res = super.newCopyArgs(name, values, lags, rate, fixedLag).init;
			currentControls.put(name, res);

... where .init converts name to a string and then, immediately after, with no intervening statements, IdentityDictionary storage is based on the string.

I might be misreading but it does look like this couldn't have worked in the past. But with the fix, it won't be a problem, so it's fine.

@mossheim mossheim merged commit a859852 into supercollider:develop Feb 15, 2020
@patrickdupuis patrickdupuis deleted the topic/fix-namedcontrol-name branch March 1, 2020 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs. comp: class library SC class library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants