diff --git a/carla b/carla index 67c6991..e78faac 160000 --- a/carla +++ b/carla @@ -1 +1 @@ -Subproject commit 67c699162d3b16526684560af55bc0e6f30f075d +Subproject commit e78faac205539ea0e240a096ca7da7cfdfd3211d diff --git a/deps/PawPaw b/deps/PawPaw index 6c11b17..df80ab8 160000 --- a/deps/PawPaw +++ b/deps/PawPaw @@ -1 +1 @@ -Subproject commit 6c11b17d5f794c224fd0ee8aa872c54e36279123 +Subproject commit df80ab802d7e758eeead02e3ad7d80e4ff332b14 diff --git a/dpf b/dpf index ac9b574..0c04a07 160000 --- a/dpf +++ b/dpf @@ -1 +1 @@ -Subproject commit ac9b574f6f8294fbfaf0aab1c943ab33de7afce2 +Subproject commit 0c04a07e562f502324bb417fb56dbaab7911b010 diff --git a/src/Cardinal/glfw.cpp b/src/Cardinal/glfw.cpp new file mode 120000 index 0000000..8c6a6e4 --- /dev/null +++ b/src/Cardinal/glfw.cpp @@ -0,0 +1 @@ +../custom/glfw.cpp \ No newline at end of file diff --git a/src/CardinalFX/glfw.cpp b/src/CardinalFX/glfw.cpp new file mode 120000 index 0000000..8c6a6e4 --- /dev/null +++ b/src/CardinalFX/glfw.cpp @@ -0,0 +1 @@ +../custom/glfw.cpp \ No newline at end of file diff --git a/src/CardinalSynth/glfw.cpp b/src/CardinalSynth/glfw.cpp new file mode 120000 index 0000000..8c6a6e4 --- /dev/null +++ b/src/CardinalSynth/glfw.cpp @@ -0,0 +1 @@ +../custom/glfw.cpp \ No newline at end of file diff --git a/src/CardinalUI.cpp b/src/CardinalUI.cpp index 19d8a2a..0c453e9 100644 --- a/src/CardinalUI.cpp +++ b/src/CardinalUI.cpp @@ -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(APP); - DISTRHO_SAFE_ASSERT_RETURN(context != nullptr, nullptr); - DISTRHO_SAFE_ASSERT_RETURN(context->ui != nullptr, nullptr); - - size_t dataSize; - return static_cast(context->ui->getClipboard(dataSize)); -} - -GLFWAPI void glfwSetClipboardString(GLFWwindow*, const char* const text) -{ - DISTRHO_SAFE_ASSERT_RETURN(text != nullptr,); - - CardinalPluginContext* const context = static_cast(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(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(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); diff --git a/src/Makefile.cardinal.mk b/src/Makefile.cardinal.mk index 5690058..71e397e 100644 --- a/src/Makefile.cardinal.mk +++ b/src/Makefile.cardinal.mk @@ -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 @@ -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 @@ -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 diff --git a/src/custom/glfw.cpp b/src/custom/glfw.cpp new file mode 100644 index 0000000..9e42296 --- /dev/null +++ b/src/custom/glfw.cpp @@ -0,0 +1,163 @@ +/* + * DISTRHO Cardinal Plugin + * Copyright (C) 2021-2022 Filipe Coelho + * + * 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 + +GLFWAPI int glfwGetKeyScancode(int) { return 0; } + +GLFWAPI const char* glfwGetClipboardString(GLFWwindow*) +{ + CardinalPluginContext* const context = static_cast(APP); + DISTRHO_SAFE_ASSERT_RETURN(context != nullptr, nullptr); + DISTRHO_SAFE_ASSERT_RETURN(context->ui != nullptr, nullptr); + + size_t dataSize; + return static_cast(context->ui->getClipboard(dataSize)); +} + +GLFWAPI void glfwSetClipboardString(GLFWwindow*, const char* const text) +{ + DISTRHO_SAFE_ASSERT_RETURN(text != nullptr,); + + CardinalPluginContext* const context = static_cast(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(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(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; + } +}