diff --git a/Makefile b/Makefile index d4cfdc01..d293180a 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ RACK_DIR ?= . VERSION = 1.dev -FLAGS += -DVERSION=$(VERSION) +FLAGS += -DAPP_VERSION=$(VERSION) FLAGS += -Iinclude FLAGS += -Idep/include -Idep/lib/libzip/include diff --git a/include/app.hpp b/include/app.hpp index 366ddaa5..ca2653e0 100644 --- a/include/app.hpp +++ b/include/app.hpp @@ -13,12 +13,18 @@ namespace history { struct State; } -struct Scene; + struct Engine; struct Window; struct PatchManager; +namespace app { + + +struct Scene; + + /** Contains the application state */ struct App { event::State *event = NULL; @@ -33,10 +39,15 @@ struct App { }; -void appInit(); -void appDestroy(); -/** Returns the global context */ -App *app(); +void init(); +void destroy(); +/** Returns the global App pointer */ +App *get(); + + +/** Accesses the global App pointer */ +#define APP rack::app::get() +} // namespace app } // namespace rack diff --git a/include/app/AudioWidget.hpp b/include/app/AudioWidget.hpp index 22940af0..aba59693 100644 --- a/include/app/AudioWidget.hpp +++ b/include/app/AudioWidget.hpp @@ -11,6 +11,9 @@ namespace audio { } +namespace app { + + struct AudioWidget : LedDisplay { /** Not owned */ audio::IO *audioIO = NULL; @@ -26,4 +29,5 @@ struct AudioWidget : LedDisplay { }; +} // namespace app } // namespace rack diff --git a/include/app/CableWidget.hpp b/include/app/CableWidget.hpp index e82b0ff1..a982f986 100644 --- a/include/app/CableWidget.hpp +++ b/include/app/CableWidget.hpp @@ -1,6 +1,6 @@ #pragma once #include "app/common.hpp" -#include "widgets/OpaqueWidget.hpp" +#include "widget/OpaqueWidget.hpp" #include "app/PortWidget.hpp" #include "app/ModuleWidget.hpp" #include "engine/Cable.hpp" @@ -8,9 +8,10 @@ namespace rack { +namespace app { -struct CableWidget : OpaqueWidget { +struct CableWidget : widget::OpaqueWidget { PortWidget *outputPort = NULL; PortWidget *inputPort = NULL; PortWidget *hoveredOutputPort = NULL; @@ -27,9 +28,10 @@ struct CableWidget : OpaqueWidget { math::Vec getInputPos(); json_t *toJson(); void fromJson(json_t *rootJ, const std::map &moduleWidgets); - void draw(const DrawContext &ctx) override; - void drawPlugs(const DrawContext &ctx); + void draw(const widget::DrawContext &ctx) override; + void drawPlugs(const widget::DrawContext &ctx); }; +} // namespace app } // namespace rack diff --git a/include/app/CircularShadow.hpp b/include/app/CircularShadow.hpp index bb48ad0f..afed3cec 100644 --- a/include/app/CircularShadow.hpp +++ b/include/app/CircularShadow.hpp @@ -1,17 +1,19 @@ #pragma once #include "app/common.hpp" -#include "widgets/TransparentWidget.hpp" +#include "widget/TransparentWidget.hpp" namespace rack { +namespace app { -struct CircularShadow : TransparentWidget { +struct CircularShadow : widget::TransparentWidget { float blurRadius; float opacity; CircularShadow(); - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; }; +} // namespace app } // namespace rack diff --git a/include/app/Knob.hpp b/include/app/Knob.hpp index 031d2730..1a748c90 100644 --- a/include/app/Knob.hpp +++ b/include/app/Knob.hpp @@ -5,6 +5,7 @@ namespace rack { +namespace app { /** Implements vertical dragging behavior for ParamWidgets */ @@ -27,4 +28,5 @@ struct Knob : ParamWidget { }; +} // namespace app } // namespace rack diff --git a/include/app/LedDisplay.hpp b/include/app/LedDisplay.hpp index 9ca1ed17..ef819c5b 100644 --- a/include/app/LedDisplay.hpp +++ b/include/app/LedDisplay.hpp @@ -1,40 +1,42 @@ #pragma once #include "app/common.hpp" -#include "widgets/Widget.hpp" -#include "widgets/TransparentWidget.hpp" +#include "widget/Widget.hpp" +#include "widget/TransparentWidget.hpp" #include "ui/TextField.hpp" namespace rack { +namespace app { -struct LedDisplay : Widget { - void draw(const DrawContext &ctx) override; +struct LedDisplay : widget::Widget { + void draw(const widget::DrawContext &ctx) override; }; -struct LedDisplaySeparator : TransparentWidget { +struct LedDisplaySeparator : widget::TransparentWidget { LedDisplaySeparator(); - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; }; -struct LedDisplayChoice : TransparentWidget { +struct LedDisplayChoice : widget::TransparentWidget { std::string text; std::shared_ptr font; math::Vec textOffset; NVGcolor color; LedDisplayChoice(); - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; void onButton(const event::Button &e) override; }; -struct LedDisplayTextField : TextField { +struct LedDisplayTextField : ui::TextField { std::shared_ptr font; math::Vec textOffset; NVGcolor color; LedDisplayTextField(); - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; int getTextPosition(math::Vec mousePos) override; }; +} // namespace app } // namespace rack diff --git a/include/app/LightWidget.hpp b/include/app/LightWidget.hpp index 2f1b7990..7dfabc39 100644 --- a/include/app/LightWidget.hpp +++ b/include/app/LightWidget.hpp @@ -1,19 +1,21 @@ #pragma once #include "app/common.hpp" -#include "widgets/TransparentWidget.hpp" +#include "widget/TransparentWidget.hpp" namespace rack { +namespace app { -struct LightWidget : TransparentWidget { +struct LightWidget : widget::TransparentWidget { NVGcolor bgColor = nvgRGBA(0, 0, 0, 0); NVGcolor color = nvgRGBA(0, 0, 0, 0); NVGcolor borderColor = nvgRGBA(0, 0, 0, 0); - void draw(const DrawContext &ctx) override; - virtual void drawLight(const DrawContext &ctx); - virtual void drawHalo(const DrawContext &ctx); + void draw(const widget::DrawContext &ctx) override; + virtual void drawLight(const widget::DrawContext &ctx); + virtual void drawHalo(const widget::DrawContext &ctx); }; +} // namespace app } // namespace rack diff --git a/include/app/MidiWidget.hpp b/include/app/MidiWidget.hpp index 14806ac7..19c89efe 100644 --- a/include/app/MidiWidget.hpp +++ b/include/app/MidiWidget.hpp @@ -11,6 +11,9 @@ namespace midi { } +namespace app { + + struct MidiWidget : LedDisplay { /** Not owned */ midi::IO *midiIO = NULL; @@ -24,4 +27,5 @@ struct MidiWidget : LedDisplay { }; +} // namespace app } // namespace rack diff --git a/include/app/ModuleBrowser.hpp b/include/app/ModuleBrowser.hpp index 01172e19..1f033605 100644 --- a/include/app/ModuleBrowser.hpp +++ b/include/app/ModuleBrowser.hpp @@ -1,14 +1,16 @@ #pragma once #include "app/common.hpp" -#include "widgets/Widget.hpp" +#include "widget/Widget.hpp" namespace rack { +namespace app { -Widget *moduleBrowserCreate(); +widget::Widget *moduleBrowserCreate(); json_t *moduleBrowserToJson(); void moduleBrowserFromJson(json_t *rootJ); +} // namespace app } // namespace rack diff --git a/include/app/ModuleLightWidget.hpp b/include/app/ModuleLightWidget.hpp index 75e505e0..e99abecb 100644 --- a/include/app/ModuleLightWidget.hpp +++ b/include/app/ModuleLightWidget.hpp @@ -5,6 +5,7 @@ namespace rack { +namespace app { /** A MultiLightWidget that points to a module's Light or a range of lights @@ -17,4 +18,5 @@ struct ModuleLightWidget : MultiLightWidget { }; +} // namespace app } // namespace rack diff --git a/include/app/ModuleWidget.hpp b/include/app/ModuleWidget.hpp index ef351de4..c0e5e736 100644 --- a/include/app/ModuleWidget.hpp +++ b/include/app/ModuleWidget.hpp @@ -1,6 +1,6 @@ #pragma once #include "app/common.hpp" -#include "widgets/OpaqueWidget.hpp" +#include "widget/OpaqueWidget.hpp" #include "ui/Menu.hpp" #include "app/PortWidget.hpp" #include "app/ParamWidget.hpp" @@ -9,14 +9,15 @@ namespace rack { +namespace app { -struct ModuleWidget : OpaqueWidget { +struct ModuleWidget : widget::OpaqueWidget { Model *model = NULL; /** Owns the module pointer */ Module *module = NULL; - Widget *panel = NULL; + widget::Widget *panel = NULL; std::vector params; std::vector outputs; std::vector inputs; @@ -30,8 +31,8 @@ struct ModuleWidget : OpaqueWidget { } ~ModuleWidget(); - void draw(const DrawContext &ctx) override; - void drawShadow(const DrawContext &ctx); + void draw(const widget::DrawContext &ctx) override; + void drawShadow(const widget::DrawContext &ctx); void onHover(const event::Hover &e) override; void onButton(const event::Button &e) override; @@ -88,10 +89,11 @@ struct ModuleWidget : OpaqueWidget { void removeAction(); void createContextMenu(); /** Override to add context menu entries to your subclass. - It is recommended to add a blank MenuEntry first for spacing. + It is recommended to add a blank ui::MenuEntry first for spacing. */ - virtual void appendContextMenu(Menu *menu) {} + virtual void appendContextMenu(ui::Menu *menu) {} }; +} // namespace app } // namespace rack diff --git a/include/app/MultiLightWidget.hpp b/include/app/MultiLightWidget.hpp index 7eea7efc..9411bbab 100644 --- a/include/app/MultiLightWidget.hpp +++ b/include/app/MultiLightWidget.hpp @@ -4,6 +4,7 @@ namespace rack { +namespace app { /** Mixes a list of colors based on a list of brightness values */ @@ -16,4 +17,5 @@ struct MultiLightWidget : LightWidget { }; +} // namespace app } // namespace rack diff --git a/include/app/ParamQuantity.hpp b/include/app/ParamQuantity.hpp index 465ca784..17ae961d 100644 --- a/include/app/ParamQuantity.hpp +++ b/include/app/ParamQuantity.hpp @@ -5,10 +5,11 @@ namespace rack { +namespace app { -/** A Quantity that wraps an engine Param */ -struct ParamQuantity : Quantity { +/** A ui::Quantity that wraps an engine Param */ +struct ParamQuantity : ui::Quantity { Module *module = NULL; int paramId = 0; @@ -32,4 +33,5 @@ struct ParamQuantity : Quantity { }; +} // namespace app } // namespace rack diff --git a/include/app/ParamWidget.hpp b/include/app/ParamWidget.hpp index 49768fc1..b0f64565 100644 --- a/include/app/ParamWidget.hpp +++ b/include/app/ParamWidget.hpp @@ -1,22 +1,23 @@ #pragma once #include "app/common.hpp" -#include "widgets/OpaqueWidget.hpp" +#include "widget/OpaqueWidget.hpp" #include "ui/Tooltip.hpp" #include "app/ParamQuantity.hpp" #include "history.hpp" namespace rack { +namespace app { -struct ParamWidget : OpaqueWidget { +struct ParamWidget : widget::OpaqueWidget { ParamQuantity *paramQuantity = NULL; float dirtyValue = NAN; - Tooltip *tooltip = NULL; + ui::Tooltip *tooltip = NULL; ~ParamWidget(); void step() override; - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; void onButton(const event::Button &e) override; void onEnter(const event::Enter &e) override; void onLeave(const event::Leave &e) override; @@ -28,4 +29,5 @@ struct ParamWidget : OpaqueWidget { }; +} // namespace app } // namespace rack diff --git a/include/app/PortWidget.hpp b/include/app/PortWidget.hpp index febc807e..8a6a8c2d 100644 --- a/include/app/PortWidget.hpp +++ b/include/app/PortWidget.hpp @@ -1,14 +1,15 @@ #pragma once #include "app/common.hpp" -#include "widgets/OpaqueWidget.hpp" +#include "widget/OpaqueWidget.hpp" #include "app/MultiLightWidget.hpp" #include "engine/Module.hpp" namespace rack { +namespace app { -struct PortWidget : OpaqueWidget { +struct PortWidget : widget::OpaqueWidget { Module *module = NULL; int portId; @@ -23,7 +24,7 @@ struct PortWidget : OpaqueWidget { ~PortWidget(); void step() override; - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; void onButton(const event::Button &e) override; void onDragStart(const event::DragStart &e) override; @@ -34,4 +35,5 @@ struct PortWidget : OpaqueWidget { }; +} // namespace app } // namespace rack diff --git a/include/app/RackRail.hpp b/include/app/RackRail.hpp index 86be2e06..4ee5f068 100644 --- a/include/app/RackRail.hpp +++ b/include/app/RackRail.hpp @@ -1,14 +1,16 @@ #pragma once #include "app/common.hpp" -#include "widgets/TransparentWidget.hpp" +#include "widget/TransparentWidget.hpp" namespace rack { +namespace app { -struct RackRail : TransparentWidget { - void draw(const DrawContext &ctx) override; +struct RackRail : widget::TransparentWidget { + void draw(const widget::DrawContext &ctx) override; }; +} // namespace app } // namespace rack diff --git a/include/app/RackScrollWidget.hpp b/include/app/RackScrollWidget.hpp index a236f084..2f260efc 100644 --- a/include/app/RackScrollWidget.hpp +++ b/include/app/RackScrollWidget.hpp @@ -4,12 +4,14 @@ namespace rack { +namespace app { -struct RackScrollWidget : ScrollWidget { +struct RackScrollWidget : ui::ScrollWidget { void step() override; - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; }; +} // namespace app } // namespace rack diff --git a/include/app/RackWidget.hpp b/include/app/RackWidget.hpp index 429ba1b8..228710d9 100644 --- a/include/app/RackWidget.hpp +++ b/include/app/RackWidget.hpp @@ -1,19 +1,20 @@ #pragma once #include "app/common.hpp" -#include "widgets/OpaqueWidget.hpp" -#include "widgets/FramebufferWidget.hpp" +#include "widget/OpaqueWidget.hpp" +#include "widget/FramebufferWidget.hpp" #include "app/ModuleWidget.hpp" #include "app/CableWidget.hpp" #include "app/PortWidget.hpp" namespace rack { +namespace app { -struct RackWidget : OpaqueWidget { - FramebufferWidget *rails; - Widget *moduleContainer; - Widget *cableContainer; +struct RackWidget : widget::OpaqueWidget { + widget::FramebufferWidget *rails; + widget::Widget *moduleContainer; + widget::Widget *cableContainer; CableWidget *incompleteCable = NULL; /** The last mouse position in the RackWidget */ math::Vec mousePos; @@ -22,7 +23,7 @@ struct RackWidget : OpaqueWidget { ~RackWidget(); void step() override; - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; void onHover(const event::Hover &e) override; void onHoverKey(const event::HoverKey &e) override; @@ -74,4 +75,5 @@ struct RackWidget : OpaqueWidget { }; +} // namespace app } // namespace rack diff --git a/include/app/SVGButton.hpp b/include/app/SVGButton.hpp index 1080873c..4cf5e822 100644 --- a/include/app/SVGButton.hpp +++ b/include/app/SVGButton.hpp @@ -1,16 +1,17 @@ #pragma once #include "app/common.hpp" -#include "widgets/OpaqueWidget.hpp" -#include "widgets/FramebufferWidget.hpp" -#include "widgets/SVGWidget.hpp" +#include "widget/OpaqueWidget.hpp" +#include "widget/FramebufferWidget.hpp" +#include "widget/SVGWidget.hpp" namespace rack { +namespace app { -struct SVGButton : OpaqueWidget { - FramebufferWidget *fb; - SVGWidget *sw; +struct SVGButton : widget::OpaqueWidget { + widget::FramebufferWidget *fb; + widget::SVGWidget *sw; std::vector> frames; SVGButton(); @@ -21,4 +22,5 @@ struct SVGButton : OpaqueWidget { }; +} // namespace app } // namespace rack diff --git a/include/app/SVGKnob.hpp b/include/app/SVGKnob.hpp index 1db7517c..f744caa3 100644 --- a/include/app/SVGKnob.hpp +++ b/include/app/SVGKnob.hpp @@ -1,20 +1,21 @@ #pragma once #include "app/common.hpp" #include "app/Knob.hpp" -#include "widgets/FramebufferWidget.hpp" -#include "widgets/TransformWidget.hpp" -#include "widgets/SVGWidget.hpp" +#include "widget/FramebufferWidget.hpp" +#include "widget/TransformWidget.hpp" +#include "widget/SVGWidget.hpp" #include "app/CircularShadow.hpp" namespace rack { +namespace app { /** A knob which rotates an SVG and caches it in a framebuffer */ struct SVGKnob : Knob { - FramebufferWidget *fb; - TransformWidget *tw; - SVGWidget *sw; + widget::FramebufferWidget *fb; + widget::TransformWidget *tw; + widget::SVGWidget *sw; CircularShadow *shadow; /** Angles in radians */ float minAngle, maxAngle; @@ -25,4 +26,5 @@ struct SVGKnob : Knob { }; +} // namespace app } // namespace rack diff --git a/include/app/SVGPanel.hpp b/include/app/SVGPanel.hpp index 4972d853..5fe84a1b 100644 --- a/include/app/SVGPanel.hpp +++ b/include/app/SVGPanel.hpp @@ -1,24 +1,26 @@ #pragma once #include "app/common.hpp" -#include "widgets/TransparentWidget.hpp" -#include "widgets/FramebufferWidget.hpp" -#include "widgets/SVGWidget.hpp" +#include "widget/TransparentWidget.hpp" +#include "widget/FramebufferWidget.hpp" +#include "widget/SVGWidget.hpp" #include "app.hpp" namespace rack { +namespace app { -struct PanelBorder : TransparentWidget { - void draw(const DrawContext &ctx) override; +struct PanelBorder : widget::TransparentWidget { + void draw(const widget::DrawContext &ctx) override; }; -struct SVGPanel : FramebufferWidget { +struct SVGPanel : widget::FramebufferWidget { void step() override; void setBackground(std::shared_ptr svg); }; +} // namespace app } // namespace rack diff --git a/include/app/SVGPort.hpp b/include/app/SVGPort.hpp index bff38e43..86f4e804 100644 --- a/include/app/SVGPort.hpp +++ b/include/app/SVGPort.hpp @@ -1,17 +1,18 @@ #pragma once #include "app/common.hpp" #include "app/PortWidget.hpp" -#include "widgets/FramebufferWidget.hpp" -#include "widgets/SVGWidget.hpp" +#include "widget/FramebufferWidget.hpp" +#include "widget/SVGWidget.hpp" #include "app/CircularShadow.hpp" namespace rack { +namespace app { struct SVGPort : PortWidget { - FramebufferWidget *fb; - SVGWidget *sw; + widget::FramebufferWidget *fb; + widget::SVGWidget *sw; CircularShadow *shadow; SVGPort(); @@ -19,4 +20,5 @@ struct SVGPort : PortWidget { }; +} // namespace app } // namespace rack diff --git a/include/app/SVGScrew.hpp b/include/app/SVGScrew.hpp index 7ce4e6c2..f6d27853 100644 --- a/include/app/SVGScrew.hpp +++ b/include/app/SVGScrew.hpp @@ -1,18 +1,20 @@ #pragma once #include "common.hpp" -#include "widgets/FramebufferWidget.hpp" -#include "widgets/SVGWidget.hpp" +#include "widget/FramebufferWidget.hpp" +#include "widget/SVGWidget.hpp" namespace rack { +namespace app { /** If you don't add these to your ModuleWidget, they will fall out of the rack... */ -struct SVGScrew : FramebufferWidget { - SVGWidget *sw; +struct SVGScrew : widget::FramebufferWidget { + widget::SVGWidget *sw; SVGScrew(); }; +} // namespace app } // namespace rack diff --git a/include/app/SVGSlider.hpp b/include/app/SVGSlider.hpp index c0f10a59..823fd744 100644 --- a/include/app/SVGSlider.hpp +++ b/include/app/SVGSlider.hpp @@ -1,20 +1,21 @@ #pragma once #include "app/common.hpp" #include "app/SliderKnob.hpp" -#include "widgets/FramebufferWidget.hpp" -#include "widgets/SVGWidget.hpp" +#include "widget/FramebufferWidget.hpp" +#include "widget/SVGWidget.hpp" namespace rack { +namespace app { -/** Behaves like a knob but linearly moves an SVGWidget between two points. +/** Behaves like a knob but linearly moves an widget::SVGWidget between two points. Can be used for horizontal or vertical linear faders. */ -struct SVGSlider : SliderKnob { - FramebufferWidget *fb; - SVGWidget *background; - SVGWidget *handle; +struct SVGSlider : app::SliderKnob { + widget::FramebufferWidget *fb; + widget::SVGWidget *background; + widget::SVGWidget *handle; /** Intermediate positions will be interpolated between these positions */ math::Vec minHandlePos, maxHandlePos; @@ -30,4 +31,5 @@ struct SVGSlider : SliderKnob { }; +} // namespace app } // namespace rack diff --git a/include/app/SVGSwitch.hpp b/include/app/SVGSwitch.hpp index f87400b0..39869759 100644 --- a/include/app/SVGSwitch.hpp +++ b/include/app/SVGSwitch.hpp @@ -1,17 +1,18 @@ #pragma once #include "app/common.hpp" -#include "widgets/FramebufferWidget.hpp" -#include "widgets/SVGWidget.hpp" +#include "widget/FramebufferWidget.hpp" +#include "widget/SVGWidget.hpp" #include "app/Switch.hpp" namespace rack { +namespace app { /** A ParamWidget with multiple frames corresponding to its value */ struct SVGSwitch : Switch { - FramebufferWidget *fb; - SVGWidget *sw; + widget::FramebufferWidget *fb; + widget::SVGWidget *sw; std::vector> frames; SVGSwitch(); @@ -21,4 +22,5 @@ struct SVGSwitch : Switch { }; +} // namespace app } // namespace rack diff --git a/include/app/Scene.hpp b/include/app/Scene.hpp index fec3e403..2a04e480 100644 --- a/include/app/Scene.hpp +++ b/include/app/Scene.hpp @@ -1,22 +1,23 @@ #pragma once #include "app/common.hpp" -#include "widgets/OpaqueWidget.hpp" -#include "widgets/ZoomWidget.hpp" +#include "widget/OpaqueWidget.hpp" +#include "widget/ZoomWidget.hpp" #include "ui/ScrollWidget.hpp" #include "app/RackWidget.hpp" #include "app/Toolbar.hpp" namespace rack { +namespace app { -struct Scene : OpaqueWidget { +struct Scene : widget::OpaqueWidget { // Convenience variables for accessing important widgets - ScrollWidget *scrollWidget; - ZoomWidget *zoomWidget; + ui::ScrollWidget *scrollWidget; + widget::ZoomWidget *zoomWidget; RackWidget *rackWidget; Toolbar *toolbar; - Widget *moduleBrowser; + widget::Widget *moduleBrowser; // Version checking bool devMode = false; @@ -27,7 +28,7 @@ struct Scene : OpaqueWidget { Scene(); ~Scene(); void step() override; - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; void onHoverKey(const event::HoverKey &e) override; void onPathDrop(const event::PathDrop &e) override; @@ -35,4 +36,5 @@ struct Scene : OpaqueWidget { }; +} // namespace app } // namespace rack diff --git a/include/app/SliderKnob.hpp b/include/app/SliderKnob.hpp index c5ec60e3..1acfca67 100644 --- a/include/app/SliderKnob.hpp +++ b/include/app/SliderKnob.hpp @@ -4,6 +4,7 @@ namespace rack { +namespace app { struct SliderKnob : Knob { @@ -17,4 +18,5 @@ struct SliderKnob : Knob { }; +} // namespace app } // namespace rack diff --git a/include/app/Switch.hpp b/include/app/Switch.hpp index 7cc7bef4..f25103bb 100644 --- a/include/app/Switch.hpp +++ b/include/app/Switch.hpp @@ -4,6 +4,7 @@ namespace rack { +namespace app { /** A ParamWidget that controls */ @@ -20,4 +21,5 @@ struct Switch : ParamWidget { }; +} // namespace app } // namespace rack diff --git a/include/app/Toolbar.hpp b/include/app/Toolbar.hpp index 2dfe1e63..0609b750 100644 --- a/include/app/Toolbar.hpp +++ b/include/app/Toolbar.hpp @@ -1,19 +1,21 @@ #pragma once #include "app/common.hpp" -#include "widgets/OpaqueWidget.hpp" +#include "widget/OpaqueWidget.hpp" namespace rack { +namespace app { -struct Toolbar : OpaqueWidget { +struct Toolbar : widget::OpaqueWidget { // TODO Move these to future Rack app state float cableOpacity = 0.5; float cableTension = 0.5; Toolbar(); - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; }; +} // namespace app } // namespace rack diff --git a/include/app/common.hpp b/include/app/common.hpp index 1d4ef548..2d31941b 100644 --- a/include/app/common.hpp +++ b/include/app/common.hpp @@ -5,32 +5,33 @@ namespace rack { +namespace app { -static const char APP_NAME[] = "VCV Rack"; -static const char APP_VERSION[] = TOSTRING(VERSION); -static const char APP_API_URL[] = "https://api.vcvrack.com"; +static const char NAME[] = "VCV Rack"; +static const char VERSION[] = TOSTRING(APP_VERSION); +static const char API_URL[] = "https://api.vcvrack.com"; -static const float APP_SVG_DPI = 75.0; +static const float SVG_DPI = 75.0; static const float MM_PER_IN = 25.4; /** Converts inch measurements to pixels */ inline float in2px(float in) { - return in * APP_SVG_DPI; + return in * SVG_DPI; } inline math::Vec in2px(math::Vec in) { - return in.mult(APP_SVG_DPI); + return in.mult(SVG_DPI); } /** Converts millimeter measurements to pixels */ inline float mm2px(float mm) { - return mm * (APP_SVG_DPI / MM_PER_IN); + return mm * (SVG_DPI / MM_PER_IN); } inline math::Vec mm2px(math::Vec mm) { - return mm.mult(APP_SVG_DPI / MM_PER_IN); + return mm.mult(SVG_DPI / MM_PER_IN); } @@ -40,4 +41,5 @@ static const float RACK_GRID_HEIGHT = 380; static const math::Vec RACK_GRID_SIZE = math::Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT); +} // namespace app } // namespace rack diff --git a/include/componentlibrary.hpp b/include/componentlibrary.hpp index effff446..a3accdb5 100644 --- a/include/componentlibrary.hpp +++ b/include/componentlibrary.hpp @@ -26,7 +26,7 @@ static const NVGcolor SCHEME_DARK_GRAY = nvgRGB(0x17, 0x17, 0x17); // Knobs //////////////////// -struct RoundKnob : SVGKnob { +struct RoundKnob : app::SVGKnob { RoundKnob() { minAngle = -0.83*M_PI; maxAngle = 0.83*M_PI; @@ -64,7 +64,7 @@ struct RoundBlackSnapKnob : RoundBlackKnob { }; -struct Davies1900hKnob : SVGKnob { +struct Davies1900hKnob : app::SVGKnob { Davies1900hKnob() { minAngle = -0.83*M_PI; maxAngle = 0.83*M_PI; @@ -108,7 +108,7 @@ struct Davies1900hLargeRedKnob : Davies1900hKnob { }; -struct Rogan : SVGKnob { +struct Rogan : app::SVGKnob { Rogan() { minAngle = -0.83*M_PI; maxAngle = 0.83*M_PI; @@ -278,7 +278,7 @@ struct Rogan1PWhite : Rogan { }; -struct SynthTechAlco : SVGKnob { +struct SynthTechAlco : app::SVGKnob { SynthTechAlco() { minAngle = -0.82*M_PI; maxAngle = 0.82*M_PI; @@ -289,7 +289,7 @@ struct SynthTechAlco : SVGKnob { } }; -struct Trimpot : SVGKnob { +struct Trimpot : app::SVGKnob { Trimpot() { minAngle = -0.75*M_PI; maxAngle = 0.75*M_PI; @@ -297,7 +297,7 @@ struct Trimpot : SVGKnob { } }; -struct BefacoBigKnob : SVGKnob { +struct BefacoBigKnob : app::SVGKnob { BefacoBigKnob() { minAngle = -0.75*M_PI; maxAngle = 0.75*M_PI; @@ -311,7 +311,7 @@ struct BefacoBigSnapKnob : BefacoBigKnob { } }; -struct BefacoTinyKnob : SVGKnob { +struct BefacoTinyKnob : app::SVGKnob { BefacoTinyKnob() { minAngle = -0.75*M_PI; maxAngle = 0.75*M_PI; @@ -319,7 +319,7 @@ struct BefacoTinyKnob : SVGKnob { } }; -struct BefacoSlidePot : SVGSlider { +struct BefacoSlidePot : app::SVGSlider { BefacoSlidePot() { math::Vec margin = math::Vec(3.5, 3.5); maxHandlePos = math::Vec(-1, -2).plus(margin); @@ -331,7 +331,7 @@ struct BefacoSlidePot : SVGSlider { } }; -struct LEDSlider : SVGSlider { +struct LEDSlider : app::SVGSlider { LEDSlider() { maxHandlePos = mm2px(math::Vec(0.738, 0.738).plus(math::Vec(2, 0))); minHandlePos = mm2px(math::Vec(0.738, 22.078).plus(math::Vec(2, 0))); @@ -374,19 +374,19 @@ struct LEDSliderWhite : LEDSlider { // Ports //////////////////// -struct PJ301MPort : SVGPort { +struct PJ301MPort : app::SVGPort { PJ301MPort() { setSVG(SVG::load(asset::system("res/ComponentLibrary/PJ301M.svg"))); } }; -struct PJ3410Port : SVGPort { +struct PJ3410Port : app::SVGPort { PJ3410Port() { setSVG(SVG::load(asset::system("res/ComponentLibrary/PJ3410.svg"))); } }; -struct CL1362Port : SVGPort { +struct CL1362Port : app::SVGPort { CL1362Port() { setSVG(SVG::load(asset::system("res/ComponentLibrary/CL1362.svg"))); } @@ -396,7 +396,7 @@ struct CL1362Port : SVGPort { // Lights //////////////////// -struct GrayModuleLightWidget : ModuleLightWidget { +struct GrayModuleLightWidget : app::ModuleLightWidget { GrayModuleLightWidget() { bgColor = nvgRGB(0x5a, 0x5a, 0x5a); borderColor = nvgRGBA(0, 0, 0, 0x60); @@ -443,7 +443,7 @@ struct RedGreenBlueLight : GrayModuleLightWidget { } }; -struct RGBLight : ModuleLightWidget { +struct RGBLight : app::ModuleLightWidget { RGBLight() { addBaseColor(nvgRGBf(1, 0, 0)); addBaseColor(nvgRGBf(0, 1, 0)); @@ -509,7 +509,7 @@ struct PB61303Light : BASE { // Switches //////////////////// -struct NKK : SVGSwitch { +struct NKK : app::SVGSwitch { NKK() { addFrame(SVG::load(asset::system("res/ComponentLibrary/NKK_0.svg"))); addFrame(SVG::load(asset::system("res/ComponentLibrary/NKK_1.svg"))); @@ -517,14 +517,14 @@ struct NKK : SVGSwitch { } }; -struct CKSS : SVGSwitch { +struct CKSS : app::SVGSwitch { CKSS() { addFrame(SVG::load(asset::system("res/ComponentLibrary/CKSS_0.svg"))); addFrame(SVG::load(asset::system("res/ComponentLibrary/CKSS_1.svg"))); } }; -struct CKSSThree : SVGSwitch { +struct CKSSThree : app::SVGSwitch { CKSSThree() { addFrame(SVG::load(asset::system("res/ComponentLibrary/CKSSThree_0.svg"))); addFrame(SVG::load(asset::system("res/ComponentLibrary/CKSSThree_1.svg"))); @@ -532,7 +532,7 @@ struct CKSSThree : SVGSwitch { } }; -struct CKD6 : SVGSwitch { +struct CKD6 : app::SVGSwitch { CKD6() { momentary = true; addFrame(SVG::load(asset::system("res/ComponentLibrary/CKD6_0.svg"))); @@ -540,7 +540,7 @@ struct CKD6 : SVGSwitch { } }; -struct TL1105 : SVGSwitch { +struct TL1105 : app::SVGSwitch { TL1105() { momentary = true; addFrame(SVG::load(asset::system("res/ComponentLibrary/TL1105_0.svg"))); @@ -548,14 +548,14 @@ struct TL1105 : SVGSwitch { } }; -struct LEDButton : SVGSwitch { +struct LEDButton : app::SVGSwitch { LEDButton() { momentary = true; addFrame(SVG::load(asset::system("res/ComponentLibrary/LEDButton.svg"))); } }; -struct BefacoSwitch : SVGSwitch { +struct BefacoSwitch : app::SVGSwitch { BefacoSwitch() { addFrame(SVG::load(asset::system("res/ComponentLibrary/BefacoSwitch_0.svg"))); addFrame(SVG::load(asset::system("res/ComponentLibrary/BefacoSwitch_1.svg"))); @@ -563,7 +563,7 @@ struct BefacoSwitch : SVGSwitch { } }; -struct BefacoPush : SVGSwitch { +struct BefacoPush : app::SVGSwitch { BefacoPush() { momentary = true; addFrame(SVG::load(asset::system("res/ComponentLibrary/BefacoPush_0.svg"))); @@ -571,14 +571,14 @@ struct BefacoPush : SVGSwitch { } }; -struct LEDBezel : SVGSwitch { +struct LEDBezel : app::SVGSwitch { LEDBezel() { momentary = true; addFrame(SVG::load(asset::system("res/ComponentLibrary/LEDBezel.svg"))); } }; -struct PB61303 : SVGSwitch { +struct PB61303 : app::SVGSwitch { PB61303() { momentary = true; addFrame(SVG::load(asset::system("res/ComponentLibrary/PB61303.svg"))); @@ -589,14 +589,14 @@ struct PB61303 : SVGSwitch { // Misc //////////////////// -struct ScrewSilver : SVGScrew { +struct ScrewSilver : app::SVGScrew { ScrewSilver() { sw->setSVG(SVG::load(asset::system("res/ComponentLibrary/ScrewSilver.svg"))); box.size = sw->box.size; } }; -struct ScrewBlack : SVGScrew { +struct ScrewBlack : app::SVGScrew { ScrewBlack() { sw->setSVG(SVG::load(asset::system("res/ComponentLibrary/ScrewBlack.svg"))); box.size = sw->box.size; diff --git a/include/engine/Param.hpp b/include/engine/Param.hpp index 3158490a..300df2cb 100644 --- a/include/engine/Param.hpp +++ b/include/engine/Param.hpp @@ -7,12 +7,14 @@ namespace rack { -struct ParamQuantity; +namespace app { + struct ParamQuantity; +} // namespace app struct ParamQuantityFactory { virtual ~ParamQuantityFactory() {} - virtual ParamQuantity *create() = 0; + virtual app::ParamQuantity *create() = 0; }; @@ -48,7 +50,7 @@ struct Param { delete paramQuantityFactory; } - template + template void config(float minValue, float maxValue, float defaultValue, std::string label = "", std::string unit = "", float displayBase = 0.f, float displayMultiplier = 1.f, float displayOffset = 0.f) { this->value = defaultValue; this->minValue = minValue; @@ -62,7 +64,7 @@ struct Param { this->displayOffset = displayOffset; struct TParamQuantityFactory : ParamQuantityFactory { - ParamQuantity *create() override {return new TParamQuantity;} + app::ParamQuantity *create() override {return new TParamQuantity;} }; if (paramQuantityFactory) delete paramQuantityFactory; diff --git a/include/event.hpp b/include/event.hpp index 968c51c4..a7c01b8f 100644 --- a/include/event.hpp +++ b/include/event.hpp @@ -7,7 +7,9 @@ namespace rack { -struct Widget; +namespace widget { + struct Widget; +} // namespace widget namespace event { @@ -17,7 +19,7 @@ struct Context { /** The Widget that consumes the event. This stops propagation of the event if applicable. */ - Widget *consumed = NULL; + widget::Widget *consumed = NULL; }; @@ -25,11 +27,11 @@ struct Context { struct Event { Context *context = NULL; - void consume(Widget *w) const { + void consume(widget::Widget *w) const { if (context) context->consumed = w; } - Widget *getConsumed() const { + widget::Widget *getConsumed() const { return context ? context->consumed : NULL; } }; @@ -169,7 +171,7 @@ Recurses until consumed. */ struct DragHover : Event, Position { /** The dragged widget */ - Widget *origin = NULL; + widget::Widget *origin = NULL; /** Change in mouse position since the last frame. Can be zero. */ math::Vec mouseDelta; }; @@ -178,7 +180,7 @@ struct DragHover : Event, Position { */ struct DragEnter : Event { /** The dragged widget */ - Widget *origin = NULL; + widget::Widget *origin = NULL; }; @@ -186,7 +188,7 @@ struct DragEnter : Event { */ struct DragLeave : Event { /** The dragged widget */ - Widget *origin = NULL; + widget::Widget *origin = NULL; }; @@ -194,7 +196,7 @@ struct DragLeave : Event { */ struct DragDrop : Event { /** The dragged widget */ - Widget *origin = NULL; + widget::Widget *origin = NULL; }; @@ -229,23 +231,23 @@ struct Zoom : Event { struct State { - Widget *rootWidget = NULL; + widget::Widget *rootWidget = NULL; /** State widgets Don't set these directly unless you know what you're doing. Use the set*() methods instead. */ - Widget *hoveredWidget = NULL; - Widget *draggedWidget = NULL; - Widget *dragHoveredWidget = NULL; - Widget *selectedWidget = NULL; + widget::Widget *hoveredWidget = NULL; + widget::Widget *draggedWidget = NULL; + widget::Widget *dragHoveredWidget = NULL; + widget::Widget *selectedWidget = NULL; /** For middle-click dragging */ - Widget *scrollWidget = NULL; + widget::Widget *scrollWidget = NULL; - void setHovered(Widget *w); - void setDragged(Widget *w); - void setDragHovered(Widget *w); - void setSelected(Widget *w); + void setHovered(widget::Widget *w); + void setDragged(widget::Widget *w); + void setDragHovered(widget::Widget *w); + void setSelected(widget::Widget *w); /** Prepares a widget for deletion */ - void finalizeWidget(Widget *w); + void finalizeWidget(widget::Widget *w); void handleButton(math::Vec pos, int button, int action, int mods); void handleHover(math::Vec pos, math::Vec mouseDelta); diff --git a/include/helpers.hpp b/include/helpers.hpp index 0e6b1b84..a0cc2c69 100644 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -21,13 +21,13 @@ Model *createModel(std::string slug) { TModule *o = new TModule; return o; } - ModuleWidget *createModuleWidget() override { + app::ModuleWidget *createModuleWidget() override { TModule *module = new TModule; TModuleWidget *o = new TModuleWidget(module); o->model = this; return o; } - ModuleWidget *createModuleWidgetNull() override { + app::ModuleWidget *createModuleWidgetNull() override { TModuleWidget *o = new TModuleWidget(NULL); o->model = this; return o; @@ -62,7 +62,7 @@ TParamWidget *createParam(math::Vec pos, Module *module, int paramId) { if (f) o->paramQuantity = f->create(); else - o->paramQuantity = new ParamQuantity; + o->paramQuantity = new app::ParamQuantity; o->paramQuantity->module = module; o->paramQuantity->paramId = paramId; } @@ -81,7 +81,7 @@ TPortWidget *createInput(math::Vec pos, Module *module, int inputId) { TPortWidget *o = new TPortWidget; o->box.pos = pos; o->module = module; - o->type = PortWidget::INPUT; + o->type = app::PortWidget::INPUT; o->portId = inputId; return o; } @@ -91,7 +91,7 @@ TPortWidget *createInputCentered(math::Vec pos, Module *module, int inputId) { TPortWidget *o = new TPortWidget; o->box.pos = pos.minus(o->box.size.div(2)); o->module = module; - o->type = PortWidget::INPUT; + o->type = app::PortWidget::INPUT; o->portId = inputId; return o; } @@ -101,7 +101,7 @@ TPortWidget *createOutput(math::Vec pos, Module *module, int outputId) { TPortWidget *o = new TPortWidget; o->box.pos = pos; o->module = module; - o->type = PortWidget::OUTPUT; + o->type = app::PortWidget::OUTPUT; o->portId = outputId; return o; } @@ -111,7 +111,7 @@ TPortWidget *createOutputCentered(math::Vec pos, Module *module, int outputId) { TPortWidget *o = new TPortWidget; o->box.pos = pos.minus(o->box.size.div(2)); o->module = module; - o->type = PortWidget::OUTPUT; + o->type = app::PortWidget::OUTPUT; o->portId = outputId; return o; } @@ -134,14 +134,14 @@ TModuleLightWidget *createLightCentered(math::Vec pos, Module *module, int first return o; } -template +template TMenuLabel *createMenuLabel(std::string text) { TMenuLabel *o = new TMenuLabel; o->text = text; return o; } -template +template TMenuItem *createMenuItem(std::string text, std::string rightText = "") { TMenuItem *o = new TMenuItem; o->text = text; @@ -149,14 +149,14 @@ TMenuItem *createMenuItem(std::string text, std::string rightText = "") { return o; } -inline Menu *createMenu() { - Menu *o = new Menu; - o->box.pos = app()->window->mousePos; +inline ui::Menu *createMenu() { + ui::Menu *o = new ui::Menu; + o->box.pos = APP->window->mousePos; - MenuOverlay *menuOverlay = new MenuOverlay; + ui::MenuOverlay *menuOverlay = new ui::MenuOverlay; menuOverlay->addChild(o); - app()->scene->addChild(menuOverlay); + APP->scene->addChild(menuOverlay); return o; } diff --git a/include/history.hpp b/include/history.hpp index 15e32905..d3e9c8ba 100644 --- a/include/history.hpp +++ b/include/history.hpp @@ -10,8 +10,10 @@ namespace rack { -struct ModuleWidget; -struct CableWidget; +namespace app { + struct ModuleWidget; + struct CableWidget; +} // namespace app namespace history { @@ -59,7 +61,7 @@ struct ModuleAdd : ModuleAction { math::Vec pos; json_t *moduleJ; ~ModuleAdd(); - void setModule(ModuleWidget *mw); + void setModule(app::ModuleWidget *mw); void undo() override; void redo() override; }; @@ -108,7 +110,7 @@ struct CableAdd : Action { int inputModuleId; int inputId; NVGcolor color; - void setCable(CableWidget *cw); + void setCable(app::CableWidget *cw); void undo() override; void redo() override; }; diff --git a/include/plugin/Model.hpp b/include/plugin/Model.hpp index c31a6f92..2933608f 100644 --- a/include/plugin/Model.hpp +++ b/include/plugin/Model.hpp @@ -8,7 +8,10 @@ namespace rack { -struct ModuleWidget; +namespace app { + struct ModuleWidget; +} // namespace app + struct Module; @@ -30,9 +33,9 @@ struct Model { /** Creates a headless Module */ virtual Module *createModule() { return NULL; } /** Creates a ModuleWidget with a Module attached */ - virtual ModuleWidget *createModuleWidget() { return NULL; } + virtual app::ModuleWidget *createModuleWidget() { return NULL; } /** Creates a ModuleWidget with no Module, useful for previews */ - virtual ModuleWidget *createModuleWidgetNull() { return NULL; } + virtual app::ModuleWidget *createModuleWidgetNull() { return NULL; } void fromJson(json_t *rootJ); }; diff --git a/include/rack.hpp b/include/rack.hpp index 585880ca..e7f45bbe 100644 --- a/include/rack.hpp +++ b/include/rack.hpp @@ -12,14 +12,14 @@ #include "midi.hpp" #include "helpers.hpp" -#include "widgets/Widget.hpp" -#include "widgets/TransparentWidget.hpp" -#include "widgets/OpaqueWidget.hpp" -#include "widgets/TransformWidget.hpp" -#include "widgets/ZoomWidget.hpp" -#include "widgets/SVGWidget.hpp" -#include "widgets/FramebufferWidget.hpp" -#include "widgets/GLWidget.hpp" +#include "widget/Widget.hpp" +#include "widget/TransparentWidget.hpp" +#include "widget/OpaqueWidget.hpp" +#include "widget/TransformWidget.hpp" +#include "widget/ZoomWidget.hpp" +#include "widget/SVGWidget.hpp" +#include "widget/FramebufferWidget.hpp" +#include "widget/GLWidget.hpp" #include "ui/SequentialLayout.hpp" #include "ui/Label.hpp" @@ -92,8 +92,11 @@ namespace rack { -// Import math:: namespace for convenience +// Import some namespaces for convenience using namespace math; +using namespace widget; +using namespace ui; +using namespace app; } // namespace rack diff --git a/include/rack0.hpp b/include/rack0.hpp index b71ec1ad..a47438a9 100644 --- a/include/rack0.hpp +++ b/include/rack0.hpp @@ -142,11 +142,11 @@ DEPRECATED TPortWidget *createPort(math::Vec pos, PortWidget::Type type, Module //////////////////// DEPRECATED inline float engineGetSampleRate() { - return app()->engine->getSampleRate(); + return APP->engine->getSampleRate(); } DEPRECATED inline float engineGetSampleTime() { - return app()->engine->getSampleTime(); + return APP->engine->getSampleTime(); } //////////////////// diff --git a/include/ui/Button.hpp b/include/ui/Button.hpp index 4b0d993a..c7d25ac7 100644 --- a/include/ui/Button.hpp +++ b/include/ui/Button.hpp @@ -1,13 +1,14 @@ #pragma once -#include "widgets/OpaqueWidget.hpp" +#include "widget/OpaqueWidget.hpp" #include "ui/common.hpp" #include "ui/Quantity.hpp" namespace rack { +namespace ui { -struct Button : OpaqueWidget { +struct Button : widget::OpaqueWidget { std::string text; BNDwidgetState state = BND_DEFAULT; /** Optional, owned. Tracks the pressed state of the button.*/ @@ -15,7 +16,7 @@ struct Button : OpaqueWidget { Button(); ~Button(); - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; void onEnter(const event::Enter &e) override; void onLeave(const event::Leave &e) override; void onDragStart(const event::DragStart &e) override; @@ -24,4 +25,5 @@ struct Button : OpaqueWidget { }; +} // namespace ui } // namespace rack diff --git a/include/ui/ChoiceButton.hpp b/include/ui/ChoiceButton.hpp index dd831881..dd69b57a 100644 --- a/include/ui/ChoiceButton.hpp +++ b/include/ui/ChoiceButton.hpp @@ -4,11 +4,13 @@ namespace rack { +namespace ui { struct ChoiceButton : Button { - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; }; +} // namespace ui } // namespace rack diff --git a/include/ui/IconButton.hpp b/include/ui/IconButton.hpp index 8521966f..c36858cc 100644 --- a/include/ui/IconButton.hpp +++ b/include/ui/IconButton.hpp @@ -1,20 +1,22 @@ #pragma once -#include "widgets/FramebufferWidget.hpp" -#include "widgets/SVGWidget.hpp" +#include "widget/FramebufferWidget.hpp" +#include "widget/SVGWidget.hpp" #include "ui/common.hpp" #include "ui/Button.hpp" namespace rack { +namespace ui { struct IconButton : Button { - FramebufferWidget *fw; - SVGWidget *sw; + widget::FramebufferWidget *fw; + widget::SVGWidget *sw; IconButton(); void setSVG(std::shared_ptr svg); }; +} // namespace ui } // namespace rack diff --git a/include/ui/Label.hpp b/include/ui/Label.hpp index 057a3498..15c54760 100644 --- a/include/ui/Label.hpp +++ b/include/ui/Label.hpp @@ -1,12 +1,13 @@ #pragma once -#include "widgets/Widget.hpp" +#include "widget/Widget.hpp" #include "ui/common.hpp" namespace rack { +namespace ui { -struct Label : Widget { +struct Label : widget::Widget { enum Alignment { LEFT_ALIGNMENT, CENTER_ALIGNMENT, @@ -19,8 +20,9 @@ struct Label : Widget { Alignment alignment = LEFT_ALIGNMENT; Label(); - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; }; +} // namespace ui } // namespace rack diff --git a/include/ui/List.hpp b/include/ui/List.hpp index 250ca8bc..a638b8d5 100644 --- a/include/ui/List.hpp +++ b/include/ui/List.hpp @@ -1,14 +1,16 @@ #pragma once -#include "widgets/OpaqueWidget.hpp" +#include "widget/OpaqueWidget.hpp" #include "ui/common.hpp" namespace rack { +namespace ui { -struct List : OpaqueWidget { +struct List : widget::OpaqueWidget { void step() override; }; +} // namespace ui } // namespace rack diff --git a/include/ui/Menu.hpp b/include/ui/Menu.hpp index 708e3f83..bff50853 100644 --- a/include/ui/Menu.hpp +++ b/include/ui/Menu.hpp @@ -1,13 +1,14 @@ #pragma once -#include "widgets/OpaqueWidget.hpp" +#include "widget/OpaqueWidget.hpp" #include "ui/common.hpp" #include "ui/MenuEntry.hpp" namespace rack { +namespace ui { -struct Menu : OpaqueWidget { +struct Menu : widget::OpaqueWidget { Menu *parentMenu = NULL; Menu *childMenu = NULL; /** The entry which created the child menu */ @@ -17,9 +18,10 @@ struct Menu : OpaqueWidget { ~Menu(); void setChildMenu(Menu *menu); void step() override; - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; void onHoverScroll(const event::HoverScroll &e) override; }; +} // namespace ui } // namespace rack diff --git a/include/ui/MenuEntry.hpp b/include/ui/MenuEntry.hpp index 7dde24d5..e0abbf4b 100644 --- a/include/ui/MenuEntry.hpp +++ b/include/ui/MenuEntry.hpp @@ -1,14 +1,16 @@ #pragma once -#include "widgets/OpaqueWidget.hpp" +#include "widget/OpaqueWidget.hpp" #include "ui/common.hpp" namespace rack { +namespace ui { -struct MenuEntry : OpaqueWidget { +struct MenuEntry : widget::OpaqueWidget { MenuEntry(); }; +} // namespace ui } // namespace rack diff --git a/include/ui/MenuItem.hpp b/include/ui/MenuItem.hpp index fc381252..6d652e04 100644 --- a/include/ui/MenuItem.hpp +++ b/include/ui/MenuItem.hpp @@ -7,6 +7,7 @@ namespace rack { +namespace ui { #define BND_LABEL_FONT_SIZE 13 @@ -17,7 +18,7 @@ struct MenuItem : MenuEntry { std::string rightText; bool disabled = false; - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; void step() override; void onEnter(const event::Enter &e) override; void onDragDrop(const event::DragDrop &e) override; @@ -26,4 +27,5 @@ struct MenuItem : MenuEntry { }; +} // namespace ui } // namespace rack diff --git a/include/ui/MenuLabel.hpp b/include/ui/MenuLabel.hpp index c66a904e..d5f4eafd 100644 --- a/include/ui/MenuLabel.hpp +++ b/include/ui/MenuLabel.hpp @@ -4,14 +4,16 @@ namespace rack { +namespace ui { struct MenuLabel : MenuEntry { std::string text; - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; void step() override; }; +} // namespace ui } // namespace rack diff --git a/include/ui/MenuOverlay.hpp b/include/ui/MenuOverlay.hpp index 1c3e84f6..3f9a8cbf 100644 --- a/include/ui/MenuOverlay.hpp +++ b/include/ui/MenuOverlay.hpp @@ -1,17 +1,19 @@ #pragma once -#include "widgets/OpaqueWidget.hpp" +#include "widget/OpaqueWidget.hpp" #include "ui/common.hpp" namespace rack { +namespace ui { /** Deletes itself from parent when clicked */ -struct MenuOverlay : OpaqueWidget { +struct MenuOverlay : widget::OpaqueWidget { void step() override; void onButton(const event::Button &e) override; void onHoverKey(const event::HoverKey &e) override; }; +} // namespace ui } // namespace rack diff --git a/include/ui/MenuSeparator.hpp b/include/ui/MenuSeparator.hpp index 994d6c6c..9e143ee4 100644 --- a/include/ui/MenuSeparator.hpp +++ b/include/ui/MenuSeparator.hpp @@ -4,12 +4,14 @@ namespace rack { +namespace ui { struct MenuSeparator : MenuEntry { MenuSeparator(); - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; }; +} // namespace ui } // namespace rack diff --git a/include/ui/PasswordField.hpp b/include/ui/PasswordField.hpp index cb378e07..0250e00c 100644 --- a/include/ui/PasswordField.hpp +++ b/include/ui/PasswordField.hpp @@ -4,11 +4,13 @@ namespace rack { +namespace ui { struct PasswordField : TextField { - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; }; +} // namespace ui } // namespace rack diff --git a/include/ui/ProgressBar.hpp b/include/ui/ProgressBar.hpp index f7805a50..a7b153f1 100644 --- a/include/ui/ProgressBar.hpp +++ b/include/ui/ProgressBar.hpp @@ -1,19 +1,21 @@ #pragma once #include "ui/common.hpp" -#include "widgets/Widget.hpp" +#include "widget/Widget.hpp" #include "ui/Quantity.hpp" namespace rack { +namespace ui { -struct ProgressBar : Widget { +struct ProgressBar : widget::Widget { Quantity *quantity = NULL; ProgressBar(); ~ProgressBar(); - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; }; +} // namespace ui } // namespace rack diff --git a/include/ui/Quantity.hpp b/include/ui/Quantity.hpp index 7aa8d43c..04ac8340 100644 --- a/include/ui/Quantity.hpp +++ b/include/ui/Quantity.hpp @@ -4,10 +4,11 @@ namespace rack { +namespace ui { /** A controller for manipulating a float value (which subclasses must store somehow) with limits and labels -Often used as a decorator component for Widgets that read or write a quantity. +Often used as a decorator component for widget::Widgets that read or write a quantity. */ struct Quantity { virtual ~Quantity() {} @@ -118,4 +119,5 @@ struct Quantity { }; +} // namespace ui } // namespace rack diff --git a/include/ui/RadioButton.hpp b/include/ui/RadioButton.hpp index fa0b7516..4f4ca66c 100644 --- a/include/ui/RadioButton.hpp +++ b/include/ui/RadioButton.hpp @@ -1,23 +1,25 @@ #pragma once #include "ui/common.hpp" -#include "widgets/OpaqueWidget.hpp" +#include "widget/OpaqueWidget.hpp" #include "ui/Quantity.hpp" namespace rack { +namespace ui { -struct RadioButton : OpaqueWidget { +struct RadioButton : widget::OpaqueWidget { BNDwidgetState state = BND_DEFAULT; Quantity *quantity = NULL; RadioButton(); ~RadioButton(); - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; void onEnter(const event::Enter &e) override; void onLeave(const event::Leave &e) override; void onDragDrop(const event::DragDrop &e) override; }; +} // namespace ui } // namespace rack diff --git a/include/ui/ScrollBar.hpp b/include/ui/ScrollBar.hpp index 0e54322b..7cbe8912 100644 --- a/include/ui/ScrollBar.hpp +++ b/include/ui/ScrollBar.hpp @@ -1,13 +1,14 @@ #pragma once -#include "widgets/OpaqueWidget.hpp" +#include "widget/OpaqueWidget.hpp" #include "ui/common.hpp" namespace rack { +namespace ui { /** Parent must be a ScrollWidget */ -struct ScrollBar : OpaqueWidget { +struct ScrollBar : widget::OpaqueWidget { enum Orientation { VERTICAL, HORIZONTAL @@ -18,11 +19,12 @@ struct ScrollBar : OpaqueWidget { float size = 0.0; ScrollBar(); - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; void onDragStart(const event::DragStart &e) override; void onDragMove(const event::DragMove &e) override; void onDragEnd(const event::DragEnd &e) override; }; +} // namespace ui } // namespace rack diff --git a/include/ui/ScrollWidget.hpp b/include/ui/ScrollWidget.hpp index 0915bdf1..fbdd9754 100644 --- a/include/ui/ScrollWidget.hpp +++ b/include/ui/ScrollWidget.hpp @@ -1,26 +1,28 @@ #pragma once #include "ui/common.hpp" -#include "widgets/OpaqueWidget.hpp" +#include "widget/OpaqueWidget.hpp" #include "ui/ScrollBar.hpp" namespace rack { +namespace ui { /** Handles a container with ScrollBar */ -struct ScrollWidget : OpaqueWidget { - Widget *container; +struct ScrollWidget : widget::OpaqueWidget { + widget::Widget *container; ScrollBar *horizontalScrollBar; ScrollBar *verticalScrollBar; math::Vec offset; ScrollWidget(); void scrollTo(math::Rect r); - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; void step() override; void onHover(const event::Hover &e) override; void onHoverScroll(const event::HoverScroll &e) override; }; +} // namespace ui } // namespace rack diff --git a/include/ui/SequentialLayout.hpp b/include/ui/SequentialLayout.hpp index 38906f69..d2293e7b 100644 --- a/include/ui/SequentialLayout.hpp +++ b/include/ui/SequentialLayout.hpp @@ -1,13 +1,14 @@ #pragma once -#include "widgets/Widget.hpp" +#include "widget/Widget.hpp" #include "ui/common.hpp" namespace rack { +namespace ui { /** Positions children in a row/column based on their widths/heights */ -struct SequentialLayout : Widget { +struct SequentialLayout : widget::Widget { enum Orientation { HORIZONTAL_ORIENTATION, VERTICAL_ORIENTATION, @@ -27,4 +28,5 @@ struct SequentialLayout : Widget { }; +} // namespace ui } // namespace rack diff --git a/include/ui/Slider.hpp b/include/ui/Slider.hpp index cbff1a3f..09aef548 100644 --- a/include/ui/Slider.hpp +++ b/include/ui/Slider.hpp @@ -1,20 +1,21 @@ #pragma once -#include "widgets/OpaqueWidget.hpp" +#include "widget/OpaqueWidget.hpp" #include "ui/Quantity.hpp" #include "ui/common.hpp" #include "app.hpp" namespace rack { +namespace ui { -struct Slider : OpaqueWidget { +struct Slider : widget::OpaqueWidget { BNDwidgetState state = BND_DEFAULT; Quantity *quantity = NULL; Slider(); ~Slider(); - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; void onDragStart(const event::DragStart &e) override; void onDragMove(const event::DragMove &e) override; void onDragEnd(const event::DragEnd &e) override; @@ -22,4 +23,5 @@ struct Slider : OpaqueWidget { }; +} // namespace ui } // namespace rack diff --git a/include/ui/TextField.hpp b/include/ui/TextField.hpp index d18cdc74..b7c27d35 100644 --- a/include/ui/TextField.hpp +++ b/include/ui/TextField.hpp @@ -1,14 +1,15 @@ #pragma once -#include "widgets/OpaqueWidget.hpp" +#include "widget/OpaqueWidget.hpp" #include "ui/common.hpp" #include "event.hpp" #include "app.hpp" namespace rack { +namespace ui { -struct TextField : OpaqueWidget { +struct TextField : widget::OpaqueWidget { std::string text; std::string placeholder; bool multiline = false; @@ -20,7 +21,7 @@ struct TextField : OpaqueWidget { int selection = 0; TextField(); - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; void onButton(const event::Button &e) override; void onHover(const event::Hover &e) override; void onEnter(const event::Enter &e) override; @@ -37,4 +38,5 @@ struct TextField : OpaqueWidget { }; +} // namespace ui } // namespace rack diff --git a/include/ui/Tooltip.hpp b/include/ui/Tooltip.hpp index aaad93d0..1b3f8212 100644 --- a/include/ui/Tooltip.hpp +++ b/include/ui/Tooltip.hpp @@ -1,17 +1,19 @@ #pragma once -#include "widgets/Widget.hpp" +#include "widget/Widget.hpp" #include "ui/common.hpp" namespace rack { +namespace ui { -struct Tooltip : Widget { +struct Tooltip : widget::Widget { std::string text; void step() override; - void draw(const DrawContext &ctx) override; + void draw(const widget::DrawContext &ctx) override; }; +} // namespace ui } // namespace rack diff --git a/include/ui/TooltipOverlay.hpp b/include/ui/TooltipOverlay.hpp index 02f80a8f..1f495de7 100644 --- a/include/ui/TooltipOverlay.hpp +++ b/include/ui/TooltipOverlay.hpp @@ -1,13 +1,15 @@ #pragma once -#include "widgets/TransparentWidget.hpp" +#include "widget/TransparentWidget.hpp" #include "ui/common.hpp" namespace rack { +namespace ui { -struct TooltipOverlay : TransparentWidget { +struct TooltipOverlay : widget::TransparentWidget { }; +} // namespace ui } // namespace rack diff --git a/include/widgets/FramebufferWidget.hpp b/include/widget/FramebufferWidget.hpp similarity index 94% rename from include/widgets/FramebufferWidget.hpp rename to include/widget/FramebufferWidget.hpp index a096710f..f43d38b6 100644 --- a/include/widgets/FramebufferWidget.hpp +++ b/include/widget/FramebufferWidget.hpp @@ -1,8 +1,9 @@ #pragma once -#include "widgets/Widget.hpp" +#include "widget/Widget.hpp" namespace rack { +namespace widget { /** Caches a widget's draw() result to a framebuffer so it is called less frequently @@ -38,4 +39,5 @@ struct FramebufferWidget : Widget { }; +} // namespace widget } // namespace rack diff --git a/include/widgets/GLWidget.hpp b/include/widget/GLWidget.hpp similarity index 76% rename from include/widgets/GLWidget.hpp rename to include/widget/GLWidget.hpp index 9b162203..90482128 100644 --- a/include/widgets/GLWidget.hpp +++ b/include/widget/GLWidget.hpp @@ -1,8 +1,9 @@ #pragma once -#include "widgets/FramebufferWidget.hpp" +#include "widget/FramebufferWidget.hpp" namespace rack { +namespace widget { struct GLWidget : FramebufferWidget { @@ -14,4 +15,5 @@ struct GLWidget : FramebufferWidget { }; +} // namespace widget } // namespace rack diff --git a/include/widgets/ObstructWidget.hpp b/include/widget/ObstructWidget.hpp similarity index 91% rename from include/widgets/ObstructWidget.hpp rename to include/widget/ObstructWidget.hpp index a9790758..8bdd6098 100644 --- a/include/widgets/ObstructWidget.hpp +++ b/include/widget/ObstructWidget.hpp @@ -1,8 +1,9 @@ #pragma once -#include "widgets/Widget.hpp" +#include "widget/Widget.hpp" namespace rack { +namespace widget { /** Widget that consumes recursing events without giving a chance for children to consume. @@ -32,4 +33,5 @@ struct ObstructWidget : Widget { }; +} // namespace widget } // namespace rack diff --git a/include/widgets/OpaqueWidget.hpp b/include/widget/OpaqueWidget.hpp similarity index 94% rename from include/widgets/OpaqueWidget.hpp rename to include/widget/OpaqueWidget.hpp index 26d65997..656ce4c6 100644 --- a/include/widgets/OpaqueWidget.hpp +++ b/include/widget/OpaqueWidget.hpp @@ -1,8 +1,9 @@ #pragma once -#include "widgets/Widget.hpp" +#include "widget/Widget.hpp" namespace rack { +namespace widget { /** Widget that consumes recursing events but gives a chance for children to consume first. @@ -48,4 +49,5 @@ struct OpaqueWidget : Widget { }; +} // namespace widget } // namespace rack diff --git a/include/widgets/SVGWidget.hpp b/include/widget/SVGWidget.hpp similarity index 89% rename from include/widgets/SVGWidget.hpp rename to include/widget/SVGWidget.hpp index 489d6b11..019ab675 100644 --- a/include/widgets/SVGWidget.hpp +++ b/include/widget/SVGWidget.hpp @@ -1,9 +1,10 @@ #pragma once -#include "widgets/Widget.hpp" +#include "widget/Widget.hpp" #include "svg.hpp" namespace rack { +namespace widget { /** Draws an SVG */ @@ -34,4 +35,5 @@ struct SVGWidget : Widget { }; +} // namespace widget } // namespace rack diff --git a/include/widgets/TransformWidget.hpp b/include/widget/TransformWidget.hpp similarity index 92% rename from include/widgets/TransformWidget.hpp rename to include/widget/TransformWidget.hpp index 5887f1c0..e47685a1 100644 --- a/include/widgets/TransformWidget.hpp +++ b/include/widget/TransformWidget.hpp @@ -1,8 +1,9 @@ #pragma once -#include "widgets/Widget.hpp" +#include "widget/Widget.hpp" namespace rack { +namespace widget { /** Transforms appearance only, not positions of events */ @@ -44,4 +45,5 @@ struct TransformWidget : Widget { }; +} // namespace widget } // namespace rack diff --git a/include/widgets/TransparentWidget.hpp b/include/widget/TransparentWidget.hpp similarity index 89% rename from include/widgets/TransparentWidget.hpp rename to include/widget/TransparentWidget.hpp index 026d7c25..9b0c32c2 100644 --- a/include/widgets/TransparentWidget.hpp +++ b/include/widget/TransparentWidget.hpp @@ -1,8 +1,9 @@ #pragma once -#include "widgets/Widget.hpp" +#include "widget/Widget.hpp" namespace rack { +namespace widget { /** Widget that does not respond to events and does not pass events to children */ @@ -18,4 +19,5 @@ struct TransparentWidget : Widget { }; +} // namespace widget } // namespace rack diff --git a/include/widgets/Widget.hpp b/include/widget/Widget.hpp similarity index 99% rename from include/widgets/Widget.hpp rename to include/widget/Widget.hpp index 46f960e5..8b60db38 100644 --- a/include/widgets/Widget.hpp +++ b/include/widget/Widget.hpp @@ -8,6 +8,7 @@ namespace rack { +namespace widget { struct DrawContext { @@ -144,4 +145,5 @@ struct Widget { }; +} // namespace widget } // namespace rack diff --git a/include/widgets/ZoomWidget.hpp b/include/widget/ZoomWidget.hpp similarity index 94% rename from include/widgets/ZoomWidget.hpp rename to include/widget/ZoomWidget.hpp index 4e32d0a0..0e4aa38d 100644 --- a/include/widgets/ZoomWidget.hpp +++ b/include/widget/ZoomWidget.hpp @@ -1,8 +1,9 @@ #pragma once -#include "widgets/Widget.hpp" +#include "widget/Widget.hpp" namespace rack { +namespace widget { struct ZoomWidget : Widget { @@ -51,4 +52,5 @@ struct ZoomWidget : Widget { }; +} // namespace widget } // namespace rack diff --git a/src/Core/AudioInterface.cpp b/src/Core/AudioInterface.cpp index aba0c073..35de6831 100644 --- a/src/Core/AudioInterface.cpp +++ b/src/Core/AudioInterface.cpp @@ -124,7 +124,7 @@ struct AudioInterface : Module { void step() override { // Update SRC states - int sampleRate = (int) app()->engine->getSampleRate(); + int sampleRate = (int) APP->engine->getSampleRate(); inputSrc.setRates(audioIO.sampleRate, sampleRate); outputSrc.setRates(sampleRate, audioIO.sampleRate); diff --git a/src/Core/Blank.cpp b/src/Core/Blank.cpp index 725f0c26..4fc7a1df 100644 --- a/src/Core/Blank.cpp +++ b/src/Core/Blank.cpp @@ -39,14 +39,14 @@ struct ModuleResizeHandle : Widget { } } void onDragStart(const event::DragStart &e) override { - dragX = app()->scene->rackWidget->mousePos.x; + dragX = APP->scene->rackWidget->mousePos.x; ModuleWidget *m = getAncestorOfType(); originalBox = m->box; } void onDragMove(const event::DragMove &e) override { ModuleWidget *m = getAncestorOfType(); - float newDragX = app()->scene->rackWidget->mousePos.x; + float newDragX = APP->scene->rackWidget->mousePos.x; float deltaX = newDragX - dragX; Rect newBox = originalBox; @@ -62,7 +62,7 @@ struct ModuleResizeHandle : Widget { newBox.size.x = roundf(newBox.size.x / RACK_GRID_WIDTH) * RACK_GRID_WIDTH; newBox.pos.x = originalBox.pos.x + originalBox.size.x - newBox.size.x; } - app()->scene->rackWidget->requestModuleBox(m, newBox); + APP->scene->rackWidget->requestModuleBox(m, newBox); } void draw(const DrawContext &ctx) override { for (float x = 5.0; x <= 10.0; x += 5.0) { diff --git a/src/Core/CV_CC.cpp b/src/Core/CV_CC.cpp index da124588..043fc3be 100644 --- a/src/Core/CV_CC.cpp +++ b/src/Core/CV_CC.cpp @@ -64,7 +64,7 @@ struct CV_CC : Module { void step() override { const float rateLimiterPeriod = 0.010f; - rateLimiterPhase += app()->engine->getSampleTime() / rateLimiterPeriod; + rateLimiterPhase += APP->engine->getSampleTime() / rateLimiterPeriod; if (rateLimiterPhase >= 1.f) { rateLimiterPhase -= 1.f; } diff --git a/src/Core/CV_MIDI.cpp b/src/Core/CV_MIDI.cpp index 42cdca90..8fdaaf23 100644 --- a/src/Core/CV_MIDI.cpp +++ b/src/Core/CV_MIDI.cpp @@ -243,7 +243,7 @@ struct CV_MIDI : Module { void step() override { const float rateLimiterPeriod = 0.005f; - rateLimiterPhase += app()->engine->getSampleTime() / rateLimiterPeriod; + rateLimiterPhase += APP->engine->getSampleTime() / rateLimiterPeriod; if (rateLimiterPhase >= 1.f) { rateLimiterPhase -= 1.f; } diff --git a/src/Core/Core.hpp b/src/Core/Core.hpp index e9c79908..752fd35b 100644 --- a/src/Core/Core.hpp +++ b/src/Core/Core.hpp @@ -102,8 +102,8 @@ struct CcChoice : LedDisplayChoice { else { text = string::f("%d", module->learnedCcs[id]); color.a = 1.0; - if (app()->event->selectedWidget == this) - app()->event->selectedWidget = NULL; + if (APP->event->selectedWidget == this) + APP->event->selectedWidget = NULL; } } @@ -140,7 +140,7 @@ struct CcChoice : LedDisplayChoice { if ((e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER) && e.action == GLFW_PRESS && (e.mods & WINDOW_MOD_MASK) == 0) { event::Deselect eDeselect; onDeselect(eDeselect); - app()->event->selectedWidget = NULL; + APP->event->selectedWidget = NULL; e.consume(this); } } @@ -179,8 +179,8 @@ struct NoteChoice : LedDisplayChoice { text = string::f("%s%d", noteNames[semi], oct); color.a = 1.0; - if (app()->event->selectedWidget == this) - app()->event->selectedWidget = NULL; + if (APP->event->selectedWidget == this) + APP->event->selectedWidget = NULL; } } diff --git a/src/Core/MIDI_CC.cpp b/src/Core/MIDI_CC.cpp index db4cb8ce..0d08ea58 100644 --- a/src/Core/MIDI_CC.cpp +++ b/src/Core/MIDI_CC.cpp @@ -45,7 +45,7 @@ struct MIDI_CC : Module { processMessage(msg); } - float lambda = app()->engine->getSampleTime() * 100.f; + float lambda = APP->engine->getSampleTime() * 100.f; for (int i = 0; i < 16; i++) { if (!outputs[CC_OUTPUT + i].isConnected()) continue; diff --git a/src/Core/MIDI_CV.cpp b/src/Core/MIDI_CV.cpp index b6055ac2..b6675716 100644 --- a/src/Core/MIDI_CV.cpp +++ b/src/Core/MIDI_CV.cpp @@ -76,7 +76,7 @@ struct MIDI_CV : Module { while (midiInput.shift(&msg)) { processMessage(msg); } - float deltaTime = app()->engine->getSampleTime(); + float deltaTime = APP->engine->getSampleTime(); outputs[CV_OUTPUT].setVoltage((lastNote - 60) / 12.f); outputs[GATE_OUTPUT].setVoltage(gate ? 10.f : 0.f); diff --git a/src/Core/MIDI_Gate.cpp b/src/Core/MIDI_Gate.cpp index 0bcb18c5..fbceb0b1 100644 --- a/src/Core/MIDI_Gate.cpp +++ b/src/Core/MIDI_Gate.cpp @@ -70,7 +70,7 @@ struct MIDI_Gate : Module { while (midiInput.shift(&msg)) { processMessage(msg); } - float deltaTime = app()->engine->getSampleTime(); + float deltaTime = APP->engine->getSampleTime(); for (int i = 0; i < 16; i++) { if (gateTimes[i] > 0.f) { diff --git a/src/app.cpp b/src/app.cpp index 7ec83858..8fcc2bfa 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -8,6 +8,7 @@ namespace rack { +namespace app { App::App() { @@ -33,20 +34,21 @@ App::~App() { static App *c = NULL; -void appInit() { +void init() { assert(!c); c = new App; } -void appDestroy() { +void destroy() { assert(c); delete c; c = NULL; } -App *app() { +App *get() { return c; } +} // namespace app } // namespace rack diff --git a/src/app/AudioWidget.cpp b/src/app/AudioWidget.cpp index b39a13f1..5fd0342d 100644 --- a/src/app/AudioWidget.cpp +++ b/src/app/AudioWidget.cpp @@ -4,9 +4,10 @@ namespace rack { +namespace app { -struct AudioDriverItem : MenuItem { +struct AudioDriverItem : ui::MenuItem { audio::IO *audioIO; int driver; void onAction(const event::Action &e) override { @@ -20,7 +21,7 @@ struct AudioDriverChoice : LedDisplayChoice { if (!audioWidget->audioIO) return; - Menu *menu = createMenu(); + ui::Menu *menu = createMenu(); menu->addChild(createMenuLabel("Audio driver")); for (int driver : audioWidget->audioIO->getDrivers()) { AudioDriverItem *item = new AudioDriverItem; @@ -40,7 +41,7 @@ struct AudioDriverChoice : LedDisplayChoice { }; -struct AudioDeviceItem : MenuItem { +struct AudioDeviceItem : ui::MenuItem { audio::IO *audioIO; int device; int offset; @@ -58,7 +59,7 @@ struct AudioDeviceChoice : LedDisplayChoice { if (!audioWidget->audioIO) return; - Menu *menu = createMenu(); + ui::Menu *menu = createMenu(); menu->addChild(createMenuLabel("Audio device")); int deviceCount = audioWidget->audioIO->getDeviceCount(); { @@ -99,7 +100,7 @@ struct AudioDeviceChoice : LedDisplayChoice { }; -struct AudioSampleRateItem : MenuItem { +struct AudioSampleRateItem : ui::MenuItem { audio::IO *audioIO; int sampleRate; void onAction(const event::Action &e) override { @@ -113,7 +114,7 @@ struct AudioSampleRateChoice : LedDisplayChoice { if (!audioWidget->audioIO) return; - Menu *menu = createMenu(); + ui::Menu *menu = createMenu(); menu->addChild(createMenuLabel("Sample rate")); std::vector sampleRates = audioWidget->audioIO->getSampleRates(); if (sampleRates.empty()) { @@ -137,7 +138,7 @@ struct AudioSampleRateChoice : LedDisplayChoice { }; -struct AudioBlockSizeItem : MenuItem { +struct AudioBlockSizeItem : ui::MenuItem { audio::IO *audioIO; int blockSize; void onAction(const event::Action &e) override { @@ -151,7 +152,7 @@ struct AudioBlockSizeChoice : LedDisplayChoice { if (!audioWidget->audioIO) return; - Menu *menu = createMenu(); + ui::Menu *menu = createMenu(); menu->addChild(createMenuLabel("Block size")); std::vector blockSizes = audioWidget->audioIO->getBlockSizes(); if (blockSizes.empty()) { @@ -227,4 +228,5 @@ void AudioWidget::step() { } +} // namespace app } // namespace rack diff --git a/src/app/CableWidget.cpp b/src/app/CableWidget.cpp index 402e60a6..9451cf8d 100644 --- a/src/app/CableWidget.cpp +++ b/src/app/CableWidget.cpp @@ -9,8 +9,9 @@ namespace rack { +namespace app { -static void drawPlug(const DrawContext &ctx, math::Vec pos, NVGcolor color) { +static void drawPlug(const widget::DrawContext &ctx, math::Vec pos, NVGcolor color) { NVGcolor colorOutline = nvgLerpRGBA(color, nvgRGBf(0.0, 0.0, 0.0), 0.5); // Plug solid @@ -31,7 +32,7 @@ static void drawPlug(const DrawContext &ctx, math::Vec pos, NVGcolor color) { nvgFill(ctx.vg); } -static void drawCable(const DrawContext &ctx, math::Vec pos1, math::Vec pos2, NVGcolor color, float thickness, float tension, float opacity) { +static void drawCable(const widget::DrawContext &ctx, math::Vec pos1, math::Vec pos2, NVGcolor color, float thickness, float tension, float opacity) { NVGcolor colorShadow = nvgRGBAf(0, 0, 0, 0.10); NVGcolor colorOutline = nvgLerpRGBA(color, nvgRGBf(0.0, 0.0, 0.0), 0.5); @@ -119,25 +120,25 @@ void CableWidget::setInput(PortWidget *inputPort) { math::Vec CableWidget::getOutputPos() { if (outputPort) { - return outputPort->getRelativeOffset(outputPort->box.zeroPos().getCenter(), app()->scene->rackWidget); + return outputPort->getRelativeOffset(outputPort->box.zeroPos().getCenter(), APP->scene->rackWidget); } else if (hoveredOutputPort) { - return hoveredOutputPort->getRelativeOffset(hoveredOutputPort->box.zeroPos().getCenter(), app()->scene->rackWidget); + return hoveredOutputPort->getRelativeOffset(hoveredOutputPort->box.zeroPos().getCenter(), APP->scene->rackWidget); } else { - return app()->scene->rackWidget->mousePos; + return APP->scene->rackWidget->mousePos; } } math::Vec CableWidget::getInputPos() { if (inputPort) { - return inputPort->getRelativeOffset(inputPort->box.zeroPos().getCenter(), app()->scene->rackWidget); + return inputPort->getRelativeOffset(inputPort->box.zeroPos().getCenter(), APP->scene->rackWidget); } else if (hoveredInputPort) { - return hoveredInputPort->getRelativeOffset(hoveredInputPort->box.zeroPos().getCenter(), app()->scene->rackWidget); + return hoveredInputPort->getRelativeOffset(hoveredInputPort->box.zeroPos().getCenter(), APP->scene->rackWidget); } else { - return app()->scene->rackWidget->mousePos; + return APP->scene->rackWidget->mousePos; } } @@ -175,7 +176,7 @@ void CableWidget::fromJson(json_t *rootJ, const std::map &mo ModuleWidget *inputModule = inputModuleIt->second; // Set ports - if (app()->patch->isLegacy(1)) { + if (APP->patch->isLegacy(1)) { // Before 0.6, the index of the "ports" array was the index of the PortWidget in the `outputs` and `inputs` vector. setOutput(outputModule->outputs[outputId]); setInput(inputModule->inputs[inputId]); @@ -205,7 +206,7 @@ void CableWidget::fromJson(json_t *rootJ, const std::map &mo } } -void CableWidget::draw(const DrawContext &ctx) { +void CableWidget::draw(const widget::DrawContext &ctx) { float opacity = settings::cableOpacity; float tension = settings::cableTension; @@ -215,7 +216,7 @@ void CableWidget::draw(const DrawContext &ctx) { } else { // Draw opaque if mouse is hovering over a connected port - PortWidget *hoveredPort = dynamic_cast(app()->event->hoveredWidget); + PortWidget *hoveredPort = dynamic_cast(APP->event->hoveredWidget); if (hoveredPort && (hoveredPort == outputPort || hoveredPort == inputPort)) opacity = 1.0; } @@ -238,13 +239,13 @@ void CableWidget::draw(const DrawContext &ctx) { drawCable(ctx, outputPos, inputPos, color, thickness, tension, opacity); } -void CableWidget::drawPlugs(const DrawContext &ctx) { +void CableWidget::drawPlugs(const widget::DrawContext &ctx) { // TODO Figure out a way to draw plugs first and cables last, and cut the plug portion of the cable off. math::Vec outputPos = getOutputPos(); math::Vec inputPos = getInputPos(); // Draw plug if the cable is on top, or if the cable is incomplete - if (!isComplete() || app()->scene->rackWidget->getTopCable(outputPort) == this) { + if (!isComplete() || APP->scene->rackWidget->getTopCable(outputPort) == this) { drawPlug(ctx, outputPos, color); if (isComplete()) { // Draw plug light @@ -255,7 +256,7 @@ void CableWidget::drawPlugs(const DrawContext &ctx) { } } - if (!isComplete() || app()->scene->rackWidget->getTopCable(inputPort) == this) { + if (!isComplete() || APP->scene->rackWidget->getTopCable(inputPort) == this) { drawPlug(ctx, inputPos, color); if (isComplete()) { nvgSave(ctx.vg); @@ -267,4 +268,5 @@ void CableWidget::drawPlugs(const DrawContext &ctx) { } +} // namespace app } // namespace rack diff --git a/src/app/CircularShadow.cpp b/src/app/CircularShadow.cpp index c9e37897..6f9c1cf9 100644 --- a/src/app/CircularShadow.cpp +++ b/src/app/CircularShadow.cpp @@ -2,6 +2,7 @@ namespace rack { +namespace app { CircularShadow::CircularShadow() { @@ -9,7 +10,7 @@ CircularShadow::CircularShadow() { opacity = 0.15; } -void CircularShadow::draw(const DrawContext &ctx) { +void CircularShadow::draw(const widget::DrawContext &ctx) { if (opacity <= 0.0) return; @@ -25,4 +26,5 @@ void CircularShadow::draw(const DrawContext &ctx) { } +} // namespace app } // namespace rack diff --git a/src/app/Knob.cpp b/src/app/Knob.cpp index 1eb0a036..b7c7b2f6 100644 --- a/src/app/Knob.cpp +++ b/src/app/Knob.cpp @@ -5,6 +5,7 @@ namespace rack { +namespace app { static const float KNOB_SENSITIVITY = 0.0015f; @@ -34,11 +35,11 @@ void Knob::onDragStart(const event::DragStart &e) { } } - app()->window->cursorLock(); + APP->window->cursorLock(); } void Knob::onDragEnd(const event::DragEnd &e) { - app()->window->cursorUnlock(); + APP->window->cursorUnlock(); if (paramQuantity) { float newValue = paramQuantity->getSmoothValue(); @@ -49,7 +50,7 @@ void Knob::onDragEnd(const event::DragEnd &e) { h->paramId = paramQuantity->paramId; h->oldValue = oldValue; h->newValue = newValue; - app()->history->push(h); + APP->history->push(h); } } } @@ -70,7 +71,7 @@ void Knob::onDragMove(const event::DragMove &e) { delta *= range; // Drag slower if mod is held - int mods = app()->window->getMods(); + int mods = APP->window->getMods(); if ((mods & WINDOW_MOD_MASK) == WINDOW_MOD_CTRL) { delta /= 16.f; } @@ -96,4 +97,5 @@ void Knob::onDragMove(const event::DragMove &e) { } +} // namespace app } // namespace rack diff --git a/src/app/LedDisplay.cpp b/src/app/LedDisplay.cpp index d7c38857..d0bbf2b4 100644 --- a/src/app/LedDisplay.cpp +++ b/src/app/LedDisplay.cpp @@ -6,15 +6,16 @@ namespace rack { +namespace app { -void LedDisplay::draw(const DrawContext &ctx) { +void LedDisplay::draw(const widget::DrawContext &ctx) { nvgBeginPath(ctx.vg); nvgRoundedRect(ctx.vg, 0, 0, box.size.x, box.size.y, 5.0); nvgFillColor(ctx.vg, nvgRGB(0x00, 0x00, 0x00)); nvgFill(ctx.vg); - Widget::draw(ctx); + widget::Widget::draw(ctx); } @@ -22,7 +23,7 @@ LedDisplaySeparator::LedDisplaySeparator() { box.size = math::Vec(); } -void LedDisplaySeparator::draw(const DrawContext &ctx) { +void LedDisplaySeparator::draw(const widget::DrawContext &ctx) { nvgBeginPath(ctx.vg); nvgMoveTo(ctx.vg, 0, 0); nvgLineTo(ctx.vg, box.size.x, box.size.y); @@ -39,7 +40,7 @@ LedDisplayChoice::LedDisplayChoice() { textOffset = math::Vec(10, 18); } -void LedDisplayChoice::draw(const DrawContext &ctx) { +void LedDisplayChoice::draw(const widget::DrawContext &ctx) { nvgScissor(ctx.vg, 0, 0, box.size.x, box.size.y); if (font->handle >= 0) { @@ -70,7 +71,7 @@ LedDisplayTextField::LedDisplayTextField() { } -void LedDisplayTextField::draw(const DrawContext &ctx) { +void LedDisplayTextField::draw(const widget::DrawContext &ctx) { nvgScissor(ctx.vg, 0, 0, box.size.x, box.size.y); // Background @@ -86,12 +87,12 @@ void LedDisplayTextField::draw(const DrawContext &ctx) { NVGcolor highlightColor = color; highlightColor.a = 0.5; int begin = std::min(cursor, selection); - int end = (this == app()->event->selectedWidget) ? std::max(cursor, selection) : -1; + int end = (this == APP->event->selectedWidget) ? std::max(cursor, selection) : -1; bndIconLabelCaret(ctx.vg, textOffset.x, textOffset.y, box.size.x - 2*textOffset.x, box.size.y - 2*textOffset.y, -1, color, 12, text.c_str(), highlightColor, begin, end); - bndSetFont(app()->window->uiFont->handle); + bndSetFont(APP->window->uiFont->handle); } nvgResetScissor(ctx.vg); @@ -99,12 +100,13 @@ void LedDisplayTextField::draw(const DrawContext &ctx) { int LedDisplayTextField::getTextPosition(math::Vec mousePos) { bndSetFont(font->handle); - int textPos = bndIconLabelTextPosition(app()->window->vg, textOffset.x, textOffset.y, + int textPos = bndIconLabelTextPosition(APP->window->vg, textOffset.x, textOffset.y, box.size.x - 2*textOffset.x, box.size.y - 2*textOffset.y, -1, 12, text.c_str(), mousePos.x, mousePos.y); - bndSetFont(app()->window->uiFont->handle); + bndSetFont(APP->window->uiFont->handle); return textPos; } +} // namespace app } // namespace rack diff --git a/src/app/LightWidget.cpp b/src/app/LightWidget.cpp index 87868088..9cfbc763 100644 --- a/src/app/LightWidget.cpp +++ b/src/app/LightWidget.cpp @@ -3,14 +3,15 @@ namespace rack { +namespace app { -void LightWidget::draw(const DrawContext &ctx) { +void LightWidget::draw(const widget::DrawContext &ctx) { drawLight(ctx); drawHalo(ctx); } -void LightWidget::drawLight(const DrawContext &ctx) { +void LightWidget::drawLight(const widget::DrawContext &ctx) { float radius = box.size.x / 2.0; nvgBeginPath(ctx.vg); @@ -30,7 +31,7 @@ void LightWidget::drawLight(const DrawContext &ctx) { nvgStroke(ctx.vg); } -void LightWidget::drawHalo(const DrawContext &ctx) { +void LightWidget::drawHalo(const widget::DrawContext &ctx) { float radius = box.size.x / 2.0; float oradius = radius + 15.0; @@ -47,4 +48,5 @@ void LightWidget::drawHalo(const DrawContext &ctx) { } +} // namespace app } // namespace rack diff --git a/src/app/MidiWidget.cpp b/src/app/MidiWidget.cpp index 2aae19d3..19cb9809 100644 --- a/src/app/MidiWidget.cpp +++ b/src/app/MidiWidget.cpp @@ -4,9 +4,10 @@ namespace rack { +namespace app { -struct MidiDriverItem : MenuItem { +struct MidiDriverItem : ui::MenuItem { midi::IO *midiIO; int driverId; void onAction(const event::Action &e) override { @@ -20,7 +21,7 @@ struct MidiDriverChoice : LedDisplayChoice { if (!midiWidget->midiIO) return; - Menu *menu = createMenu(); + ui::Menu *menu = createMenu(); menu->addChild(createMenuLabel("MIDI driver")); for (int driverId : midiWidget->midiIO->getDriverIds()) { MidiDriverItem *item = new MidiDriverItem; @@ -47,7 +48,7 @@ struct MidiDriverChoice : LedDisplayChoice { } }; -struct MidiDeviceItem : MenuItem { +struct MidiDeviceItem : ui::MenuItem { midi::IO *midiIO; int deviceId; void onAction(const event::Action &e) override { @@ -61,7 +62,7 @@ struct MidiDeviceChoice : LedDisplayChoice { if (!midiWidget->midiIO) return; - Menu *menu = createMenu(); + ui::Menu *menu = createMenu(); menu->addChild(createMenuLabel("MIDI device")); { MidiDeviceItem *item = new MidiDeviceItem; @@ -96,7 +97,7 @@ struct MidiDeviceChoice : LedDisplayChoice { } }; -struct MidiChannelItem : MenuItem { +struct MidiChannelItem : ui::MenuItem { midi::IO *midiIO; int channel; void onAction(const event::Action &e) override { @@ -110,7 +111,7 @@ struct MidiChannelChoice : LedDisplayChoice { if (!midiWidget->midiIO) return; - Menu *menu = createMenu(); + ui::Menu *menu = createMenu(); menu->addChild(createMenuLabel("MIDI channel")); for (int channel : midiWidget->midiIO->getChannels()) { MidiChannelItem *item = new MidiChannelItem; @@ -169,4 +170,5 @@ void MidiWidget::step() { } +} // namespace app } // namespace rack diff --git a/src/app/ModuleBrowser.cpp b/src/app/ModuleBrowser.cpp index 8c1f9d78..0ba8102e 100644 --- a/src/app/ModuleBrowser.cpp +++ b/src/app/ModuleBrowser.cpp @@ -1,7 +1,7 @@ #include "app/ModuleBrowser.hpp" -#include "widgets/OpaqueWidget.hpp" -#include "widgets/TransparentWidget.hpp" -#include "widgets/ZoomWidget.hpp" +#include "widget/OpaqueWidget.hpp" +#include "widget/TransparentWidget.hpp" +#include "widget/ZoomWidget.hpp" #include "ui/ScrollWidget.hpp" #include "ui/SequentialLayout.hpp" #include "ui/Label.hpp" @@ -18,19 +18,20 @@ namespace rack { +namespace app { static std::set sFavoriteModels; -struct BrowserOverlay : OpaqueWidget { +struct BrowserOverlay : widget::OpaqueWidget { void step() override { box = parent->box.zeroPos(); - OpaqueWidget::step(); + widget::OpaqueWidget::step(); } void onButton(const event::Button &e) override { - OpaqueWidget::onButton(e); + widget::OpaqueWidget::onButton(e); if (e.getConsumed() != this) return; @@ -50,15 +51,15 @@ struct BrowserOverlay : OpaqueWidget { } if (!e.getConsumed()) - OpaqueWidget::onHoverKey(e); + widget::OpaqueWidget::onHoverKey(e); } }; -struct ModuleBox : OpaqueWidget { +struct ModuleBox : widget::OpaqueWidget { Model *model; /** Lazily created */ - Widget *previewWidget = NULL; + widget::Widget *previewWidget = NULL; /** Number of frames since draw() has been called */ int visibleFrames = 0; @@ -72,13 +73,13 @@ struct ModuleBox : OpaqueWidget { p.y = box.size.y; box.size.y += 40.0; - Label *nameLabel = new Label; + ui::Label *nameLabel = new ui::Label; nameLabel->text = model->name; nameLabel->box.pos = p; p.y += nameLabel->box.size.y; addChild(nameLabel); - Label *pluginLabel = new Label; + ui::Label *pluginLabel = new ui::Label; pluginLabel->text = model->plugin->name; pluginLabel->box.pos = p; p.y += pluginLabel->box.size.y; @@ -93,22 +94,22 @@ struct ModuleBox : OpaqueWidget { } } - void draw(const DrawContext &ctx) override { + void draw(const widget::DrawContext &ctx) override { visibleFrames = 0; // Lazily create ModuleWidget when drawn if (!previewWidget) { - Widget *transparentWidget = new TransparentWidget; + widget::Widget *transparentWidget = new widget::TransparentWidget; addChild(transparentWidget); - FramebufferWidget *fbWidget = new FramebufferWidget; - if (math::isNear(app()->window->pixelRatio, 1.0)) { + widget::FramebufferWidget *fbWidget = new widget::FramebufferWidget; + if (math::isNear(APP->window->pixelRatio, 1.0)) { // Small details draw poorly at low DPI, so oversample when drawing to the framebuffer fbWidget->oversample = 2.0; } transparentWidget->addChild(fbWidget); - ZoomWidget *zoomWidget = new ZoomWidget; + widget::ZoomWidget *zoomWidget = new widget::ZoomWidget; zoomWidget->setZoom(0.5f); fbWidget->addChild(zoomWidget); @@ -123,8 +124,8 @@ struct ModuleBox : OpaqueWidget { previewWidget = transparentWidget; } - OpaqueWidget::draw(ctx); - if (app()->event->hoveredWidget == this) { + widget::OpaqueWidget::draw(ctx); + if (APP->event->hoveredWidget == this) { nvgBeginPath(ctx.vg); nvgRect(ctx.vg, 0.0, 0.0, box.size.x, box.size.y); nvgFillColor(ctx.vg, nvgRGBAf(1, 1, 1, 0.25)); @@ -136,11 +137,11 @@ struct ModuleBox : OpaqueWidget { }; -struct BrowserSearchField : TextField { +struct BrowserSearchField : ui::TextField { }; -struct BrowserSidebar : Widget { +struct BrowserSidebar : widget::Widget { BrowserSearchField *searchField; BrowserSidebar() { @@ -150,25 +151,25 @@ struct BrowserSidebar : Widget { void step() override { searchField->box.size.x = box.size.x; - Widget::step(); + widget::Widget::step(); } }; -struct ModuleBrowser : OpaqueWidget { +struct ModuleBrowser : widget::OpaqueWidget { BrowserSidebar *sidebar; - ScrollWidget *moduleScroll; - SequentialLayout *moduleLayout; + ui::ScrollWidget *moduleScroll; + ui::SequentialLayout *moduleLayout; ModuleBrowser() { sidebar = new BrowserSidebar; sidebar->box.size.x = 300; addChild(sidebar); - moduleScroll = new ScrollWidget; + moduleScroll = new ui::ScrollWidget; addChild(moduleScroll); - moduleLayout = new SequentialLayout; + moduleLayout = new ui::SequentialLayout; moduleLayout->spacing = math::Vec(10, 10); moduleScroll->container->addChild(moduleLayout); @@ -192,12 +193,12 @@ struct ModuleBrowser : OpaqueWidget { moduleLayout->box.size.x = moduleScroll->box.size.x; moduleLayout->box.size.y = moduleLayout->getChildrenBoundingBox().getBottomRight().y; - OpaqueWidget::step(); + widget::OpaqueWidget::step(); } - void draw(const DrawContext &ctx) override { + void draw(const widget::DrawContext &ctx) override { bndMenuBackground(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, 0); - Widget::draw(ctx); + widget::Widget::draw(ctx); } }; @@ -210,7 +211,7 @@ void ModuleBox::onButton(const event::Button &e) { // Create module ModuleWidget *moduleWidget = model->createModuleWidget(); assert(moduleWidget); - app()->scene->rackWidget->addModuleAtMouse(moduleWidget); + APP->scene->rackWidget->addModuleAtMouse(moduleWidget); // This is a bit nonstandard/unsupported usage, but pretend the moduleWidget was clicked so it can be dragged in the RackWidget // e.consume(moduleWidget); @@ -221,16 +222,16 @@ void ModuleBox::onButton(const event::Button &e) { // Push ModuleAdd history action history::ModuleAdd *h = new history::ModuleAdd; h->setModule(moduleWidget); - app()->history->push(h); + APP->history->push(h); } - OpaqueWidget::onButton(e); + widget::OpaqueWidget::onButton(e); } // Global functions -Widget *moduleBrowserCreate() { +widget::Widget *moduleBrowserCreate() { BrowserOverlay *overlay = new BrowserOverlay; ModuleBrowser *browser = new ModuleBrowser; @@ -275,4 +276,5 @@ void moduleBrowserFromJson(json_t *rootJ) { } +} // namespace app } // namespace rack diff --git a/src/app/ModuleLightWidget.cpp b/src/app/ModuleLightWidget.cpp index a8be91fb..db25d16e 100644 --- a/src/app/ModuleLightWidget.cpp +++ b/src/app/ModuleLightWidget.cpp @@ -2,6 +2,7 @@ namespace rack { +namespace app { void ModuleLightWidget::step() { @@ -24,4 +25,5 @@ void ModuleLightWidget::step() { } +} // namespace app } // namespace rack diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 2494323a..20d0ddb8 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -13,12 +13,13 @@ namespace rack { +namespace app { static const char PRESET_FILTERS[] = "VCV Rack module preset (.vcvm):vcvm"; -struct ModuleDisconnectItem : MenuItem { +struct ModuleDisconnectItem : ui::MenuItem { ModuleWidget *moduleWidget; ModuleDisconnectItem() { text = "Disconnect cables"; @@ -29,7 +30,7 @@ struct ModuleDisconnectItem : MenuItem { } }; -struct ModuleResetItem : MenuItem { +struct ModuleResetItem : ui::MenuItem { ModuleWidget *moduleWidget; ModuleResetItem() { text = "Initialize"; @@ -40,7 +41,7 @@ struct ModuleResetItem : MenuItem { } }; -struct ModuleRandomizeItem : MenuItem { +struct ModuleRandomizeItem : ui::MenuItem { ModuleWidget *moduleWidget; ModuleRandomizeItem() { text = "Randomize"; @@ -51,7 +52,7 @@ struct ModuleRandomizeItem : MenuItem { } }; -struct ModuleCopyItem : MenuItem { +struct ModuleCopyItem : ui::MenuItem { ModuleWidget *moduleWidget; ModuleCopyItem() { text = "Copy preset"; @@ -62,7 +63,7 @@ struct ModuleCopyItem : MenuItem { } }; -struct ModulePasteItem : MenuItem { +struct ModulePasteItem : ui::MenuItem { ModuleWidget *moduleWidget; ModulePasteItem() { text = "Paste preset"; @@ -73,7 +74,7 @@ struct ModulePasteItem : MenuItem { } }; -struct ModuleSaveItem : MenuItem { +struct ModuleSaveItem : ui::MenuItem { ModuleWidget *moduleWidget; ModuleSaveItem() { text = "Save preset as"; @@ -83,7 +84,7 @@ struct ModuleSaveItem : MenuItem { } }; -struct ModuleLoadItem : MenuItem { +struct ModuleLoadItem : ui::MenuItem { ModuleWidget *moduleWidget; ModuleLoadItem() { text = "Load preset"; @@ -93,7 +94,7 @@ struct ModuleLoadItem : MenuItem { } }; -struct ModuleCloneItem : MenuItem { +struct ModuleCloneItem : ui::MenuItem { ModuleWidget *moduleWidget; ModuleCloneItem() { text = "Duplicate"; @@ -104,7 +105,7 @@ struct ModuleCloneItem : MenuItem { } }; -struct ModuleBypassItem : MenuItem { +struct ModuleBypassItem : ui::MenuItem { ModuleWidget *moduleWidget; ModuleBypassItem() { text = "Bypass"; @@ -120,7 +121,7 @@ struct ModuleBypassItem : MenuItem { } }; -struct ModuleDeleteItem : MenuItem { +struct ModuleDeleteItem : ui::MenuItem { ModuleWidget *moduleWidget; ModuleDeleteItem() { text = "Delete"; @@ -136,12 +137,12 @@ ModuleWidget::~ModuleWidget() { setModule(NULL); } -void ModuleWidget::draw(const DrawContext &ctx) { +void ModuleWidget::draw(const widget::DrawContext &ctx) { if (module && module->bypass) { nvgGlobalAlpha(ctx.vg, 0.25); } // nvgScissor(ctx.vg, 0, 0, box.size.x, box.size.y); - Widget::draw(ctx); + widget::Widget::draw(ctx); // Power meter if (module && settings::powerMeter) { @@ -155,7 +156,7 @@ void ModuleWidget::draw(const DrawContext &ctx) { std::string cpuText = string::f("%.2f μs", module->cpuTime * 1e6f); bndLabel(ctx.vg, 2.0, box.size.y - 20.0, INFINITY, INFINITY, -1, cpuText.c_str()); - float p = math::clamp(module->cpuTime / app()->engine->getSampleTime(), 0.f, 1.f); + float p = math::clamp(module->cpuTime / APP->engine->getSampleTime(), 0.f, 1.f); nvgBeginPath(ctx.vg); nvgRect(ctx.vg, 0, (1.f - p) * box.size.y, @@ -177,7 +178,7 @@ void ModuleWidget::draw(const DrawContext &ctx) { // nvgResetScissor(ctx.vg); } -void ModuleWidget::drawShadow(const DrawContext &ctx) { +void ModuleWidget::drawShadow(const widget::DrawContext &ctx) { nvgBeginPath(ctx.vg); float r = 20; // Blur radius float c = 20; // Corner radius @@ -190,12 +191,12 @@ void ModuleWidget::drawShadow(const DrawContext &ctx) { } void ModuleWidget::onHover(const event::Hover &e) { - OpaqueWidget::onHover(e); + widget::OpaqueWidget::onHover(e); // Instead of checking key-down events, delete the module even if key-repeat hasn't fired yet and the cursor is hovering over the widget. - if ((glfwGetKey(app()->window->win, GLFW_KEY_DELETE) == GLFW_PRESS - || glfwGetKey(app()->window->win, GLFW_KEY_BACKSPACE) == GLFW_PRESS) - && (app()->window->getMods() & WINDOW_MOD_MASK) == 0) { + if ((glfwGetKey(APP->window->win, GLFW_KEY_DELETE) == GLFW_PRESS + || glfwGetKey(APP->window->win, GLFW_KEY_BACKSPACE) == GLFW_PRESS) + && (APP->window->getMods() & WINDOW_MOD_MASK) == 0) { removeAction(); e.consume(NULL); return; @@ -203,7 +204,7 @@ void ModuleWidget::onHover(const event::Hover &e) { } void ModuleWidget::onButton(const event::Button &e) { - OpaqueWidget::onButton(e); + widget::OpaqueWidget::onButton(e); if (e.getConsumed() == this) { if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) { @@ -261,12 +262,12 @@ void ModuleWidget::onHoverKey(const event::HoverKey &e) { } if (!e.getConsumed()) - OpaqueWidget::onHoverKey(e); + widget::OpaqueWidget::onHoverKey(e); } void ModuleWidget::onDragStart(const event::DragStart &e) { oldPos = box.pos; - dragPos = app()->scene->rackWidget->mousePos.minus(box.pos); + dragPos = APP->scene->rackWidget->mousePos.minus(box.pos); } void ModuleWidget::onDragEnd(const event::DragEnd &e) { @@ -276,15 +277,15 @@ void ModuleWidget::onDragEnd(const event::DragEnd &e) { h->moduleId = module->id; h->oldPos = oldPos; h->newPos = box.pos; - app()->history->push(h); + APP->history->push(h); } } void ModuleWidget::onDragMove(const event::DragMove &e) { if (!settings::lockModules) { math::Rect newBox = box; - newBox.pos = app()->scene->rackWidget->mousePos.minus(dragPos); - app()->scene->rackWidget->requestModuleBoxNearest(this, newBox); + newBox.pos = APP->scene->rackWidget->mousePos.minus(dragPos); + APP->scene->rackWidget->requestModuleBoxNearest(this, newBox); } } @@ -413,11 +414,11 @@ void ModuleWidget::copyClipboard() { DEFER({ free(moduleJson); }); - glfwSetClipboardString(app()->window->win, moduleJson); + glfwSetClipboardString(APP->window->win, moduleJson); } void ModuleWidget::pasteClipboardAction() { - const char *moduleJson = glfwGetClipboardString(app()->window->win); + const char *moduleJson = glfwGetClipboardString(APP->window->win); if (!moduleJson) { WARN("Could not get text from clipboard."); return; @@ -441,7 +442,7 @@ void ModuleWidget::pasteClipboardAction() { fromJson(moduleJ); h->newModuleJ = toJson(); - app()->history->push(h); + APP->history->push(h); } void ModuleWidget::loadAction(std::string filename) { @@ -475,7 +476,7 @@ void ModuleWidget::loadAction(std::string filename) { fromJson(moduleJ); h->newModuleJ = toJson(); - app()->history->push(h); + APP->history->push(h); } void ModuleWidget::save(std::string filename) { @@ -548,10 +549,10 @@ void ModuleWidget::saveDialog() { void ModuleWidget::disconnect() { for (PortWidget *input : inputs) { - app()->scene->rackWidget->clearCablesOnPort(input); + APP->scene->rackWidget->clearCablesOnPort(input); } for (PortWidget *output : outputs) { - app()->scene->rackWidget->clearCablesOnPort(output); + APP->scene->rackWidget->clearCablesOnPort(output); } } @@ -563,10 +564,10 @@ void ModuleWidget::resetAction() { h->moduleId = module->id; h->oldModuleJ = toJson(); - app()->engine->resetModule(module); + APP->engine->resetModule(module); h->newModuleJ = toJson(); - app()->history->push(h); + APP->history->push(h); } void ModuleWidget::randomizeAction() { @@ -577,16 +578,16 @@ void ModuleWidget::randomizeAction() { h->moduleId = module->id; h->oldModuleJ = toJson(); - app()->engine->randomizeModule(module); + APP->engine->randomizeModule(module); h->newModuleJ = toJson(); - app()->history->push(h); + APP->history->push(h); } static void disconnectActions(ModuleWidget *mw, history::ComplexAction *complexAction) { // Add CableRemove action for all cables attached to outputs for (PortWidget* output : mw->outputs) { - for (CableWidget *cw : app()->scene->rackWidget->getCablesOnPort(output)) { + for (CableWidget *cw : APP->scene->rackWidget->getCablesOnPort(output)) { if (!cw->isComplete()) continue; // history::CableRemove @@ -597,7 +598,7 @@ static void disconnectActions(ModuleWidget *mw, history::ComplexAction *complexA } // Add CableRemove action for all cables attached to inputs for (PortWidget* input : mw->inputs) { - for (CableWidget *cw : app()->scene->rackWidget->getCablesOnPort(input)) { + for (CableWidget *cw : APP->scene->rackWidget->getCablesOnPort(input)) { if (!cw->isComplete()) continue; // Avoid creating duplicate actions for self-patched cables @@ -614,7 +615,7 @@ static void disconnectActions(ModuleWidget *mw, history::ComplexAction *complexA void ModuleWidget::disconnectAction() { history::ComplexAction *complexAction = new history::ComplexAction; disconnectActions(this, complexAction); - app()->history->push(complexAction); + APP->history->push(complexAction); disconnect(); } @@ -627,12 +628,12 @@ void ModuleWidget::cloneAction() { clonedModuleWidget->fromJson(moduleJ); json_decref(moduleJ); - app()->scene->rackWidget->addModuleAtMouse(clonedModuleWidget); + APP->scene->rackWidget->addModuleAtMouse(clonedModuleWidget); // history::ModuleAdd history::ModuleAdd *h = new history::ModuleAdd; h->setModule(clonedModuleWidget); - app()->history->push(h); + APP->history->push(h); } void ModuleWidget::bypassAction() { @@ -641,7 +642,7 @@ void ModuleWidget::bypassAction() { history::ModuleBypass *h = new history::ModuleBypass; h->moduleId = module->id; h->bypass = !module->bypass; - app()->history->push(h); + APP->history->push(h); h->redo(); } @@ -654,18 +655,18 @@ void ModuleWidget::removeAction() { moduleRemove->setModule(this); complexAction->push(moduleRemove); - app()->history->push(complexAction); + APP->history->push(complexAction); // This disconnects cables, removes the module, and transfers ownership to caller - app()->scene->rackWidget->removeModule(this); + APP->scene->rackWidget->removeModule(this); delete this; } void ModuleWidget::createContextMenu() { - Menu *menu = createMenu(); + ui::Menu *menu = createMenu(); assert(model); - MenuLabel *menuLabel = new MenuLabel; + ui::MenuLabel *menuLabel = new ui::MenuLabel; menuLabel->text = model->plugin->name + " " + model->name + " " + model->plugin->version; menu->addChild(menuLabel); @@ -713,4 +714,5 @@ void ModuleWidget::createContextMenu() { } +} // namespace app } // namespace rack \ No newline at end of file diff --git a/src/app/MultiLightWidget.cpp b/src/app/MultiLightWidget.cpp index 0881efa2..9eca1e3c 100644 --- a/src/app/MultiLightWidget.cpp +++ b/src/app/MultiLightWidget.cpp @@ -3,6 +3,7 @@ namespace rack { +namespace app { void MultiLightWidget::addBaseColor(NVGcolor baseColor) { @@ -21,4 +22,5 @@ void MultiLightWidget::setBrightnesses(const std::vector &brightnesses) { } +} // namespace app } // namespace rack diff --git a/src/app/ParamQuantity.cpp b/src/app/ParamQuantity.cpp index 8f5ac3e0..e290c070 100644 --- a/src/app/ParamQuantity.cpp +++ b/src/app/ParamQuantity.cpp @@ -4,6 +4,7 @@ namespace rack { +namespace app { Param *ParamQuantity::getParam() { @@ -15,11 +16,11 @@ void ParamQuantity::setSmoothValue(float smoothValue) { if (!module) return; smoothValue = math::clamp(smoothValue, getMinValue(), getMaxValue()); - app()->engine->setSmoothParam(module, paramId, smoothValue); + APP->engine->setSmoothParam(module, paramId, smoothValue); } float ParamQuantity::getSmoothValue() { - return app()->engine->getSmoothParam(module, paramId); + return APP->engine->getSmoothParam(module, paramId); } void ParamQuantity::setValue(float value) { @@ -55,7 +56,7 @@ float ParamQuantity::getDefaultValue() { float ParamQuantity::getDisplayValue() { if (!module) - return Quantity::getDisplayValue(); + return ui::Quantity::getDisplayValue(); float v = getSmoothValue(); float displayBase = getParam()->displayBase; if (displayBase == 0.f) { @@ -92,28 +93,29 @@ void ParamQuantity::setDisplayValue(float displayValue) { } int ParamQuantity::getDisplayPrecision() { - return Quantity::getDisplayPrecision(); + return ui::Quantity::getDisplayPrecision(); } std::string ParamQuantity::getDisplayValueString() { - return Quantity::getDisplayValueString(); + return ui::Quantity::getDisplayValueString(); } void ParamQuantity::setDisplayValueString(std::string s) { - Quantity::setDisplayValueString(s); + ui::Quantity::setDisplayValueString(s); } std::string ParamQuantity::getLabel() { if (!module) - return Quantity::getLabel(); + return ui::Quantity::getLabel(); return getParam()->label; } std::string ParamQuantity::getUnit() { if (!module) - return Quantity::getUnit(); + return ui::Quantity::getUnit(); return getParam()->unit; } +} // namespace app } // namespace rack diff --git a/src/app/ParamWidget.cpp b/src/app/ParamWidget.cpp index c115c4b5..4a1a4cc3 100644 --- a/src/app/ParamWidget.cpp +++ b/src/app/ParamWidget.cpp @@ -11,15 +11,16 @@ namespace rack { +namespace app { -struct ParamField : TextField { +struct ParamField : ui::TextField { ParamWidget *paramWidget; void step() override { // Keep selected - app()->event->setSelected(this); - TextField::step(); + APP->event->setSelected(this); + ui::TextField::step(); } void setParamWidget(ParamWidget *paramWidget) { @@ -43,26 +44,26 @@ struct ParamField : TextField { h->paramId = paramWidget->paramQuantity->paramId; h->oldValue = oldValue; h->newValue = newValue; - app()->history->push(h); + APP->history->push(h); } - MenuOverlay *overlay = getAncestorOfType(); + ui::MenuOverlay *overlay = getAncestorOfType(); overlay->requestedDelete = true; e.consume(this); } if (!e.getConsumed()) - TextField::onSelectKey(e); + ui::TextField::onSelectKey(e); } }; -struct ParamTooltip : Tooltip { +struct ParamTooltip : ui::Tooltip { ParamWidget *paramWidget; void step() override { if (paramWidget->paramQuantity) { - // Quantity string + // ui::Quantity string text = paramWidget->paramQuantity->getString(); // Param description std::string description = paramWidget->paramQuantity->getParam()->description; @@ -71,21 +72,21 @@ struct ParamTooltip : Tooltip { } // Position at bottom-right of parameter box.pos = paramWidget->getAbsoluteOffset(paramWidget->box.size).round(); - Tooltip::step(); + ui::Tooltip::step(); } }; -struct ParamLabel : MenuLabel { +struct ParamLabel : ui::MenuLabel { ParamWidget *paramWidget; void step() override { text = paramWidget->paramQuantity->getString(); - MenuLabel::step(); + ui::MenuLabel::step(); } }; -struct ParamResetItem : MenuItem { +struct ParamResetItem : ui::MenuItem { ParamWidget *paramWidget; ParamResetItem() { text = "Initialize"; @@ -97,7 +98,7 @@ struct ParamResetItem : MenuItem { }; -struct ParamFineItem : MenuItem { +struct ParamFineItem : ui::MenuItem { ParamFineItem() { text = "Fine adjust"; rightText = WINDOW_MOD_CTRL_NAME "+Drag"; @@ -122,11 +123,11 @@ void ParamWidget::step() { } } - OpaqueWidget::step(); + widget::OpaqueWidget::step(); } -void ParamWidget::draw(const DrawContext &ctx) { - Widget::draw(ctx); +void ParamWidget::draw(const widget::DrawContext &ctx) { + widget::Widget::draw(ctx); // if (paramQuantity) { // nvgBeginPath(ctx.vg); @@ -157,21 +158,21 @@ void ParamWidget::onButton(const event::Button &e) { } if (!e.getConsumed()) - OpaqueWidget::onButton(e); + widget::OpaqueWidget::onButton(e); } void ParamWidget::onEnter(const event::Enter &e) { if (settings::paramTooltip && !tooltip && paramQuantity) { ParamTooltip *paramTooltip = new ParamTooltip; paramTooltip->paramWidget = this; - app()->scene->addChild(paramTooltip); + APP->scene->addChild(paramTooltip); tooltip = paramTooltip; } } void ParamWidget::onLeave(const event::Leave &e) { if (tooltip) { - app()->scene->removeChild(tooltip); + APP->scene->removeChild(tooltip); delete tooltip; tooltip = NULL; } @@ -186,7 +187,7 @@ void ParamWidget::fromJson(json_t *rootJ) { } void ParamWidget::createContextMenu() { - Menu *menu = createMenu(); + ui::Menu *menu = createMenu(); ParamLabel *paramLabel = new ParamLabel; paramLabel->paramWidget = this; @@ -218,7 +219,7 @@ void ParamWidget::resetAction() { h->paramId = paramQuantity->paramId; h->oldValue = oldValue; h->newValue = newValue; - app()->history->push(h); + APP->history->push(h); } // Here's another way of doing it, but either works. @@ -227,4 +228,5 @@ void ParamWidget::resetAction() { } +} // namespace app } // namespace rack diff --git a/src/app/PortWidget.cpp b/src/app/PortWidget.cpp index fe0ae955..11454d30 100644 --- a/src/app/PortWidget.cpp +++ b/src/app/PortWidget.cpp @@ -7,6 +7,7 @@ namespace rack { +namespace app { struct PlugLight : MultiLightWidget { @@ -29,7 +30,7 @@ PortWidget::~PortWidget() { delete plugLight; // HACK if (module) - app()->scene->rackWidget->clearCablesOnPort(this); + APP->scene->rackWidget->clearCablesOnPort(this); } void PortWidget::step() { @@ -51,26 +52,26 @@ void PortWidget::step() { plugLight->setBrightnesses(values); } -void PortWidget::draw(const DrawContext &ctx) { - CableWidget *cw = app()->scene->rackWidget->incompleteCable; +void PortWidget::draw(const widget::DrawContext &ctx) { + CableWidget *cw = APP->scene->rackWidget->incompleteCable; if (cw) { // Dim the PortWidget if the active cable cannot plug into this PortWidget if (type == OUTPUT ? cw->outputPort : cw->inputPort) nvgGlobalAlpha(ctx.vg, 0.5); } - Widget::draw(ctx); + widget::Widget::draw(ctx); } void PortWidget::onButton(const event::Button &e) { if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) { - CableWidget *cw = app()->scene->rackWidget->getTopCable(this); + CableWidget *cw = APP->scene->rackWidget->getTopCable(this); if (cw) { // history::CableRemove history::CableRemove *h = new history::CableRemove; h->setCable(cw); - app()->history->push(h); + APP->history->push(h); - app()->scene->rackWidget->removeCable(cw); + APP->scene->rackWidget->removeCable(cw); delete cw; } } @@ -79,22 +80,22 @@ void PortWidget::onButton(const event::Button &e) { void PortWidget::onDragStart(const event::DragStart &e) { CableWidget *cw = NULL; - if (type == OUTPUT && (app()->window->getMods() & WINDOW_MOD_MASK) == WINDOW_MOD_CTRL) { + if (type == OUTPUT && (APP->window->getMods() & WINDOW_MOD_MASK) == WINDOW_MOD_CTRL) { // Keep cable NULL } else { // Grab cable on top of stack - cw = app()->scene->rackWidget->getTopCable(this); + cw = APP->scene->rackWidget->getTopCable(this); } if (cw) { // history::CableRemove history::CableRemove *h = new history::CableRemove; h->setCable(cw); - app()->history->push(h); + APP->history->push(h); // Disconnect and reuse existing cable - app()->scene->rackWidget->removeCable(cw); + APP->scene->rackWidget->removeCable(cw); if (type == OUTPUT) cw->setOutput(NULL); else @@ -108,18 +109,18 @@ void PortWidget::onDragStart(const event::DragStart &e) { else cw->setInput(this); } - app()->scene->rackWidget->setIncompleteCable(cw); + APP->scene->rackWidget->setIncompleteCable(cw); } void PortWidget::onDragEnd(const event::DragEnd &e) { - CableWidget *cw = app()->scene->rackWidget->releaseIncompleteCable(); + CableWidget *cw = APP->scene->rackWidget->releaseIncompleteCable(); if (cw->isComplete()) { - app()->scene->rackWidget->addCable(cw); + APP->scene->rackWidget->addCable(cw); // history::CableAdd history::CableAdd *h = new history::CableAdd; h->setCable(cw); - app()->history->push(h); + APP->history->push(h); } else { delete cw; @@ -129,11 +130,11 @@ void PortWidget::onDragEnd(const event::DragEnd &e) { void PortWidget::onDragDrop(const event::DragDrop &e) { // Reject ports if this is an input port and something is already plugged into it if (type == INPUT) { - if (app()->scene->rackWidget->getTopCable(this)) + if (APP->scene->rackWidget->getTopCable(this)) return; } - CableWidget *cw = app()->scene->rackWidget->incompleteCable; + CableWidget *cw = APP->scene->rackWidget->incompleteCable; if (cw) { cw->hoveredOutputPort = cw->hoveredInputPort = NULL; if (type == OUTPUT) @@ -146,11 +147,11 @@ void PortWidget::onDragDrop(const event::DragDrop &e) { void PortWidget::onDragEnter(const event::DragEnter &e) { // Reject ports if this is an input port and something is already plugged into it if (type == INPUT) { - if (app()->scene->rackWidget->getTopCable(this)) + if (APP->scene->rackWidget->getTopCable(this)) return; } - CableWidget *cw = app()->scene->rackWidget->incompleteCable; + CableWidget *cw = APP->scene->rackWidget->incompleteCable; if (cw) { if (type == OUTPUT) cw->hoveredOutputPort = this; @@ -164,7 +165,7 @@ void PortWidget::onDragLeave(const event::DragLeave &e) { if (!originPort) return; - CableWidget *cw = app()->scene->rackWidget->incompleteCable; + CableWidget *cw = APP->scene->rackWidget->incompleteCable; if (cw) { if (type == OUTPUT) cw->hoveredOutputPort = NULL; @@ -174,4 +175,5 @@ void PortWidget::onDragLeave(const event::DragLeave &e) { } +} // namespace app } // namespace rack diff --git a/src/app/RackRail.cpp b/src/app/RackRail.cpp index 6b9eb08e..b5de5d6a 100644 --- a/src/app/RackRail.cpp +++ b/src/app/RackRail.cpp @@ -2,8 +2,9 @@ namespace rack { +namespace app { -void RackRail::draw(const DrawContext &ctx) { +void RackRail::draw(const widget::DrawContext &ctx) { const float railHeight = RACK_GRID_WIDTH; // Background color @@ -58,4 +59,5 @@ void RackRail::draw(const DrawContext &ctx) { } +} // namespace app } // namespace rack diff --git a/src/app/RackScrollWidget.cpp b/src/app/RackScrollWidget.cpp index 39f914e4..93e8ffe5 100644 --- a/src/app/RackScrollWidget.cpp +++ b/src/app/RackScrollWidget.cpp @@ -5,13 +5,14 @@ namespace rack { +namespace app { void RackScrollWidget::step() { - math::Vec pos = app()->window->mousePos; + math::Vec pos = APP->window->mousePos; math::Rect viewport = getViewport(box.zeroPos()); // Scroll rack if dragging cable near the edge of the screen - if (app()->scene->rackWidget->incompleteCable) { + if (APP->scene->rackWidget->incompleteCable) { float margin = 20.0; float speed = 15.0; if (pos.x <= viewport.pos.x + margin) @@ -23,13 +24,14 @@ void RackScrollWidget::step() { if (pos.y >= viewport.pos.y + viewport.size.y - margin) offset.y += speed; } - ScrollWidget::step(); + ui::ScrollWidget::step(); } -void RackScrollWidget::draw(const DrawContext &ctx) { - ScrollWidget::draw(ctx); +void RackScrollWidget::draw(const widget::DrawContext &ctx) { + ui::ScrollWidget::draw(ctx); } +} // namespace app } // namespace rack diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index c9517013..8ac21c08 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -1,5 +1,5 @@ #include "app/RackWidget.hpp" -#include "widgets/TransparentWidget.hpp" +#include "widget/TransparentWidget.hpp" #include "app/RackRail.hpp" #include "app/Scene.hpp" #include "app/ModuleBrowser.hpp" @@ -15,6 +15,7 @@ namespace rack { +namespace app { static ModuleWidget *moduleFromJson(json_t *moduleJ) { @@ -41,10 +42,10 @@ static ModuleWidget *moduleFromJson(json_t *moduleJ) { } -struct ModuleContainer : Widget { - void draw(const DrawContext &ctx) override { +struct ModuleContainer : widget::Widget { + void draw(const widget::DrawContext &ctx) override { // Draw shadows behind each ModuleWidget first, so the shadow doesn't overlap the front of other ModuleWidgets. - for (Widget *child : children) { + for (widget::Widget *child : children) { ModuleWidget *w = dynamic_cast(child); assert(w); @@ -54,17 +55,17 @@ struct ModuleContainer : Widget { nvgRestore(ctx.vg); } - Widget::draw(ctx); + widget::Widget::draw(ctx); } }; -struct CableContainer : TransparentWidget { - void draw(const DrawContext &ctx) override { - Widget::draw(ctx); +struct CableContainer : widget::TransparentWidget { + void draw(const widget::DrawContext &ctx) override { + widget::Widget::draw(ctx); // Draw cable plugs - for (Widget *w : children) { + for (widget::Widget *w : children) { CableWidget *cw = dynamic_cast(w); assert(cw); cw->drawPlugs(ctx); @@ -74,7 +75,7 @@ struct CableContainer : TransparentWidget { RackWidget::RackWidget() { - rails = new FramebufferWidget; + rails = new widget::FramebufferWidget; rails->box.size = math::Vec(); rails->oversample = 1.0; { @@ -102,7 +103,7 @@ void RackWidget::step() { box.size = box.size.max(moduleSize); // Adjust size and position of rails - Widget *rail = rails->children.front(); + widget::Widget *rail = rails->children.front(); math::Rect bound = getViewport(math::Rect(math::Vec(), box.size)); if (!rails->box.isContaining(bound)) { math::Vec cellMargin = math::Vec(20, 1); @@ -113,43 +114,43 @@ void RackWidget::step() { rail->box.size = rails->box.size; } - Widget::step(); + widget::Widget::step(); } -void RackWidget::draw(const DrawContext &ctx) { - Widget::draw(ctx); +void RackWidget::draw(const widget::DrawContext &ctx) { + widget::Widget::draw(ctx); } void RackWidget::onHover(const event::Hover &e) { // Scroll with arrow keys float arrowSpeed = 30.0; - if ((app()->window->getMods() & WINDOW_MOD_MASK) == (WINDOW_MOD_CTRL |GLFW_MOD_SHIFT)) + if ((APP->window->getMods() & WINDOW_MOD_MASK) == (WINDOW_MOD_CTRL |GLFW_MOD_SHIFT)) arrowSpeed /= 16.0; - else if ((app()->window->getMods() & WINDOW_MOD_MASK) == WINDOW_MOD_CTRL) + else if ((APP->window->getMods() & WINDOW_MOD_MASK) == WINDOW_MOD_CTRL) arrowSpeed *= 4.0; - else if ((app()->window->getMods() & WINDOW_MOD_MASK) == GLFW_MOD_SHIFT) + else if ((APP->window->getMods() & WINDOW_MOD_MASK) == GLFW_MOD_SHIFT) arrowSpeed /= 4.0; - ScrollWidget *scrollWidget = app()->scene->scrollWidget; - if (glfwGetKey(app()->window->win, GLFW_KEY_LEFT) == GLFW_PRESS) { + ui::ScrollWidget *scrollWidget = APP->scene->scrollWidget; + if (glfwGetKey(APP->window->win, GLFW_KEY_LEFT) == GLFW_PRESS) { scrollWidget->offset.x -= arrowSpeed; } - if (glfwGetKey(app()->window->win, GLFW_KEY_RIGHT) == GLFW_PRESS) { + if (glfwGetKey(APP->window->win, GLFW_KEY_RIGHT) == GLFW_PRESS) { scrollWidget->offset.x += arrowSpeed; } - if (glfwGetKey(app()->window->win, GLFW_KEY_UP) == GLFW_PRESS) { + if (glfwGetKey(APP->window->win, GLFW_KEY_UP) == GLFW_PRESS) { scrollWidget->offset.y -= arrowSpeed; } - if (glfwGetKey(app()->window->win, GLFW_KEY_DOWN) == GLFW_PRESS) { + if (glfwGetKey(APP->window->win, GLFW_KEY_DOWN) == GLFW_PRESS) { scrollWidget->offset.y += arrowSpeed; } - OpaqueWidget::onHover(e); + widget::OpaqueWidget::onHover(e); mousePos = e.pos; } void RackWidget::onHoverKey(const event::HoverKey &e) { - OpaqueWidget::onHoverKey(e); + widget::OpaqueWidget::onHoverKey(e); if (e.getConsumed() != this) return; @@ -165,30 +166,30 @@ void RackWidget::onHoverKey(const event::HoverKey &e) { } void RackWidget::onDragHover(const event::DragHover &e) { - OpaqueWidget::onDragHover(e); + widget::OpaqueWidget::onDragHover(e); mousePos = e.pos; } void RackWidget::onButton(const event::Button &e) { - OpaqueWidget::onButton(e); + widget::OpaqueWidget::onButton(e); if (e.getConsumed() == this) { if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) { - app()->scene->moduleBrowser->visible = true; + APP->scene->moduleBrowser->visible = true; } } } void RackWidget::onZoom(const event::Zoom &e) { rails->box.size = math::Vec(); - OpaqueWidget::onZoom(e); + widget::OpaqueWidget::onZoom(e); } void RackWidget::clear() { // This isn't required because removing all ModuleWidgets should remove all cables, but do it just in case. clearCables(); // Remove ModuleWidgets - std::list widgets = moduleContainer->children; - for (Widget *w : widgets) { + std::list widgets = moduleContainer->children; + for (widget::Widget *w : widgets) { ModuleWidget *moduleWidget = dynamic_cast(w); assert(moduleWidget); removeModule(moduleWidget); @@ -201,7 +202,7 @@ json_t *RackWidget::toJson() { // modules json_t *modulesJ = json_array(); - for (Widget *w : moduleContainer->children) { + for (widget::Widget *w : moduleContainer->children) { ModuleWidget *moduleWidget = dynamic_cast(w); assert(moduleWidget); // module @@ -220,7 +221,7 @@ json_t *RackWidget::toJson() { // cables json_t *cablesJ = json_array(); - for (Widget *w : cableContainer->children) { + for (widget::Widget *w : cableContainer->children) { CableWidget *cw = dynamic_cast(w); assert(cw); @@ -257,7 +258,7 @@ void RackWidget::fromJson(json_t *rootJ) { double x, y; json_unpack(posJ, "[F, F]", &x, &y); math::Vec pos = math::Vec(x, y); - if (app()->patch->isLegacy(1)) { + if (APP->patch->isLegacy(1)) { // Before 0.6, positions were in pixel units moduleWidget->box.pos = pos; } @@ -265,7 +266,7 @@ void RackWidget::fromJson(json_t *rootJ) { moduleWidget->box.pos = pos.mult(RACK_GRID_SIZE); } - if (app()->patch->isLegacy(2)) { + if (APP->patch->isLegacy(2)) { // Before 1.0, the module ID was the index in the "modules" array moduleWidgets[moduleIndex] = moduleWidget; } @@ -279,7 +280,7 @@ void RackWidget::fromJson(json_t *rootJ) { json_t *modelSlugJ = json_object_get(moduleJ, "model"); std::string pluginSlug = json_string_value(pluginSlugJ); std::string modelSlug = json_string_value(modelSlugJ); - app()->patch->warningLog += string::f("Could not find module \"%s\" of plugin \"%s\"\n", modelSlug.c_str(), pluginSlug.c_str()); + APP->patch->warningLog += string::f("Could not find module \"%s\" of plugin \"%s\"\n", modelSlug.c_str(), pluginSlug.c_str()); } } @@ -304,7 +305,7 @@ void RackWidget::fromJson(json_t *rootJ) { } void RackWidget::pastePresetClipboardAction() { - const char *moduleJson = glfwGetClipboardString(app()->window->win); + const char *moduleJson = glfwGetClipboardString(APP->window->win); if (!moduleJson) { WARN("Could not get text from clipboard."); return; @@ -320,7 +321,7 @@ void RackWidget::pastePresetClipboardAction() { // history::ModuleAdd history::ModuleAdd *h = new history::ModuleAdd; h->setModule(mw); - app()->history->push(h); + APP->history->push(h); } else { WARN("JSON parsing error at %s %d:%d %s", error.source, error.line, error.column, error.text); @@ -334,7 +335,7 @@ void RackWidget::addModule(ModuleWidget *m) { if (m->module) { // Add module to Engine - app()->engine->addModule(m->module); + APP->engine->addModule(m->module); } } @@ -352,7 +353,7 @@ void RackWidget::removeModule(ModuleWidget *m) { if (m->module) { // Remove module from Engine - app()->engine->removeModule(m->module); + APP->engine->removeModule(m->module); } // Remove module from ModuleContainer @@ -365,7 +366,7 @@ bool RackWidget::requestModuleBox(ModuleWidget *m, math::Rect requestedBox) { return false; // Check intersection with other modules - for (Widget *m2 : moduleContainer->children) { + for (widget::Widget *m2 : moduleContainer->children) { // Don't intersect with self if (m == m2) continue; @@ -407,7 +408,7 @@ bool RackWidget::requestModuleBoxNearest(ModuleWidget *m, math::Rect requestedBo } ModuleWidget *RackWidget::getModule(int moduleId) { - for (Widget *w : moduleContainer->children) { + for (widget::Widget *w : moduleContainer->children) { ModuleWidget *moduleWidget = dynamic_cast(w); assert(moduleWidget); if (moduleWidget->module->id == moduleId) @@ -421,13 +422,13 @@ bool RackWidget::isEmpty() { } void RackWidget::clearCables() { - for (Widget *w : cableContainer->children) { + for (widget::Widget *w : cableContainer->children) { CableWidget *cw = dynamic_cast(w); assert(cw); if (!cw->isComplete()) continue; - app()->engine->removeCable(cw->cable); + APP->engine->removeCable(cw->cable); } incompleteCable = NULL; cableContainer->clearChildren(); @@ -437,7 +438,7 @@ void RackWidget::clearCablesAction() { // Add CableRemove for every cable to a ComplexAction history::ComplexAction *complexAction = new history::ComplexAction; - for (Widget *w : cableContainer->children) { + for (widget::Widget *w : cableContainer->children) { CableWidget *cw = dynamic_cast(w); assert(cw); if (!cw->isComplete()) @@ -449,7 +450,7 @@ void RackWidget::clearCablesAction() { complexAction->push(h); } - app()->history->push(complexAction); + APP->history->push(complexAction); clearCables(); } @@ -469,13 +470,13 @@ void RackWidget::clearCablesOnPort(PortWidget *port) { void RackWidget::addCable(CableWidget *w) { assert(w->isComplete()); - app()->engine->addCable(w->cable); + APP->engine->addCable(w->cable); cableContainer->addChild(w); } void RackWidget::removeCable(CableWidget *w) { assert(w->isComplete()); - app()->engine->removeCable(w->cable); + APP->engine->removeCable(w->cable); cableContainer->removeChild(w); } @@ -512,7 +513,7 @@ CableWidget *RackWidget::getTopCable(PortWidget *port) { } CableWidget *RackWidget::getCable(int cableId) { - for (Widget *w : cableContainer->children) { + for (widget::Widget *w : cableContainer->children) { CableWidget *cw = dynamic_cast(w); assert(cw); if (cw->cable->id == cableId) @@ -524,7 +525,7 @@ CableWidget *RackWidget::getCable(int cableId) { std::list RackWidget::getCablesOnPort(PortWidget *port) { assert(port); std::list cables; - for (Widget *w : cableContainer->children) { + for (widget::Widget *w : cableContainer->children) { CableWidget *cw = dynamic_cast(w); assert(cw); if (cw->inputPort == port || cw->outputPort == port) { @@ -535,4 +536,5 @@ std::list RackWidget::getCablesOnPort(PortWidget *port) { } +} // namespace app } // namespace rack diff --git a/src/app/SVGButton.cpp b/src/app/SVGButton.cpp index 9401c0a5..8f79a221 100644 --- a/src/app/SVGButton.cpp +++ b/src/app/SVGButton.cpp @@ -2,13 +2,14 @@ namespace rack { +namespace app { SVGButton::SVGButton() { - fb = new FramebufferWidget; + fb = new widget::FramebufferWidget; addChild(fb); - sw = new SVGWidget; + sw = new widget::SVGWidget; fb->addChild(sw); } @@ -44,4 +45,5 @@ void SVGButton::onDragDrop(const event::DragDrop &e) { } +} // namespace app } // namespace rack diff --git a/src/app/SVGKnob.cpp b/src/app/SVGKnob.cpp index e5a4b221..4e671057 100644 --- a/src/app/SVGKnob.cpp +++ b/src/app/SVGKnob.cpp @@ -2,20 +2,21 @@ namespace rack { +namespace app { SVGKnob::SVGKnob() { - fb = new FramebufferWidget; + fb = new widget::FramebufferWidget; addChild(fb); shadow = new CircularShadow; fb->addChild(shadow); shadow->box.size = math::Vec(); - tw = new TransformWidget; + tw = new widget::TransformWidget; fb->addChild(tw); - sw = new SVGWidget; + sw = new widget::SVGWidget; tw->addChild(sw); } @@ -31,7 +32,7 @@ void SVGKnob::setSVG(std::shared_ptr svg) { } void SVGKnob::onChange(const event::Change &e) { - // Re-transform the TransformWidget + // Re-transform the widget::TransformWidget if (paramQuantity) { float angle; if (paramQuantity->isBounded()) { @@ -53,4 +54,5 @@ void SVGKnob::onChange(const event::Change &e) { } +} // namespace app } // namespace rack diff --git a/src/app/SVGPanel.cpp b/src/app/SVGPanel.cpp index 727c3330..488bc358 100644 --- a/src/app/SVGPanel.cpp +++ b/src/app/SVGPanel.cpp @@ -2,9 +2,10 @@ namespace rack { +namespace app { -void PanelBorder::draw(const DrawContext &ctx) { +void PanelBorder::draw(const widget::DrawContext &ctx) { NVGcolor borderColor = nvgRGBAf(0.5, 0.5, 0.5, 0.5); nvgBeginPath(ctx.vg); nvgRect(ctx.vg, 0.5, 0.5, box.size.x - 1.0, box.size.y - 1.0); @@ -15,15 +16,15 @@ void PanelBorder::draw(const DrawContext &ctx) { void SVGPanel::step() { - if (math::isNear(app()->window->pixelRatio, 1.0)) { + if (math::isNear(APP->window->pixelRatio, 1.0)) { // Small details draw poorly at low DPI, so oversample when drawing to the framebuffer oversample = 2.0; } - FramebufferWidget::step(); + widget::FramebufferWidget::step(); } void SVGPanel::setBackground(std::shared_ptr svg) { - SVGWidget *sw = new SVGWidget; + widget::SVGWidget *sw = new widget::SVGWidget; sw->setSVG(svg); addChild(sw); @@ -36,4 +37,5 @@ void SVGPanel::setBackground(std::shared_ptr svg) { } +} // namespace app } // namespace rack diff --git a/src/app/SVGPort.cpp b/src/app/SVGPort.cpp index 71df35f4..400b56d2 100644 --- a/src/app/SVGPort.cpp +++ b/src/app/SVGPort.cpp @@ -2,10 +2,11 @@ namespace rack { +namespace app { SVGPort::SVGPort() { - fb = new FramebufferWidget; + fb = new widget::FramebufferWidget; addChild(fb); shadow = new CircularShadow; @@ -14,7 +15,7 @@ SVGPort::SVGPort() { // In that case, just disable the shadow. shadow->box.size = math::Vec(); - sw = new SVGWidget; + sw = new widget::SVGWidget; fb->addChild(sw); } @@ -30,4 +31,5 @@ void SVGPort::setSVG(std::shared_ptr svg) { } +} // namespace app } // namespace rack diff --git a/src/app/SVGScrew.cpp b/src/app/SVGScrew.cpp index c0c5a0f6..bbdfa68e 100644 --- a/src/app/SVGScrew.cpp +++ b/src/app/SVGScrew.cpp @@ -2,12 +2,14 @@ namespace rack { +namespace app { SVGScrew::SVGScrew() { - sw = new SVGWidget; + sw = new widget::SVGWidget; addChild(sw); } +} // namespace app } // namespace rack diff --git a/src/app/SVGSlider.cpp b/src/app/SVGSlider.cpp index 6f13eeab..ae671835 100644 --- a/src/app/SVGSlider.cpp +++ b/src/app/SVGSlider.cpp @@ -2,16 +2,17 @@ namespace rack { +namespace app { SVGSlider::SVGSlider() { - fb = new FramebufferWidget; + fb = new widget::FramebufferWidget; addChild(fb); - background = new SVGWidget; + background = new widget::SVGWidget; fb->addChild(background); - handle = new SVGWidget; + handle = new widget::SVGWidget; fb->addChild(handle); speed = 2.0; @@ -42,4 +43,5 @@ void SVGSlider::onChange(const event::Change &e) { } +} // namespace app } // namespace rack diff --git a/src/app/SVGSwitch.cpp b/src/app/SVGSwitch.cpp index a4de304b..f3b8ceb5 100644 --- a/src/app/SVGSwitch.cpp +++ b/src/app/SVGSwitch.cpp @@ -2,13 +2,14 @@ namespace rack { +namespace app { SVGSwitch::SVGSwitch() { - fb = new FramebufferWidget; + fb = new widget::FramebufferWidget; addChild(fb); - sw = new SVGWidget; + sw = new widget::SVGWidget; fb->addChild(sw); } @@ -33,4 +34,5 @@ void SVGSwitch::onChange(const event::Change &e) { } +} // namespace app } // namespace rack diff --git a/src/app/Scene.cpp b/src/app/Scene.cpp index 6019a996..88f437c1 100644 --- a/src/app/Scene.cpp +++ b/src/app/Scene.cpp @@ -13,12 +13,13 @@ namespace rack { +namespace app { Scene::Scene() { scrollWidget = new RackScrollWidget; { - zoomWidget = new ZoomWidget; + zoomWidget = new widget::ZoomWidget; { rackWidget = new RackWidget; zoomWidget->addChild(rackWidget); @@ -44,25 +45,25 @@ void Scene::step() { toolbar->box.size.x = box.size.x; scrollWidget->box.size = box.size.minus(scrollWidget->box.pos); - // Resize to be a bit larger than the ScrollWidget viewport + // Resize to be a bit larger than the ui::ScrollWidget viewport rackWidget->box.size = scrollWidget->box.size .minus(scrollWidget->container->box.pos) .plus(math::Vec(500, 500)) .div(zoomWidget->zoom); - OpaqueWidget::step(); + widget::OpaqueWidget::step(); zoomWidget->box.size = rackWidget->box.size.mult(zoomWidget->zoom); // Autosave every 15 seconds - int frame = app()->window->frame; + int frame = APP->window->frame; if (frame > 0 && frame % (60 * 15) == 0) { - app()->patch->save(asset::user("autosave.vcv")); + APP->patch->save(asset::user("autosave.vcv")); settings::save(asset::user("settings.json")); } // Set zoom every few frames - if (app()->window->frame % 10 == 0) + if (APP->window->frame % 10 == 0) zoomWidget->setZoom(std::round(settings::zoom * 100) / 100); // Request latest version from server @@ -74,18 +75,18 @@ void Scene::step() { // Version popup message if (!latestVersion.empty()) { - std::string versionMessage = string::f("Rack %s is available.\n\nYou have Rack %s.\n\nClose Rack and download new version on the website?", latestVersion.c_str(), APP_VERSION); + std::string versionMessage = string::f("Rack %s is available.\n\nYou have Rack %s.\n\nClose Rack and download new version on the website?", latestVersion.c_str(), app::VERSION); if (osdialog_message(OSDIALOG_INFO, OSDIALOG_OK_CANCEL, versionMessage.c_str())) { std::thread t(system::openBrowser, "https://vcvrack.com/"); t.detach(); - app()->window->close(); + APP->window->close(); } latestVersion = ""; } } -void Scene::draw(const DrawContext &ctx) { - OpaqueWidget::draw(ctx); +void Scene::draw(const widget::DrawContext &ctx) { + widget::OpaqueWidget::draw(ctx); } void Scene::onHoverKey(const event::HoverKey &e) { @@ -93,43 +94,43 @@ void Scene::onHoverKey(const event::HoverKey &e) { switch (e.key) { case GLFW_KEY_N: { if ((e.mods & WINDOW_MOD_MASK) == WINDOW_MOD_CTRL) { - app()->patch->resetDialog(); + APP->patch->resetDialog(); e.consume(this); } } break; case GLFW_KEY_Q: { if ((e.mods & WINDOW_MOD_MASK) == WINDOW_MOD_CTRL) { - app()->window->close(); + APP->window->close(); e.consume(this); } } break; case GLFW_KEY_O: { if ((e.mods & WINDOW_MOD_MASK) == WINDOW_MOD_CTRL) { - app()->patch->loadDialog(); + APP->patch->loadDialog(); e.consume(this); } if ((e.mods & WINDOW_MOD_MASK) == (WINDOW_MOD_CTRL | GLFW_MOD_SHIFT)) { - app()->patch->revertDialog(); + APP->patch->revertDialog(); e.consume(this); } } break; case GLFW_KEY_S: { if ((e.mods & WINDOW_MOD_MASK) == WINDOW_MOD_CTRL) { - app()->patch->saveDialog(); + APP->patch->saveDialog(); e.consume(this); } if ((e.mods & WINDOW_MOD_MASK) == (WINDOW_MOD_CTRL | GLFW_MOD_SHIFT)) { - app()->patch->saveAsDialog(); + APP->patch->saveAsDialog(); e.consume(this); } } break; case GLFW_KEY_Z: { if ((e.mods & WINDOW_MOD_MASK) == WINDOW_MOD_CTRL) { - app()->history->undo(); + APP->history->undo(); e.consume(this); } if ((e.mods & WINDOW_MOD_MASK) == (WINDOW_MOD_CTRL | GLFW_MOD_SHIFT)) { - app()->history->redo(); + APP->history->redo(); e.consume(this); } } break; @@ -139,31 +140,31 @@ void Scene::onHoverKey(const event::HoverKey &e) { e.consume(this); } break; case GLFW_KEY_F11: { - app()->window->setFullScreen(!app()->window->isFullScreen()); + APP->window->setFullScreen(!APP->window->isFullScreen()); e.consume(this); } } } if (!e.getConsumed()) - OpaqueWidget::onHoverKey(e); + widget::OpaqueWidget::onHoverKey(e); } void Scene::onPathDrop(const event::PathDrop &e) { if (e.paths.size() >= 1) { const std::string &path = e.paths[0]; if (string::extension(path) == "vcv") { - app()->patch->load(path); + APP->patch->load(path); e.consume(this); } } if (!e.getConsumed()) - OpaqueWidget::onPathDrop(e); + widget::OpaqueWidget::onPathDrop(e); } void Scene::runCheckVersion() { - std::string versionUrl = APP_API_URL; + std::string versionUrl = app::API_URL; versionUrl += "/version"; json_t *versionResJ = network::requestJson(network::METHOD_GET, versionUrl, NULL); @@ -171,7 +172,7 @@ void Scene::runCheckVersion() { json_t *versionJ = json_object_get(versionResJ, "version"); if (versionJ) { std::string version = json_string_value(versionJ); - if (version != APP_VERSION) { + if (version != app::VERSION) { latestVersion = version; } } @@ -180,4 +181,5 @@ void Scene::runCheckVersion() { } +} // namespace app } // namespace rack diff --git a/src/app/Switch.cpp b/src/app/Switch.cpp index 9769cec8..a7b6be38 100644 --- a/src/app/Switch.cpp +++ b/src/app/Switch.cpp @@ -5,6 +5,7 @@ namespace rack { +namespace app { void Switch::step() { @@ -50,7 +51,7 @@ void Switch::onDragStart(const event::DragStart &e) { h->paramId = paramQuantity->paramId; h->oldValue = oldValue; h->newValue = newValue; - app()->history->push(h); + APP->history->push(h); } } } @@ -63,4 +64,5 @@ void Switch::onDragEnd(const event::DragEnd &e) { } +} // namespace app } // namespace rack diff --git a/src/app/Toolbar.cpp b/src/app/Toolbar.cpp index 4cec8499..6ae3ce88 100644 --- a/src/app/Toolbar.cpp +++ b/src/app/Toolbar.cpp @@ -19,100 +19,101 @@ namespace rack { +namespace app { -struct MenuButton : Button { +struct MenuButton : ui::Button { void step() override { - box.size.x = bndLabelWidth(app()->window->vg, -1, text.c_str()); - Widget::step(); + box.size.x = bndLabelWidth(APP->window->vg, -1, text.c_str()); + widget::Widget::step(); } - void draw(const DrawContext &ctx) override { + void draw(const widget::DrawContext &ctx) override { bndMenuItem(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, state, -1, text.c_str()); } }; -struct NewItem : MenuItem { +struct NewItem : ui::MenuItem { NewItem() { text = "New"; rightText = WINDOW_MOD_CTRL_NAME "+N"; } void onAction(const event::Action &e) override { - app()->patch->resetDialog(); + APP->patch->resetDialog(); } }; -struct OpenItem : MenuItem { +struct OpenItem : ui::MenuItem { OpenItem() { text = "Open"; rightText = WINDOW_MOD_CTRL_NAME "+O"; } void onAction(const event::Action &e) override { - app()->patch->loadDialog(); + APP->patch->loadDialog(); } }; -struct SaveItem : MenuItem { +struct SaveItem : ui::MenuItem { SaveItem() { text = "Save"; rightText = WINDOW_MOD_CTRL_NAME "+S"; } void onAction(const event::Action &e) override { - app()->patch->saveDialog(); + APP->patch->saveDialog(); } }; -struct SaveAsItem : MenuItem { +struct SaveAsItem : ui::MenuItem { SaveAsItem() { text = "Save as"; rightText = WINDOW_MOD_CTRL_NAME "+Shift+S"; } void onAction(const event::Action &e) override { - app()->patch->saveAsDialog(); + APP->patch->saveAsDialog(); } }; -struct SaveTemplateItem : MenuItem { +struct SaveTemplateItem : ui::MenuItem { SaveTemplateItem() { text = "Save template"; } void onAction(const event::Action &e) override { - app()->patch->saveTemplateDialog(); + APP->patch->saveTemplateDialog(); } }; -struct RevertItem : MenuItem { +struct RevertItem : ui::MenuItem { RevertItem() { text = "Revert"; } void onAction(const event::Action &e) override { - app()->patch->revertDialog(); + APP->patch->revertDialog(); } }; -struct DisconnectCablesItem : MenuItem { +struct DisconnectCablesItem : ui::MenuItem { DisconnectCablesItem() { text = "Disconnect cables"; } void onAction(const event::Action &e) override { - app()->patch->disconnectDialog(); + APP->patch->disconnectDialog(); } }; -struct QuitItem : MenuItem { +struct QuitItem : ui::MenuItem { QuitItem() { text = "Quit"; rightText = WINDOW_MOD_CTRL_NAME "+Q"; } void onAction(const event::Action &e) override { - app()->window->close(); + APP->window->close(); } }; @@ -122,7 +123,7 @@ struct FileButton : MenuButton { text = "File"; } void onAction(const event::Action &e) override { - Menu *menu = createMenu(); + ui::Menu *menu = createMenu(); menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y)); menu->box.size.x = box.size.x; @@ -138,26 +139,26 @@ struct FileButton : MenuButton { }; -struct UndoItem : MenuItem { +struct UndoItem : ui::MenuItem { UndoItem() { text = "Undo"; rightText = WINDOW_MOD_CTRL_NAME "+Z"; - disabled = !app()->history->canUndo(); + disabled = !APP->history->canUndo(); } void onAction(const event::Action &e) override { - app()->history->undo(); + APP->history->undo(); } }; -struct RedoItem : MenuItem { +struct RedoItem : ui::MenuItem { RedoItem() { text = "Redo"; rightText = WINDOW_MOD_CTRL_NAME "+" WINDOW_MOD_SHIFT_NAME "+Z"; - disabled = !app()->history->canRedo(); + disabled = !APP->history->canRedo(); } void onAction(const event::Action &e) override { - app()->history->redo(); + APP->history->redo(); } }; @@ -167,7 +168,7 @@ struct EditButton : MenuButton { text = "Edit"; } void onAction(const event::Action &e) override { - Menu *menu = createMenu(); + ui::Menu *menu = createMenu(); menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y)); menu->box.size.x = box.size.x; @@ -177,7 +178,7 @@ struct EditButton : MenuButton { }; -struct ZoomQuantity : Quantity { +struct ZoomQuantity : ui::Quantity { void setValue(float value) override { settings::zoom = math::clamp(value, getMinValue(), getMaxValue()); } @@ -194,7 +195,7 @@ struct ZoomQuantity : Quantity { }; -struct CableOpacityQuantity : Quantity { +struct CableOpacityQuantity : ui::Quantity { void setValue(float value) override { settings::cableOpacity = math::clamp(value, getMinValue(), getMaxValue()); } @@ -210,7 +211,7 @@ struct CableOpacityQuantity : Quantity { -struct CableTensionQuantity : Quantity { +struct CableTensionQuantity : ui::Quantity { void setValue(float value) override { settings::cableTension = math::clamp(value, getMinValue(), getMaxValue()); } @@ -223,7 +224,7 @@ struct CableTensionQuantity : Quantity { }; -struct PowerMeterItem : MenuItem { +struct PowerMeterItem : ui::MenuItem { PowerMeterItem() { text = "CPU meter"; rightText = CHECKMARK(settings::powerMeter); @@ -234,7 +235,7 @@ struct PowerMeterItem : MenuItem { }; -struct ParamTooltipItem : MenuItem { +struct ParamTooltipItem : ui::MenuItem { ParamTooltipItem() { text = "Parameter tooltips"; rightText = CHECKMARK(settings::paramTooltip); @@ -245,7 +246,7 @@ struct ParamTooltipItem : MenuItem { }; -struct LockModulesItem : MenuItem { +struct LockModulesItem : ui::MenuItem { LockModulesItem() { text = "Lock modules"; rightText = CHECKMARK(settings::lockModules); @@ -256,37 +257,37 @@ struct LockModulesItem : MenuItem { }; -struct EnginePauseItem : MenuItem { +struct EnginePauseItem : ui::MenuItem { EnginePauseItem() { text = "Pause engine"; - rightText = CHECKMARK(app()->engine->paused); + rightText = CHECKMARK(APP->engine->paused); } void onAction(const event::Action &e) override { - app()->engine->paused ^= true; + APP->engine->paused ^= true; } }; -struct SampleRateValueItem : MenuItem { +struct SampleRateValueItem : ui::MenuItem { float sampleRate; void setSampleRate(float sampleRate) { this->sampleRate = sampleRate; text = string::f("%.0f Hz", sampleRate); - rightText = CHECKMARK(app()->engine->getSampleRate() == sampleRate); + rightText = CHECKMARK(APP->engine->getSampleRate() == sampleRate); } void onAction(const event::Action &e) override { - app()->engine->setSampleRate(sampleRate); - app()->engine->paused = false; + APP->engine->setSampleRate(sampleRate); + APP->engine->paused = false; } }; -struct SampleRateItem : MenuItem { +struct SampleRateItem : ui::MenuItem { SampleRateItem() { text = "Engine sample rate"; } - Menu *createChildMenu() override { - Menu *menu = new Menu; + ui::Menu *createChildMenu() override { + ui::Menu *menu = new ui::Menu; menu->addChild(new EnginePauseItem); @@ -310,7 +311,7 @@ struct SampleRateItem : MenuItem { }; -struct ThreadCountValueItem : MenuItem { +struct ThreadCountValueItem : ui::MenuItem { int threadCount; void setThreadCount(int threadCount) { this->threadCount = threadCount; @@ -319,20 +320,20 @@ struct ThreadCountValueItem : MenuItem { text += " (default)"; else if (threadCount == system::getPhysicalCoreCount() / 2) text += " (recommended)"; - rightText = CHECKMARK(app()->engine->threadCount == threadCount); + rightText = CHECKMARK(APP->engine->threadCount == threadCount); } void onAction(const event::Action &e) override { - app()->engine->threadCount = threadCount; + APP->engine->threadCount = threadCount; } }; -struct ThreadCount : MenuItem { +struct ThreadCount : ui::MenuItem { ThreadCount() { text = "Thread count"; } - Menu *createChildMenu() override { - Menu *menu = new Menu; + ui::Menu *createChildMenu() override { + ui::Menu *menu = new ui::Menu; int coreCount = system::getPhysicalCoreCount(); for (int i = 1; i <= coreCount; i++) { @@ -345,15 +346,15 @@ struct ThreadCount : MenuItem { }; -struct FullscreenItem : MenuItem { +struct FullscreenItem : ui::MenuItem { FullscreenItem() { text = "Fullscreen"; rightText = "F11"; - if (app()->window->isFullScreen()) + if (APP->window->isFullScreen()) rightText = CHECKMARK_STRING " " + rightText; } void onAction(const event::Action &e) override { - app()->window->setFullScreen(!app()->window->isFullScreen()); + APP->window->setFullScreen(!APP->window->isFullScreen()); } }; @@ -363,7 +364,7 @@ struct SettingsButton : MenuButton { text = "Settings"; } void onAction(const event::Action &e) override { - Menu *menu = createMenu(); + ui::Menu *menu = createMenu(); menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y)); menu->box.size.x = box.size.x; @@ -374,17 +375,17 @@ struct SettingsButton : MenuButton { menu->addChild(new ThreadCount); menu->addChild(new FullscreenItem); - Slider *zoomSlider = new Slider; + ui::Slider *zoomSlider = new ui::Slider; zoomSlider->box.size.x = 200.0; zoomSlider->quantity = new ZoomQuantity; menu->addChild(zoomSlider); - Slider *cableOpacitySlider = new Slider; + ui::Slider *cableOpacitySlider = new ui::Slider; cableOpacitySlider->box.size.x = 200.0; cableOpacitySlider->quantity = new CableOpacityQuantity; menu->addChild(cableOpacitySlider); - Slider *cableTensionSlider = new Slider; + ui::Slider *cableTensionSlider = new ui::Slider; cableTensionSlider->box.size.x = 200.0; cableTensionSlider->quantity = new CableTensionQuantity; menu->addChild(cableTensionSlider); @@ -392,7 +393,7 @@ struct SettingsButton : MenuButton { }; -struct RegisterItem : MenuItem { +struct RegisterItem : ui::MenuItem { RegisterItem() { text = "Register VCV account"; } @@ -405,24 +406,24 @@ struct RegisterItem : MenuItem { }; -struct AccountEmailField : TextField { - TextField *passwordField; +struct AccountEmailField : ui::TextField { + ui::TextField *passwordField; AccountEmailField() { placeholder = "Email"; } void onSelectKey(const event::SelectKey &e) override { if (e.action == GLFW_PRESS && e.key == GLFW_KEY_TAB) { - app()->event->selectedWidget = passwordField; + APP->event->selectedWidget = passwordField; e.consume(this); return; } - TextField::onSelectKey(e); + ui::TextField::onSelectKey(e); } }; -struct AccountPasswordField : PasswordField { - MenuItem *logInItem; +struct AccountPasswordField : ui::PasswordField { + ui::MenuItem *logInItem; AccountPasswordField() { placeholder = "Password"; } @@ -432,14 +433,14 @@ struct AccountPasswordField : PasswordField { e.consume(this); return; } - PasswordField::onSelectKey(e); + ui::PasswordField::onSelectKey(e); } }; -struct LogInItem : MenuItem { - TextField *emailField; - TextField *passwordField; +struct LogInItem : ui::MenuItem { + ui::TextField *emailField; + ui::TextField *passwordField; LogInItem() { text = "Log in"; } @@ -454,7 +455,7 @@ struct LogInItem : MenuItem { }; -struct ManageItem : MenuItem { +struct ManageItem : ui::MenuItem { ManageItem() { text = "Manage plugins"; } @@ -467,7 +468,7 @@ struct ManageItem : MenuItem { }; -struct SyncItem : MenuItem { +struct SyncItem : ui::MenuItem { SyncItem() { text = "Sync plugins"; disabled = true; @@ -477,7 +478,7 @@ struct SyncItem : MenuItem { }; -// struct SyncButton : Button { +// struct SyncButton : ui::Button { // bool checked = false; // /** Updates are available */ // bool available = false; @@ -497,7 +498,7 @@ struct SyncItem : MenuItem { // // Display message if we've completed updates // if (completed) { // if (osdialog_message(OSDIALOG_INFO, OSDIALOG_OK_CANCEL, "All plugins have been updated. Close Rack and re-launch it to load new updates.")) { -// app()->window->close(); +// APP->window->close(); // } // completed = false; // } @@ -513,7 +514,7 @@ struct SyncItem : MenuItem { // }; -struct LogOutItem : MenuItem { +struct LogOutItem : ui::MenuItem { LogOutItem() { text = "Log out"; } @@ -523,7 +524,7 @@ struct LogOutItem : MenuItem { }; -struct DownloadQuantity : Quantity { +struct DownloadQuantity : ui::Quantity { float getValue() override { return plugin::downloadProgress; } @@ -547,13 +548,13 @@ struct PluginsButton : MenuButton { text = "Plugins"; } void onAction(const event::Action &e) override { - Menu *menu = createMenu(); + ui::Menu *menu = createMenu(); menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y)); menu->box.size.x = box.size.x; // TODO Design dialog box for plugin syncing if (plugin::isDownloading) { - ProgressBar *downloadProgressBar = new ProgressBar; + ui::ProgressBar *downloadProgressBar = new ui::ProgressBar; downloadProgressBar->quantity = new DownloadQuantity; menu->addChild(downloadProgressBar); } @@ -579,7 +580,7 @@ struct PluginsButton : MenuButton { } } - void draw(const DrawContext &ctx) override { + void draw(const widget::DrawContext &ctx) override { MenuButton::draw(ctx); // if (1) { // // Notification circle @@ -594,7 +595,7 @@ struct PluginsButton : MenuButton { }; -struct ManualItem : MenuItem { +struct ManualItem : ui::MenuItem { ManualItem() { text = "Manual"; rightText = "F1"; @@ -608,7 +609,7 @@ struct ManualItem : MenuItem { }; -struct WebsiteItem : MenuItem { +struct WebsiteItem : ui::MenuItem { WebsiteItem() { text = "VCVRack.com"; } @@ -621,7 +622,7 @@ struct WebsiteItem : MenuItem { }; -struct CheckVersionItem : MenuItem { +struct CheckVersionItem : ui::MenuItem { CheckVersionItem() { text = "Check version on launch"; rightText = CHECKMARK(settings::checkVersion); @@ -637,7 +638,7 @@ struct HelpButton : MenuButton { text = "Help"; } void onAction(const event::Action &e) override { - Menu *menu = createMenu(); + ui::Menu *menu = createMenu(); menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y)); menu->box.size.x = box.size.x; @@ -652,7 +653,7 @@ Toolbar::Toolbar() { const float margin = 5; box.size.y = BND_WIDGET_HEIGHT + 2*margin; - SequentialLayout *layout = new SequentialLayout; + ui::SequentialLayout *layout = new ui::SequentialLayout; layout->box.pos = math::Vec(margin, margin); layout->spacing = math::Vec(0, 0); addChild(layout); @@ -673,12 +674,13 @@ Toolbar::Toolbar() { layout->addChild(helpButton); } -void Toolbar::draw(const DrawContext &ctx) { +void Toolbar::draw(const widget::DrawContext &ctx) { bndMenuBackground(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_ALL); bndBevel(ctx.vg, 0.0, 0.0, box.size.x, box.size.y); - Widget::draw(ctx); + widget::Widget::draw(ctx); } +} // namespace app } // namespace rack diff --git a/src/event.cpp b/src/event.cpp index 7de01112..97e87350 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -1,12 +1,12 @@ #include "event.hpp" -#include "widgets/Widget.hpp" +#include "widget/Widget.hpp" namespace rack { namespace event { -void State::setHovered(Widget *w) { +void State::setHovered(widget::Widget *w) { if (w == hoveredWidget) return; @@ -25,7 +25,7 @@ void State::setHovered(Widget *w) { } } -void State::setDragged(Widget *w) { +void State::setDragged(widget::Widget *w) { if (w == draggedWidget) return; @@ -44,7 +44,7 @@ void State::setDragged(Widget *w) { } } -void State::setDragHovered(Widget *w) { +void State::setDragHovered(widget::Widget *w) { if (w == dragHoveredWidget) return; @@ -65,7 +65,7 @@ void State::setDragHovered(Widget *w) { } } -void State::setSelected(Widget *w) { +void State::setSelected(widget::Widget *w) { if (w == selectedWidget) return; @@ -84,7 +84,7 @@ void State::setSelected(Widget *w) { } } -void State::finalizeWidget(Widget *w) { +void State::finalizeWidget(widget::Widget *w) { if (hoveredWidget == w) setHovered(NULL); if (draggedWidget == w) setDragged(NULL); if (dragHoveredWidget == w) setDragHovered(NULL); @@ -102,7 +102,7 @@ void State::handleButton(math::Vec pos, int button, int action, int mods) { eButton.action = action; eButton.mods = mods; rootWidget->onButton(eButton); - Widget *clickedWidget = eButtonContext.consumed; + widget::Widget *clickedWidget = eButtonContext.consumed; if (button == GLFW_MOUSE_BUTTON_LEFT) { if (action == GLFW_PRESS) { diff --git a/src/history.cpp b/src/history.cpp index 89258f3b..910b3de7 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -37,7 +37,7 @@ ModuleAdd::~ModuleAdd() { json_decref(moduleJ); } -void ModuleAdd::setModule(ModuleWidget *mw) { +void ModuleAdd::setModule(app::ModuleWidget *mw) { model = mw->model; assert(mw->module); moduleId = mw->module->id; @@ -48,46 +48,46 @@ void ModuleAdd::setModule(ModuleWidget *mw) { } void ModuleAdd::undo() { - ModuleWidget *mw = app()->scene->rackWidget->getModule(moduleId); + app::ModuleWidget *mw = APP->scene->rackWidget->getModule(moduleId); assert(mw); - app()->scene->rackWidget->removeModule(mw); + APP->scene->rackWidget->removeModule(mw); delete mw; } void ModuleAdd::redo() { - ModuleWidget *mw = model->createModuleWidget(); + app::ModuleWidget *mw = model->createModuleWidget(); assert(mw); assert(mw->module); mw->module->id = moduleId; mw->box.pos = pos; mw->fromJson(moduleJ); - app()->scene->rackWidget->addModule(mw); + APP->scene->rackWidget->addModule(mw); } void ModuleMove::undo() { - ModuleWidget *mw = app()->scene->rackWidget->getModule(moduleId); + app::ModuleWidget *mw = APP->scene->rackWidget->getModule(moduleId); assert(mw); mw->box.pos = oldPos; } void ModuleMove::redo() { - ModuleWidget *mw = app()->scene->rackWidget->getModule(moduleId); + app::ModuleWidget *mw = APP->scene->rackWidget->getModule(moduleId); assert(mw); mw->box.pos = newPos; } void ModuleBypass::undo() { - ModuleWidget *mw = app()->scene->rackWidget->getModule(moduleId); + app::ModuleWidget *mw = APP->scene->rackWidget->getModule(moduleId); assert(mw); - app()->engine->bypassModule(mw->module, !bypass); + APP->engine->bypassModule(mw->module, !bypass); } void ModuleBypass::redo() { - ModuleWidget *mw = app()->scene->rackWidget->getModule(moduleId); + app::ModuleWidget *mw = APP->scene->rackWidget->getModule(moduleId); assert(mw); - app()->engine->bypassModule(mw->module, bypass); + APP->engine->bypassModule(mw->module, bypass); } @@ -97,32 +97,32 @@ ModuleChange::~ModuleChange() { } void ModuleChange::undo() { - ModuleWidget *mw = app()->scene->rackWidget->getModule(moduleId); + app::ModuleWidget *mw = APP->scene->rackWidget->getModule(moduleId); assert(mw); mw->fromJson(oldModuleJ); } void ModuleChange::redo() { - ModuleWidget *mw = app()->scene->rackWidget->getModule(moduleId); + app::ModuleWidget *mw = APP->scene->rackWidget->getModule(moduleId); assert(mw); mw->fromJson(newModuleJ); } void ParamChange::undo() { - ModuleWidget *mw = app()->scene->rackWidget->getModule(moduleId); + app::ModuleWidget *mw = APP->scene->rackWidget->getModule(moduleId); assert(mw); mw->module->params[paramId].value = oldValue; } void ParamChange::redo() { - ModuleWidget *mw = app()->scene->rackWidget->getModule(moduleId); + app::ModuleWidget *mw = APP->scene->rackWidget->getModule(moduleId); assert(mw); mw->module->params[paramId].value = newValue; } -void CableAdd::setCable(CableWidget *cw) { +void CableAdd::setCable(app::CableWidget *cw) { assert(cw->cable); assert(cw->cable->id > 0); cableId = cw->cable->id; @@ -136,30 +136,30 @@ void CableAdd::setCable(CableWidget *cw) { } void CableAdd::undo() { - CableWidget *cw = app()->scene->rackWidget->getCable(cableId); - app()->scene->rackWidget->removeCable(cw); + app::CableWidget *cw = APP->scene->rackWidget->getCable(cableId); + APP->scene->rackWidget->removeCable(cw); delete cw; } void CableAdd::redo() { - CableWidget *cw = new CableWidget; + app::CableWidget *cw = new app::CableWidget; cw->cable->id = cableId; - ModuleWidget *outputModule = app()->scene->rackWidget->getModule(outputModuleId); + app::ModuleWidget *outputModule = APP->scene->rackWidget->getModule(outputModuleId); assert(outputModule); - PortWidget *outputPort = outputModule->getOutput(outputId); + app::PortWidget *outputPort = outputModule->getOutput(outputId); assert(outputPort); cw->setOutput(outputPort); - ModuleWidget *inputModule = app()->scene->rackWidget->getModule(inputModuleId); + app::ModuleWidget *inputModule = APP->scene->rackWidget->getModule(inputModuleId); assert(inputModule); - PortWidget *inputPort = inputModule->getInput(inputId); + app::PortWidget *inputPort = inputModule->getInput(inputId); assert(inputPort); cw->setInput(inputPort); cw->color = color; - app()->scene->rackWidget->addCable(cw); + APP->scene->rackWidget->addCable(cw); } diff --git a/src/main.cpp b/src/main.cpp index 59dc6ea9..6d41a767 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,7 +28,7 @@ int main(int argc, char *argv[]) { #ifdef ARCH_WIN // Windows global mutex to prevent multiple instances // Handle will be closed by Windows when the process ends - HANDLE instanceMutex = CreateMutex(NULL, true, APP_NAME); + HANDLE instanceMutex = CreateMutex(NULL, true, app::NAME); if (GetLastError() == ERROR_ALREADY_EXISTS) { osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, "Rack is already running. Multiple Rack instances are not supported."); exit(1); @@ -65,7 +65,7 @@ int main(int argc, char *argv[]) { logger::init(devMode); // Log environment - INFO("%s %s", APP_NAME, APP_VERSION); + INFO("%s %s", app::NAME, app::VERSION); if (devMode) INFO("Development mode"); INFO("System directory: %s", asset::systemDir.c_str()); @@ -83,22 +83,22 @@ int main(int argc, char *argv[]) { INFO("Initialized environment"); // Initialize app - appInit(); - app()->scene->devMode = devMode; + app::init(); + APP->scene->devMode = devMode; settings::load(asset::user("settings.json")); - app()->patch->init(patchPath); + APP->patch->init(patchPath); INFO("Initialized app"); - app()->engine->start(); - app()->window->run(); + APP->engine->start(); + APP->window->run(); INFO("Window closed"); - app()->engine->stop(); + APP->engine->stop(); // Destroy app - app()->patch->save(asset::user("autosave.vcv")); + APP->patch->save(asset::user("autosave.vcv")); settings::save(asset::user("settings.json")); - appDestroy(); + app::destroy(); INFO("Cleaned up app"); // Destroy environment diff --git a/src/patch.cpp b/src/patch.cpp index 8969f05d..b2816c1d 100644 --- a/src/patch.cpp +++ b/src/patch.cpp @@ -50,9 +50,9 @@ void PatchManager::init(std::string path) { } void PatchManager::reset() { - app()->history->clear(); - app()->scene->rackWidget->clear(); - app()->scene->scrollWidget->offset = math::Vec(0, 0); + APP->history->clear(); + APP->scene->rackWidget->clear(); + APP->scene->scrollWidget->offset = math::Vec(0, 0); // Fails silently if file does not exist load(asset::user("template.vcv")); legacy = 0; @@ -159,9 +159,9 @@ bool PatchManager::load(std::string path) { json_decref(rootJ); }); - app()->history->clear(); - app()->scene->rackWidget->clear(); - app()->scene->scrollWidget->offset = math::Vec(0, 0); + APP->history->clear(); + APP->scene->rackWidget->clear(); + APP->scene->scrollWidget->offset = math::Vec(0, 0); fromJson(rootJ); return true; } @@ -207,7 +207,7 @@ void PatchManager::disconnectDialog() { // if (!osdialog_message(OSDIALOG_WARNING, OSDIALOG_OK_CANCEL, "Remove all patch cables?")) // return; - app()->scene->rackWidget->clearCablesAction(); + APP->scene->rackWidget->clearCablesAction(); } json_t *PatchManager::toJson() { @@ -215,11 +215,11 @@ json_t *PatchManager::toJson() { json_t *rootJ = json_object(); // version - json_t *versionJ = json_string(APP_VERSION); + json_t *versionJ = json_string(app::VERSION); json_object_set_new(rootJ, "version", versionJ); // Merge with RackWidget JSON - json_t *rackJ = app()->scene->rackWidget->toJson(); + json_t *rackJ = APP->scene->rackWidget->toJson(); // Merge with rootJ json_object_update(rootJ, rackJ); json_decref(rackJ); @@ -235,8 +235,8 @@ void PatchManager::fromJson(json_t *rootJ) { json_t *versionJ = json_object_get(rootJ, "version"); if (versionJ) version = json_string_value(versionJ); - if (version != APP_VERSION) { - INFO("Patch made with Rack version %s, current Rack version is %s", version.c_str(), APP_VERSION); + if (version != app::VERSION) { + INFO("Patch made with Rack version %s, current Rack version is %s", version.c_str(), app::VERSION); } // Detect old patches with ModuleWidget::params/inputs/outputs indices. @@ -251,7 +251,7 @@ void PatchManager::fromJson(json_t *rootJ) { INFO("Loading patch using legacy mode %d", legacy); } - app()->scene->rackWidget->fromJson(rootJ); + APP->scene->rackWidget->fromJson(rootJ); // Display a message if we have something to say if (!warningLog.empty()) { diff --git a/src/plugin.cpp b/src/plugin.cpp index 90d77765..1cdc847c 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -179,7 +179,7 @@ static bool syncPlugin(std::string slug, json_t *manifestJ, bool dryRun) { #endif std::string downloadUrl; - downloadUrl = APP_API_URL; + downloadUrl = app::API_URL; downloadUrl += "/download"; if (dryRun) { downloadUrl += "/available"; @@ -378,7 +378,7 @@ void logIn(std::string email, std::string password) { json_t *reqJ = json_object(); json_object_set(reqJ, "email", json_string(email.c_str())); json_object_set(reqJ, "password", json_string(password.c_str())); - std::string tokenUrl = APP_API_URL; + std::string tokenUrl = app::API_URL; tokenUrl += "/token"; json_t *resJ = network::requestJson(network::METHOD_POST, tokenUrl, reqJ); json_decref(reqJ); @@ -423,7 +423,7 @@ bool sync(bool dryRun) { // Get user's plugins list json_t *pluginsReqJ = json_object(); json_object_set(pluginsReqJ, "token", json_string(token.c_str())); - std::string pluginsUrl = APP_API_URL; + std::string pluginsUrl = app::API_URL; pluginsUrl += "/plugins"; json_t *pluginsResJ = network::requestJson(network::METHOD_GET, pluginsUrl, pluginsReqJ); json_decref(pluginsReqJ); @@ -442,7 +442,7 @@ bool sync(bool dryRun) { } // Get community manifests - std::string manifestsUrl = APP_API_URL; + std::string manifestsUrl = app::API_URL; manifestsUrl += "/community/manifests"; json_t *manifestsResJ = network::requestJson(network::METHOD_GET, manifestsUrl, NULL); if (!manifestsResJ) { diff --git a/src/settings.cpp b/src/settings.cpp index 5933da67..e946483a 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -21,14 +21,14 @@ static json_t *settingsToJson() { json_t *tokenJ = json_string(plugin::token.c_str()); json_object_set_new(rootJ, "token", tokenJ); - if (!app()->window->isMaximized()) { + if (!APP->window->isMaximized()) { // windowSize - math::Vec windowSize = app()->window->getWindowSize(); + math::Vec windowSize = APP->window->getWindowSize(); json_t *windowSizeJ = json_pack("[f, f]", windowSize.x, windowSize.y); json_object_set_new(rootJ, "windowSize", windowSizeJ); // windowPos - math::Vec windowPos = app()->window->getWindowPos(); + math::Vec windowPos = APP->window->getWindowPos(); json_t *windowPosJ = json_pack("[f, f]", windowPos.x, windowPos.y); json_object_set_new(rootJ, "windowPos", windowPosJ); } @@ -46,15 +46,15 @@ static json_t *settingsToJson() { json_object_set_new(rootJ, "zoom", zoomJ); // allowCursorLock - json_t *allowCursorLockJ = json_boolean(app()->window->allowCursorLock); + json_t *allowCursorLockJ = json_boolean(APP->window->allowCursorLock); json_object_set_new(rootJ, "allowCursorLock", allowCursorLockJ); // sampleRate - json_t *sampleRateJ = json_real(app()->engine->getSampleRate()); + json_t *sampleRateJ = json_real(APP->engine->getSampleRate()); json_object_set_new(rootJ, "sampleRate", sampleRateJ); // patchPath - json_t *patchPathJ = json_string(app()->patch->path.c_str()); + json_t *patchPathJ = json_string(APP->patch->path.c_str()); json_object_set_new(rootJ, "patchPath", patchPathJ); // skipLoadOnLaunch @@ -63,13 +63,13 @@ static json_t *settingsToJson() { } // moduleBrowser - json_object_set_new(rootJ, "moduleBrowser", moduleBrowserToJson()); + json_object_set_new(rootJ, "moduleBrowser", app::moduleBrowserToJson()); // powerMeter json_object_set_new(rootJ, "powerMeter", json_boolean(powerMeter)); // threadCount - json_object_set_new(rootJ, "threadCount", json_integer(app()->engine->threadCount)); + json_object_set_new(rootJ, "threadCount", json_integer(APP->engine->threadCount)); // checkVersion json_object_set_new(rootJ, "checkVersion", json_boolean(checkVersion)); @@ -91,7 +91,7 @@ static void settingsFromJson(json_t *rootJ) { if (windowSizeJ) { double width, height; json_unpack(windowSizeJ, "[F, F]", &width, &height); - app()->window->setWindowSize(math::Vec(width, height)); + APP->window->setWindowSize(math::Vec(width, height)); } // windowPos @@ -99,7 +99,7 @@ static void settingsFromJson(json_t *rootJ) { if (windowPosJ) { double x, y; json_unpack(windowPosJ, "[F, F]", &x, &y); - app()->window->setWindowPos(math::Vec(x, y)); + APP->window->setWindowPos(math::Vec(x, y)); } // cableOpacity @@ -120,19 +120,19 @@ static void settingsFromJson(json_t *rootJ) { // allowCursorLock json_t *allowCursorLockJ = json_object_get(rootJ, "allowCursorLock"); if (allowCursorLockJ) - app()->window->allowCursorLock = json_is_true(allowCursorLockJ); + APP->window->allowCursorLock = json_is_true(allowCursorLockJ); // sampleRate json_t *sampleRateJ = json_object_get(rootJ, "sampleRate"); if (sampleRateJ) { float sampleRate = json_number_value(sampleRateJ); - app()->engine->setSampleRate(sampleRate); + APP->engine->setSampleRate(sampleRate); } // patchPath json_t *patchPathJ = json_object_get(rootJ, "patchPath"); if (patchPathJ) - app()->patch->path = json_string_value(patchPathJ); + APP->patch->path = json_string_value(patchPathJ); // skipLoadOnLaunch json_t *skipLoadOnLaunchJ = json_object_get(rootJ, "skipLoadOnLaunch"); @@ -142,7 +142,7 @@ static void settingsFromJson(json_t *rootJ) { // moduleBrowser json_t *moduleBrowserJ = json_object_get(rootJ, "moduleBrowser"); if (moduleBrowserJ) - moduleBrowserFromJson(moduleBrowserJ); + app::moduleBrowserFromJson(moduleBrowserJ); // powerMeter json_t *powerMeterJ = json_object_get(rootJ, "powerMeter"); @@ -152,7 +152,7 @@ static void settingsFromJson(json_t *rootJ) { // threadCount json_t *threadCountJ = json_object_get(rootJ, "threadCount"); if (threadCountJ) - app()->engine->threadCount = json_integer_value(threadCountJ); + APP->engine->threadCount = json_integer_value(threadCountJ); // checkVersion json_t *checkVersionJ = json_object_get(rootJ, "checkVersion"); diff --git a/src/ui/Button.cpp b/src/ui/Button.cpp index 86f355c4..4ce7d079 100644 --- a/src/ui/Button.cpp +++ b/src/ui/Button.cpp @@ -2,6 +2,7 @@ namespace rack { +namespace ui { Button::Button() { @@ -13,7 +14,7 @@ Button::~Button() { delete quantity; } -void Button::draw(const DrawContext &ctx) { +void Button::draw(const widget::DrawContext &ctx) { bndToolButton(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str()); } @@ -45,4 +46,5 @@ void Button::onDragDrop(const event::DragDrop &e) { } +} // namespace ui } // namespace rack diff --git a/src/ui/ChoiceButton.cpp b/src/ui/ChoiceButton.cpp index 749bbbae..53912220 100644 --- a/src/ui/ChoiceButton.cpp +++ b/src/ui/ChoiceButton.cpp @@ -2,11 +2,13 @@ namespace rack { +namespace ui { -void ChoiceButton::draw(const DrawContext &ctx) { +void ChoiceButton::draw(const widget::DrawContext &ctx) { bndChoiceButton(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str()); } +} // namespace ui } // namespace rack diff --git a/src/ui/IconButton.cpp b/src/ui/IconButton.cpp index 3b30c25c..136906e8 100644 --- a/src/ui/IconButton.cpp +++ b/src/ui/IconButton.cpp @@ -2,16 +2,17 @@ namespace rack { +namespace ui { IconButton::IconButton() { box.size.x = BND_TOOL_WIDTH; - fw = new FramebufferWidget; + fw = new widget::FramebufferWidget; fw->oversample = 2; addChild(fw); - sw = new SVGWidget; + sw = new widget::SVGWidget; sw->box.pos = math::Vec(2, 2); fw->addChild(sw); } @@ -22,4 +23,5 @@ void IconButton::setSVG(std::shared_ptr svg) { } +} // namespace ui } // namespace rack diff --git a/src/ui/Label.cpp b/src/ui/Label.cpp index 5a0eba42..492acb58 100644 --- a/src/ui/Label.cpp +++ b/src/ui/Label.cpp @@ -2,6 +2,7 @@ namespace rack { +namespace ui { Label::Label() { @@ -10,7 +11,7 @@ Label::Label() { color = bndGetTheme()->regularTheme.textColor; } -void Label::draw(const DrawContext &ctx) { +void Label::draw(const widget::DrawContext &ctx) { // TODO // Custom font sizes do not work with right or center alignment float x; @@ -31,4 +32,5 @@ void Label::draw(const DrawContext &ctx) { } +} // namespace ui } // namespace rack diff --git a/src/ui/List.cpp b/src/ui/List.cpp index 56df639a..1521bb2b 100644 --- a/src/ui/List.cpp +++ b/src/ui/List.cpp @@ -2,14 +2,15 @@ namespace rack { +namespace ui { void List::step() { - Widget::step(); + widget::Widget::step(); // Set positions of children box.size.y = 0.0; - for (Widget *child : children) { + for (widget::Widget *child : children) { if (!child->visible) continue; // Increment height, set position of child @@ -21,4 +22,5 @@ void List::step() { } +} // namespace ui } // namespace rack diff --git a/src/ui/Menu.cpp b/src/ui/Menu.cpp index 22f58d11..1346bfec 100644 --- a/src/ui/Menu.cpp +++ b/src/ui/Menu.cpp @@ -1,6 +1,7 @@ #include "ui/Menu.hpp" namespace rack { +namespace ui { Menu::Menu() { @@ -26,11 +27,11 @@ void Menu::setChildMenu(Menu *menu) { } void Menu::step() { - Widget::step(); + widget::Widget::step(); // Set positions of children box.size = math::Vec(0, 0); - for (Widget *child : children) { + for (widget::Widget *child : children) { if (!child->visible) continue; // Increment height, set position of child @@ -43,14 +44,14 @@ void Menu::step() { } // Set widths of all children to maximum width - for (Widget *child : children) { + for (widget::Widget *child : children) { child->box.size.x = box.size.x; } } -void Menu::draw(const DrawContext &ctx) { +void Menu::draw(const widget::DrawContext &ctx) { bndMenuBackground(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE); - Widget::draw(ctx); + widget::Widget::draw(ctx); } void Menu::onHoverScroll(const event::HoverScroll &e) { @@ -59,4 +60,5 @@ void Menu::onHoverScroll(const event::HoverScroll &e) { } +} // namespace ui } // namespace rack diff --git a/src/ui/MenuEntry.cpp b/src/ui/MenuEntry.cpp index 6ab8452e..d36c153d 100644 --- a/src/ui/MenuEntry.cpp +++ b/src/ui/MenuEntry.cpp @@ -2,6 +2,7 @@ namespace rack { +namespace ui { MenuEntry::MenuEntry() { @@ -9,4 +10,5 @@ MenuEntry::MenuEntry() { } +} // namespace ui } // namespace rack diff --git a/src/ui/MenuItem.cpp b/src/ui/MenuItem.cpp index 65f347d2..b147dd42 100644 --- a/src/ui/MenuItem.cpp +++ b/src/ui/MenuItem.cpp @@ -2,12 +2,13 @@ namespace rack { +namespace ui { -void MenuItem::draw(const DrawContext &ctx) { +void MenuItem::draw(const widget::DrawContext &ctx) { BNDwidgetState state = BND_DEFAULT; - if (app()->event->hoveredWidget == this) + if (APP->event->hoveredWidget == this) state = BND_HOVER; // Set active state if this MenuItem @@ -30,10 +31,10 @@ void MenuItem::draw(const DrawContext &ctx) { void MenuItem::step() { // Add 10 more pixels because measurements on high-DPI screens are sometimes too small for some reason const float rightPadding = 10.0; - // HACK use app()->window->vg from the window. - // All this does is inspect the font, so it shouldn't modify app()->window->vg and should work when called from a FramebufferWidget for example. - box.size.x = bndLabelWidth(app()->window->vg, -1, text.c_str()) + bndLabelWidth(app()->window->vg, -1, rightText.c_str()) + rightPadding; - Widget::step(); + // HACK use APP->window->vg from the window. + // All this does is inspect the font, so it shouldn't modify APP->window->vg and should work when called from a widget::FramebufferWidget for example. + box.size.x = bndLabelWidth(APP->window->vg, -1, text.c_str()) + bndLabelWidth(APP->window->vg, -1, rightText.c_str()) + rightPadding; + widget::Widget::step(); } void MenuItem::onEnter(const event::Enter &e) { @@ -71,9 +72,10 @@ void MenuItem::doAction() { if (!eActionContext.consumed) return; - Widget *overlay = getAncestorOfType(); + widget::Widget *overlay = getAncestorOfType(); overlay->requestedDelete = true; } +} // namespace ui } // namespace rack diff --git a/src/ui/MenuLabel.cpp b/src/ui/MenuLabel.cpp index 92af4bb0..72c0ee60 100644 --- a/src/ui/MenuLabel.cpp +++ b/src/ui/MenuLabel.cpp @@ -3,19 +3,21 @@ namespace rack { +namespace ui { -void MenuLabel::draw(const DrawContext &ctx) { +void MenuLabel::draw(const widget::DrawContext &ctx) { bndMenuLabel(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str()); } void MenuLabel::step() { // Add 10 more pixels because Retina measurements are sometimes too small const float rightPadding = 10.0; - // HACK use app()->window->vg from the window. - box.size.x = bndLabelWidth(app()->window->vg, -1, text.c_str()) + rightPadding; - Widget::step(); + // HACK use APP->window->vg from the window. + box.size.x = bndLabelWidth(APP->window->vg, -1, text.c_str()) + rightPadding; + widget::Widget::step(); } +} // namespace ui } // namespace rack diff --git a/src/ui/MenuOverlay.cpp b/src/ui/MenuOverlay.cpp index a7dca391..92f45631 100644 --- a/src/ui/MenuOverlay.cpp +++ b/src/ui/MenuOverlay.cpp @@ -2,6 +2,7 @@ namespace rack { +namespace ui { void MenuOverlay::step() { @@ -9,15 +10,15 @@ void MenuOverlay::step() { box.size = parent->box.size; // Fit all children in the box - for (Widget *child : children) { + for (widget::Widget *child : children) { child->box = child->box.nudge(box.zeroPos()); } - Widget::step(); + widget::Widget::step(); } void MenuOverlay::onButton(const event::Button &e) { - OpaqueWidget::onButton(e); + widget::OpaqueWidget::onButton(e); if (e.getConsumed() == this && e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT) { requestedDelete = true; @@ -25,7 +26,7 @@ void MenuOverlay::onButton(const event::Button &e) { } void MenuOverlay::onHoverKey(const event::HoverKey &e) { - OpaqueWidget::onHoverKey(e); + widget::OpaqueWidget::onHoverKey(e); if (e.getConsumed() == this && e.action == GLFW_PRESS && e.key == GLFW_KEY_ESCAPE) { requestedDelete = true; @@ -33,4 +34,5 @@ void MenuOverlay::onHoverKey(const event::HoverKey &e) { } +} // namespace ui } // namespace rack diff --git a/src/ui/MenuSeparator.cpp b/src/ui/MenuSeparator.cpp index cb6d6cdc..3c39c314 100644 --- a/src/ui/MenuSeparator.cpp +++ b/src/ui/MenuSeparator.cpp @@ -2,13 +2,14 @@ namespace rack { +namespace ui { MenuSeparator::MenuSeparator() { box.size.y = BND_WIDGET_HEIGHT / 2; } -void MenuSeparator::draw(const DrawContext &ctx) { +void MenuSeparator::draw(const widget::DrawContext &ctx) { nvgBeginPath(ctx.vg); const float margin = 8.0; nvgMoveTo(ctx.vg, margin, box.size.y / 2.0); @@ -19,4 +20,5 @@ void MenuSeparator::draw(const DrawContext &ctx) { } +} // namespace ui } // namespace rack diff --git a/src/ui/PasswordField.cpp b/src/ui/PasswordField.cpp index fc365114..73c4b6da 100644 --- a/src/ui/PasswordField.cpp +++ b/src/ui/PasswordField.cpp @@ -2,9 +2,10 @@ namespace rack { +namespace ui { -void PasswordField::draw(const DrawContext &ctx) { +void PasswordField::draw(const widget::DrawContext &ctx) { std::string textTmp = text; text = std::string(textTmp.size(), '*'); TextField::draw(ctx); @@ -12,4 +13,5 @@ void PasswordField::draw(const DrawContext &ctx) { } +} // namespace ui } // namespace rack diff --git a/src/ui/ProgressBar.cpp b/src/ui/ProgressBar.cpp index d0d0cc63..352b47c4 100644 --- a/src/ui/ProgressBar.cpp +++ b/src/ui/ProgressBar.cpp @@ -2,6 +2,7 @@ namespace rack { +namespace ui { ProgressBar::ProgressBar() { @@ -13,11 +14,12 @@ ProgressBar::~ProgressBar() { delete quantity; } -void ProgressBar::draw(const DrawContext &ctx) { +void ProgressBar::draw(const widget::DrawContext &ctx) { float progress = quantity ? quantity->getScaledValue() : 0.f; std::string text = quantity ? quantity->getString() : ""; bndSlider(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_ALL, BND_DEFAULT, progress, text.c_str(), NULL); } +} // namespace ui } // namespace rack diff --git a/src/ui/Quantity.cpp b/src/ui/Quantity.cpp index 6f944de2..06d61d1d 100644 --- a/src/ui/Quantity.cpp +++ b/src/ui/Quantity.cpp @@ -3,6 +3,7 @@ namespace rack { +namespace ui { int Quantity::getDisplayPrecision() { @@ -43,4 +44,5 @@ std::string Quantity::getString() { } +} // namespace ui } // namespace rack diff --git a/src/ui/RadioButton.cpp b/src/ui/RadioButton.cpp index ba9d8a2f..d13bfe0d 100644 --- a/src/ui/RadioButton.cpp +++ b/src/ui/RadioButton.cpp @@ -2,6 +2,7 @@ namespace rack { +namespace ui { RadioButton::RadioButton() { @@ -13,7 +14,7 @@ RadioButton::~RadioButton() { delete quantity; } -void RadioButton::draw(const DrawContext &ctx) { +void RadioButton::draw(const widget::DrawContext &ctx) { std::string label; if (quantity) label = quantity->getLabel(); @@ -49,4 +50,5 @@ void RadioButton::onDragDrop(const event::DragDrop &e) { } +} // namespace ui } // namespace rack diff --git a/src/ui/ScrollBar.cpp b/src/ui/ScrollBar.cpp index 36d2c999..a598eb43 100644 --- a/src/ui/ScrollBar.cpp +++ b/src/ui/ScrollBar.cpp @@ -5,6 +5,7 @@ namespace rack { +namespace ui { static const float SCROLLBAR_SENSITIVITY = 2.f; @@ -14,13 +15,13 @@ ScrollBar::ScrollBar() { box.size = math::Vec(BND_SCROLLBAR_WIDTH, BND_SCROLLBAR_HEIGHT); } -void ScrollBar::draw(const DrawContext &ctx) { +void ScrollBar::draw(const widget::DrawContext &ctx) { bndScrollBar(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, state, offset, size); } void ScrollBar::onDragStart(const event::DragStart &e) { state = BND_ACTIVE; - app()->window->cursorLock(); + APP->window->cursorLock(); } void ScrollBar::onDragMove(const event::DragMove &e) { @@ -34,8 +35,9 @@ void ScrollBar::onDragMove(const event::DragMove &e) { void ScrollBar::onDragEnd(const event::DragEnd &e) { state = BND_DEFAULT; - app()->window->cursorUnlock(); + APP->window->cursorUnlock(); } +} // namespace ui } // namespace rack diff --git a/src/ui/ScrollWidget.cpp b/src/ui/ScrollWidget.cpp index 47134d04..086c86b6 100644 --- a/src/ui/ScrollWidget.cpp +++ b/src/ui/ScrollWidget.cpp @@ -4,10 +4,11 @@ namespace rack { +namespace ui { ScrollWidget::ScrollWidget() { - container = new Widget; + container = new widget::Widget; addChild(container); horizontalScrollBar = new ScrollBar; @@ -26,14 +27,14 @@ void ScrollWidget::scrollTo(math::Rect r) { offset = offset.clampSafe(bound); } -void ScrollWidget::draw(const DrawContext &ctx) { +void ScrollWidget::draw(const widget::DrawContext &ctx) { nvgScissor(ctx.vg, 0, 0, box.size.x, box.size.y); - Widget::draw(ctx); + widget::Widget::draw(ctx); nvgResetScissor(ctx.vg); } void ScrollWidget::step() { - Widget::step(); + widget::Widget::step(); // Clamp scroll offset math::Vec containerCorner = container->getChildrenBoundingBox().getBottomRight(); @@ -69,13 +70,13 @@ void ScrollWidget::step() { } void ScrollWidget::onHover(const event::Hover &e) { - OpaqueWidget::onHover(e); + widget::OpaqueWidget::onHover(e); } void ScrollWidget::onHoverScroll(const event::HoverScroll &e) { math::Vec scrollDelta = e.scrollDelta; // Flip coordinates if shift is held - if ((app()->window->getMods() & WINDOW_MOD_MASK) == GLFW_MOD_SHIFT) + if ((APP->window->getMods() & WINDOW_MOD_MASK) == GLFW_MOD_SHIFT) scrollDelta = scrollDelta.flip(); offset = offset.minus(scrollDelta); @@ -83,4 +84,5 @@ void ScrollWidget::onHoverScroll(const event::HoverScroll &e) { } +} // namespace ui } // namespace rack diff --git a/src/ui/SequentialLayout.cpp b/src/ui/SequentialLayout.cpp index 962651e3..a1972ff2 100644 --- a/src/ui/SequentialLayout.cpp +++ b/src/ui/SequentialLayout.cpp @@ -3,19 +3,20 @@ namespace rack { +namespace ui { #define X(_v) (orientation == HORIZONTAL_ORIENTATION ? (_v).x : (_v).y) #define Y(_v) (orientation == HORIZONTAL_ORIENTATION ? (_v).y : (_v).x) void SequentialLayout::step() { - Widget::step(); + widget::Widget::step(); // Sort widgets into rows (or columns if vertical) - std::vector> rows; + std::vector> rows; rows.resize(1); float rowWidth = 0.0; - for (Widget *child : children) { + for (widget::Widget *child : children) { if (!child->visible) continue; @@ -36,7 +37,7 @@ void SequentialLayout::step() { float offset = 0.0; if (alignment != LEFT_ALIGNMENT) { float rowWidth = 0.0; - for (Widget *child : row) { + for (widget::Widget *child : row) { rowWidth += X(child->box.size) + X(spacing); } rowWidth -= X(spacing); @@ -48,7 +49,7 @@ void SequentialLayout::step() { } float maxHeight = 0.0; - for (Widget *child : row) { + for (widget::Widget *child : row) { child->box.pos = p; X(child->box.pos) += offset; @@ -62,4 +63,5 @@ void SequentialLayout::step() { } +} // namespace ui } // namespace rack diff --git a/src/ui/Slider.cpp b/src/ui/Slider.cpp index 95fa3fb1..6d216f65 100644 --- a/src/ui/Slider.cpp +++ b/src/ui/Slider.cpp @@ -2,6 +2,7 @@ namespace rack { +namespace ui { static const float SENSITIVITY = 0.001f; @@ -16,7 +17,7 @@ Slider::~Slider() { delete quantity; } -void Slider::draw(const DrawContext &ctx) { +void Slider::draw(const widget::DrawContext &ctx) { float progress = quantity ? quantity->getScaledValue() : 0.f; std::string text = quantity ? quantity->getString() : ""; bndSlider(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, progress, text.c_str(), NULL); @@ -24,7 +25,7 @@ void Slider::draw(const DrawContext &ctx) { void Slider::onDragStart(const event::DragStart &e) { state = BND_ACTIVE; - app()->window->cursorLock(); + APP->window->cursorLock(); } void Slider::onDragMove(const event::DragMove &e) { @@ -35,7 +36,7 @@ void Slider::onDragMove(const event::DragMove &e) { void Slider::onDragEnd(const event::DragEnd &e) { state = BND_DEFAULT; - app()->window->cursorUnlock(); + APP->window->cursorUnlock(); } void Slider::onButton(const event::Button &e) { @@ -47,4 +48,5 @@ void Slider::onButton(const event::Button &e) { } +} // namespace ui } // namespace rack diff --git a/src/ui/TextField.cpp b/src/ui/TextField.cpp index 82702081..f15e5b66 100644 --- a/src/ui/TextField.cpp +++ b/src/ui/TextField.cpp @@ -1,19 +1,20 @@ #include "ui/TextField.hpp" namespace rack { +namespace ui { TextField::TextField() { box.size.y = BND_WIDGET_HEIGHT; } -void TextField::draw(const DrawContext &ctx) { +void TextField::draw(const widget::DrawContext &ctx) { nvgScissor(ctx.vg, 0, 0, box.size.x, box.size.y); BNDwidgetState state; - if (this == app()->event->selectedWidget) + if (this == APP->event->selectedWidget) state = BND_ACTIVE; - else if (this == app()->event->hoveredWidget) + else if (this == APP->event->hoveredWidget) state = BND_HOVER; else state = BND_DEFAULT; @@ -33,17 +34,17 @@ void TextField::onButton(const event::Button &e) { if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT) { cursor = selection = getTextPosition(e.pos); } - OpaqueWidget::onButton(e); + widget::OpaqueWidget::onButton(e); } void TextField::onHover(const event::Hover &e) { - if (this == app()->event->draggedWidget) { + if (this == APP->event->draggedWidget) { int pos = getTextPosition(e.pos); if (pos != selection) { cursor = pos; } } - OpaqueWidget::onHover(e); + widget::OpaqueWidget::onHover(e); } void TextField::onEnter(const event::Enter &e) { @@ -129,7 +130,7 @@ void TextField::onSelectKey(const event::SelectKey &e) { } break; case GLFW_KEY_V: { if ((e.mods & WINDOW_MOD_MASK) == WINDOW_MOD_CTRL) { - const char *newText = glfwGetClipboardString(app()->window->win); + const char *newText = glfwGetClipboardString(APP->window->win); if (newText) insertText(newText); } @@ -139,7 +140,7 @@ void TextField::onSelectKey(const event::SelectKey &e) { if (cursor != selection) { int begin = std::min(cursor, selection); std::string selectedText = text.substr(begin, std::abs(selection - cursor)); - glfwSetClipboardString(app()->window->win, selectedText.c_str()); + glfwSetClipboardString(APP->window->win, selectedText.c_str()); insertText(""); } } @@ -149,7 +150,7 @@ void TextField::onSelectKey(const event::SelectKey &e) { if (cursor != selection) { int begin = std::min(cursor, selection); std::string selectedText = text.substr(begin, std::abs(selection - cursor)); - glfwSetClipboardString(app()->window->win, selectedText.c_str()); + glfwSetClipboardString(APP->window->win, selectedText.c_str()); } } } break; @@ -203,8 +204,9 @@ void TextField::selectAll() { } int TextField::getTextPosition(math::Vec mousePos) { - return bndTextFieldTextPosition(app()->window->vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str(), mousePos.x, mousePos.y); + return bndTextFieldTextPosition(APP->window->vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str(), mousePos.x, mousePos.y); } +} // namespace ui } // namespace rack diff --git a/src/ui/Tooltip.cpp b/src/ui/Tooltip.cpp index 8ec0f227..e4f3ce5d 100644 --- a/src/ui/Tooltip.cpp +++ b/src/ui/Tooltip.cpp @@ -4,20 +4,22 @@ namespace rack { +namespace ui { void Tooltip::step() { // Wrap size to contents - box.size.x = bndLabelWidth(app()->window->vg, -1, text.c_str()) + 10.0; - box.size.y = bndLabelHeight(app()->window->vg, -1, text.c_str(), INFINITY); - Widget::step(); + box.size.x = bndLabelWidth(APP->window->vg, -1, text.c_str()) + 10.0; + box.size.y = bndLabelHeight(APP->window->vg, -1, text.c_str(), INFINITY); + widget::Widget::step(); } -void Tooltip::draw(const DrawContext &ctx) { +void Tooltip::draw(const widget::DrawContext &ctx) { bndTooltipBackground(ctx.vg, 0.0, 0.0, box.size.x, box.size.y); bndMenuLabel(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str()); - Widget::draw(ctx); + widget::Widget::draw(ctx); } +} // namespace ui } // namespace rack diff --git a/src/widgets/FramebufferWidget.cpp b/src/widget/FramebufferWidget.cpp similarity index 93% rename from src/widgets/FramebufferWidget.cpp rename to src/widget/FramebufferWidget.cpp index 76935ec2..11b61132 100644 --- a/src/widgets/FramebufferWidget.cpp +++ b/src/widget/FramebufferWidget.cpp @@ -1,8 +1,9 @@ -#include "widgets/FramebufferWidget.hpp" +#include "widget/FramebufferWidget.hpp" #include "app.hpp" namespace rack { +namespace widget { FramebufferWidget::FramebufferWidget() { @@ -17,7 +18,7 @@ FramebufferWidget::~FramebufferWidget() { void FramebufferWidget::draw(const DrawContext &ctx) { // Bypass framebuffer rendering if we're already drawing in a framebuffer // In other words, disallow nested framebuffers. They look bad. - if (ctx.vg == app()->window->fbVg) { + if (ctx.vg == APP->window->fbVg) { Widget::draw(ctx); return; } @@ -56,7 +57,7 @@ void FramebufferWidget::draw(const DrawContext &ctx) { fbBox = math::Rect::fromMinMax(min, max); // DEBUG("%g %g %g %g", RECT_ARGS(fbBox)); - math::Vec newFbSize = fbBox.size.mult(app()->window->pixelRatio * oversample); + math::Vec newFbSize = fbBox.size.mult(APP->window->pixelRatio * oversample); if (!fb || !newFbSize.isEqual(fbSize)) { fbSize = newFbSize; @@ -105,7 +106,7 @@ void FramebufferWidget::draw(const DrawContext &ctx) { } void FramebufferWidget::drawFramebuffer() { - NVGcontext *vg = app()->window->fbVg; + NVGcontext *vg = APP->window->fbVg; float pixelRatio = fbSize.x / fbBox.size.x; nvgBeginFrame(vg, fbBox.size.x, fbBox.size.y, pixelRatio); @@ -133,4 +134,5 @@ int FramebufferWidget::getImageHandle() { } +} // namespace widget } // namespace rack diff --git a/src/widgets/GLWidget.cpp b/src/widget/GLWidget.cpp similarity index 89% rename from src/widgets/GLWidget.cpp rename to src/widget/GLWidget.cpp index 75155d66..49a1fe55 100644 --- a/src/widgets/GLWidget.cpp +++ b/src/widget/GLWidget.cpp @@ -1,8 +1,9 @@ -#include "widgets/GLWidget.hpp" +#include "widget/GLWidget.hpp" #include "app.hpp" namespace rack { +namespace widget { void GLWidget::step() { @@ -31,4 +32,5 @@ void GLWidget::drawFramebuffer() { } +} // namespace widget } // namespace rack diff --git a/src/widgets/Widget.cpp b/src/widget/Widget.cpp similarity index 92% rename from src/widgets/Widget.cpp rename to src/widget/Widget.cpp index 7e652dd2..0afb44f0 100644 --- a/src/widgets/Widget.cpp +++ b/src/widget/Widget.cpp @@ -1,10 +1,11 @@ -#include "widgets/Widget.hpp" +#include "widget/Widget.hpp" #include "event.hpp" #include "app.hpp" #include namespace rack { +namespace widget { Widget::~Widget() { @@ -58,7 +59,7 @@ void Widget::removeChild(Widget *child) { // Make sure `this` is the child's parent assert(child->parent == this); // Prepare to remove widget from the event state - app()->event->finalizeWidget(child); + APP->event->finalizeWidget(child); // Delete child from children list auto it = std::find(children.begin(), children.end(), child); assert(it != children.end()); @@ -69,7 +70,7 @@ void Widget::removeChild(Widget *child) { void Widget::clearChildren() { for (Widget *child : children) { - app()->event->finalizeWidget(child); + APP->event->finalizeWidget(child); child->parent = NULL; delete child; } @@ -81,7 +82,7 @@ void Widget::step() { Widget *child = *it; // Delete children if a delete is requested if (child->requestedDelete) { - app()->event->finalizeWidget(child); + APP->event->finalizeWidget(child); it = children.erase(it); child->parent = NULL; delete child; @@ -120,7 +121,7 @@ void Widget::draw(const DrawContext &ctx) { child->draw(childCtx); // Draw red hitboxes - // if (app()->event->hoveredWidget == child) { + // if (APP->event->hoveredWidget == child) { // nvgBeginPath(ctx.vg); // nvgRect(ctx.vg, 0, 0, child->box.size.x, child->box.size.y); // nvgFillColor(ctx.vg, nvgRGBAf(1, 0, 0, 0.5)); @@ -132,4 +133,5 @@ void Widget::draw(const DrawContext &ctx) { } +} // namespace widget } // namespace rack diff --git a/src/widgets/ZoomWidget.cpp b/src/widget/ZoomWidget.cpp similarity index 92% rename from src/widgets/ZoomWidget.cpp rename to src/widget/ZoomWidget.cpp index 168605b3..7f0c0e6d 100644 --- a/src/widgets/ZoomWidget.cpp +++ b/src/widget/ZoomWidget.cpp @@ -1,7 +1,8 @@ -#include "widgets/ZoomWidget.hpp" +#include "widget/ZoomWidget.hpp" namespace rack { +namespace widget { math::Vec ZoomWidget::getRelativeOffset(math::Vec v, Widget *relative) { @@ -38,4 +39,5 @@ void ZoomWidget::draw(const DrawContext &ctx) { } +} // namespace widget } // namespace rack diff --git a/src/window.cpp b/src/window.cpp index 8c9cc410..03177c58 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -28,7 +28,7 @@ static std::map> svgCache; Font::Font(const std::string &filename) { - handle = nvgCreateFont(app()->window->vg, filename.c_str(), filename.c_str()); + handle = nvgCreateFont(APP->window->vg, filename.c_str(), filename.c_str()); if (handle >= 0) { INFO("Loaded font %s", filename.c_str()); } @@ -49,7 +49,7 @@ std::shared_ptr Font::load(const std::string &filename) { } Image::Image(const std::string &filename) { - handle = nvgCreateImage(app()->window->vg, filename.c_str(), NVG_IMAGE_REPEATX | NVG_IMAGE_REPEATY); + handle = nvgCreateImage(APP->window->vg, filename.c_str(), NVG_IMAGE_REPEATX | NVG_IMAGE_REPEATY); if (handle > 0) { INFO("Loaded image %s", filename.c_str()); } @@ -60,7 +60,7 @@ Image::Image(const std::string &filename) { Image::~Image() { // TODO What if handle is invalid? - nvgDeleteImage(app()->window->vg, handle); + nvgDeleteImage(APP->window->vg, handle); } std::shared_ptr Image::load(const std::string &filename) { @@ -71,7 +71,7 @@ std::shared_ptr Image::load(const std::string &filename) { } SVG::SVG(const std::string &filename) { - handle = nsvgParseFromFile(filename.c_str(), "px", APP_SVG_DPI); + handle = nsvgParseFromFile(filename.c_str(), "px", app::SVG_DPI); if (handle) { INFO("Loaded SVG %s", filename.c_str()); } @@ -118,7 +118,7 @@ static void mouseButtonCallback(GLFWwindow *win, int button, int action, int mod } #endif - app()->event->handleButton(window->mousePos, button, action, mods); + APP->event->handleButton(window->mousePos, button, action, mods); } static void cursorPosCallback(GLFWwindow *win, double xpos, double ypos) { @@ -144,12 +144,12 @@ static void cursorPosCallback(GLFWwindow *win, double xpos, double ypos) { window->mousePos = mousePos; - app()->event->handleHover(mousePos, mouseDelta); + APP->event->handleHover(mousePos, mouseDelta); } static void cursorEnterCallback(GLFWwindow *win, int entered) { if (!entered) { - app()->event->handleLeave(); + APP->event->handleLeave(); } } @@ -158,17 +158,17 @@ static void scrollCallback(GLFWwindow *win, double x, double y) { math::Vec scrollDelta = math::Vec(x, y); scrollDelta = scrollDelta.mult(50.0); - app()->event->handleScroll(window->mousePos, scrollDelta); + APP->event->handleScroll(window->mousePos, scrollDelta); } static void charCallback(GLFWwindow *win, unsigned int codepoint) { Window *window = (Window*) glfwGetWindowUserPointer(win); - app()->event->handleText(window->mousePos, codepoint); + APP->event->handleText(window->mousePos, codepoint); } static void keyCallback(GLFWwindow *win, int key, int scancode, int action, int mods) { Window *window = (Window*) glfwGetWindowUserPointer(win); - app()->event->handleKey(window->mousePos, key, scancode, action, mods); + APP->event->handleKey(window->mousePos, key, scancode, action, mods); // Keyboard MIDI driver if ((mods & WINDOW_MOD_MASK) == 0) { @@ -187,7 +187,7 @@ static void dropCallback(GLFWwindow *win, int count, const char **paths) { for (int i = 0; i < count; i++) { pathsVec.push_back(paths[i]); } - app()->event->handleDrop(window->mousePos, pathsVec); + APP->event->handleDrop(window->mousePos, pathsVec); } static void errorCallback(int error, const char *description) { @@ -314,12 +314,12 @@ void Window::run() { // Set window title std::string windowTitle; - windowTitle = APP_NAME; + windowTitle = app::NAME; windowTitle += " "; - windowTitle += APP_VERSION; - if (!app()->patch->path.empty()) { + windowTitle += app::VERSION; + if (!APP->patch->path.empty()) { windowTitle += " - "; - windowTitle += string::filename(app()->patch->path); + windowTitle += string::filename(APP->patch->path); } if (windowTitle != internal->lastWindowTitle) { glfwSetWindowTitle(win, windowTitle.c_str()); @@ -333,7 +333,7 @@ void Window::run() { glfwGetWindowContentScale(win, &pixelRatio, NULL); pixelRatio = std::round(pixelRatio); if (pixelRatio != this->pixelRatio) { - app()->event->handleZoom(); + APP->event->handleZoom(); this->pixelRatio = pixelRatio; } @@ -345,10 +345,10 @@ void Window::run() { windowRatio = (float)fbWidth / winWidth; // Resize scene - app()->event->rootWidget->box.size = math::Vec(fbWidth, fbHeight).div(pixelRatio); + APP->event->rootWidget->box.size = math::Vec(fbWidth, fbHeight).div(pixelRatio); // Step scene - app()->event->rootWidget->step(); + APP->event->rootWidget->step(); // Render bool visible = glfwGetWindowAttrib(win, GLFW_VISIBLE) && !glfwGetWindowAttrib(win, GLFW_ICONIFIED); @@ -359,9 +359,9 @@ void Window::run() { // nvgReset(vg); // nvgScale(vg, pixelRatio, pixelRatio); - DrawContext ctx; + widget::DrawContext ctx; ctx.vg = vg; - app()->event->rootWidget->draw(ctx); + APP->event->rootWidget->draw(ctx); glViewport(0, 0, fbWidth, fbHeight); glClearColor(0.0, 0.0, 0.0, 1.0);