That won’t work because you are passing “this” into the lambda, but the method lambdaDemo is not a method of any object, it’s just a standalone funciton so “this” does not exist
That said, in this particular case, you don’t need “this” to be passed in to that lambda. So just remove this from the square brackets and it should now compile.
Ok, so with that I made a small amount of progress. If I simply want to call a GP function after a delay (scriptLog() in this example) I can use this inside my LibMain of the extension:
void LibMain::lambdaDemo(std::string text)
{
std::string device;
gigperformer::sdk::GPMidiMessage midimessage; // I'd use this if I were really writing sysex instead of just testing using scriptLog();
juce::Timer::callAfterDelay(1000,
// Lambda starts here
[this, device, midimessage] { scriptLog("lambda demo", 1); }
); // This belongs to `juce::Timer:callAfterDelay(...)`
}
That would be fine for something like clearing a display after a certain period of time.
What I’ve been trying to use is the timerCallback() function of juce::Timer. I want to write the sysex on a schedule, such as every 100ms. If widget values reflected in the sysex change 50 times in a second I don’t want to just delay all 50 of those.
I’d like the timerCallback() approach to run every 100ms, but that approach doesn’t seem to accept this kind of lambda (or I can’t figure it out).
I can create a class and override with:
class SoftbuttonTimer : public juce::Timer
{
public:
virtual void timerCallback() override;
}
void SoftbuttonTimer::timerCallback()
{
scriptLog("timer callback",0);
}
but I can’t figure out how to get functions from the GP API or from my own LibMain accepted in that timerCallback() override when I compile.
Thanks. I had been looking at your GP Hud earlier, which also uses a timerCallback, but the lyrics chords is a lot more extensive.
I’ll have to spend some time digesting it. The key thing it seems like you’re doing (which I don’t fully understand) is:
// in ExtensionWindow.h
static ExtensionWindow* extension;
// in ExtensionWindow.cpp
ExtensionWindow* ExtensionWindow::extension = nullptr;
LibMain* lib = new LibMain(nullptr);
...
ExtensionWindow::ExtensionWindow ()
{
...
void RefreshTimer::timerCallback() {
ExtensionWindow::selectSetlistButton(lib->getCurrentSetlistIndex());
}
}
// in LibMain.cpp
void LibMain::OnOpen() {
ExtensionWindow::initialize();
}
With that you are able to use to call Gigperformer functions with things like lib-> setWidgetValue() for example.
I think I follow it enough to try to replicate it, but at the moment I don’t understand it. In my head everything that exists is created in LibMain, but we need to create a different pointer to LibMain that we can reference inside a static called “extension” in order to reference functions available in LibMain… I think I need to read a book on C++.