if some one could set me straight on how to turn this into an array id much appreciate it trying hard to change over from xojo to juice + C++
// So i want to have 10 buttons and send them to my function setMchan() when clicked
i tried to make a for loop and just ended up with errors on each attempt i could not work out how to clear them
// my plugineditor.h under private:
TextButton chanButton01{“Ch01”};
Lastly, you need to be careful about what code you put in your setMchan() function… Audio code and GUI code are run on different threads so trying to change something that’s used on the audio thread from the GUI thread can cause issues. There are tricks you can use to avoid any issues such as using atomics or locks, but thinking carefully about your plug-ins logic and workflow is very important.
Hope that helps!
This would be differant right ?
chanButton01.onClick = this {
processor.setMchan();
};
It won’t be chanButton01 any more but what will it be sorry for the noob questions
Your syntax for lambdas is still wrong. This is the best article I found about them when I was learning. You should get familiar with them because they’re a great feature in C++.
To access the object stored in an Array, you’ll have to using the [] operator, like this:
OwnedArray<TextButton> myWidgets;
for (int i = 0; i < 10; i++)
myWidgets.add(new TextButton("Button " + String(i + 1)));
myWidgets[0]->onClick = [this]() // <<<<
{ processor.setMchan(); };
Notice that [] gives you a pointer, so you have to use -> to access the member instead of the dot(.)
You can also iterate through the array to access all of the buttons at once:
Chances are, the OP used the [ and ], but since he doesn’t use the suggested ``` around his/her code, it got interpreted as markup and doesn’t show.
Until the markup is fixed, there is no point in commenting his/her code…
when I copy paste the code I just get errors …I understand what your doing but there’s something up with the naming of the buttons preventing me from trying it also is the code supposed to be sitting in the header or the cpp my code was originaly in both