
//// MINIMAL BAROQUE GROOVE

~r0 = Pn(1/8, 16);

TempoClock.default.tempo = 60/60;

TempoClock.default.tempo = 30/60;



~rx0 = Pwrand([1/8, 1/4, 1/2, 4],[80,50,20,20].normalizeSum, 1);
~rx1 = Pwrand([1/8, 1/4, 1/2, 1],[80,50,20,20].normalizeSum, 1);
~rx2 = Pwrand([1/8, 1/4, 1/2],[80,50,20].normalizeSum, 1);
~rx3 = Pwrand([1/8, 1/4],[90,30].normalizeSum, 1);

~rs = Pseq([
/*	Pconst(32, Pseq([~rx0],inf)),
	Pconst(32, Pseq([~r3],inf)),
	Pconst(32, Pseq([~r3],inf)),
	Pconst(32, Pseq([~r04],inf)),*/
	Pconst(64, Pseq([~r0],inf)),

	/*Pconst(32, Pseq([~rx0],inf)),

	Pseq([~rx2],32),
	Pseq([~rx3],32),

	Pseq([~r03],8),
	Pseq([~r04],8),
	Pseq([~r0],8),
	Pseq([~r0],8),
	Pseq([~r04],8),
	//Pseq([~r16],8),
	Pseq([~r0],inf),*/
],inf);

~rb = Pseq([
/*	Pconst(32, Pseq([~rx0],inf)),
	Pconst(32, Pseq([~r0],inf)),
	Pconst(32, Pseq([~r04],inf)),
	Pconst(32, Pseq([~r03],inf)),*/
	Pconst(64, Pseq([~r0],inf)),

	//
	// Pseq([~rx0],32),
	// Pseq([~rx1],32),
	// Pseq([~rx2],32),
	// Pseq([~rx3],32),
	//
	// Pseq([~r03],8),
	// Pseq([~r04],8),
	// Pseq([~r0],8),
	// Pseq([~r0],8),
	// Pseq([~r04],8),
	// //Pseq([~r16],8),
	// Pseq([~r0],inf),
],inf);

~s0 = Scale.harmonicMinor;
~s1 = Scale.melodicMinor;
~s2 = Scale.gong;
~s3 = Scale.whole;
~s4 = Scale.chromatic;

~bassroot = Pseq([0,4,2,3,1,4, 0],1);
~bassroot16 = Pdup(32, Pseq([0,4,2,3,1, 4,0],1));


~d0 = Pxrand([0,2,4,6],32);
~d1 =  Pxrand([1,3,5,7], 32); // 1 bar
~d2 = Pseq([2,4,6,8], 8);
~d3 = Pseq([3,5,7,9],8);
~d4 = Pseq([4,6,8,10],8);

~dseq =  Pseq([
	Pn( ~d0, 1),
	Pn( ~d4, 1),
	Pn( ~d2, 1),
	Pn( ~d3, 1),
	Pn( ~d1, 1),
	Pn( ~d4, 1),
	Pn( ~d0, 1),
], 1);

Pbindef(\m_2, \octave, ~o1);
Pbindef(\m_2, \degree, ~bassroot16);

n = NetAddr("192.168.178.166", 47120);
n.sendMsg("/mother1",  200.rand.asFloat );

// e harmonic minor

Pbindef(\m_1, \root, 4, \scale,~s2, \degree, ~dseq, \octave, ~o1, \dur,~rb,
	\p5, Pfunc { |e| n.sendMsg("/mother1",  (e[\degree]).asFloat );  },
	\rotation, Pfunc { |e| n.sendMsg("/rotation1",  (e[\octave]).asFloat );
	postln(e[\degree]);
	postln(e[\octave]);

	},
);


Pbindef(\m_2, \root, 4, \scale,~s2, \degree, ~bassroot16, \octave, 3, \dur,~rb,
	\p5, Pfunc { |e| n.sendMsg("/mother2",  (e[\degree]).asFloat );  },
	\rotation, Pfunc { |e| n.sendMsg("/rotation2",  (e[\octave]).asFloat );  },
);


/// try
var a, b, r ,t, q , w;

a = Pbind(\type, \midi, \midicmd, \noteOn, \midiout, ~m32_2,
	\root, 4, \scale,~s2, \degree, ~bassroot16, \octave, ~o1, \dur,~rb,
	\p5, Pfunc { |e| n.sendMsg("/mother2",  (e[\degree]).asFloat );  },
	\rotation, Pfunc { |e| n.sendMsg("/rotation1",  (e[\octave]).asFloat );
	postln(e[\degree], e[\octave]);
	},
);

b = Pbind( \type, \midi, \midicmd, \noteOn, \midiout, ~m32_2,
	\root, 4, \scale,~s2, \degree, ~dseq, \octave, ~o3, \dur,~rb,
	\p5, Pfunc { |e| n.sendMsg("/mother2",  (e[\degree]).asFloat );  },
	\rotation, Pfunc { |e| n.sendMsg("/rotation1",  (e[\octave]).asFloat );
	postln(e[\degree], e[\octave]);
	},
);

q = Pbind(\type, \midi, \midicmd, \noteOn, \midiout, ~m32_1,
	\root, 4, \scale,~s2, \degree, ~bassroot16, \octave, ~o1, \dur,~rb,
	\p5, Pfunc { |e| n.sendMsg("/mother2",  (e[\degree]).asFloat );  },
	\rotation, Pfunc { |e| n.sendMsg("/rotation1",  (e[\octave]).asFloat );
	postln(e[\degree], e[\octave]);
	},
);

w = Pbind( \type, \midi, \midicmd, \noteOn, \midiout, ~m32_1,
	\root, 4, \scale,~s2, \degree, ~dseq, \octave, ~o3, \dur,~rb,
	\p5, Pfunc { |e| n.sendMsg("/mother2",  (e[\degree]).asFloat );  },
	\rotation, Pfunc { |e| n.sendMsg("/rotation1",  (e[\octave]).asFloat );
	postln(e[\degree], e[\octave]);
	},
);

r = Pseq( [a,b,a,b], 1);
t = Pseq( [w,q,w,q], 1);

z = Ppar( [r,t], inf ).play;

z.stop;
z.start;
z.pause;
z.resume;


///

Pbindef(\m_1, \degree, ~dseq);
Pbindef(\m_2, \degree, ~dseq);
Pbindef(\m_2, \degree, ~bassroot16);
Pbindef(\m_1, \octave, 3);
Pbindef(\m_1, \octave, ~o3);

Pbindef(\m_1, \scale, ~s0);
Pbindef(\m_2, \scale, ~s0);

Pbindef(\m_2, \octave, ~o1);
Pbindef(\m_2, \octave, ~o2);
Pbindef(\m_2, \octave,  ~o1);


// CC Control Message 1 --->  TOP Mother32 ASSIGN OUT
( Pdef(\m_1_CC,  Pbind( \type, \midi, \midicmd, \control, \midiout, ~m32_1,
	\ctlNum, 1, \control, Pexprand(50,127, inf),\dur, 1/16)).play(quant:4));

// CC Control Message 1 --->  BOTTOM Mother32 ASSIGN OUT
Pdef(\m_2_CC,  Pbind( \type, \midi, \midicmd, \control, \midiout, ~m32_2, \ctlNum, 1, \control, Pexprand(77,127, inf), \dur, 1/8 )).play(quant:4);


Pdef(\m_1).play(quant: 4);    // TOP MOTHER
Pdef(\m_2).play(quant: 4);    // BTM MOTHER NOTEON

Pdef(\m_1).stop;
Pdef(\m_2).stop;

