# Difference between revisions of "LiveCoding"

Members of Slork are exploring group live coding, and this page documents our experiments.

# Examples from Slork rehearsal 1/21/2009

## Luke's squares1:

• Signal Flow: This code uses a square wave modulating a square wave, with a feedback delay added on to the end.
• How to play it: Modify the parameters...
• Possible piece structure: start simple, get crazy (will add a better plan -LD)
```// squares1.ck
// luke dahl, 1/21/09

// -----------------------------------------------
// bring tha noise
// -----------------------------------------------

SqrOsc mosc => SqrOsc cosc => ADSR env => dac => Delay del => LPF flt => dac;
3::second => del.max;
2 => cosc.sync;

// pitch:
Std.mtof(Std.rand2(20, 30)) => cosc.freq;

// pitch variation:
Std.rand2f(5, 20) => mosc.gain;

// speed of pitch variation:
1 => mosc.freq;

// delay feedback (be careful here!):
0.0 => del.gain;

// length of delay:
100::ms => del.delay;

// delay filter stuff:
Std.rand2f(500, 2000) => flt.freq;
Std.rand2f(0.5, 1.0) => flt.Q;

// -----------------------------------------------
// make time
// -----------------------------------------------

3.1::second => dur d;                        // how long it lasts
0.8 => float decay_frac;                     // what fraction is decay
env.set( d*0.3, d*0.01, .5, d*decay_frac );  // attack, decay, sustain, release
env.keyOn();
d*(1-decay_frac) => now;
env.keyOff();
d*decay_frac + 2::second => now;
```

## David

/* Live Coding Test 1

```   Have the user invoke different functions. */
```

Phasor s => Gain g => dac; 5000 => s.sfreq; 0 => s.sync; 0.5 => g.gain;

440.00 => float A; 466.16 => float Bb; 493.88 => float B; 523.25 => float C; 554.37 => float Db; 587.33 => float D; 622.25 => float Eb; 659.26 => float E; 698.46 => float F; 739.99 => float Gb; 783.99 => float G; 830.61 => float Ab;

fun void code1() {

```   B => s.freq;
0.5::second => now;
E => s.freq;
0.5::second => now;
```

}

fun void code2() {

```   G => s.freq;
0.25::second => now;
E => s.freq;
0.25::second => now;
D => s.freq;
0.25::second => now;
```

}

fun void code3() {

```   A => s.freq;
0.125::second => now;
B => s.freq;
0.125::second => now;
```

}

fun void code4() {

```   Gb => s.freq;
0.5::second => now;
```

}

/* SECTION ONE - SEQUENCING

```   Any sequence of the following:
code1();
code2();
code3();
code4();
```
• /

while(true) {

```   code1();
```

}

## Visda's Live code

// modulations SqrOsc mod => SinOsc car => Gain mult; // modulate the modulations Modulate vibe => mult => Envelope e => dac; // multiply 3 => mult.op; // sync 2 => car.sync; // envelope 5::second => e.duration;

//modulate between the three arrays

// an array //[ 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9,10 ] @=> int arri[];

// an array of melodic minor //[0,2,3,1,4,2,6,3,4,4] @=> int arri[]; //sequence data

// an array of major //[0,2,4,5,7,9,11,12] @=> int arri[]; //major scale

// vibrato 5 => vibe.gain; .1 => vibe.randomGain; .02 => vibe.vibratoRate;

while (true){

// modulator & carrier

Std.mtof( 300 + Std.rand2(0,10)* 50 + arri[Std.rand2(0, arri.cap()-3)]) => mod.freq; 5::ms => now;

// modulate it between mod 500 - car 100 for earth // or mod 100 - car 200 for space

4 => mod.gain; 100 => car.freq; 2 => car.gain;

```   // go for it
e.keyOn();
e.duration() => now;
e.keyOff();
e.duration() => now;
```

}

### second part of Visda's code

SinOsc s => JCRev r => dac; .3 => s.gain; .1 => r.mix;

// an array [ 5, 1, 5, 1, 5, 1, 5, 1, 5,1] @=> int arri[];

while (true) {

```   Std.mtof( 300 + Std.rand2f(0,10)* 50 + arri[Std.rand2(0, arri.cap()-3)]) => s.freq;
52::ms => now;
```
```   Std.mtof( 333 + Std.rand2(1,10) * 200 + Math.sin(arri[Std.rand2(0, arri.cap()-1)])) => s.freq;
120::ms => now;

Std.mtof( 700 + Std.rand2f(0,9)* 50 + arri[Std.rand2(0, arri.cap()-6)]) => s.freq;
3::ms => now;
```

}

## Mike Gao's Code

//MOVE DA MOUSE ON BEAT SOMETIMES SinOsc a => SinOsc b => Gain g => dac; 0 => int device; Hid hi; HidMsg msg; if( !hi.openMouse( device ) ) me.exit(); <<< "mouse '" + hi.name() + "' ready...", "" >>>; spork ~ mouser(); 220 => a.freq;

// TRY MULTIPLES OR FRACTIONS OF 100 100=>int duration;

for (;;) {

```   Math.fabs(Math.tan(now/samp))*200 => b.freq;
Math.fabs(Math.tan(now/ms))*100=>a.freq;
Math.fabs(Math.tan(now/samp))=>a.gain;

(now/ms)\$int %3=>b.sync;

duration::ms=>now;
```

}

fun void mouser() {

```   for (;;) {
while (hi.recv(msg))
{
if (msg.isMouseMotion())
{
msg.deltaX * 100=>b.freq;
msg.deltaY * 300=>a.freq;
//<<<msg.deltaX>>>;
//(Math.fabs(msg.deltaX*100)+2) \$ int => duration;
}
if (msg.isButtonDown())
{
0=>b.sync;
}

}
hi=>now;
}
```

}

## Craig's Code

### Begin Craig's code MAUI Interface

MAUI_View control_view; control_view.size( 400, 325 );

MAUI_Slider numSamps; "Number of Samples" => numSamps.name; numSamps.irange( 1,1000); numSamps.position( 0, 0 ); control_view.addElement( numSamps );

MAUI_Slider revMix; "Reverb Mix" => revMix.name; revMix.irange( 0,500); revMix.value(0); revMix.position( 0, numSamps.height() + numSamps.y() ); control_view.addElement( revMix );

control_view.display();

SinOsc s => PRCRev r => Phasor p => dac; p.gain(1.5); while(numSamps.value()::samp=>now)

```   {
s.last() + s.phase()=>s.phase =>p.phase;
revMix.value()=>r.mix;
}
```

### Begin Craig's FM code

fun void FM(float cf, float mf, float index) {

```   SinOsc s => Gain g => OnePole p => blackhole;
SinOsc m => dac;
// square the input
s => g => dac;
// multiply
3 => g.op;

mf => m.freq;
g.gain(0.5);
m.gain(0.5);

// set pole position
0.99 => p.pole;

// loop on
while( true )
{
cf + (index * m.last()) => s.freq;
20::ms => now;
}
```

}

FM(200,230,2000);

### Begin Craig's Key code

// HID Hid hi; HidMsg msg;

// which keyboard 0 => int device; // get from command line if( me.args() ) me.arg(0) => Std.atoi => device;

// open keyboard (get device number from command line) if( !hi.openKeyboard( device ) ) me.exit(); <<< "keyboard '" + hi.name() + "' ready", "" >>>;

// patch VoicForm organ => JCRev r => Echo e => Echo e2 => dac; r => dac;

// set delays 240::ms => e.max => e.delay; 480::ms => e2.max => e2.delay; // set gains .6 => e.gain; .3 => e2.gain; .05 => r.mix; 0 => organ.gain;

// infinite event loop while( true ) {

```   // wait for event
hi => now;
```
```   // get message
while( hi.recv( msg ) )
{
// check
if( msg.isButtonDown() )
{
Std.mtof( msg.which + 45 ) => float freq;
if( freq > 20000 ) continue;
```
```           freq => organ.freq;
.5 => organ.gain;
1 => organ.noteOn;
```
```           80::ms => now;
}
else
{
0 => organ.noteOff;
}
}
```

}

## a poem apropos of?

if you're bored...

Code Monkey by Jonathan Coulton

Code Monkey get up, get coffee
Code Monkey go to job
Code Monkey have boring meeting
Boring manager Rob
Rob say Code Monkey very diligent
But his output stink
His Code not functional or elegant
What do Code Monkey think?
Code Monkey think,
Maybe manager wanna write
Goddamn log-in page himself
Code Monkey not say it out loud
Code Monkey not crazy, just proud

Code Monkey like Fritos
Code Monkey like Tab and Mountain Dew
Code Monkey very simple man
Big, warm, fuzzy, secret heart
Code Monkey like you
Code Monkey like yooooouuuuu

Code Monkey hang around at front desk
Tell you sweater look nice
Code Monkey offer buy you soda
Bring you cup, bring you ice
You say no thank-you for the soda 'cause
Soda make you fat
Anyway, you busy with the telephone
No time for chat
Code Monkey have long walk back to cubicle
He sit down, pretend to work
Code Monkey not thinking so straight,
Code Monkey not feeling so great.

Code Monkey have every reason
To get out this place
Code Monkey just keep on working
See your soft pretty face
Much rather wake up, eat a coffee cake
Take bath, take nap
This job fulfilling and creative way
Such a load of crap
Code Monkey say someday he have everything
Even pretty girl, like you
Code Monkey just waiting, for now
Code Monkey say someday, somehow