Skip to content

Commit

Permalink
Move glfw convert code into its own file
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Jun 19, 2022
1 parent 383bc41 commit 8492fc7
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 148 deletions.
2 changes: 1 addition & 1 deletion carla
Submodule carla updated 1 files
+1 −1 data/macos/package.xml
2 changes: 1 addition & 1 deletion deps/PawPaw
2 changes: 1 addition & 1 deletion dpf
1 change: 1 addition & 0 deletions src/Cardinal/glfw.cpp
1 change: 1 addition & 0 deletions src/CardinalFX/glfw.cpp
1 change: 1 addition & 0 deletions src/CardinalSynth/glfw.cpp
142 changes: 0 additions & 142 deletions src/CardinalUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,148 +39,6 @@
#include "PluginContext.hpp"
#include "WindowParameters.hpp"

GLFWAPI int glfwGetKeyScancode(int) { return 0; }

GLFWAPI const char* glfwGetClipboardString(GLFWwindow*)
{
CardinalPluginContext* const context = static_cast<CardinalPluginContext*>(APP);
DISTRHO_SAFE_ASSERT_RETURN(context != nullptr, nullptr);
DISTRHO_SAFE_ASSERT_RETURN(context->ui != nullptr, nullptr);

size_t dataSize;
return static_cast<const char*>(context->ui->getClipboard(dataSize));
}

GLFWAPI void glfwSetClipboardString(GLFWwindow*, const char* const text)
{
DISTRHO_SAFE_ASSERT_RETURN(text != nullptr,);

CardinalPluginContext* const context = static_cast<CardinalPluginContext*>(APP);
DISTRHO_SAFE_ASSERT_RETURN(context != nullptr,);
DISTRHO_SAFE_ASSERT_RETURN(context->ui != nullptr,);

context->ui->setClipboard(nullptr, text, std::strlen(text)+1);
}

GLFWAPI void glfwSetCursor(GLFWwindow*, GLFWcursor* const cursor)
{
CardinalPluginContext* const context = static_cast<CardinalPluginContext*>(APP);
DISTRHO_SAFE_ASSERT_RETURN(context != nullptr,);
DISTRHO_SAFE_ASSERT_RETURN(context->ui != nullptr,);

context->ui->setCursor(cursor != nullptr ? kMouseCursorDiagonal : kMouseCursorArrow);
}

GLFWAPI double glfwGetTime(void)
{
CardinalPluginContext* const context = static_cast<CardinalPluginContext*>(APP);
DISTRHO_SAFE_ASSERT_RETURN(context != nullptr, 0.0);
DISTRHO_SAFE_ASSERT_RETURN(context->ui != nullptr, 0.0);

return context->ui->getApp().getTime();
}

GLFWAPI const char* glfwGetKeyName(const int key, int)
{
switch (key)
{
case '\"': return "\"";
case '\'': return "\'";
case '\\': return "\\";
case ' ': return " ";
case '!': return "!";
case '#': return "#";
case '$': return "$";
case '%': return "%";
case '&': return "&";
case '(': return "(";
case ')': return ")";
case '*': return "*";
case '+': return "+";
case ',': return ",";
case '-': return "-";
case '.': return ".";
case '/': return "/";
case '0': return "0";
case '1': return "1";
case '2': return "2";
case '3': return "3";
case '4': return "4";
case '5': return "5";
case '6': return "6";
case '7': return "7";
case '8': return "8";
case '9': return "9";
case ':': return ":";
case ';': return ";";
case '<': return "<";
case '=': return "=";
case '>': return ">";
case '?': return "?";
case '@': return "@";
/* Rack expects lowercase, forced below
case 'A': return "A";
case 'B': return "B";
case 'C': return "C";
case 'D': return "D";
case 'E': return "E";
case 'F': return "F";
case 'G': return "G";
case 'H': return "H";
case 'I': return "I";
case 'J': return "J";
case 'K': return "K";
case 'L': return "L";
case 'M': return "M";
case 'N': return "N";
case 'O': return "O";
case 'P': return "P";
case 'Q': return "Q";
case 'R': return "R";
case 'S': return "S";
case 'T': return "T";
case 'U': return "U";
case 'V': return "V";
case 'W': return "W";
case 'X': return "X";
case 'Y': return "Y";
case 'Z': return "Z";
*/
case '[': return "[";
case ']': return "]";
case '^': return "^";
case '_': return "_";
case '`': return "`";
case 'a': case 'A': return "a";
case 'b': case 'B': return "b";
case 'c': case 'C': return "c";
case 'd': case 'D': return "d";
case 'e': case 'E': return "e";
case 'f': case 'F': return "f";
case 'g': case 'G': return "g";
case 'h': case 'H': return "h";
case 'i': case 'I': return "i";
case 'j': case 'J': return "j";
case 'k': case 'K': return "k";
case 'l': case 'L': return "l";
case 'm': case 'M': return "m";
case 'n': case 'N': return "n";
case 'o': case 'O': return "o";
case 'p': case 'P': return "p";
case 'q': case 'Q': return "q";
case 'r': case 'R': return "r";
case 's': case 'S': return "s";
case 't': case 'T': return "t";
case 'u': case 'U': return "u";
case 'v': case 'V': return "v";
case 'w': case 'W': return "w";
case 'x': case 'X': return "x";
case 'y': case 'Y': return "y";
case 'z': case 'Z': return "z";
default: return nullptr;
}
}

namespace rack {
namespace app {
widget::Widget* createMenuBar(bool isStandalone);
Expand Down
6 changes: 3 additions & 3 deletions src/Makefile.cardinal.mk
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ endif # STATIC_BUILD
# --------------------------------------------------------------
# Import base definitions

NVG_DISABLE_SKIPPING_WHITESPACE = true
NVG_FONT_TEXTURE_FLAGS = NVG_IMAGE_NEAREST
USE_NANOVG_FBO = true
include ../../dpf/Makefile.base.mk

Expand Down Expand Up @@ -80,6 +82,7 @@ FILES_DSP += RemoteNanoVG.cpp
FILES_DSP += RemoteWindow.cpp
else
FILES_UI = CardinalUI.cpp
FILES_UI += glfw.cpp
FILES_UI += Window.cpp
endif

Expand Down Expand Up @@ -120,9 +123,6 @@ endif
# --------------------------------------------------------------
# Do some magic

NVG_DISABLE_SKIPPING_WHITESPACE = true
NVG_FONT_TEXTURE_FLAGS = NVG_IMAGE_NEAREST
USE_NANOVG_FBO = true
USE_VST2_BUNDLE = true
include ../../dpf/Makefile.plugins.mk

Expand Down
163 changes: 163 additions & 0 deletions src/custom/glfw.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* DISTRHO Cardinal Plugin
* Copyright (C) 2021-2022 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
* published by the Free Software Foundation; either version 3 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For a full copy of the GNU General Public License see the LICENSE file.
*/

#include "Application.hpp"
#include "PluginContext.hpp"

#include <GLFW/glfw3.h>

GLFWAPI int glfwGetKeyScancode(int) { return 0; }

GLFWAPI const char* glfwGetClipboardString(GLFWwindow*)
{
CardinalPluginContext* const context = static_cast<CardinalPluginContext*>(APP);
DISTRHO_SAFE_ASSERT_RETURN(context != nullptr, nullptr);
DISTRHO_SAFE_ASSERT_RETURN(context->ui != nullptr, nullptr);

size_t dataSize;
return static_cast<const char*>(context->ui->getClipboard(dataSize));
}

GLFWAPI void glfwSetClipboardString(GLFWwindow*, const char* const text)
{
DISTRHO_SAFE_ASSERT_RETURN(text != nullptr,);

CardinalPluginContext* const context = static_cast<CardinalPluginContext*>(APP);
DISTRHO_SAFE_ASSERT_RETURN(context != nullptr,);
DISTRHO_SAFE_ASSERT_RETURN(context->ui != nullptr,);

context->ui->setClipboard(nullptr, text, std::strlen(text)+1);
}

GLFWAPI void glfwSetCursor(GLFWwindow*, GLFWcursor* const cursor)
{
CardinalPluginContext* const context = static_cast<CardinalPluginContext*>(APP);
DISTRHO_SAFE_ASSERT_RETURN(context != nullptr,);
DISTRHO_SAFE_ASSERT_RETURN(context->ui != nullptr,);

context->ui->setCursor(cursor != nullptr ? kMouseCursorDiagonal : kMouseCursorArrow);
}

GLFWAPI double glfwGetTime(void)
{
CardinalPluginContext* const context = static_cast<CardinalPluginContext*>(APP);
DISTRHO_SAFE_ASSERT_RETURN(context != nullptr, 0.0);
DISTRHO_SAFE_ASSERT_RETURN(context->ui != nullptr, 0.0);

return context->ui->getApp().getTime();
}

GLFWAPI const char* glfwGetKeyName(const int key, int)
{
switch (key)
{
case '\"': return "\"";
case '\'': return "\'";
case '\\': return "\\";
case ' ': return " ";
case '!': return "!";
case '#': return "#";
case '$': return "$";
case '%': return "%";
case '&': return "&";
case '(': return "(";
case ')': return ")";
case '*': return "*";
case '+': return "+";
case ',': return ",";
case '-': return "-";
case '.': return ".";
case '/': return "/";
case '0': return "0";
case '1': return "1";
case '2': return "2";
case '3': return "3";
case '4': return "4";
case '5': return "5";
case '6': return "6";
case '7': return "7";
case '8': return "8";
case '9': return "9";
case ':': return ":";
case ';': return ";";
case '<': return "<";
case '=': return "=";
case '>': return ">";
case '?': return "?";
case '@': return "@";
/* Rack expects lowercase, forced below
case 'A': return "A";
case 'B': return "B";
case 'C': return "C";
case 'D': return "D";
case 'E': return "E";
case 'F': return "F";
case 'G': return "G";
case 'H': return "H";
case 'I': return "I";
case 'J': return "J";
case 'K': return "K";
case 'L': return "L";
case 'M': return "M";
case 'N': return "N";
case 'O': return "O";
case 'P': return "P";
case 'Q': return "Q";
case 'R': return "R";
case 'S': return "S";
case 'T': return "T";
case 'U': return "U";
case 'V': return "V";
case 'W': return "W";
case 'X': return "X";
case 'Y': return "Y";
case 'Z': return "Z";
*/
case '[': return "[";
case ']': return "]";
case '^': return "^";
case '_': return "_";
case '`': return "`";
case 'a': case 'A': return "a";
case 'b': case 'B': return "b";
case 'c': case 'C': return "c";
case 'd': case 'D': return "d";
case 'e': case 'E': return "e";
case 'f': case 'F': return "f";
case 'g': case 'G': return "g";
case 'h': case 'H': return "h";
case 'i': case 'I': return "i";
case 'j': case 'J': return "j";
case 'k': case 'K': return "k";
case 'l': case 'L': return "l";
case 'm': case 'M': return "m";
case 'n': case 'N': return "n";
case 'o': case 'O': return "o";
case 'p': case 'P': return "p";
case 'q': case 'Q': return "q";
case 'r': case 'R': return "r";
case 's': case 'S': return "s";
case 't': case 'T': return "t";
case 'u': case 'U': return "u";
case 'v': case 'V': return "v";
case 'w': case 'W': return "w";
case 'x': case 'X': return "x";
case 'y': case 'Y': return "y";
case 'z': case 'Z': return "z";
default: return nullptr;
}
}

0 comments on commit 8492fc7

Please sign in to comment.