SimpleNumber .lag .slew .varlag etc.?

can someone please point me to the Lag.kr, Slew.kr, VarLag.kr equivalents for SimpleNumber .lag .slew .varlag if they exist ? or is there a library ?
in the SimpleNumber helpfile they are called “UGen Compatibility Methods” and only return the unchanged value.
also looking for a max like “change”

thanks

can someone please point me to the Lag.kr, Slew.kr, VarLag.kr equivalents for SimpleNumber .lag .slew .varlag if they exist ? or is there a library ?
in the SimpleNumber helpfile they are called “UGen Compatibility Methods” and only return the unchanged value.

I think there is no meaningful way to implement them for simple numbers.

A simple number simply is its value. You can’t “change the state” of a simple number or transition a simple number from one state to another. A different-value simple number is a different object.

Specifically for lag etc.: gradual movement is meaningful only if there is some rate at which you are observing the change. (In Max/pd you would need a [snapshot~].) In the server, that’s easy: audio rate and control rate are running all the time. In the language, you would have to run some sort of routine to read the lag curve over time – but then this is not simply interchangeable with a simple number.

So it’s more complicated than you thought.

also looking for a max like “change”

For signals in the server, you can use Changed.ar / .kr (which is really just a shortcut for HPZ1.ar(input).abs > 0).

For SimpleNumbers, the concept of “changed” is meaningless because the number is simply its value. If it “changes” then you have a different object.

hjh

It’s not entirely clear what you want to achieve, but in case you want to interpolate between two numbers, have a look at methods linlin, explin and linexp,

e.g. to calculate the value at 30% between 4 and 5 using linear interpolation, you could write

30.linlin(0, 100, 4, 5)

to get

-> 4.3

i need the functions to smooth and filter controller values.
something that holds a value and returns something with each time step and is reusable.

something like this as classes:

filter:

(
var s = 0;
~smooth = {|val|
	var d = 0.5;
	s = (val * (1 - d)) + (s  *  d);
};
)
(
x=10.rand;
(x +" "+ ~smooth.value(x)).postln;
)

changed:

(
var prevVal = 0;
~changed = {|val|
	if(prevVal != val,{prevVal=val;true},{prevVal=val;false});	
};
)
(
x=10.rand;
// x=10;
if(~changed.value(x), {x.postln});
)

i was wondering if they already exist and i just don’t see them.

thank you

edit: changed code formating

You might want to check out the help files for NamedControl (on my phone, so typing from memory… might be wrong about the exact name). There is a lag argument there which I find very useful.

i need the functions to smooth and filter controller values. something that holds a value and returns something with each time step and is reusable.

BTW, please enclose code blocks in triple-backticks, e.g.

```
my code
```

Pasting them as plain text removes all of the indentation and also corrupts quote marks.

(
var s = 0;
~smooth = { |val|
	var d = 0.5;
	s = (val * (1 - d)) + (s * d);
};
)

OK, I see, recursive filtering, and you’re not worried about timing.

It might be slightly more elegant to encapsulate the state in a routine, e.g.

(
~makeFilter = { |initValue = 0, coefficient = 0.5|
	Routine { |inval|
		var value = initValue;  // so that you can 'reset'
		loop {
			value = (inval - value) * coefficient + value;
			inval = value.yield;
		}
	}
};
)

f = ~makeFilter.value(0, 0.5);

~steppedValues = Pstutter(20, Pwhite(0.0, 1.0, inf)).asStream;
Array.fill(100, { f.next(~steppedValues.next) }).plot

// reset to initValue and do it again -- can't do that with plain function
f.reset;
Array.fill(100, { f.next(0.5) }).plot

You might want to check out the help files for NamedControl (on my phone, so typing from memory… might be wrong about the exact name).

NamedControl is server-side. This discussion is about language side numbers.

hjh

great. this helps a lot.
also didn’t know about NamedControl.
but yes my question was language side.

thank you guys