Skip to content

Instantly share code, notes, and snippets.

@chriskiefer
Created December 2, 2015 19:38
Show Gist options
  • Save chriskiefer/353032b5ee88dfac9558 to your computer and use it in GitHub Desktop.
Save chriskiefer/353032b5ee88dfac9558 to your computer and use it in GitHub Desktop.
//remember what you did today
History.start
History.document
// Lists
x = 8 // a number
x
//accessing elements
x = [8] //a list with a number
x[0] //show the first element in the post window
//try these, looking at output in the post window
x = [10,20,30,40]
x[1]
x[..2]
x[1..3]
x[3..]
//manipulating list elements
x = [0,1,2,3]
x+1
x*2
cos(x)
sin(x)
x ** 2
x/2
x.cubed
x+x
//modifying lists
x.mirror
x.reverse
x ++ [7,8,9]
//there are many more operations, look at the Array helpfile and parent classes
// Lists in UGens
//this should appear in one speaker, not both
(
Ndef(\listTest, {
var w;
w = Saw.ar([200]);
Out.ar(0, w);
}).play;
)
Ndef(\listTest).clear;
//this should appear in both speakers
(
Ndef(\listTest, {
var w;
w = Saw.ar([300,700]);
Out.ar(0, w);
}).play;
)
Ndef(\listTest).clear;
//what's happening here? multichannel expansion
(
Ndef(\listTest, {
var w;
w = Pulse.ar([SinOsc.ar(10) + 100, 100.01].reverse);
w.poll;
Out.ar(0, w);
}).play;
)
Ndef(\listTest).clear;
//can you hear the third saw wave?
(
Ndef(\listTest, {
var w;
w = Saw.ar([200,100,1237]);
Out.ar(0, w);
}).play;
)
Ndef(\listTest).clear;
//Let's mix them together
(
Ndef(\listTest, {
var w;
w = Mix.new(Saw.ar([100,200,400,800]));
Out.ar(0, [w,w]); //why do we need [w,w]
}).play;
)
Ndef(\listTest).clear;
//A quick diversion: Functions
// input -> process -> output
// process = a function
(
~add2 = { // a name
|a,b| //parameters
var c; //declare variable
c = a+b; // do something
c //return something
}
)
~add2.(10,5)
(
~randomNumber = {
|lo,hi|
1.0.rand.linlin(0,1,lo,hi).floor
}
)
~randomNumber.(10,15)
//mixing functions and lists: use the ! operator to repeat a fuction
{~randomNumber.(3,8)}!10
({~randomNumber.(-13,18)}!1000).plot
//putting all the together in a ugen - let's make a detuned saw oscillator
(
Ndef(\supersaw, {
var w,sawFunc;
//define a function
sawFunc = {
Saw.ar(50 * (1 + 0.1.rand))
};
//repeat the function
w = Mix.new({sawFunc.()}!60);
Out.ar(0,[w,w]);
}).play;
)
//let's sequence something - another diversion
(
Ndef(\impulses, {
Out.ar(0,
Impulse.ar(1);
);
}).play;
)
//back to the saw, with an envelope
(
Ndef(\supersaw, {
var w,sawFunc,imp;
imp = Impulse.ar(1); //clock
//define a function
sawFunc = {
Saw.ar(50 * (1 + 0.1.rand))
};
//repeat the function
w = Mix.new({sawFunc.()}!10);
//envelope
w = w * Decay2.ar(imp, 0.01, 0.6);
Out.ar(0,[w,w]);
}).play;
)
//sequence the frequency
(
Ndef(\supersaw, {
var w,sawFunc,imp,freq;
imp = Impulse.ar(7); //clock
//a sequence
freq = Demand.ar(imp, 0, Dseq([50,100,200,800],inf));
//define a function
sawFunc = {|f|
Saw.ar(f * (1 + 0.1.rand))
};
//repeat the function
w = Mix.new({sawFunc.(freq)}!10);
//envelope
w = w * Decay2.ar(imp, 0.01, 0.6);
Out.ar(0,[w,w]);
}).play;
)
//more modifications
(
Ndef(\supersaw, {
var w,sawFunc,imp,freq, filterFreq, noteDecay;
imp = Impulse.ar(8); //clock
//a sequence
freq = Demand.ar(imp, 0, Dseq([50,100,200,800].mirror2 + SinOsc.kr(0.3,0,10),inf));
//define a function
sawFunc = {|f|
Saw.ar(f * (1 + 0.05.rand))
};
//repeat the function
w = Mix.new({sawFunc.(freq)}!30);
//envelope
noteDecay = Demand.ar(imp, 0, Dseq([1,3,9,2] * 0.1,inf));
w = w * Decay2.ar(imp, 0.01, noteDecay);
filterFreq = Demand.ar(imp, 0, Dseq([300,800,100] + 30,inf));
w = DFM1.ar(w, filterFreq, 0.8, 1, 1);
Out.ar(0,[w,w]);
}).play;
)
//keep a record of your session
History.document
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment