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

filter OSC response based on bufnum #3645

Merged
merged 11 commits into from
Apr 25, 2018

Conversation

patrickdupuis
Copy link
Contributor

Fixes #3611

Use argTemplate to filter query responses based on the Buffer's bufnum. This needs a UnitTest. I can write try and write one later. I've opted to based this on develop since 3.9.3 is set for tomorrow. We can always cherry-pick this into 3.9 if we want.

@patrickdupuis patrickdupuis added bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs. comp: class library SC class library labels Apr 6, 2018
@patrickdupuis patrickdupuis added this to the 3.10 milestone Apr 6, 2018
@mossheim
Copy link
Contributor

mossheim commented Apr 7, 2018

This looks good at a glance, but we should have a test. And actually, there's no way to do that easily because .query's response is hardcoded to go to the post window. This would be a good opportunity to make query more flexible. It could take an action argument like all the other buffer methods. When nil, it would have the current behavior (backwards compatibility). Otherwise, the function would be called with bufnum, numFrames, numChannels, sampleRate as arguments.

Writing tests is actually a pretty good way to catch interface design flaws IMO. :)

Thoughts @jamshark70 @telephon ?

@telephon
Copy link
Member

telephon commented Apr 7, 2018

yes, like this perhaps?

query { |action|
	if(bufnum.isNil) { Error("Cannot call % on a % that has been freed".format(thisMethod.name, this.class.name)).throw };
	action = action ?? {
		{ |bufnum, numFrames, numChannels, sampleRate|
			"bufnum: %\nnumFrames: %\nnumChannels: %\nsampleRate: %\n".format(
				bufnum, numFrames, numChannels, sampleRate
			).postln
		}
	};
	OSCFunc({ |msg| 
		action.valueArray(msg.drop(1)) 
	}, \b_info, server.addr, nil, [bufnum]).oneShot;
	server.listSendMsg([\b_query, bufnum])
}

@mossheim
Copy link
Contributor

mossheim commented Apr 7, 2018

Exactly! Then the test becomes trivial to write and the method is much more flexible.

@patrickdupuis
Copy link
Contributor Author

Sorry for the delay on this. I've modified the query method as suggested and added a simple UnitTest. Please review 👍

Copy link
Contributor

@mossheim mossheim left a comment

Choose a reason for hiding this comment

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

Correct spelling is "response", and use a non-default server

@@ -585,14 +585,18 @@ Buffer {
^[\b_close, bufnum, completionMessage.value(this) ]
}

query {
query { |action|
Copy link
Member

Choose a reason for hiding this comment

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

ah, actually, could you be so kind and also document the new argument in the Buffer helpfile?

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! Please suggest any improvements.

@patrickdupuis
Copy link
Contributor Author

FYI - I can't spell.

Will do the doc addition and change the test to use a non-default server.

@telephon telephon changed the title filter OSC responce based on bufnum filter OSC response based on bufnum Apr 16, 2018
@@ -833,7 +833,8 @@ x.free; b.free;

method:: query
Sends a b_query message to the server, asking for a description of this buffer. The results are posted to the post window. Does not update instance vars.

argument:: action
An optional Function to be evaluated which will be passed the buffer's information as argument. Providing a function here will bypass this method's normal behaviour. A description of the buffer will not be posted.
method:: updateInfo
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion, instead of " An optional Function to be evaluated which will be passed the buffer's information as argument." you could write:

An optional Function to be called with the query reply as an argument (code::["\b_query, bufnum, numFrames, numChannels, sampleRate]::).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, will do. The argument that is passed to the function is actually: [/b_info, bufnum, numFrames, numChannels, sampleRate]

@@ -833,7 +833,8 @@ x.free; b.free;

method:: query
Sends a b_query message to the server, asking for a description of this buffer. The results are posted to the post window. Does not update instance vars.

argument:: action
An optional Function to be called with the query reply as an argument (code::[/b_info, bufnum, numFrames, numChannels, sampleRate]::). Providing a function here will bypass this method's normal behaviour. A description of the buffer will not be posted.
Copy link
Contributor

Choose a reason for hiding this comment

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

iiuc the function will be called with five arguments, not 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 think it receives an array with 5 elements as argument, but i'll double check...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're right, it's 5 individual arguments.

@mossheim
Copy link
Contributor

Thanks for this! I think the unit tests are very well written and would make good examples.

@mossheim mossheim merged commit 6c7e08f into supercollider:develop Apr 25, 2018
@patrickdupuis
Copy link
Contributor Author

Merci, mon ami! 😀

@patrickdupuis patrickdupuis deleted the topic/query branch April 25, 2018 19:26
mossheim pushed a commit that referenced this pull request Apr 27, 2018
add unit tests and documentation

see also #3645
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.

3 participants