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

add that to UGen methods #7

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions classes/uGen.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
+ UGen {
that { | callback, trigger |
var oscAddress = "/that/ugen/%/%".format(synthDef, synthIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

synthDef will only add a SynthDef. You want some kind of ID, right? But one SynthDef can have many synths. .Why not get the NodeID.ir?

oscAddress.postln;
callback = callback ? {};
trigger = trigger ? Impulse.kr(10.0);
SendReply.perform(
UGen.methodSelectorForRate(trigger.rate),
trigger, // trig
oscAddress, // cmdName
this, // values
);

OSCdef(key: oscAddress, func: { |msg|
Copy link
Contributor

Choose a reason for hiding this comment

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

when the synth ends, you'll want the OSCdef to be released, otherwise you have memory leak. This is not easy to solve, because you are now inside of the build phase of the SynthDef.
Not sure yet what is best to do.

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem is that we can only add methods but no variables to an existing class, so we can not create a state within sclang, but maybe we can trick the server on giving us a clue if something is freed, like a Trigger? I couldnt find something., but if it exists we could use this trigger for a SendReply which then could initiate a deletion of a given OSCdef.

On the other hand: the expected memory leak is not nice but I would accept it for convenience if documented - you'd need to modify an existing Ndef thousands of times in order to create a significant memory usage.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I think it isn't that hard. The OSCfunc should be general, not UGen specific, and only after receiving a message it can decide what to do with it. This needs to be put somewhere, e.g. in a class variable of That. Then you also need a way to register the different Synths that run and their that-UGens, and using NodeWatcher and SimpleController you can register actions that remove the synths. But it is also possible to just say that after a certain time having received no message, the function is removed by some global task that checks. I am not so much in favour of MVC, so the latter seems also a good solution (although there may be reasons you want to have a long grace time?).

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively, the https://github.com/supercollider-quarks/Sequencer implementation could be taken and just reformulated a little.

var nodeId, replyId, values;
#nodeId, replyId ... values = msg[1..];
callback.(values, nodeId);
}, path: oscAddress).fix;
}
}