0

我正在尝试将 OSC 消息绑定松散地耦合到处理它们的函数:

f = {|msg| msg.postln};
OSCFunc({|msg, time, addr, recvPort| f(msg)}, '/2/push1')

我认为这很简单。我可以在任何时候替换 f ,因此随意处理来自路径的消息/2/push1

但是当我点击按钮(发送带有路径的消息/2/push1)时,我收到一条错误消息:

Message 'f' not understood.

所以我猜f在调用中声明的函数范围内有不同的含义OSCFunc。我想它有不同的Environment

我还尝试将函数放入常规变量中:

(
var myFunction = {|msg| msg.postln};
OSCFunc({|msg, time, addr, recvPort| myFunction(msg)}, '/2/push2');
)

但这会导致相同的错误。

有没有解决的办法?当然,我不必OSCFunc每次都在其中放置整个函数体吗?

4

2 回答 2

2

No, your problem is just a SuperCollider syntax issue - it lies in what you've written here:

  f(msg)

I think that you're hoping this "invokes" the function f with msg as an argument. However, SuperCollider's syntax isn't quite like that - it actually interprets that as being an equivalent way of calling msg.f(), which is why it throws an error saying that msg knows no f message. Instead, you need to use the value message on your Function:

  f.value(msg)

I can't find a tutorial that spells this out right now, so instead here's a link to the Function helpfile.

于 2014-03-23T19:09:53.417 回答
0

我用谷歌搜索了一下,发现了这个:

f = {|msg, time, addr, recvPort| msg.postln};
o = OSCFunc(f, '/2/push1');

这工作正常。OSCFunc还要注意对变量的调用分配。这使我能够通过调用“取消注册”绑定:

o.free;
于 2014-03-22T12:33:54.517 回答