Processing long time performance
in
Core Library Questions
•
5 months ago
i got a problem with the longtime performance of the following code.
after 2 or three hours the video jumps getting slower and slower. my code loops the movies between the first 2 seconds until it gets an sound input. with any sound input the movie jumps to the next second and the eyes get opened. at the end of the movie it jumps back to the loop at the beginning. it would be so great if you could help me with this problem.
here you can load the whole sketch with data..
heres the code
- import processing.video.*;
- import ddf.minim.*;
- Minim mySound; //CREATE A NEW SOUND OBJECT
- AudioInput in;
- int numCircles =52;
- int numMovies = 27;
- PImage maskImage;
- Movie[] eye = new Movie[numMovies];
- Circle[] circles = new Circle[numCircles];
- int selectedCircle = -1;
- int maxMovies = 27;
- boolean hak = true;
- void setup() {
- size(1920, 1000);
- imageMode(CENTER);
- smooth();
- mySound = new Minim(this);
- in = mySound.getLineIn(Minim.STEREO, 512);
- maskImage = loadImage("mask-bg.jpg");
- eye[0] = new Movie(this, "eye0.mov");
- eye[1] = new Movie(this, "eye1.mov");
- eye[2] = new Movie(this, "eye2.mov");
- eye[3] = new Movie(this, "eye3.mov");
- eye[4] = new Movie(this, "eye4.mov");
- eye[5] = new Movie(this, "eye5.mov");
- eye[6] = new Movie(this, "eye6.mov");
- eye[7] = new Movie(this, "eye7.mov");
- eye[8] = new Movie(this, "eye8.mov");
- eye[9] = new Movie(this, "eye9.mov");
- eye[10] = new Movie(this, "eye10.mov");
- eye[11] = new Movie(this, "eye11.mov");
- eye[12] = new Movie(this, "eye12.mov");
- eye[13] = new Movie(this, "eye13.mov");
- eye[14] = new Movie(this, "eye14.mov");
- eye[15] = new Movie(this, "eye15.mov");
- eye[16] = new Movie(this, "eye16.mov");
- eye[17] = new Movie(this, "eye17.mov");
- eye[18] = new Movie(this, "eye18.mov");
- eye[19] = new Movie(this, "eye19.mov");
- eye[20] = new Movie(this, "eye20.mov");
- eye[21] = new Movie(this, "eye1.mov");
- eye[22] = new Movie(this, "eye2.mov");
- eye[23] = new Movie(this, "eye3.mov");
- eye[24] = new Movie(this, "eye4.mov");
- eye[25] = new Movie(this, "eye5.mov");
- eye[26] = new Movie(this, "eye6.mov");
- for (int i=0; i<eye.length; i++) {
- eye[i].loop();
- // eye[i].stop();
- }
- for (int i=0; i<circles.length; i++) {
- circles[i] = new Circle();
- circles[i].setMovie(i % maxMovies);
- println(i % maxMovies);
- }
- }
- void draw() {
- float soundLevel = in.mix.level(); //GET OUR AUDIO IN LEVEL
- float eye0t = eye[0].time();
- float eye1t = eye[1].time();
- float eye2t = eye[2].time();
- float eye3t = eye[3].time();
- float eye4t = eye[4].time();
- float eye5t = eye[5].time();
- float eye6t = eye[6].time();
- float eye7t = eye[7].time();
- float eye8t = eye[8].time();
- float eye9t = eye[9].time();
- float eye10t = eye[10].time();
- float eye11t = eye[11].time();
- float eye12t = eye[12].time();
- float eye13t = eye[13].time();
- float eye14t = eye[14].time();
- float eye15t = eye[15].time();
- float eye16t = eye[16].time();
- float eye17t = eye[17].time();
- float eye18t = eye[18].time();
- float eye19t = eye[19].time();
- float eye20t = eye[20].time();
- float eye21t = eye[21].time();
- float eye22t = eye[22].time();
- float eye23t = eye[23].time();
- float eye24t = eye[9].time();
- float eye25t = eye[10].time();
- float eye26t = eye[11].time();
- // Schritt 1
- // hier Zeit float zum passenden Movie deklarieren Bsp. für Movie 3
- // float eye3t = eye[3].time();
- if ((soundLevel>0.08)&&(hak)) {
- hak=false;
- eye[0].jump(2);
- eye[1].jump(2);
- eye[2].jump(2);
- eye[3].jump(2);
- eye[4].jump(2);
- eye[5].jump(2);
- eye[6].jump(2);
- eye[7].jump(2);
- eye[8].jump(2);
- eye[9].jump(2);
- eye[10].jump(2);
- eye[11].jump(2);
- eye[12].jump(2);
- eye[13].jump(2);
- eye[14].jump(2);
- eye[15].jump(2);
- eye[16].jump(2);
- eye[17].jump(2);
- eye[18].jump(2);
- eye[19].jump(2);
- eye[20].jump(1);
- eye[21].jump(2);
- eye[22].jump(2);
- eye[23].jump(2);
- eye[24].jump(2);
- eye[25].jump(2);
- eye[26].jump(2);
- }
- if ((eye0t>63)) {
- hak=true;
- }
- if ((eye0t>3)&&(hak)) {
- eye[0].jump(0);
- }
- if ((eye1t>3.01)&&(hak)) {
- eye[1].jump(0);
- }
- if ((eye2t>3.02)&&(hak)) {
- eye[2].jump(0);
- }
- if ((eye3t>3.03)&&(hak)) {
- eye[3].jump(0);
- }
- if ((eye4t>3.04)&&(hak)) {
- eye[4].jump(0);
- }
- if ((eye5t>3.05)&&(hak)) {
- eye[5].jump(0);
- }
- if ((eye6t>3.06)&&(hak)) {
- eye[6].jump(0);
- }
- if ((eye7t>3.07)&&(hak)) {
- eye[7].jump(0);
- }
- if ((eye8t>3.08)&&(hak)) {
- eye[8].jump(0);
- }
- if ((eye9t>3.09)&&(hak)) {
- eye[9].jump(0);
- }
- if ((eye10t>3.10)&&(hak)) {
- eye[10].jump(0);
- }
- if ((eye11t>3.11)&&(hak)) {
- eye[11].jump(0);
- }
- if ((eye12t>3.12)&&(hak)) {
- eye[12].jump(0);
- }
- if ((eye13t>3.13)&&(hak)) {
- eye[13].jump(0);
- }
- if ((eye14t>3.14)&&(hak)) {
- eye[14].jump(0);
- }
- if ((eye15t>2.59)&&(hak)) {
- eye[15].jump(0);
- }
- if ((eye16t>2.58)&&(hak)) {
- eye[16].jump(0);
- }
- if ((eye17t>2.57)&&(hak)) {
- eye[17].jump(0);
- }
- if ((eye18t>2.56)&&(hak)) {
- eye[18].jump(0);
- }
- if ((eye19t>2.55)&&(hak)) {
- eye[19].jump(0);
- }
- if ((eye20t>2.54)&&(hak)) {
- eye[20].jump(0);
- }
- if ((eye21t>2.53)&&(hak)) {
- eye[21].jump(0);
- }
- if ((eye22t>2.52)&&(hak)) {
- eye[22].jump(0);
- }
- if ((eye23t>2.51)&&(hak)) {
- eye[23].jump(0);
- }
- if ((eye24t>2.50)&&(hak)) {
- eye[24].jump(0);
- }
- if ((eye25t>2.49)&&(hak)) {
- eye[25].jump(0);
- }
- if ((eye26t>2.48)&&(hak)) {
- eye[26].jump(0);
- }
- background(0);
- for (int i=0; i<eye.length; i++) {
- if (eye[i].available()) {
- eye[i].read();
- eye[i].mask(maskImage);
- }
- }
- for (int i=0; i< circles.length; i++) {
- circles[i].display();
- }
- }
- void mousePressed() {
- for (int i=0; i<circles.length; i++) {
- if (circles[i].mouseOverCircle()) {
- selectedCircle = i;
- break;
- }
- }
- }
- void mouseDragged() {
- if (selectedCircle>-1) {
- circles[selectedCircle].move();
- }
- }
- void mouseReleased() {
- selectedCircle = -1;
- }
- void keyPressed(){
- switch (key) {
- case 'a':
- hak = true;
- eye[0].jump(0);
- eye[1].jump(0);
- eye[2].jump(0);
- eye[3].jump(0);
- eye[4].jump(0);
- eye[5].jump(0);
- eye[6].jump(0);
- eye[7].jump(0);
- eye[8].jump(0);
- eye[9].jump(0);
- eye[10].jump(0);
- eye[11].jump(0);
- eye[12].jump(0);
- eye[13].jump(0);
- eye[14].jump(0);
- eye[15].jump(0);
- eye[16].jump(0);
- eye[17].jump(0);
- eye[18].jump(0);
- eye[19].jump(0);
- eye[20].jump(0);
- eye[21].jump(0);
- eye[22].jump(0);
- eye[23].jump(0);
- eye[24].jump(0);
- eye[25].jump(0);
- eye[26].jump(0);
- // do something if the key pressed was 'r'
- break;
- case 'm':
- hak = false;
- eye[0].jump(2);
- eye[1].jump(2);
- eye[2].jump(2);
- eye[3].jump(2);
- eye[4].jump(2);
- eye[5].jump(2);
- eye[6].jump(2);
- eye[7].jump(2);
- eye[8].jump(2);
- eye[9].jump(2);
- eye[10].jump(2);
- eye[11].jump(2);
- eye[12].jump(2);
- eye[13].jump(2);
- eye[14].jump(2);
- eye[15].jump(2);
- eye[16].jump(2);
- eye[17].jump(2);
- eye[18].jump(2);
- eye[19].jump(2);
- eye[20].jump(1);
- eye[21].jump(2);
- eye[22].jump(2);
- eye[23].jump(2);
- eye[24].jump(2);
- eye[25].jump(2);
- eye[26].jump(2);
- default:
- break;
- }
- }
- class Circle {
- float r, xpos, ypos;
- int selectedMovie;
- Circle() {
- xpos = random(width);
- ypos = random(height);
- r = 300;
- setMovie(0);
- }
- void setMovie(int _id)
- {
- selectedMovie = _id;
- if (selectedMovie>17){
- r=150;
- }
- else {
- r=180;
- }
- }
- void display() {
- image(eye[selectedMovie], xpos, ypos, r, r);
- }
- boolean mouseOverCircle() {
- return (dist(mouseX, mouseY, xpos, ypos)<40);
- }
- void move() {
- xpos += (mouseX-pmouseX);
- ypos += (mouseY-pmouseY);
- if (xpos>width) {
- xpos = 0;
- }
- if (ypos>height) {
- ypos = 0;
- }
- }
- }
1