justinfrankel / reaper-sdk

REAPER C/C++ extension SDK
125 stars 20 forks source link

plugin_register "csurf_inst" produces a bug and doesn't work when called from a loaded VST3 plugin #5

Open GZPERRA opened 2 years ago

GZPERRA commented 2 years ago

I'm trying to register the "csurf_inst" from a loaded VST3 plugin, to listen for tracks selection changes, and it's producing a bug. This is the code:

void registerCSurf() {
  auto reaper = // queryInterface(IReaperHostApplication::iid ...
  if (reaper)
  {
    auto registerFunc = static_cast<int (*)(const char*, void*)>(reaper->getReaperApi("plugin_register"));

    if (registerFunc)
    {
        if (1 == registerFunc("csurf_inst", this)) // *this* implements IReaperControlSurface.
        {
            Log::debug("register csurf_inst Ok");
        }
    }
    //reaper->release();
  }
}

The registerFunc returns 1, but no function (Run,OnTrackSelection,SetSurfaceXXX..) gets called. But what happens is that the selection becomes broken, I can't deselect tracks, unmute ...

justinfrankel commented 2 years ago

It's hard to know exactly what's going on based on the limited scope of your code, but it's likely that you need to change the register line to be: if (1 == registerFunc("csurf_inst", (void *)(IReaperControlSurface*)this))

otherwise, the cast to void * will not know which interface it should be passing