Skip to content

Instantly share code, notes, and snippets.

@enjalot
Created June 30, 2013 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enjalot/5893333 to your computer and use it in GitHub Desktop.
Save enjalot/5893333 to your computer and use it in GitHub Desktop.
timbre.js play midi dots
{"description":"timbre.js play midi dots","endpoint":"","display":"svg","public":true,"require":[{"name":"supercollider","url":"http://mohayonao.github.io/subcollider.js/builds/subcollider-min.js"},{"name":"timbre-mod","url":"https://gist.github.com/enjalot/5893275/raw/3a9f3430225510d2258381c9e6ab1506ff8bb86f/timbre-mod.js"}],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/BustcF4.png"}
//http://mohayonao.github.io/timbre.js/
//hacky modifications to make it work in tributary
TReset();
TFactory();
var svg = d3.select("svg");
var color = d3.scale.category10();
var xr = 47;
var yr = 45;
var notes = [72, 73, 74, 75, 76, 77, 78];
var data = d3.range(7).map(function(d,i) {
var permuted = [];
for(var j = 0; j < notes.length; j++) {
permuted.push(notes[(j) % notes.length]+i*notes.length)
}
return permuted
})
var msec = timbre.timevalue("bpm120 l8");
function playMidi(note) {
var synth = T("OscGen", {wave:"sin", mul:0.25, env:T("perc", {r:msec, ar:true})});
synth.noteOn(note, 100);
synth.play()
}
//playMidi(70);
svg.selectAll("g.row")
.data(data)
.enter()
.append("g")
.selectAll("circle")
.data(function(d) { return d })
.enter()
.append("circle")
.attr({
cx: function(d,i,j) { return 100 + i * xr },
cy: function(d,i,j) { return 100 + j * yr },
r: 20,
fill: function(d,i,j) { return color(i) }
}).on("mouseover", function(d,i) {
playMidi(d)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment