Language control methods


Some patterns mimic language-style control methods: conditionals (Pif), loops (Pwhile) and error cleanup (Pprotect).



p = Pbind(

\degree, Pwhite(0, 11, inf),

// odd numbered scale degrees get a shorter rhythmic value

\dur, Pif(Pkey(\degree).odd, 0.25, 0.5)

).play;


p.stop;




p = Pbind(

// the random seed is generated once, when creating the Pattern object

// so the same random seed is used every time whenever this pattern object plays

\degree, Pseed(0x7FFFFFFF.rand, Pseries({ rrand(-7, 0) }, Pwhite(1, 3, inf), { rrand(4, 10) })),

\dur, 0.25

);


q = p.play; // uses one seed

q.stop;


r = p.play; // uses the same seed

r.stop;


// reexecute the p = Pbind... and the seed will be different




// Pwhile and Ptrace

(

~go = true;

p = Pwhile({ ~go }, Pbind(

\degree, Pseries({ rrand(-7, 0) }, Pwhite(1, 3, inf), { rrand(4, 10) })

.trace(prefix: "degree: "),

\dur, 0.25

)).play;

)


~go = false; // will stop the whole pattern when the Pbind comes to an end



Previous: PG_06d_Parallel_Patterns

Next: PG_06f_Server_Control