Blocks touch data

Hi. I’d like help reading touch data from the Lightpad Block. Roli referred me here. I’d like to use the SDK, and minimal complete software to read this information. I don’t need access to connecting multiple blocks, or audio software at the moment, but the LED’s would be nice.

I’ve compiled the Xcode project into the static library and, I think, linked fine. But BlocksHeader.h sets off a bunch of errors. In the documentation here: http://developer.roli.com/documentation/the_standalone_blocks_sdk.html
JuceHeader.h is mentioned. Is this meant to be BlocksHeader.h? Because I don’t see the former in the SDK directory. Do I need everything in juce audio_ basics/_audio_devices/_blocks_basics/_core/_events?
Thanks!

yes, you need the whole juce SDK. use the ProJucer to set up your projects for BLOCKS/Plugins/Audio Apps…

Hi @jasim,

You’re correct - JuceHeader.h should be BlocksHeader.h in the documentation. I’ll fix that typo now.

You do not need the whole of JUCE to create BLOCKS apps (though it would certainly make things much easier!), the contents of the standalone SDK repository are sufficient. You’ll need everything in audio_basics, audio_devices, blocks_basics, core and events.

What errors are you seeing? Can you build the BlockFinder example application?

My program is successfully recognizing the connected block (block finder is printing out its info), but when I touch the LightPad Block (and touchChanged is called), I get a bad access code on the last line of:

/** Calls a member function on each listener in the list, with 2 parameters. */
template <LL_TEMPLATE(1), LL_TEMPLATE(2)>
void call (void (ListenerClass::*callbackFunction) (P1, P2),
LL_PARAM(1), LL_PARAM(2)) {
for (Iterator<DummyBailOutChecker, ThisType> iter (*this); iter.next():wink:
(iter.getListener()->*callbackFunction) (param1, param2); } // ERROR ON THIS LINE

The related code in my program is a new class, roliBlockHelper, (which is just a copy of what’s given here: http://developer.roli.com/documentation/getting_touch_events.html), BlockFinder.h and BlockFinder.cpp, and a couple lines in main. Here’s roliBlockHelper:

class roliBlockHelper : public TouchSurface::Listener {
public:
roliBlockHelper (Block* block){
if (auto touchSurface = block->getTouchSurface())
touchSurface->addListener (this); }

virtual void touchChanged (TouchSurface& sourceTouchSurface, const TouchSurface::Touch& touchEvent) override {
 } };

I’ve also added a line to the last for loop in BlockFinder.cpp:

for (auto& block : currentTopology.blocks) {

    roliBlockHelper rbh(block);  // LINE I ADDED
    
    Logger::writeToLog ("");
    Logger::writeToLog (String("    Description:   ") + block->getDeviceDescription());
    Logger::writeToLog (String("    Battery level: ") + String (block->getBatteryLevel()));
    Logger::writeToLog (String("    UID:           ") + String (block->uid));
    Logger::writeToLog (String("    Serial number: ") + block->serialNumber);      }

And in main, before my main loop, I just have:

ScopedJuceInitialiser_GUI platform;

BlockFinder bf;

By the way, BlockFinder is printing out the following info about my block:

New BLOCKS topology.
Detected 1 blocks:

Description:   Pad BLOCK (2x2)
Battery level: 0.548387
UID:           ..
Serial number: ..

This is an object lifetime issue.

When you are looping over each Block in the currentTopology.blocks array, any objects created within the bounds of the loop will only exist whilst you’re between the opening “{” and closing “}”. For example, if you try to access your rbh variable outside of the loop then you’ll get a compiler error and you won’t be able to build your project.

So the problem is that you are registering an object as a listener to the Touchsurface, then that object is being destroyed. The TouchSurface has no way of knowing this and attempts to call a function on an object that no longer exists, which causes your program to crash due to a “bad access”.

The solution is to ensure that your listeners have a lifetime that lasts at least as long as the TouchSurface you’re interested in.

I would suggest looking at the examples in the JUCE repo, under examples/BLOCKS/. They all handle touch events.

Got it working - mostly by using the Blocks Synth example. Thanks so much for your help, t0m!

1 Like