We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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:
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() {
[...]
}
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
to make all the if stataments in just one for loop. But it didnt work...
Thank you very much!
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.
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 :)
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...
It'd help immensely if you had re-posted your current efforts! ;;)
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:
Thank you very much :) I am trying to explain myself as good as I can...
When posting code, highlight it and hit CTRL+K in order to properly format it! L-)
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...