[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] array to emulate accelerando or ritenuto



hi Fabrice,
how about using an Env?  something like this...

~start= 0.125;
~end= 1;
~num= 10;
e= Env([~start, ~end], [1], 4);	//you may set different curvature
//e.plot;
f= Array.fill(~num, {|i| e[i/(~num-1)]});
Pbind(\dur, Pseq(f)).play

_f

18 sep 2010 kl. 23.17 skrev Fabrice Mogini:

Hi list,
What would be the best way to create an array durations which follow the three conditions: _growing exponentially, or at least increasing (or decreasing contrary depending on the case)
_have a fixed number of items
_first value has a fixed minimum duration (0.125), last value has a fixed maximum duration (1) my code somehow does it but it is clumsy, any better idea on how to proceed? cheers F.
Accel	Accelerando array

	st=1   			first value
	max=4  			bar length
	add=0.2  		substracted random value
	min=0.05 		added to random value
	minimum=0.08  	smallest value played
        st must be smaller than max

Accel.new.init(1, 4, 0.05, 0.01, 0.125);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Accel
{
var <>last;
var <>z;
var <>x;
var <>adder;
var <>y;

init{arg st=1, max=4, add=0.2, min=0.05, minimum=0.08;
		
	
	last=st;
	z=[st];
	x=st;
	
	while({ ((z.sum) < max) && ( x > minimum) },{
			y = add.rand+min;
			x=(last-y);
			z=z.add(x);
			last=x;
	});
	
	if( ((z.sum) > max),{
		z.removeAt(z[z.size-1]);
	
	});
	
	z.size.do({arg i;
		if( (z[i].isNegative) ,{ z.removeAt(i) });
		if( (z[i] < minimum) ,{ z.removeAt(i) });
	
	});
	
	adder = (max-(z.sum))/(z.size);
	
	z.size.do({arg i;
		z.put(i, z[i]+adder)
	});	

	^z;

	}
}




  #|
     fredrikolofsson.com     musicalfieldsforever.com
  |#


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/