From b22f88b8aa3abfd7b1a1ae7ea55e5bdcfb45319d Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 1 Nov 2021 01:11:16 -0400 Subject: [PATCH] Rename INTERNAL to PRIVATE. Add PRIVATE to several functions/symbols that plugins should never call/use. --- include/app/Browser.hpp | 2 +- include/app/MenuBar.hpp | 2 +- include/app/ModuleWidget.hpp | 8 ++++---- include/app/RackScrollWidget.hpp | 4 ++-- include/app/RackWidget.hpp | 4 ++-- include/app/Scene.hpp | 4 ++-- include/app/TipWindow.hpp | 2 +- include/asset.hpp | 8 ++++---- include/audio.hpp | 4 ++-- include/common.hpp | 14 +++++++------- include/componentlibrary.hpp | 4 ++-- include/discord.hpp | 4 ++-- include/engine/Cable.hpp | 2 +- include/engine/Engine.hpp | 18 +++++++++--------- include/engine/Module.hpp | 12 ++++++------ include/gamepad.hpp | 4 ++-- include/history.hpp | 6 +++--- include/keyboard.hpp | 2 +- include/library.hpp | 18 +++++++++--------- include/logger.hpp | 7 ++++--- include/midi.hpp | 4 ++-- include/network.hpp | 4 ++-- include/patch.hpp | 6 +++--- include/plugin.hpp | 4 ++-- include/rack.hpp | 17 +++++++++-------- include/rtaudio.hpp | 2 +- include/rtmidi.hpp | 2 +- include/settings.hpp | 10 +++++----- include/system.hpp | 2 +- include/ui/common.hpp | 4 ++-- include/window/Window.hpp | 18 +++++++++--------- 31 files changed, 102 insertions(+), 100 deletions(-) diff --git a/include/app/Browser.hpp b/include/app/Browser.hpp index 7dde826f..72880b47 100644 --- a/include/app/Browser.hpp +++ b/include/app/Browser.hpp @@ -7,7 +7,7 @@ namespace rack { namespace app { -widget::Widget* browserCreate(); +PRIVATE widget::Widget* browserCreate(); } // namespace app diff --git a/include/app/MenuBar.hpp b/include/app/MenuBar.hpp index ead947a6..2821f17f 100644 --- a/include/app/MenuBar.hpp +++ b/include/app/MenuBar.hpp @@ -7,7 +7,7 @@ namespace rack { namespace app { -widget::Widget* createMenuBar(); +PRIVATE widget::Widget* createMenuBar(); } // namespace app diff --git a/include/app/ModuleWidget.hpp b/include/app/ModuleWidget.hpp index f3879cba..24c5987f 100644 --- a/include/app/ModuleWidget.hpp +++ b/include/app/ModuleWidget.hpp @@ -116,10 +116,10 @@ struct ModuleWidget : widget::OpaqueWidget { void removeAction(); void createContextMenu(); - INTERNAL math::Vec& dragOffset(); - INTERNAL bool& dragEnabled(); - INTERNAL math::Vec& oldPos(); - INTERNAL engine::Module* releaseModule(); + PRIVATE math::Vec& dragOffset(); + PRIVATE bool& dragEnabled(); + PRIVATE math::Vec& oldPos(); + PRIVATE engine::Module* releaseModule(); }; diff --git a/include/app/RackScrollWidget.hpp b/include/app/RackScrollWidget.hpp index 9b5c8090..2825852a 100644 --- a/include/app/RackScrollWidget.hpp +++ b/include/app/RackScrollWidget.hpp @@ -16,8 +16,8 @@ struct RackScrollWidget : ui::ScrollWidget { widget::ZoomWidget* zoomWidget; RackWidget* rackWidget; - RackScrollWidget(); - ~RackScrollWidget(); + PRIVATE RackScrollWidget(); + PRIVATE ~RackScrollWidget(); void reset(); /** Gets the top-left scroll offset in grid coordinates. diff --git a/include/app/RackWidget.hpp b/include/app/RackWidget.hpp index 61ac544e..d8a6fe42 100644 --- a/include/app/RackWidget.hpp +++ b/include/app/RackWidget.hpp @@ -26,8 +26,8 @@ struct RackWidget : widget::OpaqueWidget { ParamWidget* touchedParam = NULL; int nextCableColorId = 0; - RackWidget(); - ~RackWidget(); + PRIVATE RackWidget(); + PRIVATE ~RackWidget(); void step() override; void draw(const DrawArgs& args) override; diff --git a/include/app/Scene.hpp b/include/app/Scene.hpp index f6d1c647..361d310f 100644 --- a/include/app/Scene.hpp +++ b/include/app/Scene.hpp @@ -23,8 +23,8 @@ struct Scene : widget::OpaqueWidget { /** The last mouse position in the Scene */ math::Vec mousePos; - Scene(); - ~Scene(); + PRIVATE Scene(); + PRIVATE ~Scene(); math::Vec getMousePos(); void step() override; void draw(const DrawArgs& args) override; diff --git a/include/app/TipWindow.hpp b/include/app/TipWindow.hpp index 1edc3a1d..413df13b 100644 --- a/include/app/TipWindow.hpp +++ b/include/app/TipWindow.hpp @@ -7,7 +7,7 @@ namespace rack { namespace app { -widget::Widget* tipWindowCreate(); +PRIVATE widget::Widget* tipWindowCreate(); } // namespace app diff --git a/include/asset.hpp b/include/asset.hpp index 49877c2e..8259b5a0 100644 --- a/include/asset.hpp +++ b/include/asset.hpp @@ -19,7 +19,7 @@ struct Module; namespace asset { -void init(); +PRIVATE void init(); /** Returns the path of a system asset. Read-only files. */ std::string system(std::string filename = ""); @@ -37,10 +37,10 @@ std::string plugin(plugin::Plugin* plugin, std::string filename = ""); // Set these before calling init() to override the default paths -extern std::string systemDir; -extern std::string userDir; +PRIVATE extern std::string systemDir; +PRIVATE extern std::string userDir; // Only defined on Mac -extern std::string bundlePath; +PRIVATE extern std::string bundlePath; } // namespace asset diff --git a/include/audio.hpp b/include/audio.hpp index 0f52ce46..fc116da9 100644 --- a/include/audio.hpp +++ b/include/audio.hpp @@ -194,8 +194,8 @@ struct Port { }; -void init(); -void destroy(); +PRIVATE void init(); +PRIVATE void destroy(); /** Registers a new audio driver. Takes pointer ownership. Driver ID is stored in patches and must be unique. -1 is reserved. */ diff --git a/include/common.hpp b/include/common.hpp index ddd8d968..38b63535 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -15,8 +15,6 @@ #include #include -#include - /** Attribute for deprecated functions and symbols. E.g. @@ -30,12 +28,10 @@ E.g. #endif /** Attribute for private functions and symbols not intended to be used by plugins. -When #including rack.hpp, using an INTERNAL function prints a compile-time warning and will not link. +When #including rack.hpp, attempting to call PRIVATE functions or access variables will result in a compile-time error. */ -#if defined ARCH_WIN - #define INTERNAL -#else - #define INTERNAL __attribute__((visibility("hidden"))) +#ifndef PRIVATE +#define PRIVATE #endif @@ -271,3 +267,7 @@ extern const std::string API_URL; } // namespace rack + + +// Logger depends on common.hpp, but it is handy to include it along with common.hpp. +#include diff --git a/include/componentlibrary.hpp b/include/componentlibrary.hpp index e15bd77f..5cb75b22 100644 --- a/include/componentlibrary.hpp +++ b/include/componentlibrary.hpp @@ -31,10 +31,10 @@ using namespace window; static const NVGcolor SCHEME_BLACK_TRANSPARENT = nvgRGBA(0x00, 0x00, 0x00, 0x00); static const NVGcolor SCHEME_BLACK = nvgRGB(0x00, 0x00, 0x00); static const NVGcolor SCHEME_WHITE = nvgRGB(0xff, 0xff, 0xff); -static const NVGcolor SCHEME_RED = nvgRGB(0xed, 0x2c, 0x24); +static const NVGcolor SCHEME_RED = nvgRGB(0xff, 0x00, 0x48); static const NVGcolor SCHEME_ORANGE = nvgRGB(0xf2, 0xb1, 0x20); static const NVGcolor SCHEME_YELLOW = nvgRGB(0xf9, 0xdf, 0x1c); -static const NVGcolor SCHEME_GREEN = nvgRGB(0x90, 0xc7, 0x3e); +static const NVGcolor SCHEME_GREEN = nvgRGB(0x00, 0xe6, 0x72); static const NVGcolor SCHEME_CYAN = nvgRGB(0x22, 0xe6, 0xef); static const NVGcolor SCHEME_BLUE = nvgRGB(0x29, 0xb2, 0xef); static const NVGcolor SCHEME_PURPLE = nvgRGB(0xd5, 0x2b, 0xed); diff --git a/include/discord.hpp b/include/discord.hpp index d4ceb4ee..74b76b9e 100644 --- a/include/discord.hpp +++ b/include/discord.hpp @@ -7,8 +7,8 @@ namespace rack { namespace discord { -void init(); -void destroy(); +PRIVATE void init(); +PRIVATE void destroy(); } // namespace discord diff --git a/include/engine/Cable.hpp b/include/engine/Cable.hpp index 0e85d607..1b86e137 100644 --- a/include/engine/Cable.hpp +++ b/include/engine/Cable.hpp @@ -20,7 +20,7 @@ struct Cable { json_t* toJson(); void fromJson(json_t* rootJ); - INTERNAL static void jsonStripIds(json_t* rootJ); + PRIVATE static void jsonStripIds(json_t* rootJ); }; diff --git a/include/engine/Engine.hpp b/include/engine/Engine.hpp index 9b3058f4..a50f3874 100644 --- a/include/engine/Engine.hpp +++ b/include/engine/Engine.hpp @@ -23,14 +23,14 @@ struct Engine { struct Internal; Internal* internal; - Engine(); - ~Engine(); + PRIVATE Engine(); + PRIVATE ~Engine(); /** Removes all modules and cables. Write-locks. */ void clear(); - INTERNAL void clear_NoLock(); + PRIVATE void clear_NoLock(); /** Advances the engine by `frames` frames. Only call this method from the master module. Read-locks. Also locks so only one stepBlock() can be called simultaneously or recursively. @@ -42,7 +42,7 @@ struct Engine { Write-locks. */ void setMasterModule(Module* module); - INTERNAL void setMasterModule_NoLock(Module* module); + PRIVATE void setMasterModule_NoLock(Module* module); Module* getMasterModule(); /** Returns the sample rate used by the engine for stepping each module. @@ -51,7 +51,7 @@ struct Engine { /** Sets the sample rate to step the modules. Write-locks. */ - INTERNAL void setSampleRate(float sampleRate); + PRIVATE void setSampleRate(float sampleRate); /** Sets the sample rate if the sample rate in the settings is "Auto". Write-locks. */ @@ -116,7 +116,7 @@ struct Engine { Write-locks. */ void removeModule(Module* module); - INTERNAL void removeModule_NoLock(Module* module); + PRIVATE void removeModule_NoLock(Module* module); /** Checks whether a Module is in the rack. Read-locks. */ @@ -173,7 +173,7 @@ struct Engine { Write-locks. */ void removeCable(Cable* cable); - INTERNAL void removeCable_NoLock(Cable* cable); + PRIVATE void removeCable_NoLock(Cable* cable); /** Checks whether a Cable is in the rack. Read-locks. */ @@ -203,7 +203,7 @@ struct Engine { Write-locks. */ void removeParamHandle(ParamHandle* paramHandle); - INTERNAL void removeParamHandle_NoLock(ParamHandle* paramHandle); + PRIVATE void removeParamHandle_NoLock(ParamHandle* paramHandle); /** Returns the unique ParamHandle for the given paramId Read-locks. */ @@ -229,7 +229,7 @@ struct Engine { /** If no master module is set, the fallback Engine thread will step blocks, using the CPU clock for timing. */ - void startFallbackThread(); + PRIVATE void startFallbackThread(); }; diff --git a/include/engine/Module.hpp b/include/engine/Module.hpp index 1de1c384..b8742691 100644 --- a/include/engine/Module.hpp +++ b/include/engine/Module.hpp @@ -440,12 +440,12 @@ struct Module { virtual void onSampleRateChange() {} bool isBypassed(); - INTERNAL void setBypassed(bool bypassed); - INTERNAL const float* meterBuffer(); - INTERNAL int meterLength(); - INTERNAL int meterIndex(); - INTERNAL void doProcess(const ProcessArgs& args); - INTERNAL static void jsonStripIds(json_t* rootJ); + PRIVATE void setBypassed(bool bypassed); + PRIVATE const float* meterBuffer(); + PRIVATE int meterLength(); + PRIVATE int meterIndex(); + PRIVATE void doProcess(const ProcessArgs& args); + PRIVATE static void jsonStripIds(json_t* rootJ); }; diff --git a/include/gamepad.hpp b/include/gamepad.hpp index d52c9d75..4c6b3fc6 100644 --- a/include/gamepad.hpp +++ b/include/gamepad.hpp @@ -7,8 +7,8 @@ namespace rack { namespace gamepad { -void init(); -void step(); +PRIVATE void init(); +PRIVATE void step(); } // namespace gamepad diff --git a/include/history.hpp b/include/history.hpp index 49612053..2763079a 100644 --- a/include/history.hpp +++ b/include/history.hpp @@ -166,9 +166,9 @@ struct State { /** Action index of saved patch state. */ int savedIndex; - State(); - ~State(); - void clear(); + PRIVATE State(); + PRIVATE ~State(); + PRIVATE void clear(); void push(Action* action); void undo(); void redo(); diff --git a/include/keyboard.hpp b/include/keyboard.hpp index 1bd47d99..608789d6 100644 --- a/include/keyboard.hpp +++ b/include/keyboard.hpp @@ -8,7 +8,7 @@ namespace rack { namespace keyboard { -void init(); +PRIVATE void init(); void press(int key); void release(int key); /** pos is in the unit box. */ diff --git a/include/library.hpp b/include/library.hpp index 35cd1884..e7127a9f 100644 --- a/include/library.hpp +++ b/include/library.hpp @@ -17,19 +17,19 @@ struct UpdateInfo { }; -void init(); -void destroy(); +PRIVATE void init(); +PRIVATE void destroy(); -void checkAppUpdate(); +PRIVATE void checkAppUpdate(); bool isAppUpdateAvailable(); bool isLoggedIn(); -void logIn(std::string email, std::string password); -void logOut(); -void checkUpdates(); -bool hasUpdates(); -void syncUpdate(std::string slug); -void syncUpdates(); +PRIVATE void logIn(std::string email, std::string password); +PRIVATE void logOut(); +PRIVATE void checkUpdates(); +PRIVATE bool hasUpdates(); +PRIVATE void syncUpdate(std::string slug); +PRIVATE void syncUpdates(); extern std::string appVersion; diff --git a/include/logger.hpp b/include/logger.hpp index 5f2cf11b..d47725fc 100644 --- a/include/logger.hpp +++ b/include/logger.hpp @@ -1,4 +1,5 @@ #pragma once +#include /** Example usage: @@ -30,8 +31,8 @@ enum Level { FATAL_LEVEL }; -void init(); -void destroy(); +PRIVATE void init(); +PRIVATE void destroy(); /** Do not use this function directly. Use the macros above. Thread-safe, meaning messages cannot overlap each other in the log. */ @@ -39,7 +40,7 @@ __attribute__((format(printf, 5, 6))) void log(Level level, const char* filename, int line, const char* func, const char* format, ...); /** Returns whether the last log file failed to end properly, due to a possible crash. */ -bool wasTruncated(); +PRIVATE bool wasTruncated(); } // namespace logger diff --git a/include/midi.hpp b/include/midi.hpp index 81e344e9..39b46f99 100644 --- a/include/midi.hpp +++ b/include/midi.hpp @@ -288,8 +288,8 @@ struct Output : Port { }; -void init(); -void destroy(); +PRIVATE void init(); +PRIVATE void destroy(); /** Registers a new MIDI driver. Takes pointer ownership. */ void addDriver(int driverId, Driver* driver); std::vector getDriverIds(); diff --git a/include/network.hpp b/include/network.hpp index 889734e0..2ba8440b 100644 --- a/include/network.hpp +++ b/include/network.hpp @@ -20,8 +20,8 @@ enum Method { METHOD_DELETE, }; -void init(); -void destroy(); +PRIVATE void init(); +PRIVATE void destroy(); /** Requests a JSON API URL over HTTP(S), using the data as the query (GET) or the body (POST, etc) Caller must json_decref() if return value is non-NULL. */ diff --git a/include/patch.hpp b/include/patch.hpp index 22bb8bde..123f753e 100644 --- a/include/patch.hpp +++ b/include/patch.hpp @@ -25,9 +25,9 @@ struct Manager { /** Append to this while loading/saving a patch to display messages to the user after success. */ std::string warningLog; - Manager(); - ~Manager(); - void launch(std::string pathArg); + PRIVATE Manager(); + PRIVATE ~Manager(); + PRIVATE void launch(std::string pathArg); /** Clears the patch. */ void clear(); /** Saves the patch and nothing else. */ diff --git a/include/plugin.hpp b/include/plugin.hpp index 62b225b3..e6178fe1 100644 --- a/include/plugin.hpp +++ b/include/plugin.hpp @@ -11,8 +11,8 @@ namespace rack { namespace plugin { -void init(); -void destroy(); +PRIVATE void init(); +PRIVATE void destroy(); /** Finds a loaded Plugin by slug. */ Plugin* getPlugin(const std::string& pluginSlug); /** Finds a loaded Model by plugin and model slug. */ diff --git a/include/rack.hpp b/include/rack.hpp index 9c3b56cf..eff8c1b4 100644 --- a/include/rack.hpp +++ b/include/rack.hpp @@ -6,6 +6,15 @@ The following headers are the "public" API of Rack. Directly including Rack headers other than rack.hpp in your plugin is unsupported/unstable, since filenames and locations of symbols may change in any Rack version. */ +#ifdef PRIVATE +#error "Plugins must only include rack.hpp. Including other Rack headers is unsupported." +#endif + +/** Functions and symbols with the PRIVATE attribute should not be called/used by plugins. +*/ +#define PRIVATE __attribute__((error("Using internal Rack function or symbol"))) + + #include #include #include @@ -113,14 +122,6 @@ Directly including Rack headers other than rack.hpp in your plugin is unsupporte #include -#undef INTERNAL -#if defined ARCH_WIN - #define INTERNAL __attribute__((error("Using internal Rack function or symbol"))) -#else - #define INTERNAL __attribute__((visibility("hidden"))) __attribute__((error("Using internal Rack function or symbol"))) -#endif - - namespace rack { diff --git a/include/rtaudio.hpp b/include/rtaudio.hpp index 7a5da39c..899f507d 100644 --- a/include/rtaudio.hpp +++ b/include/rtaudio.hpp @@ -5,7 +5,7 @@ namespace rack { -void rtaudioInit(); +PRIVATE void rtaudioInit(); } // namespace rack diff --git a/include/rtmidi.hpp b/include/rtmidi.hpp index 839b289d..83ef0d0c 100644 --- a/include/rtmidi.hpp +++ b/include/rtmidi.hpp @@ -5,7 +5,7 @@ namespace rack { -void rtmidiInit(); +PRIVATE void rtmidiInit(); } // namespace rack diff --git a/include/settings.hpp b/include/settings.hpp index 05b79925..d57eea3d 100644 --- a/include/settings.hpp +++ b/include/settings.hpp @@ -101,11 +101,11 @@ extern std::map> moduleWhitelist; bool isModuleWhitelisted(const std::string& pluginSlug, const std::string& moduleSlug); -void init(); -json_t* toJson(); -void fromJson(json_t* rootJ); -void save(std::string path = ""); -void load(std::string path = ""); +PRIVATE void init(); +PRIVATE json_t* toJson(); +PRIVATE void fromJson(json_t* rootJ); +PRIVATE void save(std::string path = ""); +PRIVATE void load(std::string path = ""); } // namespace settings diff --git a/include/system.hpp b/include/system.hpp index db4eec63..d3be5945 100644 --- a/include/system.hpp +++ b/include/system.hpp @@ -189,7 +189,7 @@ The launched process will continue running if the current process is closed. */ void runProcessDetached(const std::string& path); -void init(); +PRIVATE void init(); } // namespace system diff --git a/include/ui/common.hpp b/include/ui/common.hpp index c07557ba..fc601e07 100644 --- a/include/ui/common.hpp +++ b/include/ui/common.hpp @@ -21,8 +21,8 @@ namespace rack { namespace ui { -void init(); -void destroy(); +PRIVATE void init(); +PRIVATE void destroy(); void setTheme(NVGcolor bg, NVGcolor fg); diff --git a/include/window/Window.hpp b/include/window/Window.hpp index 6302b9bb..fbcccb03 100644 --- a/include/window/Window.hpp +++ b/include/window/Window.hpp @@ -65,19 +65,19 @@ struct Window { float windowRatio = 1.f; std::shared_ptr uiFont; - Window(); - ~Window(); + PRIVATE Window(); + PRIVATE ~Window(); math::Vec getSize(); void setSize(math::Vec size); - void run(); - void step(); + PRIVATE void run(); + PRIVATE void step(); void activateContext(); /** Takes a screenshot of the screen and saves it to a PNG file. */ - void screenshot(const std::string& screenshotPath); + PRIVATE void screenshot(const std::string& screenshotPath); /** Saves a PNG image of all modules to `screenshotsDir//.png`. Skips screenshot if the file already exists. */ - void screenshotModules(const std::string& screenshotsDir, float zoom = 1.f); + PRIVATE void screenshotModules(const std::string& screenshotsDir, float zoom = 1.f); /** Request Window to be closed after rendering the current frame. */ void close(); void cursorLock(); @@ -100,12 +100,12 @@ struct Window { return Svg::load(filename); } - INTERNAL bool& fbDirtyOnSubpixelChange(); + PRIVATE bool& fbDirtyOnSubpixelChange(); }; -void init(); -void destroy(); +PRIVATE void init(); +PRIVATE void destroy(); } // namespace window