box-o-sand/sclang-play/tutorial.sc

920 lines
14 KiB
Python
Raw Normal View History

(
s.boot;
)
2015-10-24 17:02:27 +00:00
(
s.reboot;
)
(
s.quit;
)
(
s.scope;
)
2015-10-21 16:45:15 +00:00
(
{
var pitchOsc;
var ampOsc;
2015-10-21 17:05:22 +00:00
pitchOsc = { 300 + SinOsc.kr(0.1, 1.5pi, 20, 20); };
ampOsc = SinOsc.kr(0.5, 1.5pi, 1.0, 1.0);
SinOsc.ar([pitchOsc, pitchOsc], 0, ampOsc);
2015-10-21 16:45:15 +00:00
}.play;
)
(
{ [SinOsc.ar(440, 0, 0.2), SinOsc.ar(442, 0, 0.2)] }.play;
)
2015-10-21 17:05:22 +00:00
(
{
var freq;
freq = [[600, 880], [400, 660], 1320, 880].choose;
SinOsc.ar(freq, 0, 0.2);
}.play;
)
(
{
Pan2.ar(PinkNoise.ar(0.2), SinOsc.kr(0.5));
}.play;
)
(
{
Pan2.ar(SinOsc.ar(440, 0, 0.2), SinOsc.kr(0.5));
}.play;
)
2015-10-21 17:05:22 +00:00
(
{
Pan2.ar(PinkNoise.ar(0.2), -0.3);
}.play;
)
2015-10-21 17:47:04 +00:00
(
{
PinkNoise.ar(0.2) + SinOsc.ar([440, 442], 0, 0.2) + Saw.ar([660, 662], 0.2);
}.play;
)
(
{
var a, b;
a = [
SinOsc.ar(440, 0, 0.2),
Saw.ar(662, 0.2)
];
b = [
SinOsc.ar(442, 0, 0.2),
Saw.ar(660, 0.2)
];
Mix([a, b]).postln;
}.play;
)
(
var n = 8;
{
Mix.fill(n, { SinOsc.ar([220, 500 + 500.0.rand], 0, 1 / n) });
}.play;
)
(
var n = 8;
{
Mix.fill(n, { |index|
var freq;
index.postln;
freq = 440 + index;
freq.postln;
SinOsc.ar(freq, 0, 1 / n)
});
}.play;
)
2015-10-21 18:30:23 +00:00
(
{
PinkNoise.ar(0.2) + SinOsc.ar(440, 0, 0.2) + Saw.ar(660, 0.2)
}.plot;
)
2015-10-24 17:03:07 +00:00
(
2015-10-21 18:30:23 +00:00
{
PinkNoise.ar(0.2) + SinOsc.ar(440, 0, 0.2) + Saw.ar(660, 0.2)
}.plot(1);
)
2015-10-24 17:03:07 +00:00
(
2015-10-21 18:30:23 +00:00
{
PinkNoise.ar(0.2) + SinOsc.ar(440, 0, 0.2) + Saw.ar(660, 0.2)
}.scope;
)
(
{
[
SinOsc.ar(440, 0, 0.2),
SinOsc.ar(442, 0, 0.2)
]
}.scope;
)
(
{
[
SinOsc.ar(440, 0, 0.2),
SinOsc.ar(442, 0, 0.2)
]
}.scope(zoom: 10);
)
2015-10-21 21:19:54 +00:00
(
SynthDef.new(
"tutorial-SinOsc",
{
Out.ar(0, SinOsc.ar(440, 0, 0.2))
}
).play;
)
(
SynthDef.new(
"tutorial-SinOsc-stereo",
{
var outArray;
outArray = [
SinOsc.ar(440, 0, 0.2),
SinOsc.ar(442, 0, 0.2)
];
Out.ar(0, outArray)
}
).play;
)
(
x = { SinOsc.ar(660, 0, 0.2) }.play;
y = SynthDef.new(
"tutorial-SinOsc",
{
Out.ar(0, SinOsc.ar(440, 0, 0.2))
}
).play;
)
(
x.free;
y.free;
)
(
SynthDef.new(
"tutorial-PinkNoise",
{
Out.ar(0, PinkNoise.ar(0.3))
}
).add;
x = Synth.new("tutorial-PinkNoise");
y = Synth.new("tutorial-PinkNoise");
)
(
f = {
SinOsc.ar(440 + 200.rand, 0, 0.2)
};
x = f.play;
y = f.play;
z = f.play;
)
(
SynthDef(
"tutorial-NoRand",
{
Out.ar(0, SinOsc.ar(440 + 200.rand, 0, 0.2))
}
).add;
x = Synth("tutorial-NoRand");
y = Synth("tutorial-NoRand");
z = Synth("tutorial-NoRand");
)
(
SynthDef(
"tutorial-Rand",
{
Out.ar(0, SinOsc.ar(Rand(440, 660), 0, 0.2))
}
).add;
x = Synth("tutorial-Rand");
y = Synth("tutorial-Rand");
z = Synth("tutorial-Rand");
)
(
SynthDef(
"tutorial-args",
{
|freq = 440, out = 0|
Out.ar(out, SinOsc.ar(freq, 0, 0.2))
}
).add;
Task({
x = Synth("tutorial-args");
1.wait;
y = Synth("tutorial-args", ["freq", 660]);
1.wait;
z = Synth("tutorial-args", ["freq", 880, "out", 1]);
1.wait;
//x.free; y.free; z.free;
}).play;
)
(
SynthDef.new(
\tutorialargs,
{
|freq = 440, out = 0|
Out.ar(out, SinOsc.ar(freq, 0, 0.2));
}
).add;
Task({
x = Synth(\tutorialargs);
1.wait;
x.set(\freq, 660);
1.wait;
x.set(\freq, 880, \out, 1);
1.wait;
//x.free;
}).play;
)
2015-10-24 17:02:27 +00:00
(
In.ar(0, 1);
In.ar(0, 4);
)
(
{
Out.ar(0, SinOsc.kr)
}.play;
)
(
{
Out.kr(0, SinOsc.ar)
}.scope;
)
(
SynthDef(
"tutorial-args",
{
|freq = 440, out = 0|
Out.ar(out, SinOsc.ar(freq, 0, 0.2));
}
).add;
x = Synth("tutorial-args", ["out", 1, "freq", 660]);
y = Synth("tutorial-args", ["out", 1, "freq", 770]);
)
(
b = Bus.control(s, 2);
c = Bus.audio(s);
)
(
b = Bus.control(s, 2);
b.index.postln;
b.numChannels.postln;
c = Bus.control(s);
c.index.postln;
c.numChannels.postln;
)
(
SynthDef(
"tutorial-Infreq",
{
|bus, freqOffset = 0|
Out.ar(0, SinOsc.ar(In.kr(bus) + freqOffset, 0, 0.5));
}
).add;
SynthDef(
"tutorial-Outfreq",
{
|freq = 400, bus|
Out.kr(bus, SinOsc.kr(1, 0, freq/40, freq));
}
).add;
b = Bus.control(s, 1);
x = Synth("tutorial-Outfreq", [\bus, b]);
y = Synth.after(x, "tutorial-Infreq", [\bus, b]);
z = Synth.after(x, "tutorial-Infreq", [\bus, b, \freqOffset, 200]);
)
(
SynthDef(
"tutorial-DecayPink",
{
|outBus = 0, effectBus, direct = 0.5|
var source;
source = Decay2.ar(Impulse.ar(1, 0.25), 0.01, 0.2, PinkNoise.ar);
Out.ar(outBus, source * direct);
Out.ar(effectBus, source * (1 - direct));
}
).add;
SynthDef(
"tutorial-DecaySin",
{
|outBus = 0, effectBus, direct = 0.5|
var source;
source = Decay2.ar(
Impulse.ar(1, 0.25),
0.3,
1,
SinOsc.ar(
SinOsc.kr(0.2, 0, 110, 440)
)
);
Out.ar(outBus, source * direct);
Out.ar(effectBus, source * (1 - direct));
}
).add;
SynthDef(
"tutorial-Reverb",
{
|outBus = 0, inBus|
var input;
input = In.ar(inBus, 1);
16.do({
input = AllpassC.ar(
input,
0.04,
{
Rand(0.001, 0.04);
}.dup,
3
)
});
Out.ar(outBus, input);
}
).add;
b = Bus.audio(s, 1);
x = Synth("tutorial-Reverb", [\inBus, b]);
y = Synth.before(x, "tutorial-DecayPink", [\effectBus, b]);
z = Synth.before(x, "tutorial-DecaySin", [\effectBus, b, \outBus, 1]);
y.set(\direct, 1);
z.set(\direct, 1);
y.set(\direct, 0);
z.set(\direct, 0);
)
2015-10-24 17:11:53 +00:00
(
b = Bus.control(s, 1);
b.set(880);
c = Bus.control(s, 1);
c.set(884);
x = SynthDef(
"tutorial-map",
{
|freq1 = 440, freq2 = 440|
Out.ar(0, SinOsc.ar([freq1, freq2], 0, 0.2));
}
).play(s);
// x.map(\freq1, b, \freq2, c);
/*
y = {
Out.kr(b, SinOsc.kr(1, 0, 50, 880));
}.play(addAction: \addToHead);
*/
// y.free;
// b.get({ |val| val.postln; f = val; });
// x.set(\freq2, f / 2);
// c.set(200);
// x.free;
// b.free;
// c.free;
)
(
SynthDef(
\tutorial_DecaySin2,
{
|outBus = 0, effectBus, direct = 0.5, freq = 440|
var source;
source = Pan2.ar(
Decay2.ar(
Impulse.ar(
Rand(0.3, 1),
0,
0.125
),
0.3,
1,
SinOsc.ar(
SinOsc.kr(0.2, 0, 110, freq)
)
),
Rand(-1.0, 1.0)
);
Out.ar(outBus, source * direct);
Out.ar(effectBus, source * (1 - direct));
}
).add;
SynthDef(
\tutorial_Reverb2,
{
|outBus = 0, inBus|
var input;
input = In.ar(inBus, 2);
16.do({
input = AllpassC.ar(input, 0.04, Rand(0.001, 0.04), 3)
});
Out.ar(outBus, input);
}
).add;
~sources = Group.new;
~effects = Group.after(~sources);
~bus = Bus.audio(s, 2);
x = Synth(
\tutorial_Reverb2,
[\inBus, b],
~effects
);
y = Synth(
\tutorial_DecaySin2,
[\effectBus, ~bus, \outBus, 0],
~sources
);
z = Synth(
\tutorial_DecaySin2,
[\effectBus, ~bus, \outBus, 0, \freq, 660],
~sources
);
/*
~sources.free;
~effects.free;
~bus.free;
currentEnvironment.clear;
*/
)
(
g = Group.new;
h = Group.head(g);
x = Synth.tail(h, \default);
s.queryAllNodes;
)
(
Server.default.boot;
a = Synth.new(\default);
a.group;
)
(
{
SinOsc.ar(mul: 0.2)
}.scope(1);
s.queryAllNodes;
)
(
g = Group.new;
4.do({
{
|amp = 0.1|
Pan2.ar(
SinOsc.ar(440 + 110.rand, 0, amp),
1.0.rand2
)
}.play(g);
});
g.set(\amp, 0.005);
// g.free;
)
2015-11-23 00:16:22 +00:00
(
"--- haaaay ---".postln;
Group.superclass.postln;
// Group.superclass.help;
Group.findRespondingMethodFor('set').postln;
Group.findRespondingMethodFor('postln').postln;
// Group.findHelpForMethod('postln');
)
2015-12-27 07:08:38 +00:00
(
b = Buffer.alloc(s, 100, 2);
b.free;
)
(
b = Buffer.alloc(s, s.sampleRate * 8.0, 2);
b.free;
)
(
b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
x = SynthDef(
"tutorial-PlayBuf",
{
|out = 0, bufnum|
Out.ar(out,
PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum))
)
}
).play(s, [\bufnum, b]);
// x.free;
// b.free;
)
(
SynthDef(
"tutorial-Buffer-cue",
{
|out = 0, bufnum|
Out.ar(out, DiskIn.ar(1, bufnum))
}
).add;
)
(
b = Buffer.cueSoundFile(
s,
Platform.resourceDir +/+ "sounds/a11wlk01-44_1.aiff",
0,
1
);
y = Synth.new("tutorial-Buffer-cue", [\bufnum, b], s);
b.free;
y.free;
)
(
b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
b.bufnum.postln;
b.numFrames.postln;
b.numChannels.postln;
b.sampleRate.postln;
b.free.postln;
)
(
b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav", action: { |buffer|
("numFrames after update:" + buffer.numFrames).postln;
x = {
PlayBuf.ar(1, buffer, BufRateScale.kr(buffer))
}.play;
});
("numFrames before update:" + b.numFrames).postln;
// x.free; b.free;
)
(
b = Buffer.alloc(s, s.sampleRate * 5, 1);
x = SynthDef(
"tutorial-RecordBuf",
{
|out = 0, bufnum = 0|
var noise;
noise = PinkNoise.ar(0.3);
RecordBuf.ar(noise, bufnum);
}
).play(s, [\out, 0, \bufnum, b]);
)
(
x.free;
)
(
SynthDef(
"tutorial-Playback",
{
|out = 0, bufnum = 0|
var playbuf;
playbuf = PlayBuf.ar(1, bufnum);
FreeSelfWhenDone.kr(playbuf);
Out.ar(out, playbuf);
}
).play(s, [\out, 0, \bufnum, b]);
)
(
b.free;
)
(
Date.getDate.postln;
b = Buffer.alloc(s, 8, 1);
b.updateInfo({
|buf|
buf.set(7, 0.5);
buf.get(7, { |msg| msg.postln });
});
)
(
b.free;
)
(
var nFrames = 16;
Buffer.alloc(s, nFrames).updateInfo({
|b|
Task.new({
0.01.wait;
b.setn(0, [1, 2, 3]);
b.getn(0, 3, { |msg| ("1: "+ msg).postln });
0.01.wait;
b.setn(0, Array.fill(nFrames, { 1.0.rand }));
b.getn(0, nFrames, {
|msg|
("2: " + msg).postln;
"3: buh bye".postln;
b.free
});
}).play;
});
)
(
v = FloatArray.fill(44100, { 1.0.rand2 });
b = Buffer.alloc(s, 44100);
)
(
b.loadCollection(v, action: {
|buf|
x = {
PlayBuf.ar(buf.numChannels, buf, BufRateScale.kr(buf), loop: 1) * 0.2;
}.play;
});
)
(
x.free;
)
(
b.loadToFloatArray(0, -1, { |floatArray| (floatArray == v).postln; });
b.free;
)
(
b.free;
)
(
b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
b.updateInfo({
|b|
x = b.play(true);
SystemClock.sched(5, { x.free; b.free; });
});
// b.play;
)
(
b = Buffer.alloc(s, 512, 1);
b.cheby([1, 0, 1, 1, 0, 1]);
x = play({
Shaper.ar(
b,
SinOsc.ar(300, 0, Line.kr(0, 1, 6)),
0.5
)
});
SystemClock.sched(10, { x.free; b.free; });
)
2015-12-28 19:16:28 +00:00
(
SystemClock.sched(5, { "hello".postln });
)
(
var timeNow = TempoClock.default.beats;
"Time is now: ".post;
timeNow.postln;
"Scheduling for: ".post;
(timeNow + 5).postln;
TempoClock.default.schedAbs(timeNow + 5,
{ "Time is later: ".post; thisThread.clock.beats.postln; nil }
);
)
(
var timeNow;
"------------------------------------".postln;
TempoClock.default.tempo = 2;
timeNow = TempoClock.default.beats;
"Time is now: ".post;
timeNow.postln;
"Scheduling for: ".post;
(timeNow + 5).postln;
TempoClock.default.schedAbs(timeNow + 5,
{ "Time is later: ".post; thisThread.clock.beats.postln; nil }
);
)
(
"SystemClock.beats: ".post; SystemClock.beats.postln;
"TempoClock.default.beats: ".post; TempoClock.default.beats.postln;
"AppClock.beats: ".post; AppClock.beats.postln;
Task({
"thisThread.clock.beats: ".post; thisThread.clock.beats.postln;
}).play;
)
(
TempoClock.default.sched(5, { "hello".postln; nil; });
)
(
r = Routine({
"abcde".yield;
"fghij".yield;
"klmno".yield;
"pqrst".yield;
"uvwxy".yield;
"z{|}~".yield;
});
r.next;
6.do({ r.next.postln; });
)
(
r = Routine({
var delta;
loop {
delta = rrand(1, 3) * 0.5;
"Will wait ".post; delta.postln;
delta.yield;
}
});
r.next;
TempoClock.default.sched(0, r);
)
(
r.stop;
)
(
SystemClock.sched(1, { 20.do({ "".postln; }) });
)
// {-------------------------------------------------------------------------
(
2015-12-30 03:46:26 +00:00
SynthDef(
\singrain,
{
|freq = 440, amp = 0.2, sustain = 1|
var sig = SinOsc.ar(
freq, 0, amp
) * EnvGen.kr(
Env.perc(0.01, sustain), doneAction: 2
);
Out.ar(0, sig ! 2);
}
).add;
r = Routine({
var delta;
loop {
delta = rrand(1, 3) * 0.5;
2015-12-30 03:46:26 +00:00
Synth(
\singrain,
[
freq: exprand(200, 800),
amp: rrand(0.1, 0.5),
sustain: delta * 0.8
]
);
delta.yield;
}
});
)
(
"starting routine".postln;
r.play;
)
(
"stopping routine".postln;
r.stop;
)
// }-------------------------------------------------------------------------
2015-12-30 19:52:42 +00:00
// {-------------------------------------------------------------------------
(
t = Task({
loop {
[60, 62, 64, 65, 67, 69, 71, 72].do({
|midi|
Synth(
\singrain,
[
freq: midi.midicps,
amp: 0.2,
sustain: 0.2
]
);
0.125.wait;
});
}
}).play;
)
(
t.stop;
)
// }-------------------------------------------------------------------------
// {-------------------------------------------------------------------------
(
f = {
Task({
loop {
[60, 62, 64, 65, 67, 69, 71, 72].do({
|midi|
Synth(
\singrain,
[
freq: midi.midicps,
amp: 0.2,
sustain: 0.1
]
);
0.25.wait;
});
}
});
};
t = f.value.play(quant: 4);
u = f.value.play(quant: [4, 0.5]);
)
(
t.stop;
u.stop;
)
// }-------------------------------------------------------------------------