Skip to content

Instantly share code, notes, and snippets.

@Sciss
Sciss / CupolaOSC.txt
Created May 1, 2012 18:18
CupolaOSC.txt
:::::::: OSC messages ::::::::
[ "/flock_type", "bees" | "birds" | "fish" ]
[ "/flock", (float) pos_x, (float) pos_y (float) velo_angle, (float) velo_mag, (float) density, (float) curvature ]
where pos_x, pos_y, velo_mag, density and curvature are normalised to interval: [0 ... 1]
where velo_angle is in radians
[ "/predator", (int) num, (float) distance ]
where num >= 0
where distance is normalised to interval: [0 ... 1]
@Sciss
Sciss / binarytree.gvpr
Created June 6, 2012 00:04
GraphViz formatting script for binary trees
// from Emden Gansner
// https://mailman.research.att.com/pipermail/graphviz-interest/2010q2/007101.html
// requires GraphViz 2.28.0 (fails with 2.26.3 at least)
BEGIN {
double tw[node_t]; // width of tree rooted at node
double nw[node_t]; // width of node
double xoff[node_t]; // x offset of root from left side of its tree
double sp = 36; // extra space between left and right subtrees
double wd, w, w1, w2;
double x, y, z;
@Sciss
Sciss / ScalaColliderMacroRateChecking.scala
Created July 2, 2012 16:41
ScalaColliderMacroRateChecking.scala
// for Scala 2.10.0-M4
import language.experimental.macros
import import scala.reflect.makro._
// ScalaCollider skeleton
sealed trait MaybeRate
object UndefinedRate extends MaybeRate
sealed trait Rate extends MaybeRate
object audio extends Rate
object control extends Rate
@Sciss
Sciss / macro-ret.scala
Created July 2, 2012 17:00 — forked from retronym/macro-ret.scala
macro with computed return type
scala> def retImpl(c: Context)(b: c.Expr[Boolean]): c.Expr[Any] = {
| import c.universe._
| val Literal(Constant(bool: Boolean)) = b.tree
| if (bool) c.reify(0) else c.reify(false)
| }
retImpl: (c: scala.reflect.makro.Context)(b: c.Expr[Boolean])c.Expr[Any]
scala> def ret(b: Boolean) = macro retImpl
ret: (b: Boolean)Any
@Sciss
Sciss / Bench1.scala
Created July 24, 2012 15:00
Bench1.scala
package benchmark
object Bench1 extends App {
def time(f: => Unit) = {
val start = System.nanoTime()
f
System.nanoTime() - start
}
@Sciss
Sciss / Bench2.scala
Created July 24, 2012 15:00
Bench2.scala
package benchmark
object Bench2 extends App {
val num = args.headOption.map(_.toInt).getOrElse(1000)
def time(f: => Unit) = {
val start = System.nanoTime()
f
System.nanoTime() - start
@Sciss
Sciss / BenchResults.txt
Created July 24, 2012 15:04
BenchResults.txt
(1) :::::: Scala 2.9.2 ::::::
[info] Running benchmark.Bench1
Running benchmarks for n = 1000
while1 took 630.9814 µs per run
while2 took 71.3434 µs per run
for1 took 5487.2262 µs per run
for2 took 7332.3932 µs per run
[success] Total time: 147 s, completed Jul 24, 2012 3:40:24 PM
@Sciss
Sciss / Bench3.scala
Created July 24, 2012 15:49
Bench3.scala
package benchmark
object Bench3 extends App {
val num: Int = 1000
def time[A](f: => A) : (A, Long) = {
val start = System.nanoTime()
val res = f
res -> (System.nanoTime() - start)
}
@Sciss
Sciss / Disassemble.scala
Created July 27, 2012 13:47
Disassemble.scala
// to be called from the class output folder as cwd, traverses that folder
// for class files, calls javap on each, and writes the results to text
// files relative to a base directory given as parameter -d <outputDir>
//
// e.g.
// cd scala-2.10.0-M5
// mkdir ~/Desktop/m5
// scala /path/to/Disassemble -d ~/Desktop/m5
// ../scala-2.10.0-M6
// mkdir ~/Desktop/m6
// posted sc-user nov 2012
SynthDef(\elastic  , {  arg  t_trig = 1, freq = 4;
    var signal, in ;
    t = K2A.ar( t_trig) > 0;
     m = Spring.ar(ToggleFF.ar(t), 100, 0.6);
     in = LocalIn.ar(1) * 0.098;
     
     n = Spring.ar(m + in , 3, 0.001);
         h = Spring.ar(n, 0.5  , 0.000026);