You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
5.1KB

  1. /*
  2. * DISTRHO Cardinal Plugin
  3. * Copyright (C) 2021 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 3 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the LICENSE file.
  16. */
  17. #include <common.hpp>
  18. #include <string.hpp>
  19. #ifdef NDEBUG
  20. # undef DEBUG
  21. #endif
  22. #include "OpenGL.hpp"
  23. #include "DistrhoPluginUtils.hpp"
  24. // fix blendish build, missing symbol in debug mode
  25. #ifdef DEBUG
  26. extern "C" {
  27. float bnd_clamp(float v, float mn, float mx) {
  28. return (v > mx)?mx:(v < mn)?mn:v;
  29. }
  30. }
  31. #endif
  32. // fix bogaudio build, another missing symbol
  33. #ifdef DEBUG
  34. namespace bogaudio {
  35. struct FollowerBase {
  36. static float efGainMaxDecibelsDebug;
  37. };
  38. float FollowerBase::efGainMaxDecibelsDebug = 12.0f;
  39. }
  40. #endif
  41. // fopen_u8
  42. #ifdef ARCH_WIN
  43. #include <windows.h>
  44. FILE* fopen_u8(const char* filename, const char* mode)
  45. {
  46. return _wfopen(rack::string::UTF8toUTF16(filename).c_str(), rack::string::UTF8toUTF16(mode).c_str());
  47. }
  48. #endif
  49. // Compile those nice implementation-in-header little libraries
  50. #define NANOSVG_IMPLEMENTATION
  51. #define NANOSVG_ALL_COLOR_KEYWORDS
  52. #include <nanosvg.h>
  53. // Define the global names to indicate this is Cardinal and not VCVRack
  54. namespace rack {
  55. const std::string APP_NAME = "Cardinal";
  56. const std::string APP_EDITION = getPluginFormatName();
  57. const std::string APP_EDITION_NAME = "Audio Plugin";
  58. const std::string APP_VERSION_MAJOR = "2";
  59. const std::string APP_VERSION = "2.0";
  60. #if defined(ARCH_WIN)
  61. const std::string APP_ARCH = "win";
  62. #elif defined(ARCH_MAC)
  63. const std::string APP_ARCH = "mac";
  64. #else
  65. const std::string APP_ARCH = "lin";
  66. #endif
  67. const std::string API_URL = "";
  68. Exception::Exception(const char* format, ...)
  69. {
  70. va_list args;
  71. va_start(args, format);
  72. msg = string::fV(format, args);
  73. va_end(args);
  74. }
  75. }
  76. // Custom assets location
  77. #include <algorithm>
  78. #include <asset.hpp>
  79. #include <system.hpp>
  80. #include <plugin/Plugin.hpp>
  81. namespace rack {
  82. namespace asset {
  83. std::string userDir; // ignored
  84. std::string systemDir; // points to plugin resources dir (or installed/local Rack dir)
  85. std::string bundlePath; // points to plugin manifests dir (or empty)
  86. // get rid of "res/" prefix
  87. static inline std::string& trim(std::string& s)
  88. {
  89. if (std::strncmp(s.c_str(), "res" DISTRHO_OS_SEP_STR, 4) == 0)
  90. s = s.substr(4, s.size()-4);
  91. #if DISTRHO_OS_SEP != '/'
  92. if (std::strncmp(s.c_str(), "res/", 4) == 0)
  93. s = s.substr(4, s.size()-4);
  94. #endif
  95. return s;
  96. }
  97. // ignored, returns the same as `system`
  98. std::string user(std::string filename) {
  99. return system(filename);
  100. }
  101. // get system resource, trimming "res/" prefix if we are loaded as a plugin bundle
  102. std::string system(std::string filename) {
  103. return system::join(systemDir, bundlePath.empty() ? filename : trim(filename));
  104. }
  105. // get plugin resource, also trims "res/" as needed
  106. std::string plugin(plugin::Plugin* plugin, std::string filename) {
  107. DISTRHO_SAFE_ASSERT_RETURN(plugin != nullptr, {});
  108. return system::join(plugin->path, bundlePath.empty() ? filename : trim(filename));
  109. }
  110. // path to plugin manifest
  111. std::string pluginManifest(const std::string& dirname) {
  112. if (bundlePath.empty())
  113. {
  114. if (dirname == "Core")
  115. return system::join(systemDir, "Core.json");
  116. return system::join(systemDir, "..", "..", "plugins", dirname, "plugin.json");
  117. }
  118. return system::join(bundlePath, dirname + ".json");
  119. }
  120. // path to plugin files
  121. std::string pluginPath(const std::string& dirname) {
  122. if (bundlePath.empty())
  123. {
  124. if (dirname == "Core")
  125. return systemDir;
  126. return system::join(systemDir, "..", "..", "plugins", dirname);
  127. }
  128. return system::join(systemDir, dirname);
  129. }
  130. }
  131. }
  132. // Define the stuff needed for VCVRack but unused for Cardinal
  133. #include <library.hpp>
  134. #include <network.hpp>
  135. namespace rack {
  136. namespace library {
  137. std::string appChangelogUrl;
  138. std::string appDownloadUrl;
  139. std::string appVersion;
  140. std::string loginStatus;
  141. std::map<std::string, UpdateInfo> updateInfos;
  142. std::string updateStatus;
  143. std::string updateSlug;
  144. float updateProgress = 0.f;
  145. bool isSyncing = false;
  146. bool restartRequested = false;
  147. void checkAppUpdate() {}
  148. void checkUpdates() {}
  149. bool hasUpdates() { return false; }
  150. bool isAppUpdateAvailable() { return false; }
  151. bool isLoggedIn() { return false; }
  152. void logIn(const std::string&, const std::string&) {}
  153. void logOut() {}
  154. void syncUpdate(const std::string&) {}
  155. void syncUpdates() {}
  156. }
  157. namespace network {
  158. std::string encodeUrl(const std::string&) { return {}; }
  159. json_t* requestJson(Method, const std::string&, json_t*, const CookieMap&) { return nullptr; }
  160. bool requestDownload(const std::string&, const std::string&, float*, const CookieMap&) { return false; }
  161. }
  162. }