170 likes | 284 Views
Computer Programming For Musical Applications II. 08.Scheduling_Sequencing 25 November, 2008. Review. Tempo Clock Tasks Patterns. TempoClock. Timer that runs in the background, counting beats Allows you to schedule events some time in the future. TempoClock Methods.
E N D
Computer Programming For Musical Applications II 08.Scheduling_Sequencing 25 November, 2008
Review Tempo Clock Tasks Patterns MTE2007 Computer Programming For Musical Applications II
TempoClock • Timer that runs in the background, counting beats • Allows you to schedule events some time in the future MTE2007 Computer Programming For Musical Applications II
TempoClock Methods .tempo – set or return the current tempo in beats/sec .default – returns a permanent default clock that begins at startup .sched(delta, function) – schedules a function to be evaluated delta beats from the current logical time . . . Many More MTE2007 Computer Programming For Musical Applications II
Scheduling with a TempoClock ( t =TempoClock.default; t.tempo=2; // beats per second 4.do({ arg i; TempoClock.default.sched(i, {Synth(\singrain,[freq: 440*(i+1), amp: 0.5, dur:0.8]).play;}) }); ) MTE2007 Computer Programming For Musical Applications II
TempoClock Exercise • Create a SynthDef….. • Place the default tempo clock into the variable t • Set the tempo • Create a do loop that will loop 10 times and play a SynthDef every time it loops MTE2007 Computer Programming For Musical Applications II
Tasks MTE2007 Computer Programming For Musical Applications II
Tasks • When we schedule a function, the entire function is evaluated at the designated time • A Task is like a function where we can control when each statement of the function is executed • Allows us to create a sequence of events and step through or schedule them MTE2007 Computer Programming For Musical Applications II
Tasks Task.new(func,clock); • Allows the function to be evaluated in steps, using the designated clock for timing • If no clock given, uses TempoClock.default MTE2007 Computer Programming For Musical Applications II
An Example Task ( x = { loop // when we play the task it will loop {[200, 300, 400].do({ |f| Synth(\singrain, [freq: f, amp: 0.2, dur: 0.1]); 0.125.wait;}); // wait 1/8 beat before scheduling next event } } ) t = Task(x); t.play; // play the task t.stop;/ / stop t.play;// resume from where we left off MTE2007 Computer Programming For Musical Applications II
Timing Tasks Task.play(argClock,doReset,quant); • argClock – the clock to handle the Task • doReset – boolean value, if true, start task from the beginning, else resume • quant – begin when current time is a multiple of this number • if quant is an array: [quant, phase], phase adds an offset in beats MTE2007 Computer Programming For Musical Applications II
A Timed Task f = { Task({ loop {[60, 62, 64, 65, 67, 69, 71, 72].do({ |midi| Synth(\singrain, [freq: midi.midicps, amp: 0.2, dur: 0.1]); 0.25.wait;}); // end do } // end loop }); // end Task }; t = f.value.play(quant: 4); //start on next 4-beat boundary u = f.value.play(quant: [4, 0.5]); // next 4-beat boundary + a half-beat t.stop; u.stop; MTE2007 Computer Programming For Musical Applications II
Task Exercise • Create a task that will loop through 5 values. Each time is loops through a value it should trigger a SynthDef to play, using the current value to set the frequency argument of the SynthDef. • Use different variables to play multiple versions of this task at the same time, using quant to set the start time MTE2007 Computer Programming For Musical Applications II
Patterns MTE2007 Computer Programming For Musical Applications II
Pseq: A Sequence Pattern Pseq(list,repeats,offset); • list – an array of values • repeats – number of times to repeat the pattern, set to inf to repeat forever • offset – begin at this index (0-based) Pseq.asStream; • convert a pattern to a stream • allows us to sequentially access the pattern values MTE2007 Computer Programming For Musical Applications II
Basic Sequence Pattern Example ( a = Pseq([1, 2, 3, 4], 3); // repeat 3 times b = a.asStream; 13.do({ b.next.postln; }); ) MTE2007 Computer Programming For Musical Applications II
Basic Sequence Pattern Example • Create a pattern of notes using Pseq to build the pattern into a stream. • Use this stream to control the frequency of a SynthDef which should be inside a timed do loop so that all the notes are not played at once… MTE2007 Computer Programming For Musical Applications II