class AudioShape { float x, y, w, a; float depx, depy; AudioChannel sample; int sampleNum; color c; int latency; Sensor sensor; Signal signal; AudioShape(int sampleNum, float x, float y, float w, float a, float ae, float len) { setSample(sampleNum); this.x = x; this.y = y; this.w = w; this.a = a; this.depx = 0;//random(2) - 1; this.depy = 0;//random(2) - 1; sensor = new Sensor(); signal = new Signal(this, x, y, len, a, ae); update(); } void setSample(int sampleNum) { this.sampleNum = sampleNum; sample = new AudioChannel(samples[sampleNum].file); //this.sample.sampleRate(samplerate, false); sample.adjustChannel(sample.frames(300 - sample.duration), Ess.END); // couleur de l'audioshape (relative au sample) c = samples[sampleNum].c; } void setPos(float x, float y) { this.x = x; this.y = y; update(); } void turn(float ra) { a += ra; signal.setAngle(a); } void update() { sensor.set(x+w/3*cos(a+PI), y+w/3*sin(a+PI)); //sensor.set(x, y); signal.setXY(x, y); } void moves() { setPos(x + depx, y + depy); if (x < w || x > width - w) depx = -1*depx; if (y < w || y > height - w) depy = -1*depy; } void display() { if (VIEW_SIGNALS || this == selShape) { noStroke(); fill(250, 200, 50, 100); signal.range.display(); } pushMatrix(); translate(x, y); rotate(a); if (isActive()) { stroke(0); strokeWeight(2); fill(c); rect(0, 0, w, w); noStroke(); fill(255, 150, 0); triangle(0, -w/3, 0, w/3, w/4, 0); } else { stroke(0); strokeWeight(1); fill(c); rect(0, 0, w, w); noStroke(); fill(255); triangle(0, -w/3, 0, w/3, w/4, 0); } popMatrix(); if (VIEW_SENSORS || this == selShape) sensor.display(); } void activate() { if (isActivable()) { sample.play(); latency = stepms; } } void preview() { sample.play(); } boolean isActivable() { return (latency == 0); } boolean isActive() { return (latency > 0); } void handle() { moves(); if (!isActivable()) { latency -= timeEllapsed; if (latency <= 0) { latency = 0; sendSignal(); // send a signal just after playing the sound } } } void sendSignal() { signalareas.add(signal); } void getSignal() { if (!isActivable()) return; for (java.util.ListIterator it = signalareas.listIterator(); it.hasNext(); ) { Signal s = (Signal)it.next(); if (s.getSource() == this) continue; if (sensor.receive(s)) { activate(); break; } } } boolean isUnder(int px, int py) { if (px < x - w/2 || px > x + w/2) return false; if (py < y - w/2 || py > y + w/2) return false; return true; } }