ReaperEmbeddedViewPluginDemo example: getting parent track? (develop branch)

Based on the recently added ReaperEmbeddedViewPluginDemo.h (thanks!) I’m trying to get the parent track (= a pointer to the track my plugin lives on) but it doesn’t work for me neither for VST2 nor VST3.

for VST3:

void setIHostApplication (Steinberg::FUnknown* ptr) override
{
	if (ptr == nullptr)
		return;

	void* objPtr = nullptr;

	if (ptr->queryInterface (reaper::IReaperHostApplication::iid, &objPtr) == Steinberg::kResultOk)
	{
		// this from the example code works
		if (void* fnPtr = static_cast<reaper::IReaperHostApplication*> (objPtr)->getReaperApi ("BypassFxAllTracks"))
			globalBypassFn = reinterpret_cast<void (*) (int)> (fnPtr);

		// this (my code) always returns null, why?
		if (void* foo = static_cast<reaper::IReaperHostApplication*> (objPtr)->getReaperParent(1))
			// ...
	}
}

for VST2 (though I’m more interested in getting it to work in the VST3 version):

void handleVstHostCallbackAvailable (std::function<VstHostCallbackType>&& hostcb) override
{
	// this from the example code works
	char functionName[] = "BypassFxAllTracks";
	globalBypassFn = reinterpret_cast<void (*) (int)> (hostcb ((int32_t) 0xdeadbeef, (int32_t) 0xdeadf00d, 0, functionName, 0.0));
   
	// this (my code) always returns null, why?
	// reference: https://www.reaper.fm/sdk/vst/vst_ext.php#vst_hostctx
	void* foo = (void*)hostcb(0xdeadbeef, 0xdeadf00e, 1, nullptr, 0.0);
}

Building the plugin (both VST2/3) and getting/using various Reaper API functions works fine, just not getting the parent REAPER context. In fact all of the possible parent contexts (track, take, project etc. always return NULL for me).
What am I doing wrong/missing?

(I’ve asked this question in the corresponding REAPER forum thread also btw., but no suitable reply yet.)

Did you do a “stand alone” project with your own *.cpp files ?
If yous couls you provide the CMAKElist,txt file you use to be able to build your project ? (I don’t have such for my (VST3) project allowing to upgrade same from the patched to the “official” prerelease of JUCE.
Once I can compile my project, I might be able to make it working. Same also calls ReaperAPI functions - and this does work with the depreciated patched JUCElibrary.
-Michael

I did not use CMake for this project but the Projucer to generate a VisualStudio project file.

bumping this topic btw. as I’m still stuck on getting host context (REAPER parent track).

Your code looks correct. If the call to getReaperApi works but getReaperParent doesn’t, that suggests that the problem is on REAPER’s side rather than JUCE’s. It might be worth creating a dedicated topic on the REAPER forum to see whether any of the REAPER developers can shed some light on the problem.

Thanks.
The ReaLearn dev also uses this in his plugin (though not JUCE based) and confirmed that it works correctly at least with VST2 ( Announcing ReaLearn: Improved MIDI learn for REAPER - Page 36 - Cockos Incorporated Forums) so not sure it’s a REAPER issue.
But will start a dedicated topic on the REAPER forum as suggested.

I had a quick look at this, and I think perhaps the problem is that the parent pointer is initialised a little time after setIHostApplication is called. Rather than immediately trying to call getReaperParent inside setIHostApplication, you could try storing the pointer to the IReaperHostApplication and then calling hostPtr->getReaperParent (1) at the point where you actually need to interact with the track object.

1 Like

OMG this works! :grinning:
I was going nuts because I absolutely couldn’t see where I’d be going wrong with the code lol.
And you’re right, the code snippets were just meant as initial test, not real world usage.
Thanks so much for looking into and solving it.

You also might want to check out the example code → https://stash.reaper.fm/42089/embedded_plugin.zip
-Michael