# Increasing randomness of sequence

``````Hey guys,
I just got my hands on Pseq and Prand.
I also used a bit of MouseX and MouseY.

I'm wondering if there is a clever way to transition from a sequencial composition to complete randomness depending on Mouse movement.

Basically I want the Prand to perform as Pseq when I have the mouse in one area and as Prand when in another, with varying degrees of randomness along the way.

(
~duration = 1;
Pbind(
\note, Prand([0, 2, 3, 5, 7, 8, 11, 12], inf),
\dur, Prand([~duration, ~duration*2], inf),
\legato, 1,
\amp, Prand([1,0.5],inf)
).play;
Pbind(
\note, Prand([3, 5, 7, 8, 11, 12, 14, 15], inf),
\dur, Prand([~duration, ~duration*(1/3)], inf),
\legato, 1,
\amp, Prand([1,0.5],inf)
).play;
Pbind(
\note, Prand([-12, -13, -17, -19, -21, -22, -24, -22, -21, -19, -17, -15, -13], inf),
\dur, Prand([~duration, ~duration*(3)], inf),
\legato, 1,
\amp, Prand([1,0.5],inf)
).play;
Pbind(
\note, Prand([-24, -22, -21, -25, -25, -24, -28, -29], inf),
\dur, Prand([~duration*2, ~duration*4], inf),
\legato, 1,
\amp, Prand([1,0.5],inf)
).play;
)

Â´Â´Â´``````

Please put your code inside of three backticks ```, so it will be formatted correctly

What youâ€™re describing is definitely do-able - but if you for example want `0` to be â€śnot randomâ€ť and `1` to be â€śfull randomâ€ť, what would you expect from a control value of `0.5`? Whatâ€™s â€śhalf randomâ€ť?

1 Like

If itâ€™s helpful, my `Pxfade` class will cross-fade between two (or more) streams of values. The default fade mode is `\random`, which will do a weighted random choice between the two streams youâ€™re fading between. So, if you have something like this:

``````(
Pbind(
\scale, Scale.chromatic,
\dur, 1/6,
\legato, 2,
\octave, 3,
Pseq([0, 2, 7, 9, 4], inf), // non random...
Pxrand([0, 2, 7, 9], inf), // random....
)
).play;
)
``````

then you can do:

``````Pdef(\fade).set(\fade, 0.5) // 50% from the non-random stream, 50% from the random stream
``````
3 Likes

Oh yes thank you :).
lets say we have levels [0,1,2,3,â€¦10] levels of randomness for a sequence of notes [0, 2, 3, 5, 7, 8, 11, 12].
If we are at the very beginning of the playback and the level is 0, I want the probability to play the note 0 to be 100%. If the level is 1 I want the probability to play a random note of the sequence in this position to be 1/10, if the level is 2, the probability should be 2/10 and so on.

Oh yes, the `Pxfade` pretty much does this. But if you want a simpler implementation, you can try:

``````Pif(
Pfunc({ |value| value > 0.5 }) <> Pwhite(),
Pseq([0, 2, 7, 9, 4], inf),
Pxrand([0, 2, 7, 9, 4], inf),
)
``````

(where the `0.5` is your probability of one or the other)

2 Likes

I am pretty sure you solved my issue. I am so new here to the point that it will take me a little bit to understand what you told me and use your wisdom adequately in the composition. Thank you so much!

I am working on something similar, but I donâ€™t seem to be able to use Pxfade. There is a file â€śPxfade.scâ€ť in the JITLib folder of my installation (3.12.1, macOs), but it doesnâ€™t seem to actually define the class. Is it available somewhere else?

Hmm, have you recompiled or restarted sclang? You can also place `Pxfade.sc` and `extScale.sc` in a folder on their own, and then run `Quarks.install("/path/to/pxfadefiles")` to install them. Youâ€™ll have to recompile in this case as well.

Is it supposed to be this file?

``````/Applications/SuperCollider.app/Contents/Resources/SCClassLibrary/JITLib/Patterns/Pxfade.sc
``````

Or is these two, overwriting the defaults for Pxfade.sc?
Sorry if I come of as confused, had very little sleep past few daysâ€¦

1 Like

Sorry, this IS confusing. There is a file in the core library called `Pxfade.sc`, which contains some unrelated fading classes, none of which are called `Pxfade` :). I didnâ€™t know this file existed until now.

Donâ€™t install external classes or quarks by modifying or overwriting things in `SCClassLibrary`, just add the path containing your extension files using `Quarks.install` or via the Preferences dialog â†’ Interpreter â†’ Include.

1 Like

Had another look at this (wow 6 months laterâ€¦) and got it working! But:

The class definition in Pxfade uses the method .isSymbol, which I throws an error. I canâ€™t find that method in the documentation. wslib has a .isSymbolWS method â€“ I installed that and replaced .isSymbol in Pxfade.sc with that, and it seems to work.

I also put extScale.sc in a â€śSystemOverwritesâ€ť folder, because the interpreter told me to do so on class library compilation.

Hey! Glad to hear itâ€™s working, sorry it was a bit of a pain. Iâ€™ll fix the things you mentioned for the next person.

1 Like

Pure pain for six straight months! No I am joking, itâ€™s just that I lack focus â€“ thanks for writing the extension!

(Just out of curiosity, form where did you get the .isSymbol method?)

1 Like

Good question - I probably have it defined somewhere in personal class extensions. Itâ€™s probably the same as `isSymbolWS`, which is Iâ€™m guessing just `.isKindOf(Symbol)`