Browse Source

Pass keyboard events to vst2 plugins in win/macOS

tags/v2.4.1
falkTX 3 years ago
parent
commit
c6daf00679
2 changed files with 183 additions and 4 deletions
  1. +5
    -1
      source/backend/plugin/CarlaPluginJuce.cpp
  2. +178
    -3
      source/utils/JucePluginWindow.hpp

+ 5
- 1
source/backend/plugin/CarlaPluginJuce.cpp View File

@@ -495,7 +495,11 @@ public:
uiName += " (GUI)";
}

fWindow = new JucePluginWindow(opts.frontendWinId, opts.pluginsAreStandalone);
AEffect* const effect = fDesc.pluginFormatName == "VST" || fDesc.pluginFormatName == "VST2"
? (AEffect*)fInstance->getPlatformSpecificData()
: nullptr;

fWindow = new JucePluginWindow(opts.frontendWinId, opts.pluginsAreStandalone, effect);
fWindow->setName(uiName);
}



+ 178
- 3
source/utils/JucePluginWindow.hpp View File

@@ -1,6 +1,6 @@
/*
* Juce Plugin Window Helper
* Copyright (C) 2013-2019 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2013-2021 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -19,6 +19,7 @@
#define JUCE_PLUGIN_WINDOW_HPP_INCLUDED

#include "CarlaJuceUtils.hpp"
#include "CarlaVstUtils.hpp"

#include "AppConfig.h"
#include "juce_gui_basics/juce_gui_basics.h"
@@ -42,12 +43,16 @@ namespace juce {
class JucePluginWindow : public DialogWindow
{
public:
JucePluginWindow(const uintptr_t parentId, const bool isStandalone)
JucePluginWindow(const uintptr_t parentId, const bool isStandalone, AEffect* const vstEffect)
: DialogWindow("JucePluginWindow", Colour(50, 50, 200), true, false),
fIsStandalone(isStandalone),
fClosed(false),
fShown(false),
fTransientId(parentId)
fTransientId(parentId),
fLastKeyIndex(0),
fLastKeyValue(0),
fLastModifiers(),
fVstEffect(vstEffect)
{
setVisible(false);
setOpaque(true);
@@ -78,6 +83,173 @@ public:
#endif
}

bool keyPressed (const KeyPress& key) override
{
if (DialogWindow::keyPressed (key))
return true;

if (fVstEffect != nullptr)
{
const int juceKeyCode = key.getKeyCode();
int vstKeyIndex = 0;
int vstKeyValue = 0;

do {
/**/ if (juceKeyCode == KeyPress::spaceKey) vstKeyValue = 7;
else if (juceKeyCode == KeyPress::escapeKey) vstKeyValue = 6;
else if (juceKeyCode == KeyPress::returnKey) vstKeyValue = 19; // NOTE: 4 is '\r' while 19 is '\n'
else if (juceKeyCode == KeyPress::tabKey) vstKeyValue = 2;

else if (juceKeyCode == KeyPress::deleteKey) vstKeyValue = 22;
else if (juceKeyCode == KeyPress::backspaceKey) vstKeyValue = 1;
else if (juceKeyCode == KeyPress::insertKey) vstKeyValue = 21;

else if (juceKeyCode == KeyPress::upKey) vstKeyValue = 12;
else if (juceKeyCode == KeyPress::downKey) vstKeyValue = 14;
else if (juceKeyCode == KeyPress::leftKey) vstKeyValue = 11;
else if (juceKeyCode == KeyPress::rightKey) vstKeyValue = 13;
else if (juceKeyCode == KeyPress::pageUpKey) vstKeyValue = 15;
else if (juceKeyCode == KeyPress::pageDownKey) vstKeyValue = 16;
else if (juceKeyCode == KeyPress::homeKey) vstKeyValue = 10;
else if (juceKeyCode == KeyPress::endKey) vstKeyValue = 9;

else if (juceKeyCode == KeyPress::F1Key) vstKeyValue = 40;
else if (juceKeyCode == KeyPress::F2Key) vstKeyValue = 41;
else if (juceKeyCode == KeyPress::F3Key) vstKeyValue = 42;
else if (juceKeyCode == KeyPress::F4Key) vstKeyValue = 43;
else if (juceKeyCode == KeyPress::F5Key) vstKeyValue = 44;
else if (juceKeyCode == KeyPress::F6Key) vstKeyValue = 45;
else if (juceKeyCode == KeyPress::F7Key) vstKeyValue = 46;
else if (juceKeyCode == KeyPress::F8Key) vstKeyValue = 47;
else if (juceKeyCode == KeyPress::F9Key) vstKeyValue = 48;
else if (juceKeyCode == KeyPress::F10Key) vstKeyValue = 49;
else if (juceKeyCode == KeyPress::F11Key) vstKeyValue = 50;
else if (juceKeyCode == KeyPress::F12Key) vstKeyValue = 51;

else if (juceKeyCode == KeyPress::F13Key) break;
else if (juceKeyCode == KeyPress::F14Key) break;
else if (juceKeyCode == KeyPress::F15Key) break;
else if (juceKeyCode == KeyPress::F16Key) break;
else if (juceKeyCode == KeyPress::F17Key) break;
else if (juceKeyCode == KeyPress::F18Key) break;
else if (juceKeyCode == KeyPress::F19Key) break;
else if (juceKeyCode == KeyPress::F20Key) break;
else if (juceKeyCode == KeyPress::F21Key) break;
else if (juceKeyCode == KeyPress::F22Key) break;
else if (juceKeyCode == KeyPress::F23Key) break;
else if (juceKeyCode == KeyPress::F24Key) break;
else if (juceKeyCode == KeyPress::F25Key) break;
else if (juceKeyCode == KeyPress::F26Key) break;
else if (juceKeyCode == KeyPress::F27Key) break;
else if (juceKeyCode == KeyPress::F28Key) break;
else if (juceKeyCode == KeyPress::F29Key) break;
else if (juceKeyCode == KeyPress::F30Key) break;
else if (juceKeyCode == KeyPress::F31Key) break;
else if (juceKeyCode == KeyPress::F32Key) break;
else if (juceKeyCode == KeyPress::F33Key) break;
else if (juceKeyCode == KeyPress::F34Key) break;
else if (juceKeyCode == KeyPress::F35Key) break;

else if (juceKeyCode == KeyPress::numberPad0) vstKeyValue = 24;
else if (juceKeyCode == KeyPress::numberPad1) vstKeyValue = 25;
else if (juceKeyCode == KeyPress::numberPad2) vstKeyValue = 26;
else if (juceKeyCode == KeyPress::numberPad3) vstKeyValue = 27;
else if (juceKeyCode == KeyPress::numberPad4) vstKeyValue = 28;
else if (juceKeyCode == KeyPress::numberPad5) vstKeyValue = 29;
else if (juceKeyCode == KeyPress::numberPad6) vstKeyValue = 30;
else if (juceKeyCode == KeyPress::numberPad7) vstKeyValue = 31;
else if (juceKeyCode == KeyPress::numberPad8) vstKeyValue = 32;
else if (juceKeyCode == KeyPress::numberPad9) vstKeyValue = 33;

else if (juceKeyCode == KeyPress::numberPadAdd) vstKeyValue = 35;
else if (juceKeyCode == KeyPress::numberPadSubtract) vstKeyValue = 37;
else if (juceKeyCode == KeyPress::numberPadMultiply) vstKeyValue = 34;
else if (juceKeyCode == KeyPress::numberPadDivide) vstKeyValue = 39;
else if (juceKeyCode == KeyPress::numberPadSeparator) vstKeyValue = 36;
else if (juceKeyCode == KeyPress::numberPadDecimalPoint) vstKeyValue = 38;
else if (juceKeyCode == KeyPress::numberPadEquals) vstKeyValue = 57;

else if (juceKeyCode == KeyPress::numberPadDelete) break;

else if (juceKeyCode == KeyPress::playKey) break;
else if (juceKeyCode == KeyPress::stopKey) break;
else if (juceKeyCode == KeyPress::fastForwardKey) break;
else if (juceKeyCode == KeyPress::rewindKey) break;

else vstKeyIndex = juceKeyCode;
} while (false);

fLastKeyIndex = vstKeyIndex;
fLastKeyValue = vstKeyValue;
return fVstEffect->dispatcher (fVstEffect, effEditKeyDown,
vstKeyIndex, vstKeyValue,
nullptr, 0.0f) != 0;
}

if (Component* const comp = getContentComponent())
return comp->keyPressed (key);

return false;
}

bool keyStateChanged (bool isKeyDown) override
{
if (DialogWindow::keyStateChanged (isKeyDown))
return true;

if (fVstEffect != nullptr && (fLastKeyIndex != 0 || fLastKeyValue != 0) && ! isKeyDown)
{
const int vstKeyIndex = fLastKeyIndex;
const int vstKeyValue = fLastKeyValue;
fLastKeyIndex = fLastKeyValue = 0;
return fVstEffect->dispatcher (fVstEffect, effEditKeyUp,
vstKeyIndex, vstKeyValue,
nullptr, 0.0f) != 0;
}

if (Component* const comp = getContentComponent())
return comp->keyStateChanged (isKeyDown);

return false;
}

void modifierKeysChanged (const ModifierKeys& modifiers) override
{
DialogWindow::modifierKeysChanged (modifiers);

if (fVstEffect != nullptr)
{
const int oldRawFlags = fLastModifiers.getRawFlags();
const int newRawFlags = modifiers.getRawFlags();

if ((oldRawFlags & ModifierKeys::shiftModifier) != (newRawFlags & ModifierKeys::shiftModifier))
{
fVstEffect->dispatcher (fVstEffect, (newRawFlags & ModifierKeys::shiftModifier) ? effEditKeyDown : effEditKeyUp, 0,
54, nullptr, 0.0f);
}

if ((oldRawFlags & ModifierKeys::ctrlModifier) != (newRawFlags & ModifierKeys::ctrlModifier))
{
fVstEffect->dispatcher (fVstEffect, (newRawFlags & ModifierKeys::ctrlModifier) ? effEditKeyDown : effEditKeyUp, 0,
55, nullptr, 0.0f);
}

if ((oldRawFlags & ModifierKeys::altModifier) != (newRawFlags & ModifierKeys::altModifier))
{
fVstEffect->dispatcher (fVstEffect, (newRawFlags & ModifierKeys::altModifier) ? effEditKeyDown : effEditKeyUp, 0,
56, nullptr, 0.0f);
}

if ((oldRawFlags & ModifierKeys::popupMenuClickModifier) != (newRawFlags & ModifierKeys::popupMenuClickModifier))
{
fVstEffect->dispatcher (fVstEffect, (newRawFlags & ModifierKeys::popupMenuClickModifier) ? effEditKeyDown : effEditKeyUp, 0,
58, nullptr, 0.0f);
}
}

fLastModifiers = modifiers;
}

void hide()
{
setVisible(false);
@@ -134,6 +306,9 @@ private:
volatile bool fClosed;
bool fShown;
const uintptr_t fTransientId;
int fLastKeyIndex, fLastKeyValue;
ModifierKeys fLastModifiers;
AEffect* const fVstEffect;

void setTransient()
{


Loading…
Cancel
Save