Pdef and Tdef are SuperCollider's client-side proxies for live-replacing running patterns and scheduled tasks
Where Ndef/NodeProxy operate on the server (synthesis), Pdef and Tdef work on the language side. Pdef wraps a Pattern (typically a Pbind) so it can be substituted mid-performance; the new pattern takes over seamlessly. Tdef wraps a Task — an arbitrary looping/scheduled routine — and when you rewrite it, the new routine starts at the next loop boundary rather than immediately, so you never hear a gap and never restart from scratch (unlike stopping and re-launching a Routine). Both are Def-classes: they bind a symbol to their content in a global registry, so they can be referenced and replaced from anywhere in the session. Pdefn is a value variant of Pdef that can be embedded inside other patterns as a replaceable sub-pattern, and Tdef.embed lets you compose Tdefs sequentially or in parallel to build hierarchical structures from hot-swappable blocks. Together these are the core mechanism for live-coded improvisation of musical processes in SuperCollider.
Examples
Pdef(\melody, Pbind(\degree, Pseq([0,2,4], inf), \dur, 0.5)).play; Pdef(\melody, Pbind(\degree, Pseq([0,3,7], inf), \dur, 0.25)); // swaps pattern seamlessly
Tdef(\x, { var x=4, y=13; loop { x = (x*y) % 11; (note: x, dur: 0.125).play; 0.125.wait } }).play; // rewrite to add a note; change takes effect at next loop boundary
Assessment
Define a Pdef playing a short melodic sequence and, while it plays, replace it with a different sequence; explain how Pdefn differs from Pdef and where you would embed it. Then create a Tdef playing a 4-note loop, rewrite it mid-performance to add a 5th note, confirm the change lands at the next loop boundary, and explain why Tdef differs from stopping and restarting a Routine.