ControlP5 Matrix question...

edited February 2014 in Library Questions

Hi all & Happy new year of the Hoss. I am hpoing one of the many, many excellent programmers out there might be able to help me. As part of my Android controlled arduino synth I am using the Controlp5 Matrix object as a sequencer. I have a function that sends MIDI note on messages and note pitches and velocities with every step change. A case statement is scanning the Y-axis of the matrix for the pitches. the code looks ike this:

//The <atrix function to update the ntoes played along the x axis. The y axis determines the note values
public int Sequencer(int theX, int theY) {
 println(theX);
  d[theX][theY].update();


int oct=1;
byte [] ident;
byte [] noteP;
byte [] noteV;
byte []  ident2;
 byte []  noteP2;
 byte []  noteV2;
  int note=theY;

  int next=theX;
  switch(note)
  {



    case 0:

     ident=intToByteArray(0x90);
    bt.broadcast(ident);
  noteP=intToByteArray(54);
   noteV=intToByteArray(0x7a);
  bt.broadcast(noteP);
  bt.broadcast(noteV); 

    break;
    case 1:
     ident=intToByteArray(0x90);
    bt.broadcast(ident);
  noteP=intToByteArray(56);
   noteV=intToByteArray(0x7a);
  bt.broadcast(noteP);
  bt.broadcast(noteV);

    break;
    case 2:
     ident=intToByteArray(0x90);
    bt.broadcast(ident);
  noteP=intToByteArray(57);
   noteV=intToByteArray(0x7a);
  bt.broadcast(noteP);
  bt.broadcast(noteV);
   ident=intToByteArray(0x80);
    bt.broadcast(ident);
    break;
    case 3:
     ident=intToByteArray(0x90);
    bt.broadcast(ident);
  noteP=intToByteArray(59);
   noteV=intToByteArray(0x7a);
  bt.broadcast(noteP);
  bt.broadcast(noteV); 
   ident=intToByteArray(0x80);
    bt.broadcast(ident);

    break;
    case 4:
        ident=intToByteArray(0x90);
    bt.broadcast(ident);
  noteP=intToByteArray(62);
   noteV=intToByteArray(0x7a);
  bt.broadcast(noteP);
  bt.broadcast(noteV);

    break;
    case 5:
     ident=intToByteArray(0x90);
    bt.broadcast(ident);
  noteP=intToByteArray(65);
   noteV=intToByteArray(0x7a);
  bt.broadcast(noteP);
  bt.broadcast(noteV);

    break;
    case 6:
     ident=intToByteArray(0x90);
    bt.broadcast(ident);
  noteP=intToByteArray(67);
   noteV=intToByteArray(0x7a);
  bt.broadcast(noteP);
  bt.broadcast(noteV);

    break;
    case 7:
     ident=intToByteArray(0x90);
    bt.broadcast(ident);
  noteP=intToByteArray(69);
   noteV=intToByteArray(0x7a);
  bt.broadcast(noteP);
  bt.broadcast(noteV);

    break;
    case 8:
      ident=intToByteArray(0x90);
    bt.broadcast(ident);
  noteP=intToByteArray(70);
   noteV=intToByteArray(0x7a);
  bt.broadcast(noteP);
  bt.broadcast(noteV);


    break;
    case 9:
      ident=intToByteArray(0x90);
    bt.broadcast(ident);
  noteP=intToByteArray(72);
   noteV=intToByteArray(0x7a);
  bt.broadcast(noteP);
  bt.broadcast(noteV);

    break;
    case 10:
      ident=intToByteArray(0x90);
    bt.broadcast(ident);
  noteP=intToByteArray(74);
   noteV=intToByteArray(0x7a);
  bt.broadcast(noteP);
  bt.broadcast(noteV);

    break;
    case 11:   ident=intToByteArray(0x90);
    bt.broadcast(ident);
  noteP=intToByteArray(75);
   noteV=intToByteArray(0x7a);
  bt.broadcast(noteP);
  bt.broadcast(noteV); 

    break;
    case 12:
      ident=intToByteArray(0x90);
    bt.broadcast(ident);
  noteP=intToByteArray(77);
   noteV=intToByteArray(0x7a);
  bt.broadcast(noteP);
  bt.broadcast(noteV);

    break;
    case 13:
      ident=intToByteArray(0x90);
    bt.broadcast(ident);
  noteP=intToByteArray(79);
   noteV=intToByteArray(0x7a);
  bt.broadcast(noteP);
  bt.broadcast(noteV);

    break;
    case 14:
      ident=intToByteArray(0x90);
    bt.broadcast(ident);
  noteP=intToByteArray(81);
   noteV=intToByteArray(0x7a);
  bt.broadcast(noteP);
  bt.broadcast(noteV);

    break;
    case 15:
      ident=intToByteArray(0x90);
    bt.broadcast(ident);
  noteP=intToByteArray(82);
   noteV=intToByteArray(0x7a);
  bt.broadcast(noteP);
  bt.broadcast(noteV);

    break;
    case 16:
      ident=intToByteArray(0x90);
    bt.broadcast(ident);
  noteP=intToByteArray(83);
   noteV=intToByteArray(0x7a);
  bt.broadcast(noteP);
  bt.broadcast(noteV);

    break;


  }

/* if (gui2.getController("Matrix").isUpdate())
 {
    ident=intToByteArray(0x90);
    bt.broadcast(ident);
  noteP=intToByteArray(00);
   noteV=intToByteArray(0x00);
  bt.broadcast(noteP);
  bt.broadcast(noteV);
 } */

/*switch(next)
{

  case 1:
  ident2=intToByteArray(0x90);
    bt.broadcast(ident2);
  noteP2=intToByteArray(0);
  noteV2=intToByteArray(0);
  bt.broadcast(noteP2);
  bt.broadcast(noteV2);
 break; 
  case 2:
  ident2=intToByteArray(0x90);
    bt.broadcast(ident2);
  noteP2=intToByteArray(0);
   noteV2=intToByteArray(0);
  bt.broadcast(noteP2);
  bt.broadcast(noteV2);
 break; 
  case 3:
  ident2=intToByteArray(0x90);
    bt.broadcast(ident2);
  noteP2=intToByteArray(0);
   noteV2=intToByteArray(0);
  bt.broadcast(noteP2);
  bt.broadcast(noteV2);
 break; 
  case 4:
  ident2=intToByteArray(0x90);
    bt.broadcast(ident2);
  noteP2=intToByteArray(0);
   noteV2=intToByteArray(0);
  bt.broadcast(noteP2);
  bt.broadcast(noteV2);
 break; 
  case 5:
  ident2=intToByteArray(0x90);
    bt.broadcast(ident2);
  noteP2=intToByteArray(0);
   noteV2=intToByteArray(0);
  bt.broadcast(noteP2);
  bt.broadcast(noteV2);
 break; 
  case 6:
  ident2=intToByteArray(0x90);
    bt.broadcast(ident2);
  noteP2=intToByteArray(0);
   noteV2=intToByteArray(0);
  bt.broadcast(noteP2);
  bt.broadcast(noteV2);
 break; 
  case 7:
  ident2=intToByteArray(0x90);
    bt.broadcast(ident2);
  noteP2=intToByteArray(0);
   noteV2=intToByteArray(0);
  bt.broadcast(noteP2);
  bt.broadcast(noteV2);
 break; 
  case 8:
  ident2=intToByteArray(0x90);
    bt.broadcast(ident2);
  noteP2=intToByteArray(0);
   noteV2=intToByteArray(0);
  bt.broadcast(noteP2);
  bt.broadcast(noteV2);
 break; 
  case 9:
  ident2=intToByteArray(0x90);
    bt.broadcast(ident2);
  noteP2=intToByteArray(0);
   noteV2=intToByteArray(0);
  bt.broadcast(noteP2);
  bt.broadcast(noteV2);
 break; 
  case 10:
  ident2=intToByteArray(0x90);
    bt.broadcast(ident2);
  noteP2=intToByteArray(0);
   noteV2=intToByteArray(0);
  bt.broadcast(noteP2);
  bt.broadcast(noteV2);
 break; 
  case 11:
  ident2=intToByteArray(0x90);
    bt.broadcast(ident2);
  noteP2=intToByteArray(0);
   noteV2=intToByteArray(0);
  bt.broadcast(noteP2);
  bt.broadcast(noteV2);
 break; 
  case 12:
  ident2=intToByteArray(0x90);
    bt.broadcast(ident2);
  noteP2=intToByteArray(0);
   noteV2=intToByteArray(0);
  bt.broadcast(noteP2);
  bt.broadcast(noteV2);
 break; 
  case 13:
  ident2=intToByteArray(0x90);
    bt.broadcast(ident2);
  noteP2=intToByteArray(0);
   noteV2=intToByteArray(0);
  bt.broadcast(noteP2);
  bt.broadcast(noteV2);
 break; 
  case 14:
  ident2=intToByteArray(0x90);
    bt.broadcast(ident2);
  noteP2=intToByteArray(0);
   noteV2=intToByteArray(0);
  bt.broadcast(noteP2);
  bt.broadcast(noteV2);
 break; 
  case 15:
  ident2=intToByteArray(0x90);
    bt.broadcast(ident2);
  noteP2=intToByteArray(0);
   noteV2=intToByteArray(0);
  bt.broadcast(noteP2);
  bt.broadcast(noteV2);
 break; 
  case 16:
  ident2=intToByteArray(0x90);
    bt.broadcast(ident2);
  noteP2=intToByteArray(0);
   noteV2=intToByteArray(0);
  bt.broadcast(noteP2);
  bt.broadcast(noteV2);
 break; 
}*/
 return theX+theY;
}

It works fine except I need to be able to send note off messages every time the matrix increments a step. The reason being that the second half of my synthesizer envelope is triggered with a note off message (0x80.) So I tried setting up a case statement to scan the X axis and trigger a note off with every step but it soesn't work. The Arduino synth either plays the sequence as one enveope cycle and fades out or crashes.. :( Would anyone know of a way in which I could send note off messages when the Matrix is stepping from one step to the next??

any help at all serious;y appreciated.,

Steve.

Answers

  • Your fourth message to this forum, the second one about CP5 I have to move, and I still have to format your code, it is time to read the sticky post:

    To newcomers in this forum: read attentively these instructions

    :)

  • Sorry I put it in the wrong place. I do normally format my code but for some reasonj, the C button doesn't work on my computer.. I was a bit torn on where to put it and i know i should have put it in contributed libraries folder. i'll REM next time. Cheers, Steve.

  • edited April 20

    The answer is in the custome matrix exemple where you can fint the cnt.

            `// extend the Matrix class since we need to override the Matrix's sequencer
            class CustomMatrix extends Matrix {
    
              Thread update;
    
              CustomMatrix(ControlP5 cp5, String theName) {
                super(cp5, theName);
                stop(); // stop the default sequencer and
                // create our custom sequencer thread. Here we 
                // check if the sequencer has reached the end and if so
                // we updated to the next preset.
                update = new Thread(theName) {
                  public void run( ) {
                    while ( true ) {
                      cnt++;  println(cnt);bpm();
                      cnt %= _myCellX;
                      if (cnt==0) {
                        // we reached the end and go back to start and 
                        // update the preset 
                       // println("rr");
                      }
                      trigger(cnt);
                      try {
                        sleep( _myInterval );
                      } 
                      catch ( InterruptedException e ) {
                      }
                    }
                  }
                };
                update.start();
              }
    
    
    
            }
    
    
    
    
            }
    
    
             ` hope it ll help someone 
    
Sign In or Register to comment.