From 6aedd9d2f3162399a42b24a428168935584b1d01 Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 30 Dec 2022 17:37:52 +0000 Subject: [PATCH] Cleanup, fix MOD builds Signed-off-by: falkTX --- src/CardinalPlugin.cpp | 2 +- src/CardinalRemote.cpp | 25 +++++++++++++++++++------ src/CardinalUI.cpp | 2 ++ src/WindowParameters.hpp | 6 +----- src/override/Window.cpp | 38 +++++++++++++++++++++++--------------- 5 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/CardinalPlugin.cpp b/src/CardinalPlugin.cpp index 905cc61..85c6e9c 100644 --- a/src/CardinalPlugin.cpp +++ b/src/CardinalPlugin.cpp @@ -66,7 +66,7 @@ static const constexpr uint kCardinalStateCount = kCardinalStateBaseCount; extern const std::string CARDINAL_VERSION; namespace rack { -#if DISTRHO_PLUGIN_HAS_UI && ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS +#if CARDINAL_VARIANT_MINI || defined(HEADLESS) namespace app { rack::widget::Widget* createMenuBar() { return new rack::widget::Widget; } } diff --git a/src/CardinalRemote.cpp b/src/CardinalRemote.cpp index c1313c2..9dbb700 100644 --- a/src/CardinalRemote.cpp +++ b/src/CardinalRemote.cpp @@ -32,11 +32,12 @@ # undef HAVE_LIBLO #endif -#ifdef HAVE_LIBLO -# include +#if (CARDINAL_VARIANT_MINI && !defined(HEADLESS)) || defined(HAVE_LIBLO) +# define CARDINAL_REMOTE_ENABLED #endif #ifdef HAVE_LIBLO +# include // # define REMOTE_HOST "localhost" # define REMOTE_HOST "192.168.51.1" #endif @@ -63,6 +64,7 @@ static int osc_handler(const char* const path, const char* const types, lo_arg** RemoteDetails* getRemote() { +#ifdef CARDINAL_REMOTE_ENABLED CardinalPluginContext* const context = static_cast(APP); DISTRHO_SAFE_ASSERT_RETURN(context != nullptr, nullptr); @@ -70,10 +72,14 @@ RemoteDetails* getRemote() DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr, nullptr); return ui->remoteDetails; +#else + return nullptr; +#endif } bool connectToRemote() { +#ifdef CARDINAL_REMOTE_ENABLED CardinalPluginContext* const context = static_cast(APP); DISTRHO_SAFE_ASSERT_RETURN(context != nullptr, false); @@ -82,7 +88,7 @@ bool connectToRemote() RemoteDetails* remoteDetails = ui->remoteDetails; -#if CARDINAL_VARIANT_MINI + #if CARDINAL_VARIANT_MINI if (remoteDetails == nullptr) { ui->remoteDetails = remoteDetails = new RemoteDetails; @@ -90,7 +96,7 @@ bool connectToRemote() remoteDetails->connected = true; remoteDetails->autoDeploy = true; } -#elif defined(HAVE_LIBLO) + #elif defined(HAVE_LIBLO) if (remoteDetails == nullptr) { const lo_server oscServer = lo_server_new_with_proto(nullptr, LO_UDP, nullptr); @@ -112,9 +118,12 @@ bool connectToRemote() lo_send(addr, "/hello", ""); lo_address_free(addr); } -#endif + #endif return remoteDetails != nullptr; +#else + return false; +#endif } void disconnectFromRemote(RemoteDetails* const remote) @@ -138,6 +147,7 @@ void idleRemote(RemoteDetails* const remote) void sendParamChangeToRemote(RemoteDetails* const remote, int64_t moduleId, int paramId, float value) { +#ifdef CARDINAL_REMOTE_ENABLED #if CARDINAL_VARIANT_MINI char paramBuf[512] = {}; { @@ -153,10 +163,12 @@ void sendParamChangeToRemote(RemoteDetails* const remote, int64_t moduleId, int lo_address_free(addr); #endif +#endif } void sendFullPatchToRemote(RemoteDetails* const remote) { +#ifdef CARDINAL_REMOTE_ENABLED CardinalPluginContext* const context = static_cast(APP); DISTRHO_SAFE_ASSERT_RETURN(context != nullptr,); @@ -204,11 +216,12 @@ void sendFullPatchToRemote(RemoteDetails* const remote) lo_address_free(addr); #endif +#endif } void sendScreenshotToRemote(RemoteDetails*, const char* const screenshot) { -#ifdef HAVE_LIBLO +#if defined(HAVE_LIBLO) && ! CARDINAL_VARIANT_MINI const lo_address addr = lo_address_new_with_proto(LO_UDP, REMOTE_HOST, CARDINAL_DEFAULT_REMOTE_HOST_PORT); DISTRHO_SAFE_ASSERT_RETURN(addr != nullptr,); diff --git a/src/CardinalUI.cpp b/src/CardinalUI.cpp index b33ff76..6852146 100644 --- a/src/CardinalUI.cpp +++ b/src/CardinalUI.cpp @@ -78,6 +78,8 @@ START_NAMESPACE_DISTRHO // -------------------------------------------------------------------------------------------------------------------- #if ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS +uint32_t Plugin::getBufferSize() const noexcept { return 0; } +double Plugin::getSampleRate() const noexcept { return 0.0; } const char* Plugin::getBundlePath() const noexcept { return nullptr; } bool Plugin::isSelfTestInstance() const noexcept { return false; } bool Plugin::writeMidiEvent(const MidiEvent&) noexcept { return false; } diff --git a/src/WindowParameters.hpp b/src/WindowParameters.hpp index 55c2832..d8f6780 100644 --- a/src/WindowParameters.hpp +++ b/src/WindowParameters.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Cardinal Plugin - * Copyright (C) 2021 Filipe Coelho + * 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 @@ -15,10 +15,6 @@ * For a full copy of the GNU General Public License see the LICENSE file. */ -#ifdef HEADLESS -# error wrong include -#endif - #pragma once #include "DistrhoUtils.hpp" diff --git a/src/override/Window.cpp b/src/override/Window.cpp index 2591bd7..63908b7 100644 --- a/src/override/Window.cpp +++ b/src/override/Window.cpp @@ -42,6 +42,21 @@ # undef DEBUG #endif +#include "DistrhoUI.hpp" +#include "Application.hpp" +#include "extra/String.hpp" +#include "../CardinalCommon.hpp" +#include "../PluginContext.hpp" +#include "../WindowParameters.hpp" + +#ifndef DGL_NO_SHARED_RESOURCES +# include "src/Resources.hpp" +#endif + +#if !(defined(DGL_USE_GLES) || CARDINAL_VARIANT_MINI) + +#define CARDINAL_WINDOW_CAN_GENERATE_SCREENSHOTS + // comment out if wanting to generate a local screenshot.png #define STBI_WRITE_NO_STDIO @@ -52,15 +67,6 @@ #define STB_IMAGE_WRITE_IMPLEMENTATION #include "stb_image_write.h" -#include "DistrhoUI.hpp" -#include "Application.hpp" -#include "extra/String.hpp" -#include "../CardinalCommon.hpp" -#include "../PluginContext.hpp" -#include "../WindowParameters.hpp" - -#ifndef DGL_NO_SHARED_RESOURCES -# include "src/Resources.hpp" #endif #ifdef DISTRHO_OS_WASM @@ -133,6 +139,7 @@ std::shared_ptr Image::load(const std::string& filename) { } +#ifdef CARDINAL_WINDOW_CAN_GENERATE_SCREENSHOTS enum ScreenshotStep { kScreenshotStepNone, kScreenshotStepStarted, @@ -140,6 +147,7 @@ enum ScreenshotStep { kScreenshotStepSecondPass, kScreenshotStepSaving }; +#endif struct Window::Internal { @@ -165,7 +173,7 @@ struct Window::Internal { int frame = 0; int frameSwapInterval = 1; -#ifndef DGL_USE_GLES +#ifdef CARDINAL_WINDOW_CAN_GENERATE_SCREENSHOTS int generateScreenshotStep = kScreenshotStepNone; #endif double monitorRefreshRate = 60.0; @@ -538,7 +546,7 @@ void Window::run() { } -#ifndef DGL_USE_GLES +#ifdef CARDINAL_WINDOW_CAN_GENERATE_SCREENSHOTS static void Window__flipBitmap(uint8_t* pixels, const int width, const int height, const int depth) { for (int y = 0; y < height / 2; y++) { const int flipY = height - y - 1; @@ -634,7 +642,7 @@ void Window::step() { APP->event->handleDirty(); } -#ifndef DGL_USE_GLES +#ifdef CARDINAL_WINDOW_CAN_GENERATE_SCREENSHOTS // Hide menu and background if generating screenshot if (internal->generateScreenshotStep == kScreenshotStepStarted) { #ifdef CARDINAL_TRANSPARENT_SCREENSHOTS @@ -684,7 +692,7 @@ void Window::step() { ++internal->frame; -#ifndef DGL_USE_GLES +#ifdef CARDINAL_WINDOW_CAN_GENERATE_SCREENSHOTS if (internal->generateScreenshotStep != kScreenshotStepNone) { ++internal->generateScreenshotStep; @@ -799,7 +807,7 @@ bool Window::isFullScreen() { if (emscripten_get_fullscreen_status(&status) == EMSCRIPTEN_RESULT_SUCCESS) return status.isFullscreen; return false; -#elif defined(CARDINAL_TRANSPARENT_SCREENSHOTS) && !defined(DGL_USE_GLES) +#elif defined(CARDINAL_WINDOW_CAN_GENERATE_SCREENSHOTS) && defined(CARDINAL_TRANSPARENT_SCREENSHOTS) return internal->generateScreenshotStep != kScreenshotStepNone; #else return false; @@ -880,7 +888,7 @@ int& Window::fbCount() { void generateScreenshot() { -#ifndef DGL_USE_GLES +#ifdef CARDINAL_WINDOW_CAN_GENERATE_SCREENSHOTS APP->window->internal->generateScreenshotStep = kScreenshotStepStarted; #endif }