(
SynthDef(\henonSynth1, {

	arg out=0;
	var sig, freq;

	freq = HenonN.ar(
		freq: 5000,
		a: LFNoise2.kr(1, 0.2, 1.2),
		b: LFNoise2.kr(1, 0.15, 0.15),
		mul: 0.6
	);

	// used as frequency modulator
	sig = Pulse.ar(
		freq: freq.range(40, LFNoise2.kr(0.1).range(1000,10000)),
		mul: 0.2);
	sig = sig.ring3(0.5);
	sig = sig.clip2(0.8);
	sig = LeakDC.ar(sig);

	// if you don't have sc3_plugins, comment out the following line
	//sig = sig + (Greyhole.ar(in:sig, feedback:0.2, diff: 1, delayTime: 0.6) * 0.7);

	//y = SinOsc.kr(0.1,phase:1.5pi).range(0,1);
	//x = SinOsc.kr(0.1,phase:1.5pi).range(0,1);
	//x = SinOsc.kr(0.1,phase:1pi,mul:5).clip2.range(0,1);
	
	//Out.ar(out, sig);
	//sig = ~octoPanOut.value(sig, x, y, fact);
	 
	Out.ar(out,sig);
}).add;
);

( // henonN + henonC controlling filter * volume
SynthDef(\henonLsynth1, {
	arg out=0, hpfreqmin=100;
	var snd;

	snd = (BrownNoise.ar() + Mix(SinOsc.ar(HenonN.ar(4,a:[1.4,1.1] ).range(200,400)))) * HenonN.ar(freq:1).range(0,0.5);
	snd = RHPF.ar(snd, HenonC.ar(freq:1).fold(0,1).exprange(hpfreqmin,7000), rq:1);
	snd = snd * HenonC.ar(0.5).range(0.6,1);
	
	Out.ar(out, snd);
}).add;
);


(
// henonLsynth = dark brooding melodic drone-noise
SynthDef(\henonLsynth2, {
	arg out, gate=1, fadeTime=1;
	var sig, sinfreq, env;

	env = EnvGen.kr(Env(levels: [0,1,0], times: [fadeTime, fadeTime], curve: \sin, releaseNode: 1),
		gate, doneAction: 2);
	
	sinfreq = LFPulse.kr( freq: 0.9, width:0.1);
	sinfreq = sinfreq.range(
		LFPulse.kr(0.073).range(37).midicps,
		[44.midicps,53.3.midicps]
	);
	sinfreq = sinfreq * SinOsc.kr(1).range(1,1.02);

	sig = SinOsc.ar(sinfreq);
	sig = sig + (BrownNoise.ar(0.4) * SinOsc.kr(0.1).range(0,1));
	sig = sig * HenonN.ar(20).range(0,1).clip(0,1);
	sig = RLPF.ar(sig, HenonC.ar(1).fold(0,1).exprange(40,1000), rq:0.4);
	sig = sig.clip2(0.5);
	sig = sig * HenonC.ar(0.5).range(0,0.5);
	//	sig = RHPF.ar(sig,5000);

	sig = sig + Greyhole.ar(sig * 0.6, feedback: 0.8, diff: 0.7, delayTime: 0.78123);

	sig = sig * env;

	sig = Mix.new(sig);
	
	Out.ar(out, sig);
}).add;
);




( // henonSquare being thrown around
SynthDef(\henonSquare, {

	arg out=0, gate=1, amp=0.5;

	var env = EnvGen.kr(Env([0, 1, 0], [1, 4], \sin, 1), gate);
	
	var trig = HenonTrig.kr();

	// wandering attractor into variable 'freq':
	var freq = HenonN.ar(
		TRand.kr(trig:trig).exprange(1,20),
		// parameters:
		//a: LFNoise2.kr(0.5).range(0.3,1.6),
		//b: LFNoise2.kr(0.5).range(0,0.6)
		//a: 1.4,
		a: LFTri.kr(0.01,3).range(1,1.5), // ramp up and down, slowly
		b: 0.3
	).exprange(40,1000);

	// wandering attractor applied as frequency to squarewave:
	var sig = Pulse.ar([freq,freq]);

	// adding sinwave for more clean deep/soft sound
	sig = sig + SinOsc.ar([freq,freq*0.995]);

	// back to mono:
	sig = Mix(sig);
	
	// fold distortion
	sig = sig.fold2(0.5) * 2;

	// low pass filter to give sense of closing and opening
	sig = LPF.ar(sig, LFNoise2.kr(0.2).exprange(100,20000));

	sig = sig * env;

	// add space. lots of space
	//sig = (sig * 0.5) + Greyhole.ar(sig * 0.5, delayTime:0.6, damp: 0.8, diff: 0, feedback:0.6,);

	DetectSilence.ar(sig, doneAction: Done.freeSelf); 

	sig = sig * amp;
	
	Out.ar(out,sig);
}).add;
);
