From d6eb97e6bfbf8582d75f47b6875503783fd2fac0 Mon Sep 17 00:00:00 2001 From: Jeremy Wentworth Date: Thu, 23 Nov 2017 12:51:01 -0500 Subject: [PATCH 01/19] fixed note off velocity --- src/core/MidiTriggerToCV.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/MidiTriggerToCV.cpp b/src/core/MidiTriggerToCV.cpp index 4bb60020..ec0f11db 100644 --- a/src/core/MidiTriggerToCV.cpp +++ b/src/core/MidiTriggerToCV.cpp @@ -110,7 +110,7 @@ void MIDITriggerToCVInterface::processMidi(std::vector msg) { if (status == 0x8) { // note off for (int i = 0; i < NUM_OUTPUTS; i++) { if (data1 == trigger[i].num) { - trigger[i].val = data2; + trigger[i].val = 0; } } return; From c336e67577451c521bfc03329b3cbe0606e079ff Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 25 Nov 2017 08:39:07 -0500 Subject: [PATCH 02/19] Delete MenuOverlay on mouse down --- include/widgets.hpp | 2 +- src/widgets/MenuOverlay.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/widgets.hpp b/include/widgets.hpp index b26245af..454c9c43 100644 --- a/include/widgets.hpp +++ b/include/widgets.hpp @@ -295,7 +295,7 @@ struct Label : Widget { /** Deletes itself from parent when clicked */ struct MenuOverlay : OpaqueWidget { void step() override; - void onDragDrop(EventDragDrop &e) override; + void onMouseDown(EventMouseDown &e) override; void onHoverKey(EventHoverKey &e) override; }; diff --git a/src/widgets/MenuOverlay.cpp b/src/widgets/MenuOverlay.cpp index efecef8c..85665b66 100644 --- a/src/widgets/MenuOverlay.cpp +++ b/src/widgets/MenuOverlay.cpp @@ -13,10 +13,12 @@ void MenuOverlay::step() { } } -void MenuOverlay::onDragDrop(EventDragDrop &e) { - if (e.origin == this) { +void MenuOverlay::onMouseDown(EventMouseDown &e) { + Widget::onMouseDown(e); + if (!e.consumed) { // deletes `this` gScene->setOverlay(NULL); + e.consumed = true; } } From 264c040c6a2f959a6d573238b2f4a3b623cdf624 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 25 Nov 2017 12:14:34 -0500 Subject: [PATCH 03/19] Round to nearest zoom percent --- src/app/Toolbar.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/Toolbar.cpp b/src/app/Toolbar.cpp index cde1221b..4414b2ee 100644 --- a/src/app/Toolbar.cpp +++ b/src/app/Toolbar.cpp @@ -151,12 +151,13 @@ Toolbar::Toolbar() { struct ZoomSlider : Slider { void onAction(EventAction &e) override { Slider::onAction(e); - gRackScene->zoomWidget->setZoom(value / 100.0); + gRackScene->zoomWidget->setZoom(roundf(value) / 100.0); } }; zoomSlider = new ZoomSlider(); zoomSlider->box.pos = Vec(xPos, margin); zoomSlider->box.size.x = 150; + zoomSlider->precision = 0; zoomSlider->label = "Zoom"; zoomSlider->unit = "%"; zoomSlider->setLimits(25.0, 200.0); From 79ac79f0480959cd7f84dcc3cae534a6c2a178e6 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 28 Nov 2017 04:48:21 -0500 Subject: [PATCH 04/19] Document RTAUDIO_ALL_APIS --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 40204931..6f9d0e72 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,8 @@ You may use make's `-j$(nproc)` flag to parallelize builds across all your CPU c make dep +You may use `make dep RTAUDIO_ALL_APIS=1` to attempt to build with all audio driver APIs enabled for your operating system. + You should see a message that all dependencies built successfully. Build Rack. From feff8b7571bd26481d75ffa94edb9b1c9d31423f Mon Sep 17 00:00:00 2001 From: Christoph Scholtes Date: Tue, 28 Nov 2017 19:14:37 -0700 Subject: [PATCH 05/19] Clean up libRack.a file. --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 4ebc2723..61b9bfd1 100644 --- a/Makefile +++ b/Makefile @@ -71,6 +71,7 @@ endif clean: + rm -fv libRack.a rm -rfv $(TARGET) build dist # For Windows resources From 892d4767bf9248977421e87a502428a4c063f7c2 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 29 Nov 2017 12:05:58 -0500 Subject: [PATCH 06/19] Add plugin "version" to module in .vcv file --- src/app/ModuleWidget.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 975cf835..8c04a89b 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -60,8 +60,11 @@ void ModuleWidget::setPanel(std::shared_ptr svg) { json_t *ModuleWidget::toJson() { json_t *rootJ = json_object(); - // manufacturer + // plugin json_object_set_new(rootJ, "plugin", json_string(model->plugin->slug.c_str())); + // version (of plugin) + if (!model->plugin->version.empty()) + json_object_set_new(rootJ, "version", json_string(model->plugin->version.c_str())); // model json_object_set_new(rootJ, "model", json_string(model->slug.c_str())); // pos From 4310e1c80ec84ab569114217cc2f874c7dd4e1c4 Mon Sep 17 00:00:00 2001 From: Christoph Scholtes Date: Wed, 29 Nov 2017 21:01:56 -0700 Subject: [PATCH 07/19] Ignore libRack.a file. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8e77f61a..d22540ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /Rack /Rack.exe +/libRack.a /autosave.json /settings.json /plugins From 17f3421769aaba11f250c1322edf8b6fcce341a1 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 2 Dec 2017 01:17:49 -0500 Subject: [PATCH 08/19] Don't load plugin if slug already exists --- src/plugin.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/plugin.cpp b/src/plugin.cpp index ca873ed0..d63b962f 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -144,6 +144,16 @@ static int loadPlugin(std::string path) { plugin->handle = handle; initCallback(plugin); + // Reject plugin if slug already exists + for (Plugin *p : gPlugins) { + if (plugin->slug == p->slug) { + warn("Plugin \"%s\" is already loaded, not attempting to load it again"); + // TODO + // Fix memory leak with `plugin` here + return -1; + } + } + // Add plugin to list gPlugins.push_back(plugin); info("Loaded plugin %s", libraryFilename.c_str()); From 88fb95d590a16dd7153671ac715a22d8ad5c40e5 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 2 Dec 2017 12:35:36 -0500 Subject: [PATCH 09/19] Add line cap and line join to SVGWidget renderer --- src/widgets/SVGWidget.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/widgets/SVGWidget.cpp b/src/widgets/SVGWidget.cpp index 52b503e5..10138fc2 100644 --- a/src/widgets/SVGWidget.cpp +++ b/src/widgets/SVGWidget.cpp @@ -59,16 +59,19 @@ static void drawSVG(NVGcontext *vg, NSVGimage *svg) { for (NSVGshape *shape = svg->shapes; shape; shape = shape->next, shapeIndex++) { DEBUG_ONLY(printf(" new shape: %d id \"%s\", fillrule %d, from (%f, %f) to (%f, %f)\n", shapeIndex, shape->id, shape->fillRule, shape->bounds[0], shape->bounds[1], shape->bounds[2], shape->bounds[3]);) + // Visibility if (!(shape->flags & NSVG_FLAGS_VISIBLE)) continue; nvgSave(vg); + // Opacity if (shape->opacity < 1.0) nvgGlobalAlpha(vg, shape->opacity); // Build path nvgBeginPath(vg); + // Iterate path linked list for (NSVGpath *path = shape->paths; path; path = path->next) { DEBUG_ONLY(printf(" new path: %d points, %s, from (%f, %f) to (%f, %f)\n", path->npts, path->closed ? "closed" : "open", path->bounds[0], path->bounds[1], path->bounds[2], path->bounds[3]);) @@ -81,6 +84,7 @@ static void drawSVG(NVGcontext *vg, NSVGimage *svg) { DEBUG_ONLY(printf(" bezier (%f, %f) to (%f, %f)\n", p[-2], p[-1], p[4], p[5]);) } + // Close path if (path->closed) nvgClosePath(vg); @@ -161,11 +165,12 @@ static void drawSVG(NVGcontext *vg, NSVGimage *svg) { } // Stroke shape - nvgStrokeWidth(vg, shape->strokeWidth); - // strokeDashOffset, strokeDashArray, strokeDashCount not yet supported - // strokeLineJoin, strokeLineCap not yet supported - if (shape->stroke.type) { + nvgStrokeWidth(vg, shape->strokeWidth); + // strokeDashOffset, strokeDashArray, strokeDashCount not yet supported + nvgLineCap(vg, (NVGlineCap) shape->strokeLineCap); + nvgLineJoin(vg, (int) shape->strokeLineJoin); + switch (shape->stroke.type) { case NSVG_PAINT_COLOR: { NVGcolor color = getNVGColor(shape->stroke.color); From d1ed8faa21c0dd610e6b3b16f91ed582afa36067 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sun, 3 Dec 2017 15:38:56 -0500 Subject: [PATCH 10/19] Smooth interpolate SVGSlider --- src/app/SVGSlider.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/SVGSlider.cpp b/src/app/SVGSlider.cpp index 5d0beb60..b65bcd30 100644 --- a/src/app/SVGSlider.cpp +++ b/src/app/SVGSlider.cpp @@ -23,7 +23,7 @@ void SVGSlider::step() { void SVGSlider::onChange(EventChange &e) { dirty = true; - ParamWidget::onChange(e); + Knob::onChange(e); } From c6cd497e1724e434877d9a52d8c3e20749cba84f Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 4 Dec 2017 12:49:14 -0500 Subject: [PATCH 11/19] Add SlewLimiter::setRiseFall() --- include/dsp/filter.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/dsp/filter.hpp b/include/dsp/filter.hpp index 35098ecf..a29785bd 100644 --- a/include/dsp/filter.hpp +++ b/include/dsp/filter.hpp @@ -51,6 +51,11 @@ struct SlewLimiter { float rise = 1.0; float fall = 1.0; float out = 0.0; + + void setRiseFall(float _rise, float _fall) { + rise = _rise; + fall = _fall; + } float process(float in) { float delta = clampf(in - out, -fall, rise); out += delta; From 30807e5ed715144faee69b05df7b2a8f755e093d Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 5 Dec 2017 10:43:07 -0500 Subject: [PATCH 12/19] Remove portaudio from license, add RtAudio --- LICENSE-dist.txt | 31 ++++++++++++++++++++++++------- Makefile | 7 +++++-- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/LICENSE-dist.txt b/LICENSE-dist.txt index 62b28280..7260a68e 100644 --- a/LICENSE-dist.txt +++ b/LICENSE-dist.txt @@ -180,17 +180,34 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# portaudio +# RtAudio -PortAudio Portable Real-Time Audio Library -Copyright (c) 1999-2011 Ross Bencina and Phil Burk +RtAudio: a set of realtime audio i/o C++ classes +Copyright (c) 2001-2017 Gary P. Scavone -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation files +(the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of the Software, +and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +Any person wishing to distribute modifications to the Software is +asked to send the modifications to the original developer so that +they can be incorporated into the canonical version. This is, +however, not a binding provision of this license. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # RtMidi diff --git a/Makefile b/Makefile index 61b9bfd1..790615bb 100644 --- a/Makefile +++ b/Makefile @@ -69,6 +69,11 @@ ifeq ($(ARCH), win) env PATH=dep/bin:/mingw64/bin gdb -ex run ./Rack endif +perf: $(TARGET) +ifeq ($(ARCH), lin) + LD_LIBRARY_PATH=dep/lib perf record --call-graph dwarf ./Rack +endif + clean: rm -fv libRack.a @@ -107,7 +112,6 @@ ifeq ($(ARCH), mac) cp dep/lib/libsamplerate.0.dylib $(BUNDLE)/Contents/MacOS/ cp dep/lib/libcurl.4.dylib $(BUNDLE)/Contents/MacOS/ cp dep/lib/libzip.5.dylib $(BUNDLE)/Contents/MacOS/ - cp dep/lib/libportaudio.2.dylib $(BUNDLE)/Contents/MacOS/ cp dep/lib/librtmidi.4.dylib $(BUNDLE)/Contents/MacOS/ cp dep/lib/librtaudio.6.dylib $(BUNDLE)/Contents/MacOS/ @@ -117,7 +121,6 @@ ifeq ($(ARCH), mac) install_name_tool -change $(PWD)/dep/lib/libsamplerate.0.dylib @executable_path/libsamplerate.0.dylib $(BUNDLE)/Contents/MacOS/Rack install_name_tool -change $(PWD)/dep/lib/libcurl.4.dylib @executable_path/libcurl.4.dylib $(BUNDLE)/Contents/MacOS/Rack install_name_tool -change $(PWD)/dep/lib/libzip.5.dylib @executable_path/libzip.5.dylib $(BUNDLE)/Contents/MacOS/Rack - install_name_tool -change $(PWD)/dep/lib/libportaudio.2.dylib @executable_path/libportaudio.2.dylib $(BUNDLE)/Contents/MacOS/Rack install_name_tool -change $(PWD)/dep/lib/librtmidi.4.dylib @executable_path/librtmidi.4.dylib $(BUNDLE)/Contents/MacOS/Rack install_name_tool -change $(PWD)/dep/lib/librtaudio.6.dylib @executable_path/librtaudio.6.dylib $(BUNDLE)/Contents/MacOS/Rack From 62fd356b973d44c1df7a39e93a6c87f6895a06b1 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 5 Dec 2017 22:11:15 -0500 Subject: [PATCH 13/19] Switch to glfw master, use glfwGetWindowContentScale() to get DPI of window --- dep/Makefile | 11 +++++------ src/gui.cpp | 8 +++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/dep/Makefile b/dep/Makefile index 6f43c97b..9038f68e 100755 --- a/dep/Makefile +++ b/dep/Makefile @@ -86,13 +86,12 @@ $(glew): $(MAKE) -C glew-2.1.0 GLEW_DEST="$(LOCAL)" LIBDIR="$(LOCAL)/lib" install $(glfw): - $(WGET) https://github.com/glfw/glfw/releases/download/3.2.1/glfw-3.2.1.zip - $(UNZIP) glfw-3.2.1.zip - cd glfw-3.2.1 && $(CMAKE) . \ + git clone https://github.com/glfw/glfw.git + cd glfw && $(CMAKE) . \ -DCMAKE_INSTALL_PREFIX="$(LOCAL)" -DBUILD_SHARED_LIBS=ON \ - -DGLFW_USE_CHDIR=OFF -DGLFW_USE_MENUBAR=ON -DGLFW_USE_RETINA=ON - $(MAKE) -C glfw-3.2.1 - $(MAKE) -C glfw-3.2.1 install + -DGLFW_COCOA_CHDIR_RESOURCES=OFF -DGLFW_COCOA_MENUBAR=ON -DGLFW_COCOA_RETINA_FRAMEBUFFER=ON + $(MAKE) -C glfw + $(MAKE) -C glfw install ifeq ($(ARCH),win) # Not sure why the GLFW build system puts a .dll in the lib directory mv "$(LOCAL)/lib/glfw3.dll" "$(LOCAL)/bin/" diff --git a/src/gui.cpp b/src/gui.cpp index af9632fd..bfb1165b 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -418,11 +418,9 @@ void guiRun() { } // Get framebuffer size - int width, height; - glfwGetFramebufferSize(gWindow, &width, &height); - int windowWidth, windowHeight; - glfwGetWindowSize(gWindow, &windowWidth, &windowHeight); - float pixelRatio = (float)width / windowWidth; + float pixelRatio; + glfwGetWindowContentScale(gWindow, &pixelRatio, NULL); + pixelRatio = roundf(pixelRatio); if (pixelRatio != gPixelRatio) { EventZoom eZoom; gScene->onZoom(eZoom); From 572af6e2c0151ab2b1a1231d81bdf19fae631683 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 5 Dec 2017 22:23:19 -0500 Subject: [PATCH 14/19] Fix Mac rtaudio path in `make dist` --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 4ebc2723..c504f990 100644 --- a/Makefile +++ b/Makefile @@ -108,7 +108,7 @@ ifeq ($(ARCH), mac) cp dep/lib/libzip.5.dylib $(BUNDLE)/Contents/MacOS/ cp dep/lib/libportaudio.2.dylib $(BUNDLE)/Contents/MacOS/ cp dep/lib/librtmidi.4.dylib $(BUNDLE)/Contents/MacOS/ - cp dep/lib/librtaudio.6.dylib $(BUNDLE)/Contents/MacOS/ + cp dep/lib/librtaudio.dylib $(BUNDLE)/Contents/MacOS/ install_name_tool -change /usr/local/lib/libGLEW.2.1.0.dylib @executable_path/libGLEW.2.1.0.dylib $(BUNDLE)/Contents/MacOS/Rack install_name_tool -change lib/libglfw.3.dylib @executable_path/libglfw.3.dylib $(BUNDLE)/Contents/MacOS/Rack @@ -118,7 +118,7 @@ ifeq ($(ARCH), mac) install_name_tool -change $(PWD)/dep/lib/libzip.5.dylib @executable_path/libzip.5.dylib $(BUNDLE)/Contents/MacOS/Rack install_name_tool -change $(PWD)/dep/lib/libportaudio.2.dylib @executable_path/libportaudio.2.dylib $(BUNDLE)/Contents/MacOS/Rack install_name_tool -change $(PWD)/dep/lib/librtmidi.4.dylib @executable_path/librtmidi.4.dylib $(BUNDLE)/Contents/MacOS/Rack - install_name_tool -change $(PWD)/dep/lib/librtaudio.6.dylib @executable_path/librtaudio.6.dylib $(BUNDLE)/Contents/MacOS/Rack + install_name_tool -change librtaudio.dylib @executable_path/librtaudio.dylib $(BUNDLE)/Contents/MacOS/Rack otool -L $(BUNDLE)/Contents/MacOS/Rack From ee2be22c80d9b400cd69017ca293c3847a9c3413 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 5 Dec 2017 22:23:38 -0500 Subject: [PATCH 15/19] Toggle GL2, GL3, and GLES2 with macros --- src/gui.cpp | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/gui.cpp b/src/gui.cpp index af9632fd..4aec9b93 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -8,11 +8,13 @@ #include "../ext/osdialog/osdialog.h" -#define NANOVG_GL2_IMPLEMENTATION -// #define NANOVG_GL3_IMPLEMENTATION +#define NANOVG_GL2 1 +// #define NANOVG_GL3 1 +// #define NANOVG_GLES2 1 +#define NANOVG_GL_IMPLEMENTATION 1 #include "../ext/nanovg/src/nanovg_gl.h" // Hack to get framebuffer objects working on OpenGL 2 (we blindly assume the extension is supported) -#define NANOVG_FBO_VALID 1 +// #define NANOVG_FBO_VALID 1 #include "../ext/nanovg/src/nanovg_gl_utils.h" #define BLENDISH_IMPLEMENTATION #include "../ext/oui-blendish/blendish.h" @@ -353,11 +355,22 @@ void guiInit() { glfwSetWindowSizeLimits(gWindow, 640, 480, GLFW_DONT_CARE, GLFW_DONT_CARE); // Set up NanoVG +#if defined NANOVG_GL2 gVg = nvgCreateGL2(NVG_ANTIALIAS); - // gVg = nvgCreateGL3(NVG_ANTIALIAS); +#elif defined NANOVG_GL3 + gVg = nvgCreateGL3(NVG_ANTIALIAS); +#elif defined NANOVG_GLES2 + gVg = nvgCreateGLES2(NVG_ANTIALIAS); +#endif assert(gVg); +#if defined NANOVG_GL2 gFramebufferVg = nvgCreateGL2(NVG_ANTIALIAS); +#elif defined NANOVG_GL3 + gFramebufferVg = nvgCreateGL3(NVG_ANTIALIAS); +#elif defined NANOVG_GLES2 + gFramebufferVg = nvgCreateGLES2(NVG_ANTIALIAS); +#endif assert(gFramebufferVg); // Set up Blendish @@ -375,9 +388,23 @@ void guiInit() { void guiDestroy() { gGuiFont.reset(); + +#if defined NANOVG_GL2 nvgDeleteGL2(gVg); - // nvgDeleteGL3(gVg); +#elif defined NANOVG_GL3 + nvgDeleteGL3(gVg); +#elif defined NANOVG_GLES2 + nvgDeleteGLES2(gVg); +#endif + +#if defined NANOVG_GL2 nvgDeleteGL2(gFramebufferVg); +#elif defined NANOVG_GL3 + nvgDeleteGL3(gFramebufferVg); +#elif defined NANOVG_GLES2 + nvgDeleteGLES2(gFramebufferVg); +#endif + glfwDestroyWindow(gWindow); glfwTerminate(); } From 3ecf22533994573d718d3388c0059dbd8e80250b Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 5 Dec 2017 22:33:13 -0500 Subject: [PATCH 16/19] Remove patch for glfw dll --- dep/Makefile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dep/Makefile b/dep/Makefile index 9038f68e..9582e69d 100755 --- a/dep/Makefile +++ b/dep/Makefile @@ -92,10 +92,6 @@ $(glfw): -DGLFW_COCOA_CHDIR_RESOURCES=OFF -DGLFW_COCOA_MENUBAR=ON -DGLFW_COCOA_RETINA_FRAMEBUFFER=ON $(MAKE) -C glfw $(MAKE) -C glfw install -ifeq ($(ARCH),win) - # Not sure why the GLFW build system puts a .dll in the lib directory - mv "$(LOCAL)/lib/glfw3.dll" "$(LOCAL)/bin/" -endif $(jansson): $(WGET) http://www.digip.org/jansson/releases/jansson-2.10.tar.gz From 7f1035730ae71163859256a2dad51327d708581c Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 5 Dec 2017 23:04:54 -0500 Subject: [PATCH 17/19] Add gWindowRatio and set window size on each step --- include/gui.hpp | 6 ++++++ src/gui.cpp | 22 +++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/include/gui.hpp b/include/gui.hpp index 9df01144..fd6c0e77 100644 --- a/include/gui.hpp +++ b/include/gui.hpp @@ -17,8 +17,14 @@ namespace rack { extern GLFWwindow *gWindow; extern NVGcontext *gVg; extern NVGcontext *gFramebufferVg; +/** The default font to use for GUI elements */ extern std::shared_ptr gGuiFont; +/** The scaling ratio */ extern float gPixelRatio; +/* The ratio between the framebuffer size and the window size reported by the OS. +This is not equal to gPixelRatio in general. +*/ +extern float gWindowRatio; extern bool gAllowCursorLock; extern int gGuiFrame; extern Vec gMousePos; diff --git a/src/gui.cpp b/src/gui.cpp index b74a6988..fdb58ad3 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -33,7 +33,8 @@ GLFWwindow *gWindow = NULL; NVGcontext *gVg = NULL; NVGcontext *gFramebufferVg = NULL; std::shared_ptr gGuiFont; -float gPixelRatio = 0.0; +float gPixelRatio = 1.0; +float gWindowRatio = 1.0; bool gAllowCursorLock = true; int gGuiFrame; Vec gMousePos; @@ -42,7 +43,6 @@ std::string lastWindowTitle; void windowSizeCallback(GLFWwindow* window, int width, int height) { - gScene->box.size = Vec(width, height); } void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods) { @@ -145,7 +145,7 @@ void mouseButtonStickyCallback(GLFWwindow *window, int button, int action, int m } void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) { - Vec mousePos = Vec(xpos, ypos).round(); + Vec mousePos = Vec(xpos, ypos).div(gPixelRatio / gWindowRatio).round(); Vec mouseRel = mousePos.minus(gMousePos); #ifdef ARCH_MAC @@ -411,11 +411,6 @@ void guiDestroy() { void guiRun() { assert(gWindow); - { - int width, height; - glfwGetWindowSize(gWindow, &width, &height); - windowSizeCallback(gWindow, width, height); - } gGuiFrame = 0; while(!glfwWindowShouldClose(gWindow)) { double startTime = glfwGetTime(); @@ -444,7 +439,7 @@ void guiRun() { lastWindowTitle = windowTitle; } - // Get framebuffer size + // Get desired scaling float pixelRatio; glfwGetWindowContentScale(gWindow, &pixelRatio, NULL); pixelRatio = roundf(pixelRatio); @@ -454,6 +449,15 @@ void guiRun() { gPixelRatio = pixelRatio; } + // Get framebuffer/window ratio + int width, height; + glfwGetFramebufferSize(gWindow, &width, &height); + int windowWidth, windowHeight; + glfwGetWindowSize(gWindow, &windowWidth, &windowHeight); + gWindowRatio = (float)width / windowWidth; + + gScene->box.size = Vec(width, height).div(gPixelRatio / gWindowRatio); + // Step scene gScene->step(); From 2019178cba5869db5e7bb857e641f6d7ab56898c Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 5 Dec 2017 23:14:58 -0500 Subject: [PATCH 18/19] Reenable NANOVG_FBO_VALID --- src/gui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui.cpp b/src/gui.cpp index fdb58ad3..31b961d5 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -14,7 +14,7 @@ #define NANOVG_GL_IMPLEMENTATION 1 #include "../ext/nanovg/src/nanovg_gl.h" // Hack to get framebuffer objects working on OpenGL 2 (we blindly assume the extension is supported) -// #define NANOVG_FBO_VALID 1 +#define NANOVG_FBO_VALID 1 #include "../ext/nanovg/src/nanovg_gl_utils.h" #define BLENDISH_IMPLEMENTATION #include "../ext/oui-blendish/blendish.h" From f7ea40f677a73671463728ef47d5410888b72b7f Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 5 Dec 2017 23:43:29 -0500 Subject: [PATCH 19/19] Add glfw and rtaudio git submodules --- .gitmodules | 6 ++++++ dep/Makefile | 2 -- dep/glfw | 1 + dep/rtaudio | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) create mode 160000 dep/glfw create mode 160000 dep/rtaudio diff --git a/.gitmodules b/.gitmodules index 0d52f7cb..1dc85fb4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,9 @@ [submodule "ext/oui-blendish"] path = ext/oui-blendish url = https://github.com/AndrewBelt/oui-blendish.git +[submodule "dep/glfw"] + path = dep/glfw + url = https://github.com/glfw/glfw.git +[submodule "dep/rtaudio"] + path = dep/rtaudio + url = https://github.com/thestk/rtaudio.git diff --git a/dep/Makefile b/dep/Makefile index 9582e69d..9218d608 100755 --- a/dep/Makefile +++ b/dep/Makefile @@ -86,7 +86,6 @@ $(glew): $(MAKE) -C glew-2.1.0 GLEW_DEST="$(LOCAL)" LIBDIR="$(LOCAL)/lib" install $(glfw): - git clone https://github.com/glfw/glfw.git cd glfw && $(CMAKE) . \ -DCMAKE_INSTALL_PREFIX="$(LOCAL)" -DBUILD_SHARED_LIBS=ON \ -DGLFW_COCOA_CHDIR_RESOURCES=OFF -DGLFW_COCOA_MENUBAR=ON -DGLFW_COCOA_RETINA_FRAMEBUFFER=ON @@ -131,7 +130,6 @@ $(rtmidi): $(MAKE) -C rtmidi-3.0.0 install $(rtaudio): - git clone https://github.com/thestk/rtaudio.git cd rtaudio && mkdir -p cmakebuild cd rtaudio/cmakebuild && cmake -G 'Unix Makefiles' -DCMAKE_INSTALL_PREFIX="$(LOCAL)" $(RTAUDIO_FLAGS) .. $(MAKE) -C rtaudio/cmakebuild diff --git a/dep/glfw b/dep/glfw new file mode 160000 index 00000000..30489c5a --- /dev/null +++ b/dep/glfw @@ -0,0 +1 @@ +Subproject commit 30489c5aa1392f698e904c6aced1d7a486634c40 diff --git a/dep/rtaudio b/dep/rtaudio new file mode 160000 index 00000000..ce13dfbf --- /dev/null +++ b/dep/rtaudio @@ -0,0 +1 @@ +Subproject commit ce13dfbf30fd1ab4e7f7eff8886a80f144c75e5d