Controlp5 MAtrix object. Storing a matrix pattern.

edited April 2014 in Library Questions

Hi all from London(UK). :) I am trying to work out a way of storing a matrix pattern as an array so it can be recalled later. I have tried using the getCells() function by sending the x/y values to a 2 dimensional array and it seems to do it but then when I change the matrix in any way the array values change in real time with me changing the matrix cells..? Has anyone had success with storing the cell positions in a matrix for recall later? say, on a key press?? Any help would be appreciated. Thanks. Steve.S.

Answers

  • Answer ✓

    As usual. Thanks for all the interest & help. I've managed to do it. SO I've put it here in case anyone ever has the same problem.

    this keypress stores the MAtrix values as a 2D array and converts the 2D array into a 1D array:

    if (key=='u')
    {
     for (currentrow=0;currentrow<rowsnumber;currentrow++){
        for (currentcolumn=0;currentcolumn<columnsnumber;currentcolumn++)
    gets[currentrow][currentcolumn]= cp5.get(Matrix.class, "myMatrix").get(currentrow,currentcolumn); 
    gets2=gets;
    
      for (int currentrow = 0; currentrow < rowsnumber; currentrow++)
     {
     for (int currentcolumn = 0; currentcolumn < columnsnumber; currentcolumn++)
     {
     bxval[currentrow * columnsnumber + currentcolumn] = gets[currentrow] [currentcolumn];
    
     value =bxval[currentrow * columnsnumber + currentcolumn];
      bval=value;
        println(value);  
     }
     }
    
     }
      }}
    

    This keypress recalls the values of the 1D array and plants them back into the matrix. The values of the atrix are stored in emory until the user presses the save key again (in this case the lettet 'u'):

     if (key=='j') {
    
    for (int currentrow = 0; currentrow < rowsnumber; currentrow++)
     {
     for (int currentcolumn = 0; currentcolumn < columnsnumber; currentcolumn++)
     {
     bxval[currentrow * columnsnumber + currentcolumn] = gets2[currentrow] [currentcolumn];
    
     value =bxval[currentrow * columnsnumber + currentcolumn];
      bval=value;
        println(value);
      cp5.get(Matrix.class, "myMatrix").set(currentrow,currentcolumn,value);  
     }
     }
    
       } 
    

    Thanks again everybody!! :D

Sign In or Register to comment.