Friday 29 November 2013

Scheduling

Scheduling


Time is a very important thing in music. Supercollider uses clocks in order to schedule when things happen. Clocks can therefore get things to stop and start when needed. There are 3 types of clocks in Supercollider; SystemClock, TempoClock and AppClock.

The SystemClock schedules in seconds. If you are scheduling something then it means you are scheduling for it to happen at some point in the future, for example in this code that I got from course notes:
(
SystemClock.sched(0.0,//start at 0.0 sec from now, i.e. immediately
{//a function which states what you wish to schedule
Synth(\bleep);
1 //repeat every second
}
)
)

SystemClock is scheduled to start at 0.0 seconds from when the code is run. It then runs a SynthDef (\bleep) once a second after .sched has been run, this is called relative scheduling.
As well as relative scheduling there is also absolute scheduling. In order to get the current systemClock time you need to run the code:

Main.elapsedTime; //gives a time since the application started

schedAbs is used for scheduling in absolute time.

TempoClock is more commonly used than SystemClock as it allows you to schedule in beats and measures. There can be many different TempoClocks running at the same time to different measures but there can only be one SystemClock.

In Supercollider tempo is measured in beats per seconds (bps) as apposed to bpm.

1 bps = 60 bpm
1.6666667 bps = 100 bpm
2 bps = 120 bpm
2.4 bps = 144 bpm
3 bps = 180 bpm
etc

In order to go from bps to bpm you need to multiply by 60. To go in the other direction then divide by 60.

This code demonstrates the SynthDef \bleep being played followed by a pause (wait) of different lengths of time:
(
{
Synth(\bleep);
1.0.wait;
Synth(\bleep);
0.5.wait;
Synth(\bleep);
}.fork(TempoClock(2))
)

A regular TempoClock schedules at a clock tempo of 1 bps. TempoClock(2) is a clock running at a tempo of 2 bps.

The wait times are in beats. 1.0 is the equivalent to a crotchet, 0.5 is equivalent to a quaver and 0.25 is the equivalent to a semi quaver.



There is a default TempoClock: TempoClock.default, it is best to assign it to a variable to save typing:
t = TempoClock.default;

The TempoClock may have been running for a while. It is possible to check where in time it is at:

t.elapsedBeats; //what exact logical beat time are we at

t.bar; //which bar are we in (default assumption is 4/4)

t.elapsedBeats.ceil; //find next beat

t.elapsedBeats.floor; //find last beat

If you are using a different clock the ways to check are:
SystemClock.beats;
AppClock.beats

In class we looked at scheduling something more musical. We were shown how an array for midi notes could be played at a tempo of 120 bpm with a 1 second wait in-between:
(
{

[64,64,64,64,64,64,64,67,61,63,64].do{arg valuefromarray;
Synth(\bleep,[\note,valuefromarray]);
1.0.wait;
};
}.fork(TempoClock(2))
)

We then looked at simultaneously using quarter notes and eight notes:

(
{

[48,48,43,48].do{arg whichnote;

Synth(\bleep, [\note,whichnote]);
1.0.wait;
}

}.fork
)
(
{

[60,64,62,60].do{arg whichnote;

Synth(\bleep, [\note,whichnote]);
1.0.wait;
}

}.fork;(TempoClock(2.0));


{

[68,63,61,66].do{arg whichnote;

Synth(\bleep, [\note,whichnote]);
1.0.wait;
}

}.fork(TempoClock(3.0));

)

(
{
4.do{arg whattimeround;
{

4.do{
Synth(\bleep,[\note, 60+whattimeround]);


(TempoClock(2.0)); plays the notes in the array as quaver notes and (TempoClock(3.0));plays them as semi quavers.

.
In regards to the above code it basically means that they can run autonomously so we can therefore run the quarter notes and the eight notes at the same time using the same argument.

Here is an example of scheduling from code used in an algorithmic metal composition I made for uni coursework;

(
//Sets up the tempo clock in order to schedule the piece
// TempoClock(2); is a clock running at 2beatspersecond

var tempoclock = TempoClock(2);
var effect,effect2;

//add effects
effect = Synth.tail(Group.basicNew(s,1),\PlayBuffEffecta);
effect2 = Synth.tail(Group.basicNew(s,1),\PlayBufEffect);

{
//opening section

//part 1
5.do{
// vox- solo to begin with
{
Synth("PlayBuf",[\bufnum, a[20],\pos,1.0.rand,\dur,8.0,\loop,1,\amp,0.1]);
}.fork(tempoclock);


//16*spb = 8.0 IF spb = 0.5
// layer 2; backdrop accompaniment, guitar leit motif
{

8.wait;
Synth("PlayBuf",[\bufnum, a[8],\pos,1.0.rand,\dur,8.0,\loop,1,\amp,0.1]);

}.fork(tempoclock);

// layer 3 ; granular part, guitar
{
16.wait;
32.do{
Synth("PlayBuf",[\bufnum, a[18],\pos,rrand(0.2,0.4),\dur,0.1,\amp,0.05]);
0.5.wait;
}

}.fork(tempoclock);

No comments:

Post a Comment