Several PGraphics conditioned by a "switch / case" command in a same sketch & triggered by MidiBus

edited January 2015 in Library Questions

Hello there, I'm front of a problem that i can't resolve for the moment by myself. I've made a patch who include different forms generated in real time with PGraphics. That's ok, the patch work. PGraphics is used with Minim and Syphon.

I would like to use TheMidi Bus to change the conditional display of these different forms (say for example : when i play a C3 note, i would like to hide the Generated Form 01 and reveal the Generated Form 02, or when i play C4, i would like to play both of them, or when i play A2 i would like to hide Generated Form 01 and 02 and reveal the simple animated Form 03).

Is it possible ? And how can i achieve that with a new element : TheMidiBus library for example.

Here's the code (section draw) :

    void draw()
    {
      pg.beginDraw();
      pg.strokeWeight(1);
      pg.stroke(255);
      pg.background(0);

      for(int i = 0; i < in.bufferSize() - 1; i++)
      {    
        // Generated Form 01
        pg.line(i, 100, i, 100 + in.left.get(1)*300);

        // Generated Form 02
        pg.point(i, 400  + in.left.get(i)*400);
      }


      // A third and simple animated form 03 without PGraphics
      pg.rect(x+in.left.get(1) , 200 , in.left.get(1) , 100);

       // A fourth and simple animated form 04  without PGraphics
      pg.rect(x, 594 , 100 , 6);

      // Call of the move function to animated these simple form 03 and  04 
      move();


      pg.endDraw();
      image(pg, 0, 0);
      server.sendImage(pg); 
    }

    void move() {
      x = x + speed;
      if (x > width) {
        x = 0;
      }
    }


    void stop()
    {
      in.close();
      minim.stop();
      super.stop();
    }

I know that i must declare the Midibus library, but i wonder how can i make the conditions work between all of these forms, PGraphics, Minim and Midibus.

Best Crem'

Answers

  • edited January 2015

    You could have a PGraphics array with all your forms. Inside the draw loop you decide which ones to draw and which ones not. You could have an ArrayList for visibility. You add numbers to the ArrayList to make PGraphics visible, and you remove numbers to hide forms. The draw loop iterates through the ArrayList drawing the shapes it includes. Finally you need another data structure to map a midi value to a set of reactions. It could be a 2D array.

    reaction[60] = { 4, 7, -2 };
    reaction[61] = {-4, 8 };
    

    This could mean that when midi note 60 arrives, show PGraphics 4 and 7, hide 2. When 61 arrives, hide 4, show 8.

    When the midi note 60 arrives, you should go through the elements 4, 7 and -2, and do modifications to the visibility array list, by adding items 4 and 7, and removing item 2.

    Something like that? :)

  • Hi Hamoid ! Thanks for your message. Yes, it makes sense but do you have a concrete example (declaration of the variable in the setup() and draw() functions for example ? Best E'

  • unfortunately no, sorry

Sign In or Register to comment.