Archive for the ‘SuperCollider Coding’ Category

h1

BBCut2

November 16, 2009

This is a SuperCollider Patch that was created by Nick Collins, very good for drumbeats and crazy noise in one or two lines of code!!

http://www.informatics.sussex.ac.uk/users/nc81/bbcut2.html

Download it. Install it. Play with it. FUN!!

h1

Transferring SuperCollider Recordings to Logic.

November 16, 2009

s.recSampleFormat_(“int16″);
Note, you will need to delete and re-enter “int16″ if you are copying and pasting the text, as for some reason the html reads it as something else.

If you evaluate this code in your piece and press record, it will save the .aiff file in the  SuperCollider Recordings folder and you will be able to edit and use the audio in Logic.

The Record Button is only active on the default server. Press once to arm and twice to record, as shown below.

Picture 2

Picture 3

Picture 5

h1

First Finished Composition (with all code)

November 6, 2009

I have finished my first compositional task in SuperCollider using MIDI in Logic, my own programmed synths and a heck of a lot of code. This probably going to be the longest blog in history….

I’ll start where my last blog left off, I had a play with the code of  two synthdefs and this is what if you want to see how I made these, refer to my last blog Synthetic Toys.

My composition starts with the two synths, the scale I have chosen to start the piece in is [0, 3, 5, 8, 9]+9 or as musical notes [A, C, D, F, F#] I have chosen a minor 3rd and a perfect 4th which make a relatively pleasant intervals, the dissonance comes from the minor and major 6th’s from the root note, both in the same scale.
I’m using Pstutter on the octave, degree and dur, to repeat each phrase the set amount of times, in this case it is 4, what this does for the octave is it holds it in the octave that has been selected by the Prand and repeat it 4 times before selecting another octave at random. I’m using randomised time signatures and a Pxrand on the degree to add elements of unpredictability into the piece.

Pdef(\synth,
Pbind(\instrument, \synth1,
\octave, Pstutter(4, Prand([1, 2, 3], inf), inf),
\scale, [0, 3, 5, 8, 9]+9,
\degree, Pstutter(4, Pxrand([1, 2, 3, 4, 5]-1, 4), 4),
\dur, Pstutter(4, Prand([1/8, 1/4, 1/2], inf), inf)
)).play;

When this ends after 4 repetitions of the Pstutter, it moves into this:

Pdef(\test1,
Pbind(
\instrument, \synth1,
\octave, Pstutter(2, Prand([1, 2, 3], inf), inf),
\scale, [0, 3, 5, 8, 9]+9,
\degree, Pstutter(8, Pxrand([1, 2, 3, 4, 5]-1, 8), 4),
\dur, Pstutter(4, Prand([1/8, 1/4, 1/2], inf), inf)
)).play;

Pdef(\test2,
Pbind(
\instrument, \synth2,
\octave, Pstutter(8, Prand([3, 4, 5], inf ), inf),
\scale, [0, 3, 5, 8, 9]+9,
\degree, Pxrand([1, 2, 3, 4, 5]-1, 76),
\dur, Pstutter(4, Pseq([1/8, 1/4, 1/2, 1/4], inf), inf),
\legato, 1
)).play;

When the first synth runs out the second one goes on for a couple of seconds longer to suspend the immediate input of other instruments, then I bring in drums, a hammer dulcimer and a piano using MIDI in Logic as the output for these tracks, along with 2 different versions of the synths that are longer, so each instruments Pdef runs for the same time.
One thing to note to do is I have setup a couple of Pseq’s on the dur for the drums, synth and Piano so even though there is an ever changing time signature, it still is manageable and I am able to accurately calculate how long each will last, one of my original problems I had with the piece was the over-complex time structure that I couldn’t predict its duration because of too many randomised elements.

Pdef(\test1x2,
Pbind(
\instrument, \synth1,
\octave, Pstutter(2, Prand([1, 2, 3], inf), inf),
\scale, [0, 3, 5, 8, 9]+9,
\degree, Pstutter(8, Pxrand([1, 2, 3, 4, 5]-1, 8), inf),
\dur, Pstutter(4, Prand([1/8, 1/4, 1/2], inf), inf)
)).play;

Pdef(\test2x2,
Pbind(
\instrument, \synth2,
\octave, Pstutter(8, Prand([3, 4, 5], inf ), inf),
\scale, [0, 3, 5, 8, 9]+9,
\degree, Pxrand([1, 2, 3, 4, 5]-1, 80),
\dur, Pstutter(4, Pseq([1/8, 1/4, 1/2, 1/4], inf), inf),
\legato, 1
)).play;

Pdef(\drums1,
Pbind(
\type, \midi, \chan, 0, \midiout, m,
\dur,  Pstutter(4, Pseq ([1/8, 1/4, 1/2, 1/4], 5), inf),
\db, -3,
\midinote, Pseq([66,\rest, 102, \rest, 61, \rest, 94, \rest, 66, \rest, 63, \rest, 102, \rest, 61, \rest]-30, inf))
).play;

Pdef(\pian,
Pbind(
\type, \midi, \chan, 1, \midiout, m,
\octave, Pstutter(2, Prand([4, 5], inf), inf),
\scale, [0, 3, 5, 8, 9]+9,
\degree, Pxrand([[1, 2, 3], [1, 3, 5], [2, 3, 4], [3, 4, 6]]-1, inf),
\dur, Pseq ([1, 1, 2, 2, 4, 4], 1),
\db, -6)
).play;

Pdef(\hammer1,
Pbind(
\type, \midi, \chan, 2, \midiout, m,
\octave, Pstutter(4, Prand([3, 4, 5], inf), inf),
\scale, [0, 3, 5, 8, 9]+9,
\degree,  Pxrand([1, 2, 3, 4, 5], inf),
\dur, Pseq ([1/8, 1/8, 1/4, 1/4, 1/2, 1/2, 1/4, 1/4], 9.75),
\db, -12)).play;

The scale then moves away from the original by adding 2 scales that are programmed in a pattern to change every 2 bars, adding dissonance to the piece, [0, 2, 3, 5, 7, 9]+9 which is using a major 2nd, minor 3rd, perfect 4th, perfect 5th and major 6th from the root note of A, so in musical notes [A, B, C, D, E, F] then it changes to the dissonant scale [1, 6, 7, 9, 11]+9 using Bb as the root note of the scale with a perfect 4th, a augmented 4th and minor 6th and minor 7th, [Bb, Eb, E, Gb, Ab].
I achieve changing scales in a pattern by using Pn
which is a pattern repeater, you give each pattern a set amount of repeats and they will play in a sequence or random order within the Pdef.

Pdef(\test3,
Pbind(
\instrument, \synth1,
\octave, Pstutter(4, Prand([1, 2, 3], inf), inf),
\scale, Pseq([Pn(#[0, 3, 5, 8, 9]+9, 4),Pn(#[0, 2, 3, 5, 7]+9, 4),Pn(#[1, 6, 7, 9, 11]+9, 2)], inf),
\degree, Pstutter(8, Pxrand([1, 2, 3, 4, 5]-1, inf), inf),
\dur, Pstutter(8, Pxrand ([1/8, 1/4, 1/2], 9), inf)
)).play;

Pdef(\test4,
Pbind(
\instrument, \synth2,
\octave, Pstutter(8, Prand([3, 4, 5], inf), inf),
\scale, Pseq([Pn(#[0, 3, 5, 8, 9]+9, 4),Pn(#[0, 2, 3, 5, 7]+9, 4),Pn(#[1, 6, 7, 9, 11]+9, 2)], inf),
\degree, Pxrand([1, 2, 3, 4, 5]-1, inf),
\dur, Pseq([1/4, 1/4, 1/2, 1/2, 1/4, 1/4], 12),
\legato, 1)
).play;

Pdef(\hammer2,
Pbind(
\type, \midi, \chan, 2, \midiout, m,
\octave, Prand([2, 3], inf),
\scale, Pseq([Pn(#[0, 3, 5, 8, 9]+9, 2),Pn(#[0, 2, 3, 5, 7]+9, 2),Pn(#[1, 6, 7, 9, 11]+9, 2)], inf),
\degree, Pseq([[1, 2, 3], [2, 3, 4], [1, 3, 4], [3, 4, 5]]-1,inf),
\dur, Pseq ([1, 1, 1, 1/2, 1/2], 6),
\db, -6)).play;

I then go back to the original scale and build up the piece up again, starting with a harp:

Pdef(\harp,
Pbind(
\type, \midi, \chan, 3, \midiout, m,
\octave, Pstutter(4, Prand([4, 5], inf), inf),
\scale, [0, 3, 5, 8, 9]+9,
\degree, Prand([1, 2, 4, 3, 6, 7, 6, 10],inf),
\dur, Pstutter(4, Pseq([1/8, 1/4, 1/2], 2), inf),
\db, -9)).play;

Then I add a piano:

Pdef(\pian2,
Pbind(
\type, \midi, \chan, 1, \midiout, m,
\octave, Pstutter(2, Prand([4, 5], inf), inf),
\scale, [0, 3, 5, 8, 9]+9,\degree, Pxrand([[1, 2, 3], [1, 3, 5], [2, 3, 4], [3, 4, 6]]-1, inf),
\dur, Pseq ([1, 1, 2, 2, 1], 1),
\db, -6)).play;

Hammer Dulcimer:

Pdef(\hammer1x2,
Pbind(
\type, \midi, \chan, 2, \midiout, m,
\octave, Pstutter(4, Prand([3, 4, 5], inf), inf),
\scale, [0, 3, 5, 8, 9]+9,
\degree, Pxrand([1, 2, 3, 4, 5], inf),
\dur, Pseq ([1/8, 1/8, 1/8, 1/8, 1/4, 1/4], 7),
\db, -12)).play;

Synth:

Pdef(\test2x2,
Pbind(\instrument, \synth2,
\octave, Pstutter(8, Prand([3, 4, 5], inf ), inf),
\scale, [0, 3, 5, 8, 9]+9,
\degree, Pxrand([1, 2, 3, 4, 5]-1, 80),
\dur, Pstutter(4, Pseq([1/8, 1/4, 1/2, 1/4], inf), inf),
\legato, 1)).play;

Drums:

Pdef(\drums3,
Pbind(\type, \midi, \chan, 0, \midiout, m,
\dur,  Pstutter(8, Pseq ([1/8], 7), inf),
\db, -3,
\midinote, Pseq([66,\rest, 102, \rest, 61, \rest, 94, \rest, 66,  \rest, 63, \rest, 102, \rest, 61, \rest]-30, inf)
)).play;

Each phrase lasts 7 seconds before adding a new instrument, then it changes scale 3 times, using the original scale with a major 2nd instead of a minor 3rd and changes the root note from A to F, then I use the alternating scales from the 3rd section of this piece, then finally back to the main riff with a one note ending on 3 instruments (and a crash cymbal):

Pdef(\crash,
Pbind(\type, \midi, \chan, 0, \midiout, m,
\dur, 1/8,\db, -3,
\midinote, Pseq([84], 1))).play;

Pdef(\harpend,
Pbind(\type, \midi, \chan, 3, \midiout, m,
\octave, Prand([4, 5], inf),
\scale, [0, 3, 5, 8, 9]+9,
\degree, Prand([1, 2, 4, 3, 6, 7, 6, 10], 1),
\dur, 1/8,
\db, -9)).play;

Pdef(\pian2end,
Pbind(
\type, \midi, \chan, 1, \midiout, m,
\octave, Prand([4, 5], inf),
\scale, [0, 3, 5, 8, 9]+9,
\degree, Pxrand([[1, 2, 3], [1, 3, 5], [2, 3, 4], [3, 4, 6]]-1, 1),
\dur, 1/8,\db, -6),
\legato, 1).play;

Pdef(\hammer1x2end,
Pbind(\type, \midi, \chan, 2, \midiout, m,
\octave, Prand([3, 4, 5], inf),
\scale, [0, 3, 5, 8, 9]+9,
\degree, Pxrand([1, 2, 3, 4, 5], 1),
\dur, 1/8,
\db, -12)).play;

I’ve also used the ++ symbols we have been taught to make the Ppar’s, which contain Pdef’s, follow on from each other in a sequence, so live coding is made easy if you have already have setup your structure, as it automatically plays the piece as you’ve coded it. So this is it:

(

(Pdef(\synth)
++
Ppar([Pdef(\test1), Pdef(\test2)], 1)
++
Ppar([Pdef(\pian), Pdef(\hammer1),Pdef(\drums1), Pdef(\test1x2), Pdef(\test2x2)], 1)
++
Ppar([Pdef(\crash), Pdef(\test3), Pdef(\test4), Pdef(\hammer2), Pdef(\drums2)], 1)
++
Ppar([Pdef(\crash), Pdef(\harp)], 1)
++
Ppar([Pdef(\harp), Pdef(\pian2)], 1)
++
Ppar([Pdef(\harp), Pdef(\pian2), Pdef(\hammer1x2)], 1)
++
Ppar([Pdef(\harp), Pdef(\pian2), Pdef(\hammer1x2), Pdef(\test2x3)], 1)
++
Ppar([Pdef(\harp), Pdef(\pian2), Pdef(\hammer1x2), Pdef(\test2x3), Pdef(\crash), Pdef(\drums3)], 1)
++
Ppar([Pdef(\harp2), Pdef(\pian2x2), Pdef(\hammer1x3), Pdef(\test2x4), Pdef(\crash), Pdef(\drums3)], 1)
++
Ppar([Pdef(\harp), Pdef(\pian2), Pdef(\hammer1x2), Pdef(\test2x3), Pdef(\crash), Pdef(\drums3)], 1)
++
Ppar([Pdef(\test3x2), Pdef(\test4x2), Pdef(\hammer2x2), Pdef(\crash), Pdef(\drums3)], 1)
++
Ppar([Pdef(\harp2), Pdef(\pian2x2), Pdef(\hammer1x3), Pdef(\test2x4), Pdef(\crash), Pdef(\drums3)], 1)
++
Ppar([Pdef(\harp), Pdef(\pian2), Pdef(\hammer1x2), Pdef(\test2x3), Pdef(\crash), Pdef(\drums3)], 1)
++
Ppar([Pdef(\crash), Pdef(\harpend), Pdef(\pian2end), Pdef(\hammer1x2end)], 1)
).play

)


h1

Synthetic Toys

October 26, 2009

This week other than finishing off my composition, I have been playing with synths within SuperCollider using the help files as a guide:

Here is the original synth from Julio’s lecture:

SynthDef(\helpsynth, { arg i_out=0, sustain=1, freq;

var out;

out = RLPF.ar(

LFSaw.ar( freq ),

LFNoise1.kr(1, 36, 110).midicps,

0.1

) * EnvGen.kr( Env.perc, levelScale: 0.3,

timeScale: sustain, doneAction: 2 );

4.do({ out = AllpassN.ar(out, 0.05, [0.05.rand, 0.05.rand], 4) });

Out.ar( i_out, out );

}).store;


The first argument I have played with is the Resonant Low Pass Filter (RLPF) and you can experiment with this argument to change it to a number of different filters such as MoogFF, Ringz and LPF, with varying degrees of success.

(

SynthDef(\synth1, { arg i_out=0, sustain=1, freq;

var out;

out = MoogFF.ar(

Secondly, I experimented with different UGens to create the main synth sound i.e. SinOsc, LFSaw, Saw, for example here are the two synths I experimented with, each carry different values and completely different sounds.

Saw.ar( freq),

LFNoise2.kr(1, 37, 76).midicps,

0.1

LFSaw.ar( freq, mul: 0.3),

LFNoise1.kr(1, 30, 125).midicps,

0.1

Thirdly, I experimented with the Envelope Generator (EnvGen) using the helpfile to guide me I used the linen on the first synth which gives the envelope specification a trapezoidal shape and on the second synth I used perc, which quite simply has a percussive shape. I also experimented with triangle and sine.

EnvGen.kr( Env.linen, levelScale: 0.3,

timeScale: sustain, doneAction: 2 );

EnvGen.kr( Env.perc, levelScale: 0.3,

timeScale: sustain, doneAction: 2 );

Although I experimented a little with other controls beyond that I found the preset given to us were easier to use. So my presets so far look like this. Underneath that is an experiment in the Mixolydian scale using an octave randomiser.

(

SynthDef(\synth1, { arg i_out=0, sustain=1, freq;

var out;

out = RLPF.ar(

LFSaw.ar( freq, mul: 0.3),

LFNoise1.kr(1, 30, 125).midicps,

0.1

) * EnvGen.kr( Env.linen, levelScale: 0.3,

timeScale: sustain, doneAction: 2 );

4.do({ out = AllpassN.ar(out, 0.05, [0.05.rand, 0.05.rand], 4) });

Out.ar( i_out, out );

}).store;

)

(

SynthDef(\synth2, { arg i_out=0, sustain=1, freq;

var out;

out = RLPF.ar(

Saw.ar( freq),

LFNoise2.kr(1, 37, 76).midicps,

0.1

) * EnvGen.kr( Env.perc, levelScale: 0.3,

timeScale: sustain, doneAction: 2 );

4.do({ out = AllpassN.ar(out, 0.05, [0.05.rand, 0.05.rand], 4) });

Out.ar( i_out, out );

}).store;

)

(

Pdef(\test,

Pbind(

\instrument, \synth1,

\octave, Prand([1, 2, 3], inf),

\scale, [0, 2, 3, 5, 7, 8, 10, 12]+9,

\degree, Pxrand([1, 2, 3, 4, 5, 6, 7, 8]-1, inf),

\dur, 1/8

)).play

)

(

Pdef(\test2,

Pbind(

\instrument, \synth2,

\octave, Prand([3, 4, 5], inf),

\scale, [0, 2, 3, 5, 7, 8, 10, 12]+9,

\degree, Pxrand([1, 2, 3, 4, 5, 6, 7, 8]-1, inf),

\dur, 1/8,

\db, -3

)).play

)

h1

MIDI Theory.

October 17, 2009

I’d never thought I’d say this but MIDI had made music theory a lot easier.

For example: The Ionian Mode is C to C, which has no sharps or flats, which is probably the most commonly used mode in western music. In MIDI it looks like this: [0, 2, 4, 5, 7, 9, 11] Each number correlates to the semitone being played in anyscale for instance 5 = F as the 4th note and 5th semitone from C is F.

Each Mode is transposed to MIDI in the same way:
Dorian (D – D) [2, 4, 5, 7, 9, 11, 12, 14]
Phrygian (E – E) [4, 5, 7, 9, 11, 12, 14, 16]
Lydian (F-F) [5, 7, 9, 11, 12, 14, 16, 17]
Mixolydian (G-G) [7, 9, 11, 12, 14, 16, 17, 19]
Aeolian (A-A) [9, 11, 12, 14, 16, 17, 19, 21]
Locrian (B-B) [11, 12, 14, 16, 17, 19, 21, 23]

Each mode in these instances runs from its start to end note without any sharps or flats, but what happens when you transpose them into other keys?? Well, quite simply using the Lydian scale as an example, transposing it down from its original starting point at F to C. As there are 5 semitones between F and C each MIDI note will be 5 notes lower in this scale.

Lydian in C: [0, 2, 4, 6, 7, 9, 10, 12]
As you can see this is different from the Ionian mode, it gives us an Augmented 4th instead of a Perfect 4th.
So how is this relevant to SuperCollider?


(

Pbind( \type, \midi, \midiout, m,

\scale, [ 0, 2, 4, 6, 7, 9, 11, 12 ],

\degreePseq([1, 2, 3, 4, 5, 6, 7, 8]-1,  inf),

\dur, 1/8,

\db, -3

).play

)

As you can see from this quick example this is the Lydian mode in C with all the coding in place, when evaluated this will play the Lydian mode in a sequence order.
Now I’m going to show the composition I have been working on using the Locrian mode, it’s still in its rough draft stage but here goes:
(

Pdef(\a,

Ppar(

[ Pbind\type\midi\chan, 0, \midiout, m,

\scale, [ 0, 1, 3, 5, 6, 8, 10, 12 ],

\degreePseq([[1, 3, 4], [1, 3, 4], [3, 4, 6], [2, 4, 6]]-1,  inf),

\dur, 2/1,

\db, -3),

Pbind( \type, \midi, \chan, 2, \midiout, m,

\scale, [ 0, 1, 3, 5, 6, 8, 10, 12 ],

\degreePseq([1, 4, 3, 2]-1,  inf),

\dur, 2/1,

\db, -3),

Pbind( \type, \midi, \chan, 1, \midiout, m,

\dur, 1/2,

\db, -6,

\midinotePseq ([48, 48, 51, 50], inf)),

Pbind\type\midi, \chan, 5, \midiout, m,

\scale, [ 0, 1, 3, 5, 6, 8, 10, 12 ],

\degreePrand([\rest, 1, 2, 3, 4, 6, 8]-1,  inf),

\dur, 1/4,

\db, -300),

Pbind(\type, \midi, \chan, 3, \midiout, m,

\dur, 1/2,

\db, -3,

\midinotePseq ([12, 13, 14, 15, 16, 17, 18, 19], inf)

)])).play

)


Using a number of Pbind’s and using 5 different MIDI channels on Logic I have managed to create a short loop. As the loop is playing through SuperCollider, I am changing different settings and then re-evaluating the piece (using the Pdef so it changes the whole piece instead of adding multiple layers of sound), most notably one of the channels starts at -300 db because I don’t want this part to be heard at the beginning. Also note the first instrument is playing chords using the Locrian scale and the fourth instrument is improvising using the Locrian scale.
I am currently working on a different section to accompany this part experimenting with improvisation techniques, so far not quite got it right, but will post it up if I manage to do so.



h1

Noise and The Sad Grey Elephant.

October 1, 2009

I’ve had a lot to take in since Monday afternoon’s session of science-related logic session. And I have a lot of work to do over the weekend. Some fun. Some not so fun.
As for Laptop Musicianship, the session became an hour of intense learning about music theory and MIDI within SuperCollider combined with the science of different aspects of music, heavy heavy stuff. I think I understood most of it. Only problem is it comes so fast that you barely have time to take it in before there’s something equally as important being slung your direction. I did always figure this would be the case, having not been in education for 4 years and it’s easy to pay so much attention to what’s being said and understand, but when the topic moves on to forget everything you thought you’d learnt.

In SC (SuperCollider) we have started to learn different bits of code for example:

( ).play

This will play the default note in SC, which happens to be Middle C

Pbind(\dur, Prand ([1/11, 1/64, 1,5, 1/4, 1/13], inf)  ).play

This will continue to play the default note but a couple of important bits of coding determine how SC plays this note. Pbind combines several value patterns to one event stream by binding each of the values, Prand is a randomiser and in this case randomises the duration between the notes, but is also used for randomising different notes and sequences, depending on how complex the code is. Lastly the end value tells us how long the note should continue playing for .inf in this example means the note will play until you press Cmd and full stop. But if we changed it to 10 it would repeat 10 times before stopping.

We also started to learn briefly about UGens, about the different bits of code being named different things i.e. Pbind is a Classand all Classes begin with upper-case and these are what you use to make objects. No doubt my weekend will be devoted to experimenting with different frequencies of Sine Waves and Grey Noise.

Also for those keen to hook up Logic and SuperCollider I have been looking at Julio’s tutorial and have followed instructions and even I can do it! Try it out!

http://teaching.bitbongo.com/ and it is under the TutorialsCasts section.

Follow

Get every new post delivered to your Inbox.