-
-
Save lgvr123/a6d027695991abdecbb805a03c43a919 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( | |
Pdef(\line,Pbind( | |
\dur, Pn(Pconst(4,Pseq([ | |
1, | |
Pwrand([1,Pseq([0.66,0.34]),Pseq([0.34,0.66]),Pseq([0.33,0.33,0.34])],[0.6,0.2,0.1,0.1],inf)]) | |
, tolerance: 0.5),topEnvironment[\tProgression].size,\bar), | |
// \dur, Pn(1,inf), | |
\type, Pfunc({(~harmony!?{\note}?\rest).debug("type")}), // Si pas d' harmony => on ne fait rien | |
\amp,Pfunc({|e| if(e.bar.notNil) {0.4} { 0.1.rrand(0.4)}}), | |
\gtranspose, Pfunc({ ~harmony!?{~harmony.gtranspose - 12}?0}/*.inEnvir*/), | |
\scale, Pfunc({~harmony!?{~harmony.scale}?Scale.major}/*.inEnvir*/), | |
\note,Pfunc({|current| | |
var pn, step, n, o, z; | |
~pE.debug("Past event"); | |
pn=if (~pE.notNil) {current.freqToNote( ~pE[\freq].value).round(1)} { 0 }; | |
step = 1.5.gauss(1.5)*[-1,1].choose; | |
n=pn+step; | |
o=n.div(12).round(1); | |
z=n.mod(12); | |
if(current.bar.notNil) {(~harmony!?{~harmony.name}?"(??)").debug("Chord");}; | |
n = case | |
// pas de context => on devrait être dans un silence | |
{~harmony.isNil} | |
{ 0 } | |
// root: new bar (at 0.8) - ou - pas d'évènement précédent | |
{~pE.isNil.or(current.bar.notNil.and(0.8.coin))} | |
{ | |
var deg; | |
"Fetching at root".postln; | |
deg=if(((z-0).abs)<((z-12).abs)) {0} {12}; | |
deg=deg+(12*o); | |
} | |
// chord: new bar (at 0.2) or in-between ( at 0.7) | |
{(current.bar.notNil).or(current['dur'].lincurve(0,1,1,0.2,1).coin)} | |
{ | |
// In the chord | |
var full, deg,idx, tmp; | |
"Fetching from the chord".postln; | |
full=(~harmony.note++12).debug("full"); | |
idx=full.indexOfGreaterThan(z.asInteger); | |
tmp=(idx>0).if({idx-1},{idx}); | |
[z.asInteger,tmp,idx].debug("look for"); | |
if (((z-full[tmp]).abs)<((z-full[idx]).abs)) {idx=tmp}; | |
deg=full[idx]+(12*o); | |
} | |
// scale : other cases | |
{ true } | |
{ | |
// In the scale | |
var deg; | |
"Fetching from the scale".postln; | |
// ~harmony.scale.debug("scale"); | |
// [pn,n,o,z].debug("data"); | |
deg=z.keyToDegree(~harmony.scale).round; | |
deg=deg.degreeToKey(~harmony.scale)+(12*o); | |
deg; | |
} | |
; | |
pn.debug("previous note"); | |
if (n<(-20)) {n=n+12}; | |
if (n>16) {n=n-12}; | |
n.debug("current note"); | |
n; | |
}) | |
, | |
).collect{|evt| if (evt.type==\note){~pE=evt;"Setting ~pE".postln; }; "----".postln; evt;}); | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment