//Step by Step (sc3d)
//nr 0.1
//belongs to http://swiki.hfbk.uni-hamburg.de:8080/MusicTechnology/292

Commandline Music (Julian Rohrhuber)

//a few starters, to be evaluated line by line:
#{  "nothing real".postln   }.send;
"nothing non realtime".postln;

// a little sound:
#{
 { Formant.ar(100, 700, 200, 0.1) }.play(0.3)
}.send;

//a little random sound:
#{
 { Formant.ar(rrand(70,100), rrand(70, 60).midicps, 200, 0.1) }.play(0.8.rand)
}.send;

// a plug in control:
#{
 {
  p = Plug.kr(100);
  Formant.ar(p, p*3, 200, 0.1)
 }.play
}.send;

// p is an interpreter variable, that means it doesn't have to be
//declared first and is accessible in a special manner:

#{ p.set(200) }.send;
#{ p.line(500, 0.4) }.send;
#{ { p.source = LFNoise0.kr(3, 100, 200); Plug.ar(0) }.play; }.send; //the plug is just an empty tone.
// try cmd-3 to stop the melody
#{ { p.source = LFNoise1.kr(3, 10, 200); Plug.ar(0) }.play; }.send;
#{ { p.source = LFClipNoise.kr(3, 10, 200); Plug.ar(0) }.play; }.send;

//add impulses
#{
 {
  var imp;
  p = Plug.kr(200);
  imp = Impulse.ar(p/10);
  Formant.ar(p, p*3, 200, 0.1) + imp
 }.play
}.send;


//lag the impulses using Decay
#{
 {
  var imp;
  p = Plug.kr(200);
  imp = Decay.ar(Impulse.ar(p/10), 0.04, 0.3);
  Formant.ar(p, p*3, 200, 0.1) + imp
 }.play
}.send;

//multiply the impulses with the formant osc
#{
 {
  var imp;
  p = Plug.kr(200);
  imp = Decay.ar(Impulse.ar(p/10), 0.04, 0.3);
  Formant.ar(p, p*3, 200,  imp)
 }.play
}.send;

#{ { p.source = LFNoise0.kr(3, 400, 500); Plug.ar(0) }.play; }.send; //the plug is just an empty tone.

//stereo
#{
 {
  var imp;
  p = Plug.kr(LFNoise0.kr([3, 3], 400, 500));
  imp = Decay.ar(Impulse.ar(p*0.1), 0.04, 0.1);
  Formant.ar(p*[1, 1.1], p*[3.0.rand, 3.0.rand], 200,  imp)
 }.play
}.send;

//why not spawn ?
#{
 {
  
  p = Plug.kr(300);
  Spawn.ar({
   var env;
   env = Env.perc(0.02, 0.2, 0.2);
   Formant.ar(p*[1, 1.1], p*[3.0.rand, 3.0.rand], 200, EnvGen.kr(env, 2) )
  }, 2, 1)
  
  
 }.play
}.send;

//controlling the spawn next time
#{
 {
  
  p = Plug.kr(300);
  Spawn.ar({ arg spawn, i;
   var env;
   env = Env.perc(0.02, 0.2, 0.2);
   spawn.nextTime = [1, 1/2, 5/7, 2/7, 1/3, 2/3].wrapAt(i) * 0.2;
   Formant.ar(p*[1, 1.1], p*[3.0.rand, 3.0.rand], 200, EnvGen.kr(env, 2) )
  }, 2, 1)
  
  
 }.play
}.send;

//_____slower
#{
 {
  var imps;
  p = Plug.kr(300);
  imps = [
   10,
   { Line.kr(rrand(1.5, 37.5)) },
    Pseq([3, 5, 4, 2], inf).asStream
   
  ];
  Spawn.ar({ arg spawn, i;
   var env;
   env = Env.perc(0.2, 0.6, 0.2);
   Formant.ar(p, p*[3.0.rand, 3.0.rand], 200,
     Decay2.kr(Impulse.kr(imps.wrapAt(i).value), 0.01, 0.5) * EnvGen.kr(env, 2)
     )
  }, 2, 0.2)
  
  
 }.play
}.send;