Tonada Recursiva, a set of synthdefs to manipulate live audio from a harpsichord and a baroque flute follwing my score.

//check jackpilot is going with the studio setup, microphone harpsichord and baroque flute into different channels, compress and apply space designer with spatious hall reverb...

Server.local.boot;

Server.internal.boot;

Server.internal = s = Server.default;

/****** sending the synthdefs*******/

(    //Click here to send all the synthdefs to the server

// PLAYBACK a synthdef for playing back the buffers
(
SynthDef("playback", { arg out=0,bufnum=0, rate=1, trigger=1, startPos=0, loop=0;
	Out.ar(out,
		Pan2.ar(PlayBuf.ar(1,bufnum, BufRateScale.kr(bufnum)*rate, trigger, BufFrames.kr(bufnum)*startPos, loop),0.0)
	)
}).send(s); 
);

( // PERC PLAYBACK
SynthDef("percplay", { arg out=0,bufnum=0, rate=1, trigger=1, startPos=0, loop=0, pan=0, 
					att=0.001 , rel=1, lev=1, curve=(-4), level; //the env args
	level = EnvGen.kr(Env.perc(att, rel, lev, curve), 1.0, doneAction:2 ) ;  //the perc env
	Out.ar(out,
		    Pan2.ar(PlayBuf.ar(1,bufnum, BufRateScale.kr(bufnum)*rate, trigger, BufFrames.kr(bufnum)*startPos, loop),pan, level)
	           )
}).send(s); 
);

( // GROW PLAYBACK
SynthDef("grow", { arg out=0,bufnum=0, rate=1, trigger=1, startPos=0, loop=0, pan=0, 
					att=0.001 , sus=1, rel=1, lev=1, curve=(-4), level; //the env args
	level = EnvGen.kr(Env.linen(att, sus, rel, lev, curve), 1.0, doneAction:2 ) ;  //a linear env
	Out.ar(out,
		Pan2.ar(PlayBuf.ar(1,bufnum, BufRateScale.kr(bufnum)*rate, trigger, BufFrames.kr(bufnum)*startPos, loop),pan, level)
	)
}).send(s); 
);

(  // THE ENVELOPED MUNGER
SynthDef(\mungEnv, { arg munge, bufnum=0, bufdur=50000, panpos=(0.0), panlev=1,
					rate=(1.0), ratevar=(10.0), glength=(1000.0), lvar=20.0, speed=(0.2),
					speedvar=(0.9), gain=0.3, gainvar=(0.1), dir=0, pos=(-1.0), maxvox=40,
					panspread=(1.0), smooth=1, 
					envelope,
					att=3, sus=1, rel=1, lev=1,curve=1;  

munge = Munger.ar(bufnum, //buffer number
			bufdur,   //sample.bufFramesKr,
			rate, //rate in ms must be > 0
			ratevar, //rate variation in ms
			glength, //grain lenght in ms
			lvar, //length var
			speed, //speed
			speedvar, //speed var
			gain, //gain
			gainvar, //gain var
			dir, //direction  0: random; 1: fwd; -1: bwd;
			pos, //position -1 random
			maxvox, //max voices
			panspread,  //pan spread
			smooth //smoothPitch ==1: speed var continuos; ==0: diatonic steps
			);
Out.ar(0, Pan2.ar(munge, panpos, EnvGen.kr(Env.linen(att, sus,rel, lev, curve), 1.0, doneAction:2 )))  //panlev

}).send(s)
);

(  // THE STREAMING MUNGER
SynthDef(\munge, { arg out=0, munge, bufnum=0, bufdur=50000, panpos=(0.0), panlev=1,
					rate=(1.0), ratevar=(10.0), glength=(1000.0), lvar=20.0, speed=(0.2),
					speedvar=(0.9), gain=0.3, gainvar=(0.1), dir=0, pos=(-1.0), maxvox=40,
					panspread=(1.0), smooth=1;  

munge = Munger.ar(bufnum, //buffer number
			bufdur,   //sample.bufFramesKr,
			rate, //rate in ms must be > 0
			ratevar, //rate variation in ms
			glength, //grain lenght in ms
			lvar, //length var
			speed, //speed
			speedvar, //speed var
			gain, //gain
			gainvar, //gain var
			dir, //direction  0: random; 1: fwd; -1: bwd;
			pos, //position -1 random
			maxvox, //max voices
			panspread,  //pan spread
			smooth //smoothPitch ==1: speed var continuos; ==0: diatonic steps
			);
Out.ar(out, Pan2.ar(munge, panpos, panlev))  

}).send(s)
);

//DELAY myDelay;  direct and delayed signal
(
SynthDef(\myDelay,{ arg out=0, inputChannel=8, delay=5, feedback=10, dizzyDelay,directSignal, sum;
			directSignal = In.ar(8,1);
			dizzyDelay = Pan2.ar(
								CombL.ar(In.ar(inputChannel),20, delay, feedback),  //in
								FSinOsc.kr(0.20),     //autopanning slow..
								0.7);   //level
			sum = dizzyDelay + directSignal;
Out.ar(out, sum)
}).send(s);
);

//Pitch Shift DELAY myDelay;  direct and delayed signal
(
SynthDef(\pitchDelay,{ arg out=0, inputChannel=8, delay=5, feedback=10, dizzyDelay,directSignal, shifted, sum, shiftratio=(0.01);
			directSignal = In.ar(8,1);
			shifted = PitchShift.ar(
						directSignal,	// stereo audio input
						0.1, 			// grain size
						shiftratio,	// mouse x controls pitch shift ratio
						0, 				// pitch dispersion
						0.004);			// time dispersion

			dizzyDelay = Pan2.ar(
								CombL.ar(shifted ,20, delay, feedback),  //in
								FSinOsc.kr(0.20),     //autopanning slow..
								0.8);   //level
			sum = dizzyDelay;//+ directSignal;
Out.ar(out, sum)
}).send(s);
);

 // rePERC PLAYBACK tremolo
(SynthDef(\repercplay, 
		{
		arg att=0.1, startFreq, endFreq, timeFreq, panFreq, bufnum=0, rate=1,trigger=1, startPos=0, loop=0;
		var signal, amp, percFreq, overamp, pan;
		pan = SinOsc.kr(panFreq);
		percFreq = XLine.kr(startFreq, endFreq, timeFreq);
		amp = EnvGen.ar(Env.perc(att, (1/percFreq) , 0.9, -4), Impulse.kr(percFreq ));
		overamp = EnvGen.ar(Env.new([0,1,0.5,0], [timeFreq/3,timeFreq/3,timeFreq/3],'linear'), 1, doneAction:2);
		signal = PlayBuf.ar(1,bufnum, BufRateScale.kr(bufnum)*rate, trigger, BufFrames.kr(bufnum)*startPos, loop);
		Out.ar(0, Pan2.ar(signal, pan ,amp*overamp)); //scale the amp by an adsr style env
		}
         ).send(s);
);

// making a recording synthdef...
 SynthDef(\recordnewbuf,{arg in=8, bufnum;  RecordBuf.ar( In.ar(in,1), bufnum); }).send(s);
  // allocate a very large buffer to copy from
b=Buffer.alloc(s,44100*30,1);

~buffers= List[];   // the list to which new buffers will be added

(  //the startrec function so I can call it up with just the global variable name in performance
~startrec = {
~startTime= Main.elapsedTime;   //find the timestamp...
~recsynth=Synth(\recordnewbuf,[\in,8,\bufnum, b.bufnum]);  //record to the huge buffer
});

(   // the stoprec function so I can call it up with just the global variable name in performance
// check the current time and subtract it from previous to find duration
~stoprec= {var length;
~endTime= Main.elapsedTime;
~length=~endTime-~startTime;
~recsynth.free;   // free up the recorder
~buffers.add(Buffer.alloc(s, 44100*~length, 1) ); //add a new empty buffer to the list
b.copy(~buffers.last, 0, 0, 44100*~length); }  //copy into it the stuff you just recorded
 );

);

~pitchdelay = Synth(\pitchDelay, [\delay, 3,\feedback,20])
 ~pitchdelay.free
~pitchdelay = Synth(\pitchDelay, [\delay, 3,\feedback,10]) ;//mouse controls shift
~pitchdelay.set(\shiftratio,4);
/****** Tonada Recursiva: electronic manipulations*******/

//Cue 0: get the pitched delay going before you start !

~delay = Synth(\myDelay, [ \inputChannel,8, \out, 0,\delay,1; ] );  
~delay.free; 

//Cue 1:  first grow munge, wait till long note is being sounded to stoprec+munge
~startrec.value;   
~stoprec.value; a=Synth(\mungEnv, [\bufnum, ~buffers.last.bufnum, \bufdur, ~buffers.last.numFrames,\att,~length*2/3, \rel,7,\maxvox, 60,\curve,3]);
//wait...

~pingpong = Synth(\repercplay, [\att, 0.01, \startFreq, 3, \endFreq, 100, \timeFreq, ~length, \panFreq, 0.3] );                                 				

//cue 2: before 1st  finishes. launch 2nd
Synth(\mungEnv, [\bufnum, ~buffers.last.bufnum, \bufdur, ~buffers.last.numFrames,\att,~length/2, \rel,7,\maxvox, 5,\curve,3, \speed, 2]);
Synth(\mungEnv, [\bufnum, ~buffers.last.bufnum, \bufdur, ~buffers.last.numFrames,\att,~length/2, \rel,7,\maxvox, 5,\curve,3, \speed, 5]);

//cue 3
~startrec.value;
~stoprec.value; ~pingpong = Synth(\repercplay, [\att, 0.01, \startFreq, 3, \endFreq, 100, \timeFreq, ~length, \panFreq, 0.3] ); 
Synth(\mungEnv, [\bufnum, ~buffers.last.bufnum, \bufdur, ~buffers.last.numFrames,\att,~length/2, \rel,7,\maxvox, 10,\curve,3, \speed, 12, \ratevar,100]);
~pitchdelay.free; 

//cue 4
~startrec.value;
~stoprec.value;~grow =Synth(\grow, [\bufnum,~buffers.last.bufnum, \att, ~length/3, \sus, ~length/3, \rel,~length/3 , \curve,'sine',\rate, 0.5]);
Synth(\mungEnv, [\bufnum, ~buffers.last.bufnum, \bufdur, ~buffers.last.numFrames,\att,~length*2, \rel,7,\maxvox, 5,\curve,3, \speed, 5]);
~grow =Synth(\grow, [\bufnum,~buffers.last.bufnum, \att, ~length/3, \sus, ~length/3, \rel,~length/3 , \curve,'sine',\rate, 0.5]);
  
~delay.free

//cue 5
Synth(\mungEnv, [\bufnum, ~buffers.last.bufnum, \bufdur, ~buffers.last.numFrames,\att,~length*3, \rel, 7,\maxvox, 5,\curve,1, \speed, 2, \glength,3000]);
~delay.set(\delay,3);

//cue 6
~startrec.value;
~stoprec.value; Synth(\mungEnv, [\bufnum, ~buffers.last.bufnum, \bufdur, ~buffers.last.numFrames,\att,~length*2, \rel, 7,\maxvox, 20,\curve,2, \speed, 0.5, \glength,3000]);
Synth(\mungEnv, [\bufnum, ~buffers.last.bufnum, \bufdur, ~buffers.last.numFrames,\att,~length*2, \rel, 7,\maxvox, 20,\curve,1, \speed, 0.5, \glength,30]);
~grow =Synth(\grow, [\bufnum,~buffers.last.bufnum, \att, ~length/3, \sus, ~length/3, \rel,~length/3 , \curve,'sine',\rate, 0.25 ]);
Synth(\mungEnv, [\bufnum, ~buffers.last.bufnum, \bufdur, ~buffers.last.numFrames,\att,~length*2, \rel, 7,\maxvox, 20,\curve,1, \speed, 0.5, \glength,30]); 

~grow =Synth(\grow, [\bufnum,~buffers.last.bufnum, \att, ~length/3, \sus, ~length/3, \rel,~length/3 , \curve,'sine',\rate, 0.25 ]);
Synth(\mungEnv, [\bufnum, ~buffers.last.bufnum, \bufdur, ~buffers.last.numFrames,\att,~length*2, \rel, 7,\maxvox, 20,\curve,1, \speed, 0.5, \glength,30]); 

~grow =Synth(\grow, [\bufnum,~buffers.last.bufnum, \att, ~length/2, \sus, ~length/3, \rel,~length/3 , \curve,'sine',\rate, 0.25 ]);
Synth(\mungEnv, [\bufnum, ~buffers.last.bufnum, \bufdur, ~buffers.last.numFrames,\att,~length*2, \rel, 3,\maxvox, 20,\curve,1, \speed, 0.5, \glength,30]); 

~grow =Synth(\grow, [\bufnum,~buffers.last.bufnum, \att, ~length, \sus, ~length/3, \rel,~length/3 , \curve,'sine',\rate, 0.12 ]);
Synth(\mungEnv, [\bufnum, ~buffers.last.bufnum, \bufdur, ~buffers.last.numFrames,\att,~length*2, \rel, 5,\maxvox, 30,\curve,1, \speed, 0.8, \glength,30]); 

~grow =Synth(\grow, [\bufnum,~buffers.last.bufnum, \att, ~length/3, \sus, ~length/3, \rel,~length/3 , \curve,'sine',\rate, 0.25 ]);
Synth(\mungEnv, [\bufnum, ~buffers.last.bufnum, \bufdur, ~buffers.last.numFrames,\att,~length*2, \rel, 3,\maxvox, 40,\curve,1, \speed, 4, \glength,30]); 

~grow =Synth(\grow, [\bufnum,~buffers.last.bufnum, \att, ~length/3, \sus, ~length/3, \rel,~length*2 , \curve,'sine',\rate, 0.25 ]);
Synth(\mungEnv, [\bufnum, ~buffers.last.bufnum, \bufdur, ~buffers.last.numFrames,\att,~length*2, \rel, 7,\maxvox, 50,\curve,1, \speed, 9, \glength,30]); 

//cue 7
~startrec.value;
~stoprec.value; 
~delay.set(\delay,1);

~grow =Synth(\grow, [\bufnum,~buffers.last.bufnum, \att, ~length/3, \sus, ~length/3, \rel,~length*2 , \curve,'sine',\rate, 0.12 ]);
Synth(\mungEnv, [\bufnum, ~buffers.last.bufnum, \bufdur, ~buffers.last.numFrames,\att,~length*2, \rel, 10,\maxvox, 80,\curve,1, \speed, 9, \glength,30]);
  
~percplay=Synth(\percplay,[\bufnum,~buffers.last.bufnum,\rate, 0.25, \rel,2]);

~grow =Synth(\grow, [\bufnum,~buffers.last.bufnum, \att, ~length/3, \sus, ~length*2, \rel,~length*2 , \curve,'sine',\rate, 0.06 ]);
Synth(\mungEnv, [\bufnum, ~buffers.last.bufnum, \bufdur, ~buffers.last.numFrames,\att,~length*2, \rel, 7,\maxvox, 50,\curve,1, \speed, 20, \glength,30]);  

										//~pitchdelay = Synth(\pitchDelay, [\delay, 3,\feedback,20]) ;//mouse controls shift

//cue 14
make some really long diffusing delays and with pitch shift...

//you can check the buffer number
b.bufnum 

//first delay setting

a = Synth(\myDelay, [ \inputChannel,8, \out, 0]);  //ch8 is Left_in and out is 0... 

a.free

~buffers// check the list by just typing this global variable to which the list was assigned

~buffers.last.plot  //you may show a GUI of the recording you just made

~playback = Synth(\playback, [\out, 0, \bufnum,~buffers.last.bufnum ]);
~playback.free;

~percplay =Synth(\percplay, [\bufnum,~buffers.last.bufnum, \rel, ~length/2 ]);
~percplay.free

~grow =Synth(\grow, [\bufnum,~buffers.last.bufnum, \att, ~length/3, \sus, ~length/3, \rel,~length/3 , \curve,'sine',\rate, 0.5]);

~grow =Synth(\grow, [\bufnum,~buffers.last.bufnum, \att, ~length*2/3, \sus, ~length/6, \rel,~length/6 , \curve,'sine' ]);

Buffer   //for looking up the help file

~buffers.last.bufnum
~buffers.last.numFrames

 

//using the streaming munger

a = Synth(\munge, [\glength, 50]);

a.set(\glength, 500)
a.set(\glength, 1500)
a.set(\glength, 10)
a.set(\glength, 1000)
a.set(\speedvar,10)
a.set(\gain, 0.3)
a.free

to do:

-make a variable playback that will have an XLine so the sound can slow down or speed up, use the playback synthdef for this
-make a routine that will use the percplay and make rhythmic patterns by playing back at random ratios sometimes and others define a list of ratios to choose from.
-add reverb to a bus and send some of the signal of each synthdef there to get a sweeter sound with a little delay also...

BufRd

BufRd is similar to PlayBuf but lets you directly read from a buffer (note you could also use this with non-soundfiles) via a phase argument. This is more convenient for taking custom control of how you read through a sample. 

(
s = Server.local;
//this loads into a buffer the default sound that comes with SuperCollider
//.read brings in the whole sound at once
b = Buffer.read(s,"sounds/a11wlk01.wav");

//using Mouse to scrub through- X position is normalised position 0 to 1 phase through the source file 
SynthDef("bufrd",{ arg out=0,bufnum=0, rate=1, trigger=1, startPos=0, loop=1;
	Out.ar(out,
		Pan2.ar(BufRd.ar(1, bufnum, K2A.ar(BufFrames.ir(b.bufnum)*MouseX.kr(0.0,1.0))),0.0)
	)
}).play(s); 
)

[BufRd] //the help file has more examples

**************

//the following gives me this:  exception in real time: alloc failed

//SynthDef-: massiveBend; 
(
SynthDef(\massiveBend,{ arg out=0, inputChannel=8, delay, feedback=10, dizzyDelay, startLine=0.12, endLine=5, timeXline=20;
			delay = XLine.ar(startLine, endLine, timeXline);
			dizzyDelay = Pan2.ar(
								CombL.ar(In.ar(inputChannel),20, delay, feedback),  //in
								FSinOsc.kr(0.20),     //autopanning slow..
								0.7);   //level
Out.ar(out, dizzyDelay)
}).send(s);
)

Synth( \massiveBend);