«first  …14 15 16 17 18 19 20 last»

A Script that Rules the World

2010-11-21 01:26 supercollider

clean-up #6:

This is a hack from 2007. It was done in CocoaCollider, but now I updated it using the standard SCNSObject in SuperCollider. It works by talking to Google Earth via AppleScript.

//redFrik 2007 - updated 2010
//req. mac OSX, Google Earth, SC 3.6

//--init
(
s.waitForBoot{
    SynthDef(\redGoogleKick, {|out= 0, t_trig= 1, freq= 50, dur= 0.5, envFreq= 500, envAtk= 0.005, envRel= 0.1, amp= 1|
        var z, env, fenv, click;
        env= EnvGen.ar(Env.linen(0, 0, dur, amp), t_trig);
        fenv= EnvGen.kr(Env([envFreq, envFreq-freq*0.275+freq, freq], [envAtk, envRel]), t_trig);
        click= EnvGen.ar(Env.linen(0, 0, 0), t_trig);
        z= SinOsc.ar(fenv, 0, env, click);
        Out.ar(out, z);
    }).add;
    SynthDef(\redGoogleSynth, {|out= 0, t_trig= 1, freq= 200, atk= 0.005, dec= 0.5, pm= 0.5, amp= 1|
        var z, env, pmod;
        env= EnvGen.kr(Env.perc(atk, dec, 1, -3), t_trig);
        pmod= LFSaw.ar(freq*2.pow(TIRand.kr(1, 3, t_trig)), 0, env*pm);
        z= SinOsc.ar(freq, pmod, env);
        Out.ar(out, z*amp);
    }).add;
    SynthDef(\redGoogleDelay, {|in= 0, out= 0, depth= 3, time= 0.45, amp= 1, dist= 2, pan= 0|
        var src, z;
        src= In.ar(in, 1);
        z= CombL.ar(src, 1.5, time.min(1.5), depth, amp, src);
        Out.ar(out, Pan2.ar(Clip.ar(z*dist, -1, 1), pan));
    }, #[\ir, \ir, 0, 0.5, 0, 0, 0]).add;
};
f= {|cmd|
    {
        var o;
        o= SCNSObject("NSAppleScript", "initWithSource:", ["tell application \"Google Earth\"\n"++cmd++"\nend tell"]);
        o.invoke("executeAndReturnError:", [nil], true);
        o.release;
    }.defer;
};
f.value("open");
)

//--run (wait until localhost and google earth started, also disable all overlays in google earth)
(
f.value("SetViewInfo{latitude:0, longitude:0, distance:10000000, tilt:0, azimuth:0} speed 5");
d= Synth(\redGoogleDelay, [\out, 0, \in, 32]);
k= Synth(\redGoogleKick, [\t_trig, 0]);
e= Synth(\redGoogleSynth, [\out, 32, \t_trig, 0]);
Tdef(\redGoogle).play;
Tdef(\redGoogle, {
    var dist, xxx= 0, yyy= 0;
    300.do{|i|
        if(i%25==0, {
            if(i%100==0, {
                k.set(\t_trig, 1, \amp, 0.1, \out, 32, \freq, 2000, \dur, 1.5, \envAtk, 0.005, \envRel, 0.2);
            });
            e.set(\t_trig, 1, \freq, [500, 600, 700].wrapAt(i), \amp, 0.5, \dec, 0.5, \pm, 0.2);
            if(i%4==0, {
                xxx= xxx+1.0.rand2;
                yyy= yyy+20.rand2;
                f.value("SetViewInfo{latitude:"++1.0.rand2++", longitude:"++yyy++", distance:10000000, tilt:0, azimuth:0} speed 0.4");
            });
        });
        (1/25).wait;
    };
    f.value("SetViewInfo{latitude:0, longitude:0, distance:10000000, tilt:0, azimuth:0} speed 0.5");
    300.do{|i|
        if(i%25==0, {
            dist= [400, 600, 700, 800].wrapAt(i);
            k.set(\t_trig, 1, \amp, 1, \out, 32, \freq, 50, \dur, 0.5, \envAtk, 0.005, \envRel, 0.1);
            e.set(\t_trig, 1, \freq, dist, \amp, 0.5, \dec, 0.5, \pm, 1-(i/300));
            f.value("SetViewInfo{latitude:0, longitude:0, distance:"++8000000++", tilt:"++45.rand++", azimuth:0} speed 5");
        }, {
            if(i%25==1, {
                f.value("SetViewInfo{latitude:0, longitude:"++([100, -100].choose)++", distance:"++5000000++", tilt:0, azimuth:10} speed 0.5");
            });
        });
        (1/25).wait;
    };
    d.set(\dist, 4);
    f.value("SetViewInfo{latitude:52.45, longitude:-1.93, distance:300, tilt:0, azimuth:0} speed 0.5");
    50.do{|i|
        if(i%25==0, {
            k.set(\t_trig, 1, \amp, 1, \out, 32, \freq, 50, \dur, 0.5, \envAtk, 0.005, \envRel, 0.1);
            e.set(\t_trig, 1, \freq, [100, 500, 600, 700].wrapAt(i), \amp, 0.5, \dec, 1.1, \pm, 2);
        });
        (1/25).wait;
    };
    d.set(\dist, 5);
    500.do{|i|
        if(i%25==0, {
            k.set(\t_trig, 1, \amp, 1, \out, 32, \freq, 50, \dur, 0.5, \envAtk, 0.005, \envRel, 0.1);
            e.set(\t_trig, 1, \freq, [200, 500, 600, 700].wrapAt(i), \amp, 0.5, \dec, 1.1, \pm, 2);
            f.value("SetViewInfo{latitude:52.45, longitude:-1.93, distance:"++200.rrand(300)++", tilt:"++(i%45)++", azimuth:"++(i%180)++"} speed 1");
        }, {
            if(i%20==18, {
                k.set(\t_trig, 1, \amp, 0.3, \out, [0, 1].choose, \freq, [2100, 100].wrapAt(i), \dur, 0.9, \envAtk, 0.1.linrand, \envRel, i%3);
            })
        });
        (1/25).wait;
    };
})
)

f.value("quit");
/*
SCNSObject.dumpPool;
SCNSObject.freePool;
*/

Some notes:

There are two ways to run AppleScripts from within SuperCollider. One is to construct a string with osascript -e and a unixCmd, the other is creating a cocoa NSAppleScript object with the SCNSObject cocoa binding class. The later method is slightly more involved but runs way faster.

//--unixCmd version
"osascript -e 'tell application \"Finder\" to activate'".unixCmd;
"osascript -e 'tell application \"TextEdit\" to activate'".unixCmd;
//--NSObject version - this only work on old OSX SuperCollider versions
a= SCNSObject("NSAppleScript", "initWithSource:", ["tell application \"Finder\" to activate"]);
a.invoke("executeAndReturnError:", [nil], true);
a.release;

SCNSObject.dumpPool;  //should be 0
SCNSObject.freePool;  //free stray objects if any left

Also, I've attached a simple class that wraps the functionality. It's called RedEarth.

Attachments:
RedEarth.zip

Eco

2010-11-19 23:15 supercollider

clean-up #5:

An ecosystem as described in Gary William Flake's book - "The Computational Beauty of Nature" (page 191). I started coding it 1.5 years ago but never finished it until today.

eco
  • white = empty space
  • green = plant
  • red = herbivore
  • blue = carnivore
  • For every time step:
    • For every empty cell, e:
      • If e has three or more neighbours that are plants, then e will become a plant at the next time step (assuming it isn't trampled by a herbivore or carnivore).
    • For every herbivore, h (in random order):
      • Decrease energy reserves of h by a fixed amount.
      • If h has no more energy, then h dies and becomes an empty space.
      • Else, if there is a plant next to h, then h moves on top of the plant, eats it, and gains the plant's energy.
        • If h has sufficient energy reserves, then it will spawn a baby herbivore on the space that it just exited.
      • Else, h will move into a randomly selected empty space, if one exists, that is next to h's current location.
    • For every carnivore, c (in random order):
      • Decrease energy reserves of c by a fixed amount.
      • If c has no more energy, then c dies and becomes an empty space.
      • Else, if there is a herbivore next to c, then c moves on top of the herbivore, eats it, and gains the herbivore's energy.
        • If c has sufficient energy reserves, then it will spawn a baby carnivore on the space that it just exited.
      • Else, c will move into a randomly selected empty space that is next to c's current location. If there are no empty spaces, then c will move through plants.

The rules are fairly simple but the result is complex. Carnivores feed on herbivores that in turn feed on plants. Populations grow, get overpopulated and die out just like in nature. The SuperCollider code is a bit cryptic using a lot of nested arrays for efficiency reasons but near the top, there are user settings to play with.

Here's also a JavaScript version... /software/p5js/eco/, a version for Processing... /software/processing/eco/ and also a C++ version written in Cinder... /software/cinder/eco/.

Updates:

  • 180101: changed the file format from .rtf to .scd
  • 200727: ported to JavaScript
  • 200801: rebuilt and improved the C++ version for Cinder 0.9.2
Attachments:
eco.scd
eco.app.zip

Whitney Balls

2010-11-19 00:31 supercollider

clean-up #4:

This is something I originally wrote for the article Audiovisuals with SC and now rewrote as separate classes. There are four classes all implementing the same system slightly differently. Two for graphics (Whitney, Whitney2) and the other two for patterns (Pwhitney, Pwhitney2).

The principle for this system is described by John Whitney in his book Digital Harmony (1980) and reimplemented musically by Jim Bumgardner in his Whitney Music Box (2006). The idea is simple but complex patterns arise - both in graphics and in harmony/rhythm. The innermost ball moves at a certain speed, the ball next to it doubles that speed and the ball next to that triples the speed etc. There's a sound played for each ball as it passes through 0. Each ball's sound plays at a different frequency mapped to some scale, overtone series or something else.

The code for the above video example is taken from the help file...

(
s.latency= 0.05;
s.waitForBoot{
    var width= 500, height= 500;
    var w= Window("Whitney balls", Rect(99, 99, width, height), false);
    var u= UserView(w, Rect(0, 0, width, height));
    
    SynthDef(\sin, {|freq= 400, amp= 0.2, pan= 0, rel= 0.9|
        var e= EnvGen.ar(Env.perc(0.005, rel), 1, doneAction:2);
        var z= SinOsc.ar(freq, e*pi, e);
        Out.ar(0, Pan2.ar(z, pan, amp));
    }).send(s);
    s.sync;
    
    //--set up the whitney system
    f= Whitney(20, {|ball, i|
        Synth(\sin, [\freq, (64+i).midicps, \amp, 2/f.num]);
        Pen.fillOval(Rect.aboutPoint(Point(ball.x, ball.y), 5, 5));
    });
    
    u.drawFunc= {
        Pen.rotate(2pi*0.75, width*0.5, height*0.5);
        Pen.translate(width*0.5, height*0.5);
        Pen.strokeColor= Color.red;
        Pen.line(Point(0, 0), Point(0, width*0.5));
        Pen.stroke;
        Pen.color= Color.grey(1, 0.7);
        
        f.next;  //update the system
        f.balls.do{|b, i|  //draw the balls
            Pen.strokeOval(Rect.aboutPoint(Point(b.x, b.y), 4, 4));
        };
    };
    
    CmdPeriod.doOnce({if(w.isClosed.not, {w.close})});
    u.background= Color.black;
    w.front;
    
    u.animate= true;  //replace this line with the one below if you use SwingOSC
    //Routine({while({w.isClosed.not}, {u.refresh; (1/60).wait})}).play(AppClock);
};
)

f.speed= 0.02  //change speed
f.speed= 0.002
f.theta= 0  //restart
f.spread= 15  //change distance between balls
f.spread= 5
(
f.func= {|ball, i|
    Synth(\sin, [
        \freq, i.linexp(0, f.num-1, 300, 3000),
        \amp, i.linlin(0, f.num-1, 0.1, 0.05),
        \rel, i.linlin(0, f.num-1, 1, 0.2),
        \pan, 0.4.rand2
    ]);
    Pen.fillOval(Rect.aboutPoint(Point(ball.x, ball.y), 5, 5));
}
)
f.num= 10
f.num= 30
f.num= 55
f.speed= 0.01
f.speed= 0.0002
f.speed= 0.001
f.speed= 0.005


(
f.func= {|ball, i|
    Synth(\sin, [
        \freq, (i.degreeToKey(Scale.indian)+48).midicps,
        \amp, i.linlin(0, f.num-1, 0.1, 0.05),
        \rel, i.linlin(0, f.num-1, 2, 0.2),
        \pan, 0.4.rand2
    ]);
    Pen.fillOval(Rect.aboutPoint(Point(ball.x, ball.y), 6, 6));
};
f.num= 36;
f.theta= 0;
f.spread= 6;
f.speed= 0.001;
)

Updates:

  • 131118: added Whitney2 class and new help docs - just download the attached zip file again
Attachments:
Whitney.zip

rot

2010-11-17 23:55 supercollider

clean-up #3:

Beat rotation as described here...

music.columbia.edu/~douglas/strange_things/?p=78 (archive.org)

implemented as a method for SequenceableCollection. Some test code...

s.boot
(
SynthDef(\segMono, {|out= 0, buffer, amp= 0.5, rate= 1, offset= 0, atk= 0.01, rel= 0.1, gate= 1|
    var env= EnvGen.ar(Env.asr(atk, amp, rel), gate, doneAction:2);
    var src= PlayBuf.ar(1, buffer, rate*BufRateScale.ir(buffer), 1, offset*BufFrames.ir(buffer));
    OffsetOut.ar(out, Pan2.ar(src*env));
}).add;
SynthDef(\segStereo, {|out= 0, buffer, amp= 0.5, rate= 1, offset= 0, atk= 0.01, rel= 0.1, gate= 1|
    var env= EnvGen.ar(Env.asr(atk, amp, rel), gate, doneAction:2);
    var src= PlayBuf.ar(2, buffer, rate*BufRateScale.ir(buffer), 1, offset*BufFrames.ir(buffer));
    OffsetOut.ar(out, src*env);
}).add;
)
b= Buffer.read(s, "/Users/asdf/soundfiles/amen.wav")  //***edit to match***
b.numChannels  //use instrument \segStereo for 2 channel files and instrument \segMono for 1 channel files
~bpm= 60/(b.duration/16)  //calculate tempo in bpm. 16 is the number of beats in the file. ***edit to match***
c= TempoClock(~bpm/60);  //create a tempo clock in the tempo of the file
Pdef(\test).play(c, quant:1)
(  //rot example 1 - shuffle
Pdef(\test, Pbind(
    \instrument, \segStereo,  //***edit to match***
    \buffer, b,
    \dur, 1,
    \amp, 0.75,
    \offset, Pseq((0..15).rot(2, 1, 0, 4)/16, inf)
))
)
(  //rot example 2 - double tempo
Pdef(\test, Pbind(
    \instrument, \segStereo,
    \buffer, b,
    \dur, 0.5,
    \amp, 0.75,
    \offset, Pseq((0..15).rot(2, 1, 1, 4)/16, inf)
))
)
(  //rot example 3 - double and triple tempo
Pdef(\test, Pbind(
    \instrument, \segStereo,
    \buffer, b,
    \dur, Pseq([0.5, 0.25, 0.25], inf),
    \amp, 0.75,
    \offset, Pseq((0..15).rot(0, 1, 1, 8)/16, inf)
))
)
(  //rot example 4 - subdivide into 32 segments
Pdef(\test, Pbind(
    \instrument, \segStereo,
    \buffer, b,
    \dur, Pseq([0.5, 0.25, 0.25], inf),
    \amp, 0.75,
    \offset, Pseq((0..31).rot(1, 1, 1, 4)/32, inf)
))
)
(  //rot example 5 - back to original
Pdef(\test, Pbind(
    \instrument, \segStereo,
    \buffer, b,
    \dur, 1,
    \amp, 0.75,
    \offset, Pseq((0..15).rot(0, 0, 0, 4)/16, inf)
))
)
Pdef(\test).stop
b.free;

In the MP3 recording of the above code, each rotation example gets to play for 16 beats.

Attachments:
extSequenceableCollection-rot.sc_.zip

Pfork

2010-11-17 00:21 supercollider

clean-up #2:

Another very old SuperCollider class I never got around to publish. It's called Pfork and makes it possible to blend or fade out patterns in other ways than plain [volume] crossfading. It was originally written for the installation Intelligent Street (in SC2) where it was used as a way of creating new music styles from a mix of multiple other styles.

Here's one example of slowly zeroing out amplitudes in a 16 step pattern. frac is a value slowly changing from 1.0 to 0.0 and indicates how many values to zero out. The fork pattern is [3, 1, 2, 0]. This pattern decides which indices to zero out and in which order. So here index 3 is first in the fork pattern and will thereby be seen as the least important in the original pattern. All indices 3 will be zeroed out first. After that all indices 1 and so on. The last indices zeroed out (i.e. kept until frac is almost 0.0) are the indices 0 - ie the first beat out of 4 in the original amplitude step pattern.

This ASCII printout should help visualise what is happening...

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1  //frac is 1.0
1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1
1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1
1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0
1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 0
1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0  //frac is 0.5
1 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0
1 0 0 0 1 0 0 0 1 0 1 0 1 0 1 0
1 0 0 0 1 0 0 0 1 0 0 0 1 0 1 0
1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0
0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  //frac is 0.0

One can also imagine 1 or 0 to be other things than amplitude and basically any array can fork into any other.

Here's an example going slowly from one melodic pattern into another. (MP3 recording below)

//slowly fork from one pattern to another in the opposite channel
(
a= 0.2.dup(16);  //amplitudes
f= [0, 2, 1, 3];  //forkpattern for left channel
g= [3, 1, 2, 0];  //forkpattern for right channel
Pbind(\pan, -1, \dur, 0.125, \degree, Pseq([5, 6, 7, 8], inf), \amp, Pfork(a, f, Pseries(1, -0.1, 11), 0, 11)).play;
Pbind(\pan, 1, \dur, 0.125, \degree, Pseq([3, 2, 1, 0], inf), \amp, Pfork(a, g, Pseries(0, 0.1, 11), 0, 11)).play;
)

See the help file for more examples.

I plan to (someday) write a Pfunc2 class that works in a similar way but inherits from FilterPattern instead of ListPattern.

Updates:

  • 180101: added new help file
Attachments:
Pfork.zip

Bjorklund

2010-11-16 02:05 supercollider

clean-up #1:

Two SuperCollider classes I wrote long ago (Nov. 2008) after a technique described by Godfried Toussaint in his paper 'The Euclidean Algorithm Generates Traditional Musical Rhythms' www-cgrl.cs.mcgill.ca/~godfried/publications/banff.pdf

Also, see ruinwesen.com/blog?id=216 for another implementation with some great demos. And Bjorn Westergard has a SuperCollider demo (archive.org).

Lots of typical patterns in say techno music can be described like this using only two numbers (relation).

Bjorklund is now available as a SuperCollider quark. Install it via the following commands...

Quarks.install("Bjorklund");
//and recompile

Below is some example SuperCollider code with resulting output as MP3. The hihat plays a 9/16 rhythm throughout and the snare plays 3 different ones... 5/8, 15/16 and 3/8.

s.boot
a= Buffer.read(s, "sounds/Free_CR68/CR68_BD_B_03.wav")
b= Buffer.read(s, "sounds/Free_CR68/CR68_SD_B1.wav")
c= Buffer.read(s, "sounds/Free_CR68/CR68_hh_02.wav")

(
SynthDef(\oneshotMono, {|out= 0, amp= 0.1, pan= 0, rate= 1, buffer|
    var src= PlayBuf.ar(1, buffer, rate*BufRateScale.ir(buffer), doneAction:2);
    Out.ar(out, Pan2.ar(src, pan, amp));
}).add;
)

d= TempoClock(120/60)
Pdef(\bd).play(d, quant:4)
Pdef(\hh).play(d, quant:4)
Pdef(\sd).play(d, quant:4)
Pdef(\bd, Pbind(\instrument, \oneshotMono, \buffer, a, \dur, 1.00, \amp, 0.7))
Pdef(\hh, Pbind(\instrument, \oneshotMono, \buffer, c, \dur, 0.25, \amp, Pbjorklund(9, 16, inf)*0.7, \pan, Pbrown(-1, 1, 0.2, inf)))
Pdef(\sd, Pbind(\instrument, \oneshotMono, \buffer, b, \dur, 0.25, \amp, Pbjorklund(5, 8, inf)*0.3))
Pdef(\sd, Pbind(\instrument, \oneshotMono, \buffer, b, \dur, 0.25, \amp, Pbjorklund(15, 16, inf)*0.3))
Pdef(\sd, Pbind(\instrument, \oneshotMono, \buffer, b, \dur, 0.25, \amp, Pbjorklund(3, 8, inf)*0.3))
Pdef(\bd).stop
Pdef(\sd).stop
Pdef(\hh).stop

Updates:

  • 110316: adapted Pbjorklund to also take patterns as arguments.
  • 110320: made a quark out of it

redThermoKontroll

2010-07-21 17:40 electronics

My latest controller. I'll premiere it this Friday (23 July 2010) at the bring-your-own-laptop event at staalplaat. It includes a light sensor, 2 touch sensors, some big switches and lots of knobs for control. It is also wireless and runs off either a 9V battery or a 9-14V wall adapter. The controller data is picked up by redWirelessMaster and is then read by the computer via a serial port.

Firmware, parts list and schematics attached below. A SuperCollider class for interpreting the data is also included.

redThermoKontroll photo

Flickr photostream from the build process. I took out most of these beautiful old electronics and replaced it with my own circuit board. Only kept the front end interface with the nice knobs.

Updates:

  • 101109: minor updates
  • 130122: SuperCollider GUI class updated and new help files and MIDI control (via a nanoKontroll).
Attachments:
redThermoKontroll-schematics.png
redThermoKontroll.zip

OpenObject Tutorials

2010-03-31 20:48 supercollider

7 short screencasts with code examples showing how to connect SuperCollider with MaxMSP/Pd/Processing (etc) using the OpenObject quark.
Download the example code here... www.subnet.at/content/supercollider-tutorials-0

To run all the examples you will need SuperCollider, Processing (with the oscP5 library), MaxMSPJitter and Pure Data.

Install OpenObject from within SuperCollider with Quarks.install("OpenObject");

These screencasts were made at the 10days of SuperCollider network music workshop at subnet, Salzburg, October 2009.

OpenObject quark by Julian Rohrhuber, tutorials by Fredrik Olofsson, voiceover and support by Max Kickinger.

Thanks to subnet.at

Updates:

  • 150316: uploaded the code here below and made it compatible with sc3.6. thanks to edN for noticing.
  • 180101: updated the Pd examples to use Pd vanilla instead of Pd extended
Attachments:
openobject_demos.zip

«first  …14 15 16 17 18 19 20 last»