Skip to content

Commit

Permalink
Merge pull request #135 from 4ms/hetrickcv-port-3
Browse files Browse the repository at this point in the history
Add HetrickCV modules
  • Loading branch information
danngreen authored Oct 10, 2023
2 parents 63b6d58 + bca848c commit 843da99
Show file tree
Hide file tree
Showing 174 changed files with 37,244 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
[submodule "firmware/src/VCV_adaptor/simde"]
path = firmware/src/VCV_adaptor/simde
url = https://github.com/simd-everywhere/simde.git
[submodule "firmware/vcv_ports/hetrickcv"]
path = firmware/vcv_ports/hetrickcv
url = https://github.com/mhetrick/hetrickcv.git
[submodule "firmware/lib/jansson/jansson"]
path = firmware/lib/jansson/jansson
url = https://github.com/4ms/jansson.git
5 changes: 5 additions & 0 deletions firmware/src/VCV_adaptor/app/ModuleWidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace rack

struct ModuleWidget : widget::Widget {
engine::Module *module;
widget::Widget panel;

void setModule(engine::Module *m) {
module = m;
Expand All @@ -22,6 +23,10 @@ struct ModuleWidget : widget::Widget {
void setPanel(std::shared_ptr<window::Svg> svg) {
}

widget::Widget *getPanel() {
return &panel;
}

void place_at(std::vector<MetaModule::Element> &elements, int id, const MetaModule::Element &el) {
if (id < 0)
return;
Expand Down
25 changes: 25 additions & 0 deletions firmware/src/VCV_adaptor/app/SvgScrew.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once
#include "VCV_adaptor/settings.hpp"
#include "VCV_adaptor/widget/Widget.hh"
#include "common.hpp"

namespace rack::app
{

/** If you don't add these to your ModuleWidget, they will fall out of the rack... */
struct SvgScrew : widget::Widget {
widget::FramebufferWidget *fb;
widget::SvgWidget *sw;

void setSvg(std::shared_ptr<window::Svg> svg) {
}
};

struct ThemedSvgScrew : SvgScrew {
void setSvg(std::shared_ptr<window::Svg> lightSvg, std::shared_ptr<window::Svg> darkSvg) {
}
void step() override {
}
};

} // namespace rack::app
11 changes: 11 additions & 0 deletions firmware/src/VCV_adaptor/app/Widget.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ struct SvgPort : PortWidget {
}
};

struct ThemedSvgPort : SvgPort {
std::shared_ptr<window::Svg> lightSvg;
std::shared_ptr<window::Svg> darkSvg;

void setSvg(std::shared_ptr<window::Svg> lightSvg, std::shared_ptr<window::Svg> darkSvg) {
}

void step() override {
}
};

// Lights

struct ModuleLightWidget : widget::Widget {
Expand Down
109 changes: 106 additions & 3 deletions firmware/src/VCV_adaptor/nanovg.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,116 @@ struct NVGcolor {
};
};

struct NVGpaint {
float xform[6];
float extent[2];
float radius;
float feather;
NVGcolor innerColor;
NVGcolor outerColor;
int image;
};
typedef struct NVGpaint NVGpaint;

enum NVGwinding {
NVG_CCW = 1, // Winding for solid shapes
NVG_CW = 2, // Winding for holes
};

enum NVGsolidity {
NVG_SOLID = 1, // CCW
NVG_HOLE = 2, // CW
};

enum NVGlineCap {
NVG_BUTT,
NVG_ROUND,
NVG_SQUARE,
NVG_BEVEL,
NVG_MITER,
};

enum NVGalign {
// Horizontal align
NVG_ALIGN_LEFT = 1 << 0, // Default, align text horizontally to left.
NVG_ALIGN_CENTER = 1 << 1, // Align text horizontally to center.
NVG_ALIGN_RIGHT = 1 << 2, // Align text horizontally to right.
// Vertical align
NVG_ALIGN_TOP = 1 << 3, // Align text vertically to top.
NVG_ALIGN_MIDDLE = 1 << 4, // Align text vertically to middle.
NVG_ALIGN_BOTTOM = 1 << 5, // Align text vertically to bottom.
NVG_ALIGN_BASELINE = 1 << 6, // Default, align text vertically to baseline.
};

enum NVGblendFactor {
NVG_ZERO = 1 << 0,
NVG_ONE = 1 << 1,
NVG_SRC_COLOR = 1 << 2,
NVG_ONE_MINUS_SRC_COLOR = 1 << 3,
NVG_DST_COLOR = 1 << 4,
NVG_ONE_MINUS_DST_COLOR = 1 << 5,
NVG_SRC_ALPHA = 1 << 6,
NVG_ONE_MINUS_SRC_ALPHA = 1 << 7,
NVG_DST_ALPHA = 1 << 8,
NVG_ONE_MINUS_DST_ALPHA = 1 << 9,
NVG_SRC_ALPHA_SATURATE = 1 << 10,
};

enum NVGcompositeOperation {
NVG_SOURCE_OVER,
NVG_SOURCE_IN,
NVG_SOURCE_OUT,
NVG_ATOP,
NVG_DESTINATION_OVER,
NVG_DESTINATION_IN,
NVG_DESTINATION_OUT,
NVG_DESTINATION_ATOP,
NVG_LIGHTER,
NVG_COPY,
NVG_XOR,
};

struct NVGcompositeOperationState {
int srcRGB;
int dstRGB;
int srcAlpha;
int dstAlpha;
};

struct NVGglyphPosition {
const char *str; // Position of the glyph in the input string.
float x; // The x-coordinate of the logical glyph position.
float minx, maxx; // The bounds of the glyph shape.
};

struct NVGtextRow {
const char *start; // Pointer to the input text where the row starts.
const char *end; // Pointer to the input text where the row ends (one past the last character).
const char *next; // Pointer to the beginning of the next row.
float width; // Logical width of the row.
float minx,
maxx; // Actual bounds of the row. Logical with and bounds can differ because of kerning and some parts over extending.
};

enum NVGimageFlags {
NVG_IMAGE_GENERATE_MIPMAPS = 1 << 0, // Generate mipmaps during creation of the image.
NVG_IMAGE_REPEATX = 1 << 1, // Repeat image in X direction.
NVG_IMAGE_REPEATY = 1 << 2, // Repeat image in Y direction.
NVG_IMAGE_FLIPY = 1 << 3, // Flips (inverses) image in Y direction when rendered.
NVG_IMAGE_PREMULTIPLIED = 1 << 4, // Image data has premultiplied alpha.
NVG_IMAGE_NEAREST = 1 << 5, // Image interpolation is Nearest instead Linear
};

struct NVGcontext {};
struct NVGLUframebuffer {};
struct NVGglyphPosition {};
struct NVGtextRow {};
struct NVGpaint {};

// clang-format off
inline void nvgBeginFrame(NVGcontext* ctx, float windowWidth, float windowHeight, float devicePixelRatio) {}
inline void nvgCancelFrame(NVGcontext* ctx) {}
inline void nvgEndFrame(NVGcontext* ctx) {}
inline void nvgGlobalCompositeOperation(NVGcontext* ctx, int op) {}
inline void nvgGlobalCompositeBlendFunc(NVGcontext* ctx, int sfactor, int dfactor) {}
inline void nvgGlobalCompositeBlendFuncSeparate(NVGcontext* ctx, int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) {}
inline NVGcolor nvgRGB(unsigned char r, unsigned char g, unsigned char b) { return {}; }
inline NVGcolor nvgRGBf(float r, float g, float b) { return {}; }
inline NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a) { return {}; }
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/VCV_adaptor/rack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Directly including Rack headers other than rack.hpp in your plugin is unsupporte
#include "window.hpp"
// #include "audio.hpp"
// #include "midi.hpp"
// #include "settings.hpp"
#include "helpers.hpp"
#include "settings.hpp"
// #include "componentlibrary.hpp"

// #include "widget/TransparentWidget.hpp"
Expand Down
125 changes: 125 additions & 0 deletions firmware/src/VCV_adaptor/settings.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#pragma once
#include "color.hpp"
#include "common.hpp"
#include "json.hpp"
#include "math.hpp"
#include <list>
#include <map>
#include <set>
#include <tuple>
#include <vector>

namespace rack
{

struct settings {

// Runtime state, not serialized.

/** Path to settings.json */
// static inline std::string settingsPath;
static inline bool devMode;
static inline bool headless;
static inline bool isPlugin;

// Persistent state, serialized to settings.json.

/** Launches Rack without loading plugins or the autosave patch. Always set to false when settings are saved. */
static inline bool safeMode;
/** vcvrack.com user token */
static inline std::string token;
/** Whether the window is maximized */
static inline bool windowMaximized;
/** Size of window in pixels */
static inline math::Vec windowSize;
/** Position in window in pixels */
static inline math::Vec windowPos;
/** Reverse the zoom scroll direction */
static inline bool invertZoom;
/** Ratio between UI pixel and physical screen pixel.
0 for auto.
*/
static inline float pixelRatio;
/** Name of UI theme, specified in ui::refreshTheme() */
static inline std::string uiTheme;
/** Opacity of cables in the range [0, 1] */
static inline float cableOpacity;
/** Straightness of cables in the range [0, 1]. Unitless and arbitrary. */
static inline float cableTension;
static inline float rackBrightness;
static inline float haloBrightness;
/** Allows rack to hide and lock the cursor position when dragging knobs etc. */
static inline bool allowCursorLock;
enum KnobMode {
KNOB_MODE_LINEAR,
KNOB_MODE_SCALED_LINEAR,
KNOB_MODE_ROTARY_ABSOLUTE,
KNOB_MODE_ROTARY_RELATIVE,
};
static inline KnobMode knobMode;
static inline bool knobScroll;
static inline float knobLinearSensitivity;
static inline float knobScrollSensitivity;
static inline float sampleRate;
static inline int threadCount;
static inline bool tooltips;
static inline bool cpuMeter;
static inline bool lockModules;
static inline bool squeezeModules;
static inline bool preferDarkPanels;
/** Maximum screen redraw frequency in Hz, or 0 for unlimited. */
static inline float frameRateLimit;
/** Interval between autosaves in seconds. */
static inline float autosaveInterval;
static inline bool skipLoadOnLaunch;
static inline std::list<std::string> recentPatchPaths;
static inline std::vector<NVGcolor> cableColors;
static inline bool autoCheckUpdates;
static inline bool showTipsOnLaunch;
static inline int tipIndex;
enum BrowserSort {
BROWSER_SORT_UPDATED,
BROWSER_SORT_LAST_USED,
BROWSER_SORT_MOST_USED,
BROWSER_SORT_BRAND,
BROWSER_SORT_NAME,
BROWSER_SORT_RANDOM,
};
static inline BrowserSort browserSort;
static inline float browserZoom;
static inline json_t *pluginSettingsJ;

struct ModuleInfo {
bool enabled = true;
bool favorite = false;
int added = 0;
double lastAdded = NAN;
};
/** pluginSlug -> (moduleSlug -> ModuleInfo) */
static inline std::map<std::string, std::map<std::string, ModuleInfo>> moduleInfos;
/** Returns a ModuleInfo if exists for the given slugs.
*/
ModuleInfo *getModuleInfo(const std::string &pluginSlug, const std::string &moduleSlug);

/** The VCV JSON API returns the data structure
{pluginSlug: [moduleSlugs] or true}
where "true" represents that the user is subscribed to the plugin (all modules and future modules).
C++ isn't weakly typed, so we need the PluginWhitelist data structure to store this information.
*/
struct PluginWhitelist {
bool subscribed = false;
std::set<std::string> moduleSlugs;
};
static inline std::map<std::string, PluginWhitelist> moduleWhitelist;

bool isModuleWhitelisted(const std::string &pluginSlug, const std::string &moduleSlug);

// PRIVATE void init();
// PRIVATE void destroy();
// PRIVATE json_t *toJson();
// PRIVATE void fromJson(json_t *rootJ);
// PRIVATE void save(std::string path = "");
// PRIVATE void load(std::string path = "");
};

} // namespace rack
42 changes: 41 additions & 1 deletion firmware/src/VCV_adaptor/widget/Widget.hh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ struct Widget {
}
virtual void onDoubleClick(const DoubleClickEvent &e) {
}
bool hasChild(Widget *child) {
return false;
}
void addChild(Widget *child) {
}
void addChildBottom(Widget *child) {
}
void addChildBelow(Widget *child, Widget *sibling) {
}
void addChildAbove(Widget *child, Widget *sibling) {
}
void removeChild(Widget *child) {
}
void clearChildren() {
}

MetaModule::Element element;

Expand All @@ -57,7 +72,32 @@ struct Widget {

struct OpaqueWidget : Widget {};
struct TransparentWidget : Widget {};
struct FramebufferWidget : Widget {};
struct FramebufferWidget : Widget {
bool dirty = true;
bool bypassed = false;
float oversample = 1.0;
bool dirtyOnSubpixelChange = true;
math::Vec viewportMargin = math::Vec(INFINITY, INFINITY);
void setDirty(bool dirty = true) {
}
int getImageHandle() {
return 0;
}
NVGLUframebuffer *getFramebuffer() {
return nullptr;
}
math::Vec getFramebufferSize() {
return {0, 0};
}
void deleteFramebuffer() {
}
void render(math::Vec scale = math::Vec(1, 1),
math::Vec offsetF = math::Vec(0, 0),
math::Rect clipBox = math::Rect::inf()) {
}
virtual void drawFramebuffer() {
}
};

// Should be called SvgParamWidget
struct SvgWidget : Widget {
Expand Down
Loading

0 comments on commit 843da99

Please sign in to comment.