«  …12 13 14 15 16 17 18 »

atolf lftoa

2011-02-17 01:10 supercollider

Using SuperCollider I reverse-engineered two old MaxMSPJitter externals from Cycling'74. They came as part of the pluggo installer and were compiled in the cfm binary format. This format is since long-defunct and cfm externals can't be loaded into MaxMSPJitter running under Windows or newer Intel macs (afaik). Luckily I could still run the externals and help files under Max4.6 on my old PPC mac.

And as far as I could tell, the source code for these binaries was never released. So I took the trial&error route and managed to figure out how they work internally by using simple input strings like 'aa', 'ab', 'ac', 'ba', 'bb', 'aba', 'abc' etc. Then I just observed the output arrays of floating-point numbers and tried to mimic that in SuperCollider code. It was fairly quick to come up with the algorithms that encode (atolf) and decode (lftoa) shown below.

Also a note on MaxMSPJitter vs SuperCollider: no way I could have solved this using MaxMSPJitter only. Algorithms like these are horrendous to implement with patchcords. See the mess in the screenshots below. Also, MaxMSPJitter's floating-point number boxes, as well as the [print] object, does not show the whole 32bit float values! They round off to 6 digits after the decimal point. Why? So MaxMSPJitter can calculate just fine using 32bit floats as long as you don't try to print or output them in any way.

Anyway, I first wrote RedALF for SuperCollider (it is now in the redSys quark) and from that, I then patched f0.atolf and f0.lftoa (now part of my f0.abs MaxMSPJitter abstractions).

(
~atolf= {|str|
  var res= [1/2**5];
  var tre= [2**12, 2**20, 2**28];
  str.do{|chr, i|
    var j= i.div(3);
    if(i%3==2, {
      res= res++(1/2**5);
    });
    res.put(j, res[j]+(chr.ascii/tre[i%3]));
  };
  res;
};
~lftoa= {|arr|
  var res= "";
  arr.do{|val|
    var a, b, c;
    val= val-(1/2**5)*(2**12);
    a= val.asInteger;
    val= val-a*(2**8);
    b= val.asInteger;
    val= val-b*(2**8);
    c= val.asInteger;
    res= res++a.asAscii++b.asAscii++c.asAscii;
  };
  res;
};
)
a= ~atolf.value("aber")  //--> [0.055025476962328, 0.05908203125]
~lftoa.value(a)  //--> "aber"

sinusdeklinationen

2011-02-15 17:59 supercollider

A quick port of a very simple Pure Data demonstration patch made by Malte Steiner. Just to show one way how to go about things in SuperCollider.

Get the Pd patch here... sinusdeklinationen.pd

and then compare it with the following...

//--sinusdeklinationen by Malte Steiner, ported to SC by redFrik

s.boot;

(
SynthDef(\sinuscell, {|out= 0, pan= 0, amp= 0.5, fre= 400, atk= 1, sus= 0.2, rel= 1|
  var env= EnvGen.kr(Env.linen(atk, sus, rel, amp), doneAction:2);
  var snd= SinOsc.ar(fre, 0, env);
  Out.ar(out, Pan2.ar(snd, pan));
}).send(s);
)


(
var cells= [-1, -0.6, -0.5, 0, 0.2, 0.5, 0.4, 1];
~mainVol= 0.1;
cells.do{|c|
  Routine({
    inf.do{
      var fre= 1100.rand;
      var atk= 1.0.rand;
      var sus= 0.2;
      var rel= 1.0.rand;
      Synth(\sinuscell, [\fre, fre, \amp, 1.0.rand*~mainVol, \atk, atk, \sus, sus, \rel, rel, \pan, c]);
      (atk+sus+rel).wait;
    };
  }).play;
};
)


~mainVol= 0.2
~mainVol= 0.02

//stop with cmd+.

redUniverse: Support for Discrete Worlds

2010-12-15 06:22 supercollider

clean-up #30:

As the last thing for this month-of-cleaning-up-old-code-and-taking-care-of-forgotten-projects, I finally wrote some methods that I had been planning for a long time. They add support for discrete worlds to my redUniverse quark.

It's all fairly simple.

In a 2 dimensional world there are 8 neighbouring cells/locations. The surroundings method returns them.

a= RedWorld(RedVector[100, 200])  //a 2D world
a.surroundings
[ [ -1, -1 ], [ -1, 0 ], [ -1, 1 ], [ 0, -1 ], [ 0, 1 ], [ 1, -1 ], [ 1, 0 ], [ 1, 1 ] ]

And in a 3 dimensional world, the number of surrounding cells grows to 26. That is 3 * 3 * 3 - 1 where the minus one is the [0, 0] location.

a= RedWorld(RedVector[100, 200, 300])  //a 3D world
a.surroundings
[ [ -1, -1, -1 ], [ -1, -1, 0 ], [ -1, -1, 1 ], [ -1, 0, -1 ], [ -1, 0, 0 ], [ -1, 0, 1 ], [ -1, 1, -1 ], [ -1, 1, 0 ], [ -1, 1, 1 ], [ 0, -1, -1 ], [ 0, -1, 0 ], [ 0, -1, 1 ], [ 0, 0, -1 ], [ 0, 0, 1 ], [ 0, 1, -1 ], [ 0, 1, 0 ], [ 0, 1, 1 ], [ 1, -1, -1 ], [ 1, -1, 0 ], [ 1, -1, 1 ], [ 1, 0, -1 ], [ 1, 0, 0 ], [ 1, 0, 1 ], [ 1, 1, -1 ], [ 1, 1, 0 ], [ 1, 1, 1 ] ]

And the numbers for 4, 5 and 6 dimensional worlds (not that I ever used >3) are 80, 242, 728 respectively. (A RedWorld can have any number of dimensions.)

Also it is possible to not only get the directly adjacent cell, but neighbours further away. This example bumps up the surroundingArea variable from the default 1 to 2. Now the surroundings are all the cells next to and two steps away from [0, 0].

a= RedWorld(RedVector[100, 200])  //a 2F world
a.surroundingArea= 2
a.surroundings
[ [ -2, -2 ], [ -2, -1 ], [ -2, 0 ], [ -2, 1 ], [ -2, 2 ], [ -1, -2 ], [ -1, -1 ], [ -1, 0 ], [ -1, 1 ], [ -1, 2 ], [ 0, -2 ], [ 0, -1 ], [ 0, 1 ], [ 0, 2 ], [ 1, -2 ], [ 1, -1 ], [ 1, 0 ], [ 1, 1 ], [ 1, 2 ], [ 2, -2 ], [ 2, -1 ], [ 2, 0 ], [ 2, 1 ], [ 2, 2 ] ]

That is 24 neighbour locations per single cell in a 2D world.

So the surroundings method only give relative positions and the size of the neighbourhood. Not so useful. But there are the two other methods called surroundingLocations and neighbours that is what one should use. surroundingLocations takes an object and returns a list of locations depending on the current surroundings.

a= RedWorld(RedVector[100, 200])  //a 2D world
b= RedObject(a, RedVector[10, 20])  //an object at location [10, 20]
a.surroundingLocations(b)  //get the surrounding locations of object b
[ RedVector[ 9, 19 ], RedVector[ 9, 20 ], RedVector[ 9, 21 ], RedVector[ 10, 19 ], RedVector[ 10, 21 ], RedVector[ 11, 19 ], RedVector[ 11, 20 ], RedVector[ 11, 21 ] ]

Last the neighbours method that returns an array of any nearby objects.

a= RedWorld(RedVector[100, 200])  //a 2D world
b= RedObject(a, RedVector[10, 20])  //an object at location [10, 20]
c= RedObject(a, RedVector[11, 21])  //an object at location [11, 21]
a.neighbours(b)  //get the neighbouring objects of object b
[ a RedObject ]

The different worlds deals with border conditions differently. RedWorld wraps all the locations around and RedWorld3 filters out locations. Compare...

a= RedWorld(RedVector[100, 200])  //a 2D world without borders
b= RedObject(a, RedVector[0, 0])  //an object at upper left corner location [0, 0]
a.surroundingLocations(b)  //get the surrounding locations of object b
[ RedVector[ 99, 199 ], RedVector[ 99, 0 ], RedVector[ 99, 1 ], RedVector[ 0, 199 ], RedVector[ 0, 1 ], RedVector[ 1, 199 ], RedVector[ 1, 0 ], RedVector[ 1, 1 ] ]
a= RedWorld3(RedVector[100, 200])  //a 2D world with borders
b= RedObject(a, RedVector[0, 0])  //an object at upper left corner location [0, 0]
a.surroundingLocations(b)  //get the surrounding locations of object b
[ RedVector[ 0, 1 ], RedVector[ 1, 0 ], RedVector[ 1, 1 ] ]

The neighbours method is quite slow at the moment, but I hope to be able to speed it up considerably later on.

Anyway, here is the complete SVN diff: sourceforge.net/p/quarks/code/1765/


redMaggot

2010-12-14 01:51 supercollider

clean-up #29:

Probably the last in this series (can't think of any more names).

Previous low life:

Note: will only run under older SuperCollider, version <=3.6 with OSX (Cocoa).

Attachments:
redMaggot.scd

redLeech

2010-12-13 03:21 supercollider

clean-up #28:

Code that performs itself. This is number six in a series all working in a similar manner. See low life, more low life and even more low life.

This virtual leech runs around the code and sucks up words now and then. When it's full (c.size>30) it spits them all out wherever it happens to be. And some characters are lost so the code slowly disappears.

At the end of the video, it got stuck in a loop so I killed it off manually with the delete key.

Thanks to Chris for the title.

SuperCollider document attached below. Note: will only run under older SuperCollider, version <=3.6 with OSX (Cocoa).

Attachments:
redLeech.scd

CrucialLib Introduction

2010-12-12 04:21 supercollider

clean-up #27:

Between 2002-2004 Nick and I were giving SuperCollider summer workshops in London, and one little part of that was to show a variety of ways how one could work with SuperCollider. Attached here below is the code+comments used to demo Felix's Crucial library.

Attachments:
intro_to_CrucialLibrary_for_SC_Server.scd

redUniverse: Clean-up and some New Features

2010-12-11 04:01 supercollider

clean-up #26:

My redUniverse quark still has a lot of features missing that I want to put in. It is endless work and I only get to it now and then. But at least after today the help files are in a bit better shape, and examples are changed to use animate to run more smoothly (most now look a lot better!).

Here is the complete SVN diff: sourceforge.net/p/quarks/code/1759/


Vertex

2010-12-10 05:01 supercollider

clean-up #25:

Attached is a little class that draws polygons in SuperCollider. With inspiration from processing.org/reference/beginShape_.html.

If you want to use the \points type of shape it will look better with smoothing set to false and Vertex.pointSize= 0;

vertextest screenshot
(
var win= Window("vertex test", Rect(100, 100, 430, 320), false);
win.drawFunc= {
  Pen.fillColor= Color.white;
  Pen.strokeColor= Color.black;

  Pen.use{
    Pen.translate(10, 10);
    Vertex.beginShape();
    Vertex(Point(30, 20));
    Vertex(Point(85, 20));
    Vertex(Point(85, 75));
    Vertex(Point(30, 75));
    Vertex.endShape(1);  //1 means close
    Pen.fillStroke;  //also try fill and stroke
  };
  Pen.use{
    Pen.translate(110, 10);
    Vertex.beginShape(\points);
    Vertex(Point(30, 20));
    Vertex(Point(85, 20));
    Vertex(Point(85, 75));
    Vertex(Point(30, 75));
    Vertex.endShape();
    Pen.stroke;
  };
  Pen.use{
    Pen.translate(210, 10);
    Vertex.beginShape(\lines);
    Vertex(Point(30, 20));
    Vertex(Point(85, 20));
    Vertex(Point(85, 75));
    Vertex(Point(30, 75));
    Vertex.endShape();
    Pen.stroke;
  };
  Pen.use{
    Pen.translate(310, 10);
    Vertex.beginShape();
    Vertex(Point(30, 20));
    Vertex(Point(85, 20));
    Vertex(Point(85, 75));
    Vertex(Point(30, 75));
    Vertex.endShape(0);  //0 means not close (default)
    Pen.stroke;
  };

  Pen.use{
    Pen.translate(10, 110);
    Vertex.beginShape();
    Vertex(Point(30, 20));
    Vertex(Point(85, 20));
    Vertex(Point(85, 75));
    Vertex(Point(30, 75));
    Vertex.endShape(1);  //1 means close
    Pen.stroke;
  };
  Pen.use{
    Pen.translate(110, 110);
    Vertex.beginShape(\triangles);
    Vertex(Point(30, 75));
    Vertex(Point(40, 20));
    Vertex(Point(50, 75));
    Vertex(Point(60, 20));
    Vertex(Point(70, 75));
    Vertex(Point(80, 20));
    Vertex.endShape();
    Pen.fillStroke;  //also try fill and stroke
  };
  Pen.use{
    Pen.translate(210, 110);
    Vertex.beginShape(\triangleStrip);
    Vertex(Point(30, 75));
    Vertex(Point(40, 20));
    Vertex(Point(50, 75));
    Vertex(Point(60, 20));
    Vertex(Point(70, 75));
    Vertex(Point(80, 20));
    Vertex(Point(90, 75));
    Vertex.endShape();
    Pen.fillStroke;  //also try fill and stroke
  };
  Pen.use{
    Pen.translate(310, 110);
    Vertex.beginShape(\triangleFan);
    Vertex(Point(57.5, 50));
    Vertex(Point(57.5, 15));
    Vertex(Point(92, 50));
    Vertex(Point(57.5, 85));
    Vertex(Point(22, 50));
    Vertex(Point(57.5, 15));
    Vertex.endShape();
    Pen.fillStroke;  //also try fill and stroke
  };

  Pen.use{
    Pen.translate(10, 210);
    Vertex.beginShape(\quads);
    Vertex(Point(30, 20));
    Vertex(Point(30, 75));
    Vertex(Point(50, 75));
    Vertex(Point(50, 20));
    Vertex(Point(65, 20));
    Vertex(Point(65, 75));
    Vertex(Point(85, 75));
    Vertex(Point(85, 20));
    Vertex.endShape();
    Pen.fillStroke;  //also try fill and stroke
  };
  Pen.use{
    Pen.translate(110, 210);
    Vertex.beginShape(\quadStrip);
    Vertex(Point(30, 20));
    Vertex(Point(30, 75));
    Vertex(Point(50, 20));
    Vertex(Point(50, 75));
    Vertex(Point(65, 20));
    Vertex(Point(65, 75));
    Vertex(Point(85, 20));
    Vertex(Point(85, 75));
    Vertex.endShape();
    Pen.fillStroke;  //also try fill and stroke
  };
  Pen.use{
    Pen.translate(210, 210);
    Vertex.beginShape();
    Vertex(Point(20, 20));
    Vertex(Point(40, 20));
    Vertex(Point(40, 40));
    Vertex(Point(60, 40));
    Vertex(Point(60, 60));
    Vertex(Point(20, 60));
    Vertex.endShape(1);  //also try 0 here
    Pen.fillStroke;  //also try fill and stroke
  };
  Pen.use{
    Pen.translate(310, 210);
    Vertex.beginShape();
    14.do{
      Vertex(Point(85.rand, 85.rand));
    };
    Vertex.endShape(1);  //also try 0 here
    Pen.fillStroke;  //also try fill and stroke
  };
};
win.front;
)
//https://processing.org/reference/bezierVertex_.html
(
var win= Window("beziervertex test1", Rect(100, 100, 300, 300), false);
win.drawFunc= {
  Pen.fillColor= Color.white;
  Pen.strokeColor= Color.black;
  BezierVertex.beginShape(Point(30, 20));
  BezierVertex(Point(80, 0), Point(80, 75), Point(30, 75));
  BezierVertex.endShape;
  Pen.stroke;  //also try fillStroke and fill
};
win.front;
)

//https://processing.org/reference/bezierVertex_.html
(
var win= Window("beziervertex test2", Rect(100, 100, 300, 300), false);
win.drawFunc= {
  Pen.fillColor= Color.white;
  Pen.strokeColor= Color.black;
  BezierVertex.beginShape(Point(30, 20));
  BezierVertex(Point(80, 0), Point(80, 75), Point(30, 75));
  BezierVertex(Point(50, 80), Point(60, 25), Point(30, 20));
  BezierVertex.endShape;
  Pen.fillStroke;  //also try stroke and fill
};
win.front;
)

Updates:

Attachments:
Vertex.sc
BezierVertex.sc

«  …12 13 14 15 16 17 18 »