/* Class 11 */
/* creating Scores with the CtkObjects. */
/*
CtkScore is the main object here. Instead of telling the note objects to .play, you can give them starttimes and durations. CtkScores can be played or written (or, the Score itself can simply be saved as a Score file). In any of these cases, a Score is created before any synthesis begins. If there is memory to be loaded or allocated, this is done before performance begins to ensure everything will play as expected, and the memory will be freed after the performance is finished OR cmd-. is pressed. While working in this mode is a little different then the above examples, it allows you to use the same interface consistently.
*/
(
var scpn, score, grainfun, gliss;
scpn = CtkProtoNotes(
SynthDef(\control, {arg outbus, rate, low, hi;
Out.kr(outbus, LFNoise2.kr(rate).range(low, hi))
}),
SynthDef(\test, {arg freq, amp, dur;
var env, envgen, src;
env = Env([0, 1, 0], [0.5, 0.5], \sin);
envgen = EnvGen.kr(env, timeScale: dur);
src = BPF.ar(WhiteNoise.ar(amp), freq, 0.01, amp * envgen);
Out.ar(0, Pan2.ar(src, Rand(-1.0, 1.0)));
})
);
score = CtkScore.new;
/*
creates a granular gesture of duration. Each grain is 0.1 seconds long, new grain every 0.02 seconds
*/
grainfun = {arg starttime, duration, ampenv, lowfreq, hifreq;
var now, note, mydur;
now = 0;
ampenv.times = ampenv.times.normalizeSum * duration; // scale the Env's time to the gestures
while({
mydur = 1.0.rand;
// create a note... add it to the CtkScore
note = scpn[\test].new(starttime + now, mydur) // give a starttime and duration of this note
.freq_(lowfreq.rrand(hifreq))
.amp_(ampenv[now])
.dur_(mydur)
.addTo(score);
now = now + 0.02;
now < duration;
});
};
gliss = {arg starttime, duration, rate, lowfreq, hifreq;
var cbus, control, note;
cbus = CtkControl.new;
control = scpn[\control].new(starttime, duration)
.outbus_(cbus.bus)
.rate_(rate)
.low_(lowfreq)
.hi_(hifreq)
.addTo(score);
note = scpn[\test].new(starttime, duration, \tail, 1) // use the addAction and target parameter
.freq_(cbus)
.amp_(2)
.dur_(duration)
.addTo(score);
};
/* call the above functions to populate the score */
grainfun.value(1, 10, Env([0, 1, 0], [0.5, 0.5], [3, -5]), 440, 880);
grainfun.value(4, 4, Env([0, 1, 0], [0.5, 0.5], [3, -5]), 4400, 8800);
grainfun.value(6, 12, Env([0, 1, 0], [0.5, 0.5], [3, -5]), 300, 400);
grainfun.value(23, 10, Env([0, 1, 0], [0.5, 0.5], [3, -5]), 200, 200);
grainfun.value(15, 20, Env([0, 1, 0], [0.5, 0.5], [3, -5]), 7000, 7100);
/* call the above functions algorithmically */
5.do({arg i;
var j;
j = i + 1;
gliss.value(3 + (i * 4), 10.rrand(7), j.reciprocal, 440 * j, 880 * j);
});
// uncomment to play the CtkScore you have created
//score.play(s);
// uncomment to write the score to a soundfile
score.write("~/Desktop/test.aiff".standardizePath, 42,
options: ServerOptions.new.numOutputBusChannels_(2));
// uncomment to save the CtkScore as a file
//score.saveToFile("~/Desktop/test.sc".standardizePath);
)
a = Player.new
a.gui