forked from supercollider-quarks/ddwVoicer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuantTask.sc
89 lines (79 loc) · 2.32 KB
/
QuantTask.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// DEPRECATED.
// Retained for the odd backward-compatibility purpose.
QuantTask : Task {
// works like Task but with more flexible quantizing
// starting / stopping etc. can be quantized using a quantize factor AND an offset
play { arg quant, argClock, doReset;
var schedTime;
if (stream.notNil, { "already playing".postln; ^this });
if (doReset ? false, { this.reset });
clock = argClock ? clock ? TempoClock.default;
//clock.dump;
stream = originalStream;
(quant == 0 || quant.isNil).if({ // no quantize, do it now
clock.play(this, quant)
}, {
schedTime = quant.asTimeSpec.nextTimeOnGrid(clock);
// is it too late to schedule? this can happen b/c of a negative offset
//["QuantTask-play", clock.elapsedBeats, clock.elapsedBeats.roundUp(quant), schedTime].postln;
(clock.elapsedBeats > schedTime).if({ ^stream = nil });
clock.schedAbs(schedTime, this);
});
}
reset { arg quant;
(quant == 0 || quant.isNil).if({ // no quantize, do it now
originalStream.reset
}, {
//["QuantTask-reset", clock.elapsedBeats.roundUp(quant) + offset - (0.01*clock.tempo)].postln;
clock.schedAbs(quant.asTimeSpec.nextTimeOnGrid(clock) - (0.01*clock.tempo), {
originalStream.reset;
nil
});
});
}
stop { arg quant;
(quant == 0 || quant.isNil).if({ // no quantize, do it now
stream = nil
}, {
clock.schedAbs(quant.asTimeSpec.nextTimeOnGrid(clock), {
stream = nil
});
});
}
pause { arg quant;
(quant == 0 || quant.isNil).if({ // no quantize, do it now
stream = nil
}, {
clock.schedAbs(quant.asTimeSpec.nextTimeOnGrid(clock), {
stream = nil
});
});
}
resume { arg quant;
^this.play(quant, clock, false)
}
start { arg quant;
^this.play(quant, clock, true)
}
schedTime { arg quant;
^quant.asTimeSpec.nextTimeOnGrid(clock)
}
stream_ { arg argStream, quant;
(quant == 0 || quant.isNil).if({ // no quantize, do it now
originalStream = argStream;
if (stream.notNil, { stream = argStream });
}, {
clock.schedAbs(quant.asTimeSpec.nextTimeOnGrid(clock), {
originalStream = argStream;
if (stream.notNil, { stream = argStream });
});
});
}
clock_ { arg cl;
stream.isNil.if({ // must never change the clock while the task is playing
clock = cl;
}, {
"QuantTask-clock_ : can't change the clock while the task is playing.".warn;
});
}
}