xxxxxxxxxx
346
let inteval = 0;
let img;
// declare kinectron
let kinectron = null;
// address for kinectron
let address = null;
let rawRightHandX = null;
let mappedRightHandX = null;
//code for shiny
//and a compressor
var drumCompress = new Tone.Compressor({
"threshold" : -30,
"ratio" : 6,
"attack" : 0.3,
"release" : 0.1
}).toMaster();
var distortion = new Tone.Distortion({
"distortion" : 0.4,
"wet" : 0.4
});
//hats
var hats = new Tone.Player({
"url" : "./audio/505/hh.[mp3|ogg]",
"volume" : -10,
"retrigger" : true,
"fadeOut" : 0.05
}).chain(distortion, drumCompress);
var hatsLoop = new Tone.Loop({
"callback" : function(time){
hats.start(time).stop(time + 0.05);
},
"interval" : "16n",
"probability" : 0.8
}).start("1m");
//SNARE PART
var snare = new Tone.Player({
"url" : "./audio/505/snare.[mp3|ogg]",
"retrigger" : true,
"fadeOut" : 0.1
}).chain(distortion, drumCompress);
var snarePart = new Tone.Sequence(function(time, velocity){
snare.volume.value = Tone.gainToDb(velocity);
snare.start(time).stop(time + 0.1);
}, [null, 1, null, [1, 0.3]]).start(0);
var kick = new Tone.MembraneSynth({
"pitchDecay" : 0.01,
"octaves" : 6,
"oscillator" : {
"type" : "square4"
},
"envelope" : {
"attack" : 0.001,
"decay" : 0.2,
"sustain" : 0
}
}).connect(drumCompress);
var kickPart = new Tone.Sequence(function(time, probability){
if (Math.random() < probability){
kick.triggerAttack("C1", time);
}
}, [1, [1, [null, 0.3]], 1, [1, [null, 0.5]], 1, 1, 1, [1, [null, 0.8]]], "2n").start(0);
// BASS
var bass = new Tone.FMSynth({
"harmonicity" : 1,
"modulationIndex" : 3.5,
"carrier" : {
"oscillator" : {
"type" : "custom",
"partials" : [0, 1, 0, 2]
},
"envelope" : {
"attack" : 0.08,
"decay" : 0.3,
"sustain" : 0,
},
},
"modulator" : {
"oscillator" : {
"type" : "sine"
},
"envelope" : {
"attack" : 0.1,
"decay" : 0.2,
"sustain" : 0.3,
"release" : 0.01
},
}
}).toMaster();
//
//code for tone js syth
var synth = new Tone.MonoSynth({
"portamento" : 0.00,
"oscillator" : {
"type" : "sawtooth"
},
"envelope" : {
"attack" : 0.315,
"decay" : 0.052,
"sustain" : 0.34,
"release" : 0.04,
},
"filterEnvelope" : {
"attack" : 0.05,
"decay" : 0.051,
"sustain" : 0.095,
"release" : 0.05,
"baseFrequency" :300,
"octaves" : 3
}
}).toMaster();
//code for metal synth
var bell = new Tone.MetalSynth({
"harmonicity" : 12,
"resonance" : 1000,
"modulationIndex" : 20,
"envelope" : {
"decay" : 0.4,
},
"volume" : -15
}).toMaster();
var bellPart = new Tone.Sequence(function(time, freq){
bell.frequency.setValueAtTime(freq, time, Math.random()*0.5 + 0.5);
bell.triggerAttack(time);
}, [300, null, 200, null, 200, 200, null, 200, null, 200, null, 200], "8t").start(0);
// bellPart.loop = true;
// bellPart.loopEnd = "1m";
var conga = new Tone.MembraneSynth({
"pitchDecay" : 0.008,
"octaves" : 2,
"envelope" : {
"attack" : 0.0006,
"decay" : 0.5,
"sustain" : 0
}
}).toMaster();
class Column {
constructor(x, y, img) {
this.img = img;
this.x = x;
this.y = y;
this.index = 2;
}
display() {
let yPos = -1 * ((this.index) * 950);
image(img, this.x, yPos);
}
displayNumber(){
text(this.index, this.x + (55/2), width / 2);
}
changeIndex(idx) {
this.index = idx;
}
mouseOver() {
if (mouseX > this.x && mouseX < this.x + 55) {
return true;
} else {
return false;
}
}
}
function preload() {
img = loadImage("pattern_2_50_3800_thinner.png"); // Load the image
//imgBlank = loadImage("single_column_100_1440.jpg");
}
// columnX = 0;
// columnY = 0;
// yImage = -800;
let w_img = 55;
let num_columns = 25;
let w = w_img * num_columns;
let h = 950;
let columns = [];
function setup() {
createCanvas(w, h);
// cnv = createCanvas(w, h);
//cnv.mouseMoved(playSound);
for (let i = 0; i < num_columns; i++) {
columns.push(new Column(i * 55, 0, img));
}
// definir address
// ingresar la ip del computador windows
// cuatro numeros, todos entre 0 y 255,
// separados por un punto y todo entre comillas
address = "172.16.242.61";
// definir kinectron
kinectron = new Kinectron(address);
// conectar a kinectron
kinectron.makeConnection();
// pedir tracking de cuerpos
// cuando llega un cuerpo, se ejecuta funcion trackBody
kinectron.startTrackedBodies(trackBody);
}
//if mouseover mouseX is within a certian radius then have
//object touched translate it's image inside it -50 px up.
//
//and the object next to it (to the right of it)
//translates it's image +50px.
//object to the right of the right does another +50px
//object to the left of the left does another -50px
function column(x, y) {
// Displays the image at its actual size at point (0,0)
image(img, x, yImage);
// Displays the imag fill(0, 200, 255);
//rect(x-10, y, 20, 50);
// frameRate(10);
// print(yImage);
}
function draw() {
background(240, 230, 218);
print(h);
// default all to position 2;
for (let i = 0; i < num_columns; i++) {
columns[i].changeIndex(2);
}
// adjust dpeending on mouse Position:
for (let i = 0; i < num_columns; i++) {
// columns[i].changeIndex(2);
// if (columns[i].mouseOver()) {
if (mappedRightHandX > i * w_img && mappedRightHandX < (i+1) * w_img) {
columns[i].changeIndex(4);
if ((i + 1) < num_columns) {
columns[i + 1].changeIndex(3);
}
if ((i - 1) >= 0) {
columns[i - 1].changeIndex(0);
}
if ((i - 2) >= 0) {
columns[i - 2].changeIndex(1);
}
}
}
// display that shit:
for (let i = 2; i < num_columns - 2; i++) {
columns[i].display();
// columns[i].displayNumber();
}
// lines between
// for (let i = 0; i < num_columns; i++) {
// line(i * 50, 0, i * 50, height);
// }
}
//callback for when this sketch receives a new skeleton info
function trackBody(body) {
console.log(body);
console.log(body.bodyIndex);
if(body.bodyIndex == 1){
console.log("main body moved");
//retrieve info from kinect skeleton
rawRightHandX = body.joints[kinectron.HANDRIGHT].cameraX;
//console.log(rawRightHandX);
//map the value
mappedRightHandX = map(rawRightHandX,-0.7,0.7,0,w);
mouseMoved();
}else{
console.log("sopme other person, dot worry");
}
}
function mouseMoved() {
//
synth.triggerAttack(10);
// synth.triggerAttack("7", );
//Tone.Transport.start("+0.1");
// Tone.Transport.start("+0.9");
//let interval = .05;
// xNoise.start();
//Tone.Master.volume.rampTo(mouseX/50, interval);
///interval = interval + .05;
//if (interval == 1){
// interval = .05;
// }
}