Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Processing long time performance

$
0
0
 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
  1. import processing.video.*;
  2. import ddf.minim.*;

  3. Minim mySound; //CREATE A NEW SOUND OBJECT
  4. AudioInput in;

  5. int numCircles =52;
  6. int numMovies = 27;
  7. PImage maskImage;
  8. Movie[] eye = new Movie[numMovies];
  9. Circle[] circles = new Circle[numCircles];
  10. int selectedCircle = -1;
  11. int maxMovies = 27;
  12. boolean hak = true;



  13. void setup() {
  14.   size(1920, 1000);
  15.   imageMode(CENTER);
  16.   smooth();

  17.   mySound = new Minim(this);
  18.   in = mySound.getLineIn(Minim.STEREO, 512);

  19.   maskImage = loadImage("mask-bg.jpg");

  20.   eye[0] = new Movie(this, "eye0.mov");
  21.   eye[1] = new Movie(this, "eye1.mov");
  22.   eye[2] = new Movie(this, "eye2.mov");
  23.   eye[3] = new Movie(this, "eye3.mov");
  24.   eye[4] = new Movie(this, "eye4.mov");
  25.   eye[5] = new Movie(this, "eye5.mov");
  26.   eye[6] = new Movie(this, "eye6.mov");
  27.   eye[7] = new Movie(this, "eye7.mov");
  28.   eye[8] = new Movie(this, "eye8.mov");
  29.   eye[9] = new Movie(this, "eye9.mov");
  30.   eye[10] = new Movie(this, "eye10.mov");
  31.   eye[11] = new Movie(this, "eye11.mov");
  32.   eye[12] = new Movie(this, "eye12.mov");
  33.   eye[13] = new Movie(this, "eye13.mov");
  34.   eye[14] = new Movie(this, "eye14.mov");
  35. eye[15] = new Movie(this, "eye15.mov");
  36. eye[16] = new Movie(this, "eye16.mov");
  37. eye[17] = new Movie(this, "eye17.mov");
  38. eye[18] = new Movie(this, "eye18.mov");
  39. eye[19] = new Movie(this, "eye19.mov");
  40. eye[20] = new Movie(this, "eye20.mov");
  41. eye[21] = new Movie(this, "eye1.mov");
  42. eye[22] = new Movie(this, "eye2.mov");
  43. eye[23] = new Movie(this, "eye3.mov");
  44. eye[24] = new Movie(this, "eye4.mov");
  45. eye[25] = new Movie(this, "eye5.mov");
  46. eye[26] = new Movie(this, "eye6.mov");





  47.   for (int i=0; i<eye.length; i++) {
  48.     eye[i].loop();
  49.     // eye[i].stop();
  50.   }

  51.   for (int i=0; i<circles.length; i++) {
  52.     circles[i] = new Circle();
  53.     circles[i].setMovie(i % maxMovies);
  54.     println(i % maxMovies);
  55.   }
  56. }

  57. void draw() {

  58.   float soundLevel = in.mix.level(); //GET OUR AUDIO IN LEVEL
  59.   float eye0t = eye[0].time();
  60.   float eye1t = eye[1].time();
  61.   float eye2t = eye[2].time();
  62.   float eye3t = eye[3].time();
  63.   float eye4t = eye[4].time();
  64.   float eye5t = eye[5].time();
  65.   float eye6t = eye[6].time();
  66.   float eye7t = eye[7].time();
  67.   float eye8t = eye[8].time();
  68.   float eye9t = eye[9].time();
  69.   float eye10t = eye[10].time();
  70.   float eye11t = eye[11].time();
  71.   float eye12t = eye[12].time();
  72.   float eye13t = eye[13].time();
  73.   float eye14t = eye[14].time();
  74.    float eye15t = eye[15].time();
  75.   float eye16t = eye[16].time();
  76.   float eye17t = eye[17].time();
  77.   float eye18t = eye[18].time();
  78.   float eye19t = eye[19].time();
  79.   float eye20t = eye[20].time();
  80.   float eye21t = eye[21].time();
  81.   float eye22t = eye[22].time();
  82.   float eye23t = eye[23].time();
  83.   float eye24t = eye[9].time();
  84.   float eye25t = eye[10].time();
  85.   float eye26t = eye[11].time();


  86.   // Schritt 1
  87.   // hier Zeit float zum passenden Movie deklarieren Bsp. für Movie 3 
  88.   //  float eye3t = eye[3].time();
  89.   if ((soundLevel>0.08)&&(hak)) {
  90.     hak=false;

  91.     eye[0].jump(2);
  92.     eye[1].jump(2);
  93.     eye[2].jump(2);
  94.     eye[3].jump(2);
  95.     eye[4].jump(2);
  96.     eye[5].jump(2);
  97.     eye[6].jump(2);
  98.     eye[7].jump(2);
  99.  eye[8].jump(2);
  100.  eye[9].jump(2);
  101.  eye[10].jump(2);
  102.  eye[11].jump(2);
  103.  eye[12].jump(2);
  104.   eye[13].jump(2);
  105.  eye[14].jump(2);
  106.      eye[15].jump(2);
  107.     eye[16].jump(2);
  108.     eye[17].jump(2);
  109.     eye[18].jump(2);
  110.     eye[19].jump(2);
  111.     eye[20].jump(1);
  112.     eye[21].jump(2);
  113.     eye[22].jump(2);
  114.  eye[23].jump(2);
  115.  eye[24].jump(2);
  116.  eye[25].jump(2);
  117.  eye[26].jump(2);

  118.   }

  119.   if ((eye0t>63)) {
  120.    hak=true;
  121.   }
  122.   if ((eye0t>3)&&(hak)) {
  123.  eye[0].jump(0);
  124.   }
  125.   if ((eye1t>3.01)&&(hak)) {
  126.     eye[1].jump(0);
  127.   }
  128.   if ((eye2t>3.02)&&(hak)) {
  129.     eye[2].jump(0);
  130.   }
  131.   if ((eye3t>3.03)&&(hak)) {
  132.     eye[3].jump(0);
  133.   }
  134.         
  135.   if ((eye4t>3.04)&&(hak)) {
  136.     eye[4].jump(0);
  137.           }
  138.   if ((eye5t>3.05)&&(hak)) {
  139.     eye[5].jump(0);
  140.   }
  141.   if ((eye6t>3.06)&&(hak)) {
  142.     eye[6].jump(0);
  143.     }
  144.       if ((eye7t>3.07)&&(hak)) {
  145.     eye[7].jump(0);
  146.       }
  147.         if ((eye8t>3.08)&&(hak)) {
  148.  eye[8].jump(0);
  149.         }
  150.           if ((eye9t>3.09)&&(hak)) {
  151.  eye[9].jump(0);
  152.           }
  153.             if ((eye10t>3.10)&&(hak)) {
  154.  eye[10].jump(0);
  155.             }
  156.               if ((eye11t>3.11)&&(hak)) {
  157.  eye[11].jump(0);
  158.               }
  159.                 if ((eye12t>3.12)&&(hak)) {
  160.  eye[12].jump(0);
  161.                 }
  162.                   if ((eye13t>3.13)&&(hak)) {
  163.   eye[13].jump(0);
  164.                   }
  165.                     if ((eye14t>3.14)&&(hak)) {
  166.  eye[14].jump(0);
  167.                     }
  168.                       if ((eye15t>2.59)&&(hak)) {
  169.      eye[15].jump(0);
  170.                       }
  171.        if ((eye16t>2.58)&&(hak)) {
  172.     eye[16].jump(0);
  173.        }  
  174.        
  175.        if ((eye17t>2.57)&&(hak)) {
  176.     eye[17].jump(0);
  177.        }
  178.       if ((eye18t>2.56)&&(hak)) {
  179.     eye[18].jump(0);
  180.       }
  181.       if ((eye19t>2.55)&&(hak)) {
  182.     eye[19].jump(0);
  183.       }
  184.       if ((eye20t>2.54)&&(hak)) {
  185.     eye[20].jump(0);
  186.       }
  187.       if ((eye21t>2.53)&&(hak)) {
  188.     eye[21].jump(0);
  189.       }
  190.       if ((eye22t>2.52)&&(hak)) {
  191.     eye[22].jump(0);
  192.       }
  193.       
  194.       if ((eye23t>2.51)&&(hak)) {
  195.  eye[23].jump(0);
  196.       }
  197.       
  198.       if ((eye24t>2.50)&&(hak)) {
  199.  eye[24].jump(0);
  200.       }
  201.       
  202.       if ((eye25t>2.49)&&(hak)) {
  203.  eye[25].jump(0);
  204.       }
  205.       
  206.       if ((eye26t>2.48)&&(hak)) {
  207.  eye[26].jump(0);
  208.   }
  209.   

  210.   background(0);
  211.   for (int i=0; i<eye.length; i++) {
  212.     if (eye[i].available()) {
  213.       eye[i].read();
  214.       eye[i].mask(maskImage);
  215.     }
  216.   }




  217.   for (int i=0; i< circles.length; i++) {
  218.     circles[i].display();
  219.   }
  220. }

  221. void mousePressed() {
  222.   for (int i=0; i<circles.length; i++) {
  223.     if (circles[i].mouseOverCircle()) {
  224.       selectedCircle = i;
  225.       break;
  226.     }
  227.   }
  228. }

  229. void mouseDragged() {
  230.   if (selectedCircle>-1) {
  231.     circles[selectedCircle].move();
  232.   }
  233. }

  234. void mouseReleased() {
  235.   selectedCircle = -1;
  236. }
  237.   void keyPressed(){

  238.  switch (key) {
  239.     case 'a':
  240.     hak = true;
  241.       eye[0].jump(0);
  242.     eye[1].jump(0);
  243.     eye[2].jump(0);
  244.     eye[3].jump(0);
  245.     eye[4].jump(0);
  246.     eye[5].jump(0);
  247.     eye[6].jump(0);
  248.     eye[7].jump(0);
  249.  eye[8].jump(0);
  250.  eye[9].jump(0);
  251.  eye[10].jump(0);
  252.  eye[11].jump(0);
  253.  eye[12].jump(0);
  254.   eye[13].jump(0);
  255.  eye[14].jump(0);
  256.      eye[15].jump(0);
  257.     eye[16].jump(0);
  258.     eye[17].jump(0);
  259.     eye[18].jump(0);
  260.     eye[19].jump(0);
  261.     eye[20].jump(0);
  262.     eye[21].jump(0);
  263.     eye[22].jump(0);
  264.  eye[23].jump(0);
  265.  eye[24].jump(0);
  266.  eye[25].jump(0);
  267.  eye[26].jump(0);
  268.       // do something if the key pressed was 'r'
  269.      break;
  270.     case 'm':
  271.     hak = false;
  272.      eye[0].jump(2);
  273.     eye[1].jump(2);
  274.     eye[2].jump(2);
  275.     eye[3].jump(2);
  276.     eye[4].jump(2);
  277.     eye[5].jump(2);
  278.     eye[6].jump(2);
  279.     eye[7].jump(2);
  280.  eye[8].jump(2);
  281.  eye[9].jump(2);
  282.  eye[10].jump(2);
  283.  eye[11].jump(2);
  284.  eye[12].jump(2);
  285.   eye[13].jump(2);
  286.  eye[14].jump(2);
  287.      eye[15].jump(2);
  288.     eye[16].jump(2);
  289.     eye[17].jump(2);
  290.     eye[18].jump(2);
  291.     eye[19].jump(2);
  292.     eye[20].jump(1);
  293.     eye[21].jump(2);
  294.     eye[22].jump(2);
  295.  eye[23].jump(2);
  296.  eye[24].jump(2);
  297.  eye[25].jump(2);
  298.  eye[26].jump(2);
  299.    
  300.     default:  
  301.       break;
  302.   }
  303. }

  304. class Circle {
  305.   float r, xpos, ypos;
  306.   int selectedMovie;



  307.   Circle() {
  308.     xpos = random(width);
  309.     ypos = random(height);
  310.     r = 300;

  311.     setMovie(0);
  312.   }


  313.   void setMovie(int _id)
  314.   {
  315.     selectedMovie = _id;
  316.     if (selectedMovie>17){
  317.       r=150;
  318.     }
  319.     else {
  320.       r=180;
  321.     }
  322.   }

  323.   void display() {   

  324.     image(eye[selectedMovie], xpos, ypos, r, r);
  325.   }

  326.   boolean mouseOverCircle() {
  327.     return (dist(mouseX, mouseY, xpos, ypos)<40);
  328.   }

  329.   void move() {
  330.     xpos += (mouseX-pmouseX);
  331.     ypos += (mouseY-pmouseY);
  332.     if (xpos>width) { 
  333.       xpos = 0;
  334.     }
  335.     if (ypos>height) { 
  336.       ypos = 0;
  337.     }
  338.   }
  339. }



Viewing all articles
Browse latest Browse all 1768

Trending Articles