Algorithmic Freq / Marimba?

Hi everyone!
I’m trying to discover what is up into the ~n and ~rut // How are they related to the Algorithmic Pattern?

Andrea Gómez

(
~n=3;
SynthDef.new(\bellA,{
arg freq=4, amp=0.8;
var fund, harm1,harm2,harm3,harm4,sig,env,p;
//envelope
env=EnvGen.kr(Env.perc(1,0.1));
//spectral content
sig=Klang.ar(`[
[1]++Array.rand((~n-1),1,300).sort,
Array.rand(~n,0.01,0.5).sort.reverse,
Array.rand(~n,0,pi)
],freq);
sig=sigenv;
//effects
sig=Pan2.ar(sig,0);
//output
Out.ar(0,sig);
}).play;
)
(~rut=Routine({
{
p = Pbind(
[
instrument: (\default),
freq: Pseq(Array.rand(5,10,1000).scramble),
db: Pseq(Array.rand(1,-10, -30).scramble),
pan: Pseq([-1,0,1,0], inf),
dur: Pseq([Array.rand(4,1.0,3.0).scramble], inf),
]);

p.play;
1.wait;
}.loop;
}).play;

)

////////////////////////////

(~n=2;
Synth(\bellA))

Could you please format code blocks like so?

```
your code here
```

These are backticks (usually top left key, to the left of 1).

I can see that some * characters in your example were treated as formatting marks (note the italics in the middle of the code), so we have to fix it before trying to run it – can’t just copy/paste.

hjh

(
~n=3;
SynthDef.new(\bellA,{
arg freq=4, amp=0.8;
var fund, harm1,harm2,harm3,harm4,sig,env,p;

env=EnvGen.kr(Env.perc(1,0.1));

sig=Klang.ar(`[
	[1]++Array.rand((~n-1),1,300).sort,
	Array.rand(~n,0.01,0.5).sort.reverse,
	Array.rand(~n,0,pi)
	],freq);
sig=sig*env;

sig=Pan2.ar(sig,0);

Out.ar(0,sig);

}).play;
)
(~rut=Routine({
{
p = Pbind(*[
instrument: (\default),
freq: Pseq(Array.rand(5,10,1000).scramble),
db: Pseq(Array.rand(1,-10, -30).scramble),
pan: Pseq([-1,0,1,0], inf),
dur: Pseq([Array.rand(4,1.0,3.0).scramble], inf),
]);

p.play;
1.wait;
}.loop;
}).play;

)

////////////////////////////

(~n=2;
Synth(\bellA))

////////////////////////////////

I donnot know why the forum uses 2 formats of text using Linux Mint as SC user.

The first line before a code example should be only three backticks.

Then paste the code under that.

Then, under the last line in the example, put another line with only three backticks.

Your last code posting begins with a text font, not a code font. From this, I can tell that you didn’t start with three backticks.

If you put in the backticks as explained, it will work.

```
^^ that is the opening 3-backtick line
Your code goes here
vv then finish with another 3 backticks
```

hjh

Hi Andrea -

A few things, just looking at this code:

  1. You can get rid of the error messages in your post window if you change the line
dur: Pseq([Array.rand(4,1.0,3.0).scramble], inf),

to:

dur: Pseq(Array.rand(4,1.0,3.0).scramble, inf),
  1. ~n, in this case, is referring to a number that is being used as an argument in the Klang uGen. Klang is basically a bunch of sine wave oscillators, wrapped into a single uGen. You can have more or less sine waves by how large your array is. That’s what ~n is controlling.

  2. ~rut isn’t really doing much of anything. Try removing it and see what happens. It tends to be “good practice” to assign a routine to some sort of variable, since that will give you control later on, if you want to start, pause, or stop that routine.

Thanks too much James now I understands.

I was thinking ~rut was doing something, no matters, now I understands Gbal.

the last time ~n is used it isn’t doing anything.

when ~n is used in the SynthDef, it is the value of ~n that is passed into SynthDef: 3.

if you change the value of ~n tp 2 after that it won’t change the SynthDef as its already been computed.