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 currentSettingsAsCompileString #33

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

LFSaw
Copy link
Contributor

@LFSaw LFSaw commented May 28, 2024

I often find myself in the situation that I'd like to save only the specific settings for a NodeProxy.
This method (extracted from NodeProxy:asCode, src) returns the current settings as a compileString, ready to be used further.

I am unsure about the (quite clunky) name, feedback welcome.

Here is a testcase:

(
Ndef(\testMeSettings, {|amp = 0.1, fFreq = 100, fRq = 0.1|
	RLPF.ar(WhiteNoise.ar(amp, AmpComp.kr(fFreq)), fFreq, fRq)!2
})
)

Ndef(\testMeSettings).play
Ndef(\testMeSettings).set(\fFreq, exprand(100, 4000), \fRq, rrand(0.01, 2))


Ndef(\testMeSettings).currentSettingsAsCompileString;
// -> Ndef('testMeSettings').set('fFreq', 551.13632443201, 'fRq', 0.46147141933441);

Copy link
Contributor

@telephon telephon left a comment

Choose a reason for hiding this comment

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

I wonder if this whole thing of using a = is so practical (in general and also here). We could also:

  • return .set(...) for anonymous proxies, or
  • pass in a default name that is added

Is it useful to pass in the environment?
In the case where envir is nil, the envir.use is redundant:

envir = envir ? currentEnvironment;
nameStr = envir.use { this.asCompileString };

So if you have a use case, that would be good.

@LFSaw
Copy link
Contributor Author

LFSaw commented Jun 6, 2024

Thanks for looking into this!

my usecase is as above.

That said, I am happy to streamline the function, however, I also have to say that I do not fully understand the inner workings of NodeProxy enough to see what the envir is used for in this case, so I do not understand why it might need to be passed in here.
My approach in "writing" this function was merely to provide some functionality (namely exposing the current state of a NodeProxy) for people to use further and independent of the monolithic approach of NodeProxy:asCode.

@LFSaw
Copy link
Contributor Author

LFSaw commented Jun 6, 2024

maybe @adcxyz wants to add his ideas?

@adcxyz
Copy link
Contributor

adcxyz commented Jun 6, 2024

Yes nodeProxy.asCode is too monolithic.

The main thing that is needed across its parts is accessStr,
and duplicating that to a new method seems inelegant.
Those first few lines of NodeProxy.asCode could be a separate method accessStr,

then currentSettingsAsCompileString (or maybe settingsCS ?) could be

+ NodeProxy
	settingsCS { |accessStr| 
		accessStr = accessStr ? this.accessStr;
		this.nodeMap.asCode(accessStr);
	}
// default use 
Ndef(\testMeSettings).settingsCS;
// custom name
x.settingsCS("x");

@LFSaw
Copy link
Contributor Author

LFSaw commented Nov 12, 2024

Teaching classes, I again and again stumble over the demand to quickly and programmatically access the current state of an Ndef (NodeProxy) in order to (a) reproduce it e.g. as a preset or (b) us it as a basis for (hand-crafted) derivations.
This was my original intention with this PR.
Since I seem to be the only one stumbling over this, do I miss a better way of doing this?

My original test case (above) is pretty much summing up what I'd love to have...

An intermediate step would be to be able to save presets and recall, manipulate programmatically, or postcs them.

I know that there is ProxyPreset, however, the documentation is based on Tdef and not very intuitive... Also, when I try to use it, I run into all kinds of issues with the preset crossfade that is not behaving the way I'd expect it... (e.g. it resets the crossfade slider and its target values when saving a new preset). It does, however, provide a list of all parameters per preset in a file; maybe the behavior I am describing above could be derived from there?

@telephon
Copy link
Contributor

I am very much in favour of bringing source code and object as close together as possible.

Sorry for having left this lying around. I was unsure if I should really keep this "a = " in the standard library.

We have three cases:

  1. free standing NodeProxy
  2. NodeProxy in a ProxySpace
  3. Ndef (which is also in a ProxySpace)

It would be good to resolve these more clearly. But for now, we can go along the lines of what is there, we can refactor later.

Copy link
Contributor

@telephon telephon left a comment

Choose a reason for hiding this comment

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

just a few minor things.

@@ -0,0 +1,18 @@
+ NodeProxy {
accessStr { | envir |
Copy link
Contributor

Choose a reason for hiding this comment

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

Calling it accessString reads better, and we know that it is not a stream.

@@ -0,0 +1,18 @@
+ NodeProxy {
accessStr { | envir |
var accessStr = "a", nameStr, isAnon;
Copy link
Contributor

Choose a reason for hiding this comment

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

why not "a ="?

isAnon = nameStr.beginsWith("a = ");
if (isAnon.not) { accessStr = nameStr };

^accessStr;
Copy link
Contributor

Choose a reason for hiding this comment

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

you can drop the semicolon if you like.

^accessStr;
}

currentSettingsAsCompileString {
Copy link
Contributor

Choose a reason for hiding this comment

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

settingsAsCompileString would be better. Settings are always current, just like any object.

Copy link
Contributor

@adcxyz adcxyz Dec 20, 2024

Choose a reason for hiding this comment

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

For consistency, I would propose settingsAsCode.
on N/P/Tdefs, asCompileString only posts the access string,
while asCode fully reconstructs the object.

Also for consistency, PatternProxy should have a settingsAsCode method.

And all asCode and settingsAsCode methods should allow passing in an accessString
that overrides the auto-generated (or guessed) ones, since users might know better.
I can try that here, or in a different PR.

2c, adc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please try :)

Copy link
Contributor

Choose a reason for hiding this comment

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

will do!
Until this is finalized, you could do:

Ndef(\x, { LFSaw.ar(\freq.kr) }).set(\freq, 123);
Ndef(\x).nodeMap.asCode(Ndef(\x), true); 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hello, so wow; I was not aware of ProxyNodeMap:asCode, somehow...

so would

+ NodeProxy {
	settingsAsCode{|namestring, dropOut = true| 
		namestring = namestring ?? {this.asCompileString};
		^this.nodeMap.asCode(namestring, dropOut); 
}

do the trick?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants