The BLOCKS SDK
The BitmapLEDProgram class

A LittleFoot example

The BitmapLEDProgram class is a simple example of a LittleFoot program.

roli_blocks_basics/visualisers/roli_BitmapLEDProgram.h

/*
==============================================================================
Copyright (c) 2020 - ROLI Ltd
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED “AS IS” AND ROLI LTD DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL ROLI LTD BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
==============================================================================
*/
namespace roli
{
{
void setLED (juce::uint32 x, juce::uint32 y, LEDColour);
private:
juce::String getLittleFootProgram() override;
};
} // namespace roli
Represents an individual BLOCKS device.
Definition: roli_Block.h:31
unsigned int uint32
Definition: roli_LittleFootRunner.h:48
Definition: roli_BlockConfigId.h:28
A simple Program to set the colours of individual LEDs.
Definition: roli_BitmapLEDProgram.h:31
A program that can be loaded onto a block.
Definition: roli_Block.h:242
A simple ARGB colour class for setting LEDs.
Definition: roli_LEDGrid.h:31

roli_blocks_basics/visualisers/roli_BitmapLEDProgram.cpp

/*
==============================================================================
Copyright (c) 2020 - ROLI Ltd
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED “AS IS” AND ROLI LTD DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL ROLI LTD BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
==============================================================================
*/
namespace roli
{
/*
The heap format for this program is just an array of 15x15 5:6:5 colours,
and the program just copies them onto the screen each frame.
*/
{
if (auto ledGrid = block.getLEDGrid())
{
auto w = (juce::uint32) ledGrid->getNumColumns();
auto h = (juce::uint32) ledGrid->getNumRows();
if (x < w && y < h)
{
auto bit = (x + y * w) * 16;
block.setDataBits (bit, 5, (juce::uint32) (colour.getRed() >> 3));
block.setDataBits (bit + 5, 6, (juce::uint32) (colour.getGreen() >> 2));
block.setDataBits (bit + 11, 5, (juce::uint32) (colour.getBlue() >> 3));
}
}
else
{
jassertfalse;
}
}
juce::String BitmapLEDProgram::getLittleFootProgram()
{
juce::String program (R"littlefoot(
#heapsize: 15 * 15 * 2
void repaint()
{
for (int y = 0; y < NUM_ROWS; ++y)
{
for (int x = 0; x < NUM_COLUMNS; ++x)
{
int bit = (x + y * NUM_COLUMNS) * 16;
fillPixel (makeARGB (255,
getHeapBits (bit, 5) << 3,
getHeapBits (bit + 5, 6) << 2,
getHeapBits (bit + 11, 5) << 3), x, y);
}
}
}
)littlefoot");
if (auto ledGrid = block.getLEDGrid())
return program.replace ("NUM_COLUMNS", juce::String (ledGrid->getNumColumns()))
.replace ("NUM_ROWS", juce::String (ledGrid->getNumRows()));
jassertfalse;
return {};
}
} // namespace roli
virtual void setDataBits(juce::uint32 startBit, juce::uint32 numBits, juce::uint32 value)=0
Sets multiple bits on the littlefoot heap.
virtual LEDGrid * getLEDGrid() const =0
If this block has a grid of LEDs, this will return an object to control it.
BitmapLEDProgram(Block &)
void setLED(juce::uint32 x, juce::uint32 y, LEDColour)
Set the colour of the LED at coordinates {x, y}.
Block & block
Definition: roli_Block.h:252
juce::uint8 getBlue() const noexcept
Definition: roli_LEDGrid.h:44
juce::uint8 getRed() const noexcept
Definition: roli_LEDGrid.h:42
juce::uint8 getGreen() const noexcept
Definition: roli_LEDGrid.h:43

The repaint() method of the LittleFoot program is called at approximately 25 Hz, and each time it simply inspects the heap (the shared area of memory used to communicate between your application code and your LittleFoot program) and sets the LEDs based on the heap's content. To update the heap, and hence the LEDs, your application code calls BitmapLEDProgram::setLED().

A more advanced example can be found in the source code of the DrumPadGridProgram class or in the BlocksSynth example.