How to set the BPM rate of a wrapped plugin?

I am working on a VST3 adapter for VST2 plugins.

  1. The wrapped plugin does not receive the BPM rate unless I use setPlayHead like in the following code below. Is this the correct way to do it?

class WrapperProcessor: public juce::AudioProcessor, public juce::AudioProcessorListener
{
WrapperProcessor(std::unique_ptrjuce::AudioPluginInstance processorToUse): AudioProcessor(getBusesPropertiesFromProcessor(processorToUse.get())),plugin(std::move(processorToUse))
{
plugin->addListener(this);
}

std::unique_ptrjuce::AudioPluginInstance plugin;
}

void processBlock(juce::AudioBuffer& buffer, juce::MidiBuffer& midiMessages) override
{
juce::AudioPlayHead* playHeadPt;
playHeadPt = this->getPlayHead();
if (playHeadPt != NULL) plugin->setPlayHead(playHeadPt);
plugin->processBlock(buffer, midiMessages);
}

  1. The wrapped plugin does not receive receive key presses. How do I forward key presses to a wrapped plugin?

Forwarding the playhead like that is the way to go, yes.

Have you set the pluginEditorRequiresKeys plugin characteristic in the Projucer/CMake for your project? If you have, then I think keypresses should just work.

If not, please can you provide more details about the failure? Do keypresses work in the ‘outer’ plugin editor, but not the ‘inner’ editor, or do they not work for either? To track down the problem, it would also be useful to know what operating system you’re running, and the host that you’re using for testing (some hosts intercept keypresses before they reach the plugin, and some such hosts also have an option to customise this behaviour).

I can’t find pluginEditorRequiresKeys in the Projucer. However there is an option for ‘Plugin Editor Requeires Keyboard Focus’. Do you mean this one?

Yes, that’s the one.

I enabled ‘Plugin Editor Requeires Keyboard Focus’ in the Projucer. However I am still not able to react properly on key presses. It works only randomly in Reaper. Other DAWs like FLStudio, Ableton and Savihost fail.

class MyKeyListener : public juce::KeyListener
{
public:
bool keyPressed(const juce::KeyPress& key, juce::Component* orginatingComponent) override
{
MessBox(“”, “Key has been pressed”);
return false;
}
};

class WrapperProcessor: public juce::AudioProcessor, public juce::AudioProcessorListener

{
public:

WrapperProcessor(std::unique_ptrjuce::AudioPluginInstance processorToUse): AudioProcessor(getBusesPropertiesFromProcessor(processorToUse.get())),plugin(std::move(processorToUse))
{
plugin->addListener(this);
}

juce::AudioProcessorEditor* createEditor() override
{
juce::AudioProcessorEditor* ed;
ed = plugin->createEditor();
ed->setWantsKeyboardFocus(true);
return ed;
}

std::unique_ptrjuce::AudioPluginInstance plugin;//juce 5.4
MyKeyListener keyListener;
};

In REAPER, does enabling the “send all keyboard input to plugin” option help? (It’s in the “+” menu that can be opened from the plugin window’s top bar.)

Do keypresses work in the ‘outer’ plugin editor, but not the ‘inner’ editor, or do they not work for either? To track down the problem, it would also be useful to know what operating system you’re running.

enabling the + in Reaper results in the same behavior like all other tested DAWs: no keyboard input at all.
I am on Win10 x64.

I am not sure if it is the ‘outer’ or ‘inner’ editor. My code looks like this:

class MyKeyListener : public juce::KeyListener
{
public:
bool keyPressed(const juce::KeyPress& key, juce::Component* orginatingComponent) override
{
MessBox(“”, “Key has been pressed”);
return false;
}
};

class WrapperProcessor: public juce::AudioProcessor, public juce::AudioProcessorListener
{
public:

juce::AudioProcessorEditor* createEditor() override
{
juce::AudioProcessorEditor* ed;
ed = plugin->createEditor();
ed->setWantsKeyboardFocus(true);
ed->addKeyListener(&keyListener);
return ed;
}

std::unique_ptrjuce::AudioPluginInstance plugin;
MyKeyListener keyListener;
};

juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{

auto wrapped = pluginFormatManager.createPluginInstance(*pluginDescriptions[0], 44100.0, 512, msg);
return std::make_unique(std::move(wrapped)).release();
}

What I need to do is to forward incoming keypresses to the editor of the wrapped vst2 plugin.

I see. I assume that your KeyListener doesn’t get any callbacks. Does keyboard input work on the wrapped plugin at all? That is, assuming the inner plugin has text fields or something similar, do those controls respond to the keyboard correctly?

The text fields in the inner plugin do receive keyboard input.
The wrapped VST2.4 plugin does not receive anything on “bool onKeyDown (VstKeyCode &keyCode)”.
It appears as if this function is not supported by the interface of JUCE when a plugin is wrapped with createPluginInstance

Yes, it sounds like keyboard handling is working as expected. JUCE cannot intercept keyboard events on the hosted plugin instance, and it sounds like the wrapped plugin is receiving keyboard input correctly.