HierSch Hierarchical Scheduler

HierSch schedules and quantises prioritised functions to a TempoClock grid. At any given time by default only the function with the highest priority is evaluated. 



*new(aTempoClock)

aTempoClock.default is used if aTempoClock is not supplied. 


test

prints 4 beats of test values 

testRate

prints 1 beat's worth of test values at rate 

schedAbs(beat, priority, function, interval, quant, schedQuant)

schedules a function at a particular beat.  

priority is an integer between 0 (highest)  and 12 (lowest). 

By default priority 0 functions always play, others play according to the settings outlined below.

interval if nil defaults to a one shot stream.  

quant is time per beat to quant to, default value is 32 dividions.  

schedQuant determines at what point on the grid the first function will be scheduled, should the quant be different to rate

sched(priority, function, interval, quant)

schedules a function at next beat, arguments as per schedAbs

schedBar(priority, function, interval, quant)

schedule a function at next bar, arguments as per schedAbs

mute

do not evaluate functions if true

play

unmute 


restart

restarts after command period, scheduled streams do not survive


stop

stop task that checks for functions to paly, scheduled streams survive upon restart


rate_(int)

sets rate at which the checker runs

rate

retruns rate at which the checker runs, default is 32 divisions per beat


cease

stops all scheduled functions; does not require restart


stop

temporarily stops all scheduled functions; requires restart



The methods below change the default playing behaviour in relation to priorities

ignore_(arr)

mute particular fns with priorities listed in the arr


unignore

unmute listed priority functions 

playOnly_(arr)

opposite of ignore_

playGT_(int)

equivalent to ignore_((1..int))

playLT_(int)

equivalent to ignore_((int..1))

flip_(bool)

inverts priorities to play if true


width_(int)

the number of priority levels to play, default is 1

single_(bool)

determines whether only one function within the chosen priority plays, true by default. If true, the played function is chosen randomly from among those of the dominant priority

playEach

equivalent to width_(12); single_(true)


playAll

equivalent to width_(12); single_(false)

default

equivalent to width_(1); single_(true)

muteH0_(bool)

mutes or unmutes Hierachy 0 (false by default)



The functions when evaluated have the following arguments passed in:

arg beat, priority, durToNextVal, counter;



// Examples


t = TempoClock.default // assign a TempoClock to t

b = HierSch.new(t)


b.test


b.rate

b.testRate


s.boot

(

SynthDef.new(\midiPing, {

arg out = 0, mfreq = 69, pan = 0, gain = 0.2, dur = 0.25;

Out.ar(out, Pan2.ar(

SinOsc.ar(mfreq.midicps, 0, 

EnvGen.kr(envelope: (Env.perc(0.01, dur)), doneAction: 2)),

pan, gain));

}).add;


m = {|f| Synth(\midiPing, [\mfreq, f + 69]);}

)


b.sched(1, {"prio 0, a oneShot stream".postln; m.value(0)}); 



// Priorities range from 0 ("highest") to 12 ("lowest")

// By default, only the highest p-fns play


(

//  only priority-function 1 plays by default

b.sched(1, {"prio 1".postln; m.value(0)}, 1); 

b.sched(2, {"prio 2".postln; m.value(4)}, 1); 

b.sched(3, {"prio 3a".postln; m.value(5)}, 1); 

b.sched(3, {"prio 3b".postln; m.value(6)}, 1); 

)



b.mute

b.play


b.flip_(true)

b.single_(false)

b.single_(true)

b.flip_(false)


b.ignore_([1])

b.unignore

b.width_(2)

b.ignore_([1])

b.unignore

b.width_(1)


b.playEach // play every prio, though only 1 of each

b.playAll // play every prio and each within

b.default


thisProcess.stop // kill off streams




// Quantisation demonstration

b.restart

t.tempo_(48/60);

b.rate_(128); // per beat

b.playAll;


(

var quant, freqsArr5, freqsArr4, freqsArr3, freqsArr7, beatsArr; 

var beats, r, fn, durStrm, quantArr;

fn = {|arr, pan| {|b, p, d, c| 

Synth("midiPing",[\mfreq, arr[c%arr.size], \pan, pan, \gain, 0.1]); 

}};

durStrm = {|num, beats| Pser.new([num.reciprocal], num * beats) };

beatsArr = [ 8, 8, 8, 10, 9, 8, 7, 6, 5, 4, 3, 2, 4];

freqsArr7 = [0, 2, 4, 5, 7, 9, 11] + 40;

freqsArr5 = (7..3) + 88;

freqsArr4 = [12, 7, 4, 7] + 64;

freqsArr3 = [0, 7, 12] + 52;

quantArr = [b.rate, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1];

r = Routine.new({ 

(beatsArr.size).do({ |i|

quant = quantArr[i];

["Quant is", quant].postln;

beats = beatsArr[i];

b.sched(4, fn.value(freqsArr7, -0.5), durStrm.value(7, beats), quant);

b.sched(3, fn.value(freqsArr5, 1), durStrm.value(5, beats), quant);

b.sched(2, fn.value(freqsArr4, -1), durStrm.value(4, beats),quant);

b.sched(1, fn.value(freqsArr3, 0.5), durStrm.value(3, beats),quant);

(beats + 1).wait;

});

});

t.play(r);

)


// Try each below while the above running

b.default; // many notes are not played due to the quant values

b.playAll; // all notes played