Creation of Presets/Cues

edited July 2014 in How To...

Hi all,

Thanks for this forum, it is making my life sooo much easier!

I am writing a program that will show several text files into 3 LED screens for a show. I have created 4 modes to show the text in the screens (like scrolling, popping up, zigzag and so on). I will have to use like 50 different text files, which will be shown in different parts of the show with different colors, and modes.

The program seems to be working fine, i am controlling it with the letters of my keypad. But I need to create some kind of Presets/Cues for the life performance - say TextFile20 - Screen 2- Font Color x - Background Color X - Mode - Other parameters needed.

In order to play life in the performance (and because I am running out of keys in my keypad!), I though I would better do some kind of GUI and I am using ControlP5, so that I could tigger my presets/cues in the different parts of the show.

However I am having lot of problems to save and load these presets with the values. I am a bit lost with the whole ControlP5. So far I just managed to add the ColorPicker but I cannot save the values I like, nor load values stored...

Any ideas??

Many thanks!!

Answers

  • How about a Preset class & making controllers using the names/indices of the Presets?

    Pseudocode:

    Preset {
      int indexInList;
      String name;
      String textFileName;
      int screenMode;
      color fontColor;
      color backGroundColor;
      etc.
    
      Preset(int indexInList, name, textFileName, etc.) {
        this.indexInList = indexInList
        this.name = name;
        etc.
      }
    }
    
    ArrayList <Preset> presets = new ArrayList <Preset> ();
    
    presets.add(new Preset(presets.size(), "AwesomeGreen", "TextFile20.txt", etc.));
    
    for (Preset p : presets) {
      p5.addSomeControllerListItem(p.name, p.indexInList); // name or index to find it later
    }
    
    void controlEvent() {
      // get name or value of controlEvent
      // get Preset out of the list based on name or value/index
      // use Preset to change settings in your program
    }
    
  • edited July 2014

    Hi,

    Many thanks for your response! I kind of solved the problem using arrays and toggles too. Here is the code. I have been thinking very much to shorten the "if"statements in the DRAW part, but it doesnt seem to work. I have like 60 buttons in my GUI at the moment among colors, texts and so on... so my code has too much lines. Any idea? Here is the code.

    Many thanks once again :)

    // Color presets toggle led 1 boolean l1c1 = false; boolean l1c2 = false; boolean l1c3 = false; boolean l1c4 = false; boolean l1c5 = false; boolean l1c6 = false; boolean l1c7 = false; boolean l1c8 = false; boolean l1c9 = false; boolean l1c10 = false; boolean l1c11 = false; boolean l1c12 = false; boolean l1c13 = false; boolean l1c14 = false; boolean l1c15 = false; boolean l1c16 = false; boolean [] l1ctogglebool = {l1c1, l1c2, l1c3, l1c4, l1c4, l1c5, l1c6, l1c7, l1c8, l1c9,l1c10, l1c11,l1c12, l1c13, l1c14, l1c15, l1c15, l1c16}; String [] l1ctogglenames= {"l1c1","l1c2","l1c3","l1c4","l1c5","l1c6","l1c7","l1c8","l1c9","l1c10", "l1c11","l1c12", "l1c13", "l1c14", "l1c15", "l1c16"};

    [...]

    void setup() { // create a toggle buttons for Color presets of LED 1 textSize(12); fill(220); xtoggle = 570; ytoggle = 150; text("Color Presets LED 1", xtoggle, ytoggle-5);
    for (int i=0; i < l1ctogglenames.length; i++){ cp5.addToggle(l1ctogglenames[i]) .setPosition(xtoggle,ytoggle) .setSize(25,20) ; xtoggle = xtoggle + 30; if (i == 7) { xtoggle = 570; ytoggle = 190;
    }
    }

    [...] }

    void draw() {

     pushMatrix();
      if(l1c1==true) {
        fontcolor = fontcolor11;
        backcolor = backcolor11;
      }       
      if(l1c2==true) {
        fontcolor = fontcolor12;
        backcolor = backcolor12;
      }       
      if(l1c3==true) {
        fontcolor = fontcolor13;
        backcolor = backcolor13;
      }        
      if(l1c4==true) {
        fontcolor = fontcolor14;
        backcolor = backcolor14;
      } 
    
      if(l1c5==true) {
        fontcolor = fontcolor15;
        backcolor = backcolor15;
      } 
      if(l1c6==true) {
        fontcolor = fontcolor16;
        backcolor = backcolor16;
      }
    
      if(l1c7==true) {
        fontcolor = fontcolor17;
        backcolor = backcolor17;
      }
    
      if(l1c8==true) {
        fontcolor = fontcolor18;
        backcolor = backcolor18;
      } 
    
     if(l1c9==true) {
        fontcolor = fontcolor19;
        backcolor = backcolor19;
      }       
      if(l1c10==true) {
        fontcolor = fontcolor20;
        backcolor = backcolor20;
      }       
      if(l1c11==true) {
        fontcolor = fontcolor21;
        backcolor = backcolor21;
      }        
      if(l1c12==true) {
        fontcolor = fontcolor22;
        backcolor = backcolor22;
      } 
    
      if(l1c13==true) {
        fontcolor = fontcolor23;
        backcolor = backcolor23;
      } 
      if(l1c14==true) {
        fontcolor = fontcolor24;
        backcolor = backcolor24;
      }
    
      if(l1c15==true) {
        fontcolor = fontcolor25;
        backcolor = backcolor25;
      }
    
      if(l1c16 ==true) {
        fontcolor = fontcolor26;
        backcolor = backcolor26;
      } 
      popMatrix();
    

    [...]

    }

  • Answer ✓

    Yeah, that is unpractical and unneeded.

    First step: wiki.processing.org/w/From_several_variables_to_arrays

    => Arrays of booleans, fontColors, backColors, etc.

    Second step: wiki.processing.org/w/From_several_arrays_to_classes

    => Objects composed of multiple settings (see previous answer on Preset class)

  • Hi,

    Thanks for the links! Definitively very interesting, although it looks very scary for a newie like me. I did not quite even know about classes!! Reading this I should have really created more than one class in my code...

    I am seeing if I have the time to re-write my whole code into a smarter approach! Cus it seems it will take me ages (I am a total newie). I really appreciate your proposition!!

    However, before knowing about classes, I tried

      boolean [] l1ctogglebool = {l1c1, l1c2, l1c3, l1c4, l1c4, l1c5, l1c6, l1c7, l1c8, l1c9,l1c10, l1c11,l1c12, l1c13, l1c14, l1c15, l1c15, l1c16};
      pushMatrix();      
      for ( int i= 0; i<l1ctogglebool.length; i++){
        if(l1ctogglebool[i]==true) {
          fontcolor = fontcolors[i];
          backcolor = backcolors[i];
        } 
    
      }
      popMatrix();  
    

    to make all the if stataments in just one for loop. But it didnt work...

    Thank you very much!

  • Answer ✓

    What didn't work?

  • I wanted to make my code shorter and replace all the if statements of my second post (that effectively load a color into the variable depending on which button you press) by the for loop above. And it does not work in the sense, it would not pick the color.

  • edited July 2014 Answer ✓

    In my opinion, these problems are all caused by your code structure. As said before it is unpractical and unneeded to have 20 booleans, when you are just setting one color. Also, it doesn't work, because what if 10 of them are true, then the last will be selected. Instead use the GUI to set the SELECTED preset (color, etc), then read the selected option from an array or object. Then you don't need ANY boolean at all, your code will be much shorter, the solution is flexible for an unlimited numbers of presets without code changes, etc. So just replace all those booleans by a single int selectedColor (ranging from 0 to colorArray.length-1) and to be set via the GUI. Your current solution is much more code, much more prone to errors, inflexible and overcomplicated. By going for the 'basic option' you are only making it harder for yourself.

  • Yes, you are totally right indeed! It was just the only approach I could think of with what I knew. I will try to redo the whole code in a better way... Thanks a lot :)

  • edited August 2014

    Hello, I am still struggling with the ColorPresets and the objects in general u_u I could not make it work other way. It is so impractical! It is driving me nuts, I just managed to create a few functions that shorten my code, but when it comes to pick the value from the Gui and asign it to the variable, I cannot make it work in a shorter way. I ve read the links you posted over and over (thanks for that really, very useful), but still I am missing something!

    Should I use other sort of Controller that is not a Toggle? However, I think it is more due to my lack on Processing knowledge in objects and classes rather than the sort of buttom I use...

  • edited August 2014 Answer ✓

    It'd help immensely if you had re-posted your current efforts! ;;)

  • edited August 2014

    Hi, well it is effectivibly the same problem as in my first post. I have an if loop for each toggle I have (more than 80 at the moment). So I have to define loads of booleans and so it is super impractical, just cus I dont know how to solve this if statements!! I know this is not the way of doing it!! I have been reading and trying, but no success so far.

    For instance:

    boolean l1c1 = false;
    boolean l1c2 = false;
    boolean l1c3 = false;
    boolean l1c4 = false;
    boolean l1c5 = false;
    boolean l1c6 = false;
    boolean l1c7 = false;
    boolean l1c8 = false;
    boolean l1c9 = false;
    boolean l1c10 = false;
    boolean l1c11 = false;
    boolean l1c12 = false;
    boolean l1c13 = false;
    boolean l1c14 = false;
    boolean l1c15 = false;
    boolean l1c16 = false;
    boolean [] l1ctogglebool = {l1c1, l1c2, l1c3, l1c4, l1c4, l1c5, l1c6, l1c7, l1c8, l1c9,l1c10, l1c11,l1c12, l1c13, l1c14, l1c15, l1c15, l1c16};
    String [] l1ctogglenames= {"l1c1","l1c2","l1c3","l1c4","l1c5","l1c6","l1c7","l1c8","l1c9","l1c10", "l1c11","l1c12", "l1c13", "l1c14", "l1c15", "l1c16"};
    
    
    // In the setup I add the toggle buttoms, for what I have created a function
    
    addNewGridToggles (xtoggle, ytoggle, l1ctogglenames, 25, 20, "Color Presets LED 1", true);
    
    // in the draw part I have to have all these very annozing if loops, so that I can assign the value from the toggle to the text :(
    
          // SCREEN 1
          pushMatrix();
          if(l1c1==true) {
            fontcolor = fontcolor11;
            backcolor = backcolor11;
    //        cpback1.setColorValue(backcolor11);
          }       
          if(l1c2==true) {
            fontcolor = fontcolor12;
            backcolor = backcolor12;
    //        cpback1.setColorValue(backcolor12);
          }       
          if(l1c3==true) {
            fontcolor = fontcolor13;
            backcolor = backcolor13;
    //        cpback1.setColorValue(backcolor13);
          }        
          if(l1c4==true) {
            fontcolor = fontcolor14;
            backcolor = backcolor14;
    //        cpback1.setColorValue(backcolor14);
          } 
    
          if(l1c5==true) {
            fontcolor = fontcolor15;
            backcolor = backcolor15;
    //        cpback1.setColorValue(backcolor15);
          } 
          if(l1c6==true) {
            fontcolor = fontcolor16;
            backcolor = backcolor16;
    //        cpback1.setColorValue(backcolor16);
          }
    
          if(l1c7==true) {
            fontcolor = fontcolor17;
            backcolor = backcolor17;
    //        cpback1.setColorValue(backcolor17);
          }
    
          if(l1c8==true) {
            fontcolor = fontcolor18;
            backcolor = backcolor18;
    //        cpback1.setColorValue(backcolor18);
          } 
    
         if(l1c9==true) {
            fontcolor = fontcolor19;
            backcolor = backcolor19;
    //        cpback1.setColorValue(backcolor19);
          }       
          if(l1c10==true) {
            fontcolor = fontcolor20;
            backcolor = backcolor20;
    //        cpback1.setColorValue(backcolor20);
          }       
          if(l1c11==true) {
            fontcolor = fontcolor21;
            backcolor = backcolor21;
    //        cpback1.setColorValue(backcolor21);
          }        
          if(l1c12==true) {
            fontcolor = fontcolor22;
            backcolor = backcolor22;
    //        cpback1.setColorValue(backcolor22);
          } 
    
          if(l1c13==true) {
            fontcolor = fontcolor23;
            backcolor = backcolor23;
    //        cpback1.setColorValue(backcolor23);
          } 
          if(l1c14==true) {
            fontcolor = fontcolor24;
            backcolor = backcolor24;
    //        cpback1.setColorValue(backcolor24);
          }
    
          if(l1c15==true) {
            fontcolor = fontcolor25;
            backcolor = backcolor25;
    //        cpback1.setColorValue(backcolor25);
          }
    
          if(l1c16 ==true) {
            fontcolor = fontcolor26;
            backcolor = backcolor26;
    //        cpback1.setColorValue(backcolor26);
          }
    
  • Thank you very much :) I am trying to explain myself as good as I can...

  • Answer ✓

    When posting code, highlight it and hit CTRL+K in order to properly format it! L-)

  • Answer ✓

    When I see code like that, I feel the urge to post the link to the From several variables to arrays article... :-)

  • Thanks for the CTROL+K hint!

    PhiLho, I know Amnon did already, and I have used it a lot in other parts of my code. However, I could not apply it to this specific case I copied...

Sign In or Register to comment.