title:: Patch spawning and patterns
summary:: creating Patches for grains or Patterns
categories:: Libraries>crucial>Instr

see also link::Classes/InstrSpawner::

section::Spawning grains

code::
(

a = Patch({
	SinOsc.ar(800,0.0)
});


c = Bus.audio;
a.play(bus: c);
// a is now playing on bus c, which we can't hear

// patch b will listen to buss c and play one enveloped grain
b = Patch({ arg tone;
	var gate;
	gate = Trig1.kr(1.0,0.25);
	tone = In.ar(tone,1);
	tone * EnvGen.kr(Env([0,1,0],[0.05,0.05],\welch,1),gate,doneAction: 2)
},[
	c.index
]);

b.prepareForPlay(s);

// play one grain
b.spawn(atTime: 0.1);

// play 100 grains
Routine({
	1.0.wait;
	100.do({
		b.spawn(atTime: 0.1);
		0.25.wait
	})
}).play(SystemClock)

)

::

Note that there is a Patch method .respawn which is different.

section:: Events

Patch-asEvent will create a link::Classes/Event:: that can be .play(ed) or used in an Event stream

see also link::Classes/InstrEventListPlayer::


