-
Notifications
You must be signed in to change notification settings - Fork 757
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
Conversation
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 Writing tests is actually a pretty good way to catch interface design flaws IMO. :) Thoughts @jamshark70 @telephon ? |
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])
}
|
Exactly! Then the test becomes trivial to write and the method is much more flexible. |
Sorry for the delay on this. I've modified the |
There was a problem hiding this 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| |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
FYI - I can't spell. Will do the doc addition and change the test to use a non-default server. |
HelpSource/Classes/Buffer.schelp
Outdated
@@ -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 |
There was a problem hiding this comment.
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]::).
There was a problem hiding this comment.
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]
HelpSource/Classes/Buffer.schelp
Outdated
@@ -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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
Thanks for this! I think the unit tests are very well written and would make good examples. |
Merci, mon ami! 😀 |
add unit tests and documentation see also #3645
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
since3.9.3
is set for tomorrow. We can always cherry-pick this into3.9
if we want.