Controlling control buttons

In addition to sending button pressed and button released events, ControlButton objects can allow your application code to change the colour of the LED behind the corresponding physical button on a BLOCKS device.

An array of pointers to the available ControlButton objects can be obtained from the Block::getButtons() method of a Block — see the Discovering BLOCKS section for details of how to obtain a Block object. Once you have a ControlButton, the functions involving the LED are ControlButton::hasLight() and ControlButton::setLightColour(), which are descriptively named. A code snippet showing how to turn all the available buttons of a Block red is shown below.

class BlockButtonExample
void setAllButtonsRed (Block& block)
for (auto button : block.getButtons())
if (button->hasLight())
button->setLightColour (LEDColour (0xffff0000));

Example usage

To add this functionality to the BlockFinder example project, add the above function to the BlockFinder class implementation. Then in the topologyChanged() callback, check if the connected Block is a Control Block and call the above function as shown below:

void topologyChanged() override
for (auto& block : currentTopology.blocks)
if (block->getType() == Block::liveBlock || block->getType() == Block::loopBlock
setAllButtonsRed (*block);

If you run the application now and connect a Control Block, you should see the control buttons turn red.

The control buttons on a Control Block

Learn more about other Block methods from the following pages:

Getting touch events

Getting control button events

Controlling LED grids

Controlling LED strips

@ developerControlBlock
Developer control block type.
Definition: juce_Block.h:48
@ liveBlock
Live control block type.
Definition: juce_Block.h:46
virtual Type getType() const =0
Returns the type of this device.
@ loopBlock
Loop control block type.
Definition: juce_Block.h:47
Represents an individual BLOCKS device.
Definition: juce_Block.h:32
A simple ARGB colour class for setting LEDs.
Definition: juce_LEDGrid.h:32
@ touchBlock
Touch control block type.
Definition: juce_Block.h:49
virtual juce::Array< ControlButton * > getButtons() const =0
If this block has any control buttons, this will return an array of objects to control them.