From 6049c0abe5ecb7d47b99dfc7cbd6cd6d4d4a1346 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 24 Feb 2018 09:33:08 -0500 Subject: [PATCH] Added util/color.hpp, fixed LightWidget color algorithm, added Ctrl+U key command for "Disconnect cables", refactor audio.cpp/midi.cpp, add new Audio Interface panel --- include/app.hpp | 7 +- include/audio.hpp | 8 +- include/componentlibrary.hpp | 19 +- include/util/color.hpp | 36 +++ res/Core/AudioInterface.svg | 552 +++++++++++++++++++--------------- src/app/AudioWidget.cpp | 16 +- src/app/LedDisplay.cpp | 4 + src/app/LightWidget.cpp | 25 +- src/app/MidiWidget.cpp | 16 +- src/app/ModuleLightWidget.cpp | 2 +- src/app/ModuleWidget.cpp | 20 +- src/app/MultiLightWidget.cpp | 11 +- src/audio.cpp | 26 +- src/core/AudioInterface.cpp | 111 +++---- 14 files changed, 482 insertions(+), 371 deletions(-) create mode 100644 include/util/color.hpp diff --git a/include/app.hpp b/include/app.hpp index f42b67f4..273a14e3 100644 --- a/include/app.hpp +++ b/include/app.hpp @@ -388,8 +388,8 @@ struct MidiWidget : LedDisplay { //////////////////// struct LightWidget : TransparentWidget { - NVGcolor bgColor = nvgRGBf(0, 0, 0); - NVGcolor color = nvgRGBf(1, 1, 1); + NVGcolor borderColor = nvgRGBA(0, 0, 0, 0); + NVGcolor color = nvgRGBA(0, 0, 0, 0); void draw(NVGcontext *vg) override; virtual void drawLight(NVGcontext *vg); virtual void drawHalo(NVGcontext *vg); @@ -397,6 +397,9 @@ struct LightWidget : TransparentWidget { /** Mixes a list of colors based on a list of brightness values */ struct MultiLightWidget : LightWidget { + /** Color of the "off" state */ + NVGcolor bgColor = nvgRGBA(0, 0, 0, 0); + /** Colors of each value state */ std::vector baseColors; void addBaseColor(NVGcolor baseColor); /** Sets the color to a linear combination of the baseColors with the given weights */ diff --git a/include/audio.hpp b/include/audio.hpp index 5af6d6a7..7dcde1db 100644 --- a/include/audio.hpp +++ b/include/audio.hpp @@ -16,6 +16,7 @@ struct AudioIO { int driver = 0; int device = -1; int offset = 0; + int maxChannels = 8; int sampleRate = 44100; int blockSize = 256; int numOutputs = 0; @@ -33,10 +34,11 @@ struct AudioIO { int getDeviceCount(); bool getDeviceInfo(int device, RtAudio::DeviceInfo *deviceInfo); - int getDeviceMaxChannels(int device); + /** Returns the number of inputs or outputs, whichever is greater */ + int getDeviceChannels(int device); std::string getDeviceName(int device); - std::string getDeviceDetail(int device, int offset, int maxChannels); - void setDevice(int device, int offset, int maxChannels); + std::string getDeviceDetail(int device, int offset); + void setDevice(int device, int offset); void setSampleRate(int sampleRate); void setBlockSize(int blockSize); diff --git a/include/componentlibrary.hpp b/include/componentlibrary.hpp index 7f6a8fca..70e5807b 100644 --- a/include/componentlibrary.hpp +++ b/include/componentlibrary.hpp @@ -370,39 +370,46 @@ struct CL1362Port : SVGPort { // Lights //////////////////// -struct RedLight : ModuleLightWidget { +struct GrayModuleLightWidget : ModuleLightWidget { + GrayModuleLightWidget() { + bgColor = nvgRGB(0x5a, 0x5a, 0x5a); + borderColor = nvgRGBA(0, 0, 0, 0x60); + } +}; + +struct RedLight : GrayModuleLightWidget { RedLight() { addBaseColor(COLOR_RED); } }; -struct GreenLight : ModuleLightWidget { +struct GreenLight : GrayModuleLightWidget { GreenLight() { addBaseColor(COLOR_GREEN); } }; -struct YellowLight : ModuleLightWidget { +struct YellowLight : GrayModuleLightWidget { YellowLight() { addBaseColor(COLOR_YELLOW); } }; -struct BlueLight : ModuleLightWidget { +struct BlueLight : GrayModuleLightWidget { BlueLight() { addBaseColor(COLOR_BLUE); } }; /** Reads two adjacent lightIds, so `lightId` and `lightId + 1` must be defined */ -struct GreenRedLight : ModuleLightWidget { +struct GreenRedLight : GrayModuleLightWidget { GreenRedLight() { addBaseColor(COLOR_GREEN); addBaseColor(COLOR_RED); } }; -struct RedGreenBlueLight : ModuleLightWidget { +struct RedGreenBlueLight : GrayModuleLightWidget { RedGreenBlueLight() { addBaseColor(COLOR_RED); addBaseColor(COLOR_GREEN); diff --git a/include/util/color.hpp b/include/util/color.hpp new file mode 100644 index 00000000..485c53a7 --- /dev/null +++ b/include/util/color.hpp @@ -0,0 +1,36 @@ +#pragma once + + +#include "util/math.hpp" +#include "../ext/nanovg/src/nanovg.h" + + +namespace rack { + + +inline NVGcolor colorClip(NVGcolor a) { + for (int i = 0; i < 4; i++) + a.rgba[i] = clamp(a.rgba[i], 0.f, 1.f); + return a; +} + +inline NVGcolor colorMinus(NVGcolor a, NVGcolor b) { + for (int i = 0; i < 4; i++) + a.rgba[i] -= b.rgba[i]; + return a; +} + +inline NVGcolor colorPlus(NVGcolor a, NVGcolor b) { + for (int i = 0; i < 4; i++) + a.rgba[i] += b.rgba[i]; + return a; +} + +inline NVGcolor colorMult(NVGcolor a, float x) { + for (int i = 0; i < 4; i++) + a.rgba[i] *= x; + return a; +} + + +} // namespace rack diff --git a/res/Core/AudioInterface.svg b/res/Core/AudioInterface.svg index 175ba6ac..94b59f8c 100644 --- a/res/Core/AudioInterface.svg +++ b/res/Core/AudioInterface.svg @@ -13,11 +13,11 @@ height="128.4993mm" viewBox="0 0 50.799999 128.4993" version="1.1" - id="svg28799" + id="svg48736" inkscape:version="0.92.2 5c3e80d, 2017-08-06" - sodipodi:docname="Audio.svg"> + sodipodi:docname="AudioInterface.svg"> + id="defs48730" /> + inkscape:snap-page="true" /> + id="metadata48733"> @@ -58,406 +59,463 @@ inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" - transform="translate(88.9,-244.84559)" + transform="translate(-339.725,84.74965)" style="display:inline"> + + + + + id="path44516" + d="m 367.69091,39.60727 c -0.11714,0 -0.22325,-0.0661 -0.27561,-0.17088 l -1.00321,-2.00504 c -0.0758,-0.15297 -0.0138,-0.33762 0.13918,-0.41341 0.15158,-0.0772 0.33762,-0.0152 0.41341,0.1378 l 0.72623,1.45246 0.72622,-1.45246 c 0.0758,-0.15296 0.26183,-0.21497 0.41341,-0.1378 0.15297,0.0758 0.21498,0.26044 0.13781,0.41341 l -1.00184,2.00504 c -0.0524,0.10474 -0.15847,0.17088 -0.2756,0.17088" + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.35277775" /> + id="path44518" + d="m 365.08779,39.60727 c -0.72347,0 -1.31051,-0.58842 -1.31051,-1.31189 0,-0.72209 0.58704,-1.31052 1.31051,-1.31052 0.28663,0 0.55811,0.091 0.78686,0.26183 0.13505,0.10335 0.16261,0.29628 0.0606,0.43271 -0.10197,0.13642 -0.2949,0.16398 -0.43132,0.0606 -0.12127,-0.0896 -0.26459,-0.13918 -0.41617,-0.13918 -0.3831,0 -0.69453,0.31282 -0.69453,0.69453 0,0.38309 0.31143,0.69453 0.69453,0.69453 0.15158,0 0.2949,-0.0482 0.41617,-0.13918 0.13642,-0.10198 0.32935,-0.0744 0.43132,0.062 0.10198,0.13643 0.0744,0.32935 -0.0606,0.43132 -0.22875,0.17226 -0.50023,0.26321 -0.78686,0.26321" + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.35277775" /> + id="path44520" + d="m 365.50809,38.28022 c 0,0.22186 -0.17914,0.40101 -0.40101,0.40101 -0.22048,0 -0.39963,-0.17915 -0.39963,-0.40101 0,-0.22186 0.17915,-0.40101 0.39963,-0.40101 0.22187,0 0.40101,0.17915 0.40101,0.40101" + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.35277775" /> + d="m 357.73078,-75.466247 c 0,0.170879 0.12678,0.308681 0.29766,0.308681 0.1378,0 0.24805,-0.07717 0.30317,-0.203948 l 0.20395,-0.490583 h 1.30638 l 0.19843,0.468535 c 0.0606,0.132291 0.15986,0.225996 0.3142,0.225996 0.17087,0 0.30868,-0.143316 0.30868,-0.314191 0,-0.0441 -0.011,-0.08819 -0.0331,-0.132292 l -1.03629,-2.331642 c -0.0717,-0.159851 -0.19844,-0.259069 -0.37483,-0.259069 h -0.0386 c -0.17639,0 -0.30868,0.09922 -0.38033,0.259069 l -1.03078,2.331642 c -0.0221,0.0441 -0.0386,0.0937 -0.0386,0.137802 z m 1.04731,-0.959114 0.41341,-0.975649 0.4079,0.975649 z m 0,0" + id="path48232" /> + d="m 362.31948,-75.141028 c 0.79375,0 1.30087,-0.435462 1.30087,-1.333941 v -1.372528 c 0,-0.181899 -0.14882,-0.325215 -0.33073,-0.325215 -0.1819,0 -0.32521,0.143316 -0.32521,0.325215 v 1.394577 c 0,0.474045 -0.24254,0.711066 -0.63941,0.711066 -0.39688,0 -0.63941,-0.248045 -0.63941,-0.727604 v -1.378039 c 0,-0.181899 -0.14332,-0.325215 -0.32522,-0.325215 -0.1819,0 -0.32522,0.143316 -0.32522,0.325215 v 1.394577 c 0,0.87092 0.48507,1.311892 1.28433,1.311892 z m 0,0" + id="path48228" /> + style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.35277775" + d="m 364.34866,-75.510344 c 0,0.181903 0.14332,0.325219 0.32522,0.325219 h 0.82682 c 0.93156,0 1.57648,-0.650434 1.57648,-1.482771 v -0.0055 c 0,-0.837847 -0.64492,-1.477257 -1.57648,-1.477257 h -0.82682 c -0.1819,0 -0.32522,0.148827 -0.32522,0.330729 z m 0.65044,-0.264583 v -1.785937 h 0.5016 c 0.53468,0 0.89297,0.369316 0.89297,0.892968 v 0.01101 c 0,0.523657 -0.35829,0.881945 -0.89297,0.881945 z m 0,0" + id="path48216" /> + style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.35277775" + d="m 367.69515,-75.488295 c 0,0.181903 0.14332,0.330729 0.32522,0.330729 0.1819,0 0.32522,-0.148826 0.32522,-0.330729 v -2.359202 c 0,-0.181899 -0.14332,-0.325215 -0.32522,-0.325215 -0.1819,0 -0.32522,0.143316 -0.32522,0.325215 z m 0,0" + id="path48220" /> + style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.35277775" + d="m 370.53713,-75.135517 c 0.91502,0 1.57648,-0.689018 1.57648,-1.532379 v -0.0055 c 0,-0.843361 -0.65595,-1.526868 -1.57097,-1.526868 -0.91501,0 -1.57647,0.689021 -1.57647,1.532379 v 0.01101 c 0,0.843361 0.65594,1.521354 1.57096,1.521354 z m 0.005,-0.600823 c -0.52365,0 -0.89848,-0.424438 -0.89848,-0.931556 v -0.0055 c 0,-0.507118 0.3638,-0.926041 0.89297,-0.926041 0.52365,0 0.89297,0.424434 0.89297,0.931552 v 0.01101 c 0,0.507118 -0.3638,0.920531 -0.88746,0.920531 z m 0,0" + id="path48224" /> + d="m 347.52677,21.78311 c 0.35278,0 0.60082,-0.21497 0.60082,-0.55672 v -0.006 c 0,-0.35829 -0.24804,-0.51262 -0.56224,-0.51262 -0.0937,0 -0.14882,0.011 -0.21497,0.0276 l 0.0221,-0.27561 h 0.54019 c 0.0827,0 0.15434,-0.0717 0.15434,-0.15434 0,-0.0827 -0.0717,-0.15434 -0.15434,-0.15434 h -0.70005 c -0.0827,0 -0.14882,0.0662 -0.15434,0.14883 l -0.0331,0.5457 c -0.005,0.0606 0.0165,0.10473 0.0661,0.14331 0.0717,0.0496 0.11025,0.0717 0.15986,0.0717 0.0496,0 0.11024,-0.0441 0.24253,-0.0441 0.17088,0 0.28663,0.0827 0.28663,0.22048 0,0.14332 -0.11024,0.226 -0.25907,0.226 -0.11575,0 -0.20946,-0.0331 -0.30868,-0.10473 -0.0275,-0.022 -0.0551,-0.033 -0.0937,-0.033 -0.0937,0 -0.16537,0.0772 -0.16537,0.17087 0,0.0606 0.0275,0.10473 0.0661,0.13781 0.13229,0.0882 0.28663,0.14882 0.50712,0.14882 z m 0,0" + id="path48212" /> + d="m 359.15679,21.78311 c 0.34727,0 0.61185,-0.22599 0.61185,-0.55672 v -0.006 c 0,-0.33073 -0.24253,-0.50712 -0.56224,-0.50712 -0.15985,0 -0.25355,0.0496 -0.33624,0.0992 0.0276,-0.20946 0.12678,-0.36931 0.32522,-0.36931 0.0992,0 0.16536,0.022 0.23702,0.0661 0.0276,0.011 0.0551,0.022 0.0882,0.022 0.0882,0 0.16537,-0.0717 0.16537,-0.15986 0,-0.0717 -0.0386,-0.12126 -0.0937,-0.15434 -0.0937,-0.0551 -0.226,-0.0937 -0.38586,-0.0937 -0.47955,0 -0.70555,0.38034 -0.70555,0.87643 v 0.005 c 0,0.31419 0.0772,0.49058 0.19292,0.60634 0.11025,0.11024 0.25356,0.17087 0.46302,0.17087 z m -0.011,-0.30317 c -0.17639,0 -0.28112,-0.10473 -0.28112,-0.23702 v -0.005 c 0,-0.13781 0.0992,-0.23151 0.27561,-0.23151 0.17088,0 0.27561,0.0992 0.27561,0.23151 v 0.005 c 0,0.13781 -0.0992,0.23702 -0.2701,0.23702 z m 0,0" + id="path48208" /> + d="m 370.30942,21.61224 c 0,0.0992 0.0882,0.15434 0.1819,0.15434 0.0717,0 0.12127,-0.0331 0.17087,-0.11576 l 0.64493,-1.16858 c 0.0276,-0.0551 0.0496,-0.12126 0.0496,-0.17087 0,-0.10473 -0.0606,-0.15986 -0.15985,-0.15986 h -0.87092 c -0.0882,0 -0.15434,0.0661 -0.15434,0.15435 0,0.0827 0.0661,0.14882 0.15434,0.14882 h 0.61185 l -0.59532,1.04731 c -0.0165,0.0331 -0.0331,0.0772 -0.0331,0.11025 z m 0,0" + id="path48204" /> - - - - + d="m 382.3372,21.7776 c 0.35829,0 0.61736,-0.17088 0.61736,-0.47404 0,-0.19293 -0.0937,-0.29766 -0.25907,-0.38034 0.12678,-0.0772 0.20395,-0.17639 0.20395,-0.35278 0,-0.24805 -0.22049,-0.44097 -0.56224,-0.44097 -0.34175,0 -0.56224,0.19292 -0.56224,0.44097 0,0.17639 0.0772,0.27561 0.20395,0.35278 -0.17088,0.0772 -0.25907,0.19292 -0.25907,0.38585 v 0.006 c 0,0.28112 0.26458,0.46302 0.61736,0.46302 z m 0,-0.97014 c -0.1378,0 -0.23151,-0.0882 -0.23151,-0.19843 v -0.006 c 0,-0.0992 0.0882,-0.18741 0.23151,-0.18741 0.14332,0 0.23151,0.0937 0.23151,0.19293 0,0.11575 -0.0937,0.19843 -0.23151,0.19843 z m 0,0.678 c -0.17639,0 -0.27561,-0.0882 -0.27561,-0.19844 v -0.006 c 0,-0.12126 0.11576,-0.19292 0.27561,-0.19292 0.15985,0 0.27561,0.0717 0.27561,0.19292 v 0.006 c 0,0.11576 -0.0992,0.19844 -0.27561,0.19844 z m 0,0" + id="path48200" /> + d="m 347.46233,5.595996 c 0,0.09371 0.0772,0.170879 0.17639,0.170879 0.0937,0 0.17087,-0.07717 0.17087,-0.170879 V 4.300641 c 0,-0.09371 -0.0772,-0.170878 -0.17087,-0.170878 h -0.005 c -0.0496,0 -0.0992,0.01101 -0.16537,0.02755 l -0.22599,0.06615 c -0.0717,0.02204 -0.12127,0.08268 -0.12127,0.154342 0,0.08268 0.0717,0.148825 0.15434,0.148825 0.0221,0 0.0441,-0.0055 0.0661,-0.01101 l 0.12126,-0.02755 z m 0,0" + id="path48148" /> + d="m 358.52261,5.590485 c 0,0.10473 0.0772,0.165365 0.18742,0.165365 h 0.87092 c 0.0882,0 0.15434,-0.06615 0.15434,-0.148831 0,-0.08819 -0.0661,-0.15434 -0.15434,-0.15434 h -0.55673 l 0.25907,-0.203948 c 0.28663,-0.220486 0.42444,-0.352777 0.42444,-0.622874 v -0.0055 c 0,-0.297656 -0.22049,-0.490582 -0.55122,-0.490582 -0.24253,0 -0.39687,0.08268 -0.52365,0.23151 -0.0276,0.03306 -0.0441,0.07166 -0.0441,0.110241 0,0.09371 0.0717,0.165365 0.15985,0.165365 0.0551,0 0.0992,-0.02755 0.12127,-0.05512 0.0882,-0.0937 0.15985,-0.137803 0.26458,-0.137803 0.12127,0 0.21497,0.07166 0.21497,0.209463 0,0.132292 -0.0772,0.220485 -0.28112,0.38585 l -0.45199,0.374827 c -0.0606,0.0441 -0.0937,0.10473 -0.0937,0.17639 z m 0,0" + id="path48144" /> + d="m 370.73732,5.783409 c 0.35829,0 0.57878,-0.220486 0.57878,-0.523653 v -0.0055 c 0,-0.297657 -0.20946,-0.413409 -0.42995,-0.451996 l 0.31419,-0.297656 c 0.0661,-0.06063 0.10473,-0.110244 0.10473,-0.198438 0,-0.0937 -0.0772,-0.154342 -0.17639,-0.154342 h -0.78272 c -0.0827,0 -0.15434,0.06615 -0.15434,0.148831 0,0.08268 0.0717,0.154339 0.15434,0.154339 h 0.49058 l -0.30868,0.314193 c -0.0551,0.05512 -0.0772,0.09371 -0.0772,0.143314 0,0.08268 0.0661,0.148831 0.14883,0.148831 h 0.0551 c 0.19843,0 0.31419,0.07717 0.31419,0.203949 v 0.0055 c 0,0.121267 -0.0937,0.198438 -0.226,0.198438 -0.12678,0 -0.22049,-0.0441 -0.31419,-0.12127 -0.0275,-0.02204 -0.0606,-0.04409 -0.11024,-0.04409 -0.0937,0 -0.17088,0.07717 -0.17088,0.170873 0,0.04961 0.0276,0.09922 0.0606,0.126783 0.13229,0.110241 0.30317,0.181899 0.52917,0.181899 z m 0,0" + id="path48140" /> + d="m 382.46388,5.60151 c 0,0.0937 0.0716,0.165365 0.16536,0.165365 0.0937,0 0.17087,-0.07166 0.17087,-0.165365 V 5.408581 h 0.0827 c 0.0827,0 0.14332,-0.06063 0.14332,-0.143314 0,-0.07717 -0.0606,-0.143317 -0.14332,-0.143317 h -0.0827 V 4.295127 c 0,-0.0937 -0.0772,-0.170876 -0.17087,-0.170876 -0.10473,0 -0.15434,0.0441 -0.22049,0.12127 l -0.69453,0.810283 c -0.0551,0.06064 -0.0827,0.115758 -0.0827,0.192927 0,0.0937 0.0772,0.15985 0.17088,0.15985 h 0.66146 z m -0.42995,-0.47956 0.42995,-0.501605 V 5.12195 Z m 0,0" + id="path48136" /> + d="m 358.96308,-0.685109 c 0.60634,0 1.03629,-0.463021 1.03629,-1.019752 v -0.0055 c 0,-0.556728 -0.42444,-1.019749 -1.03077,-1.019749 -0.60634,0 -1.03629,0.468535 -1.03629,1.02526 v 0.0055 c 0,0.556725 0.42444,1.014235 1.03077,1.014235 z m 0.005,-0.319706 c -0.39136,0 -0.67248,-0.319704 -0.67248,-0.700046 v -0.0055 c 0,-0.38585 0.27561,-0.700045 0.66697,-0.700045 0.39136,0 0.67248,0.319706 0.67248,0.705556 v 0.0055 c 0,0.380336 -0.27561,0.694531 -0.66697,0.694531 z m 0,0" + id="path48084" /> + d="m 361.29911,-0.685109 c 0.51814,0 0.84887,-0.297656 0.84887,-0.88746 v -0.964623 c 0,-0.09371 -0.0772,-0.170879 -0.17088,-0.170879 -0.0992,0 -0.17639,0.07717 -0.17639,0.170879 v 0.981162 c 0,0.363802 -0.18741,0.545701 -0.49609,0.545701 -0.30868,0 -0.50161,-0.192924 -0.50161,-0.56224 v -0.964623 c 0,-0.09371 -0.0717,-0.170879 -0.17087,-0.170879 -0.0992,0 -0.17639,0.07717 -0.17639,0.170879 v 0.981162 c 0,0.573265 0.33073,0.870921 0.84336,0.870921 z m 0,0" + id="path48076" /> + d="m 363.16958,-0.878038 c 0,0.09922 0.0772,0.17639 0.17639,0.17639 0.0937,0 0.17639,-0.07717 0.17639,-0.17639 v -1.49379 h 0.47955 c 0.0882,0 0.15986,-0.07166 0.15986,-0.159856 0,-0.08819 -0.0717,-0.15985 -0.15986,-0.15985 h -1.31189 c -0.0882,0 -0.15985,0.07166 -0.15985,0.15985 0,0.0882 0.0717,0.159856 0.15985,0.159856 h 0.47956 z m 0,0" + id="path48080" /> + d="m 364.55734,-0.878038 c 0,0.09922 0.0772,0.17639 0.17639,0.17639 0.0937,0 0.17087,-0.07717 0.17087,-0.17639 v -0.474043 h 0.39137 c 0.43545,0 0.79375,-0.231511 0.79375,-0.677995 v -0.0055 c 0,-0.396875 -0.29215,-0.655945 -0.75517,-0.655945 h -0.60082 c -0.0992,0 -0.17639,0.07166 -0.17639,0.170876 z m 0.34726,-0.788236 v -0.711068 h 0.40239 c 0.25907,0 0.42995,0.121267 0.42995,0.352777 v 0.0055 c 0,0.203948 -0.16537,0.352777 -0.42995,0.352777 z m 0,0" + id="path48072" /> + d="m 367.31016,-0.685109 c 0.51814,0 0.84887,-0.297656 0.84887,-0.88746 v -0.964623 c 0,-0.09371 -0.0772,-0.170879 -0.17088,-0.170879 -0.0992,0 -0.17639,0.07717 -0.17639,0.170879 v 0.981162 c 0,0.363802 -0.18741,0.545701 -0.49609,0.545701 -0.30868,0 -0.50161,-0.192924 -0.50161,-0.56224 v -0.964623 c 0,-0.09371 -0.0716,-0.170879 -0.17087,-0.170879 -0.0992,0 -0.17639,0.07717 -0.17639,0.170879 v 0.981162 c 0,0.573265 0.33073,0.870921 0.84336,0.870921 z m 0,0" + id="path48068" /> + d="m 369.17922,-0.878038 c 0,0.09922 0.0772,0.17639 0.17639,0.17639 0.0937,0 0.17639,-0.07717 0.17639,-0.17639 v -1.49379 h 0.47955 c 0.0882,0 0.15986,-0.07166 0.15986,-0.159856 0,-0.08819 -0.0717,-0.15985 -0.15986,-0.15985 h -1.31189 c -0.0882,0 -0.15985,0.07166 -0.15985,0.15985 0,0.0882 0.0717,0.159856 0.15985,0.159856 h 0.47956 z m 0,0" + id="path48064" /> + d="m 371.24966,-0.690623 c 0.41341,0 0.70555,-0.220488 0.70555,-0.589798 v -0.0055 c 0,-0.325215 -0.21497,-0.474046 -0.6339,-0.578776 -0.38033,-0.08819 -0.47404,-0.159853 -0.47404,-0.308679 v -0.0055 c 0,-0.132292 0.12127,-0.237022 0.32522,-0.237022 0.15434,0 0.29765,0.05512 0.45199,0.148826 0.0276,0.01654 0.0551,0.02755 0.0937,0.02755 0.0882,0 0.15986,-0.07166 0.15986,-0.159856 0,-0.06615 -0.0331,-0.115753 -0.0772,-0.137801 -0.17639,-0.121269 -0.37483,-0.187415 -0.62287,-0.187415 -0.39137,0 -0.678,0.237022 -0.678,0.573265 v 0.0055 c 0,0.363802 0.23702,0.490582 0.66146,0.589801 0.3638,0.0882 0.44648,0.165364 0.44648,0.303167 v 0.0055 c 0,0.148825 -0.1378,0.248044 -0.35278,0.248044 -0.21497,0 -0.39136,-0.07165 -0.55121,-0.203946 -0.022,-0.01654 -0.0551,-0.02755 -0.10473,-0.02755 -0.0882,0 -0.15985,0.07166 -0.15985,0.159856 0,0.05512 0.0276,0.104727 0.0661,0.132292 0.22048,0.165364 0.47404,0.248044 0.74414,0.248044 z m 0,0" + id="path48060" /> + d="m 347.52916,-16.216976 c 0.34726,0 0.5898,-0.220488 0.5898,-0.545706 0,-0.341754 -0.24805,-0.507119 -0.56224,-0.507119 -0.10473,0 -0.17639,0.01654 -0.25356,0.0441 l 0.0276,-0.374827 h 0.60082 c 0.0661,0 0.12678,-0.05512 0.12678,-0.121266 0,-0.07166 -0.0606,-0.126778 -0.12678,-0.126778 h -0.7276 c -0.0661,0 -0.12127,0.04961 -0.12678,0.126778 l -0.0331,0.578778 c -0.005,0.04961 0.011,0.0937 0.0551,0.121267 0.0496,0.03858 0.0882,0.05512 0.13229,0.05512 0.0441,0 0.11575,-0.05512 0.27561,-0.05512 0.19292,0 0.33073,0.09922 0.33073,0.264583 v 0.0055 c 0,0.170879 -0.1323,0.275609 -0.3142,0.275609 -0.12678,0 -0.23702,-0.0441 -0.34726,-0.132292 -0.0221,-0.01654 -0.0496,-0.02755 -0.0827,-0.02755 -0.0717,0 -0.13229,0.06063 -0.13229,0.132291 0,0.04961 0.022,0.08268 0.0551,0.110244 0.13229,0.10473 0.29766,0.17639 0.51264,0.17639 z m 0,0" + id="path48056" /> + d="m 358.53419,-31.385057 c 0,0.08268 0.0661,0.132292 0.14882,0.132292 h 0.90951 c 0.0717,0 0.12678,-0.05512 0.12678,-0.121267 0,-0.07166 -0.0551,-0.126778 -0.12678,-0.126778 h -0.65043 l 0.33072,-0.275608 c 0.28664,-0.231508 0.41893,-0.369313 0.41893,-0.622874 0,-0.286631 -0.21498,-0.479555 -0.52917,-0.479555 -0.25356,0 -0.40239,0.0937 -0.53468,0.25907 -0.0165,0.02204 -0.0275,0.05512 -0.0275,0.08268 0,0.07165 0.0551,0.132292 0.12678,0.132292 0.0441,0 0.0772,-0.02204 0.0992,-0.0441 0.0992,-0.121266 0.18741,-0.181904 0.31419,-0.181904 0.14883,0 0.25907,0.09371 0.25907,0.253561 0,0.143314 -0.0772,0.248047 -0.29765,0.429948 l -0.4961,0.418923 c -0.0496,0.04409 -0.0717,0.08819 -0.0717,0.143314 z m 0,0" + id="path48040" /> + d="m 359.15851,-16.217153 c 0.33624,0 0.59532,-0.225997 0.59532,-0.545701 v -0.0055 c 0,-0.319707 -0.24805,-0.501605 -0.55673,-0.501605 -0.19293,0 -0.30317,0.07717 -0.38585,0.159851 0.011,-0.292143 0.14883,-0.512628 0.38585,-0.512628 0.10473,0 0.18741,0.03305 0.27561,0.0937 0.022,0.01101 0.0441,0.01654 0.0717,0.01654 0.0717,0 0.13229,-0.05512 0.13229,-0.12678 0,-0.06063 -0.0276,-0.0937 -0.0717,-0.121269 -0.10473,-0.07166 -0.23702,-0.115753 -0.39688,-0.115753 -0.4575,0 -0.68901,0.380336 -0.68901,0.870921 v 0.0055 c 0,0.325217 0.0717,0.490582 0.19292,0.611848 0.11024,0.110244 0.24805,0.170876 0.44648,0.170876 z m -0.005,-0.248045 c -0.19843,0 -0.33073,-0.121269 -0.33073,-0.286633 0,-0.15434 0.12679,-0.286631 0.32522,-0.286631 0.19844,0 0.32522,0.121266 0.32522,0.281117 v 0.0055 c 0,0.165365 -0.12127,0.286634 -0.31971,0.286634 z m 0,0" + id="path48036" /> + d="m 370.74015,-31.225201 c 0.33624,0 0.56224,-0.214977 0.56224,-0.507119 v -0.0055 c 0,-0.297657 -0.226,-0.418923 -0.46853,-0.451996 l 0.37482,-0.391361 c 0.0496,-0.04961 0.0827,-0.08819 0.0827,-0.154339 0,-0.07166 -0.0606,-0.12127 -0.14331,-0.12127 h -0.82131 c -0.0661,0 -0.12127,0.05512 -0.12127,0.12127 0,0.06614 0.0551,0.121266 0.12127,0.121266 h 0.58429 l -0.37483,0.402383 c -0.0441,0.0441 -0.0606,0.07717 -0.0606,0.115756 0,0.06614 0.0551,0.121269 0.12127,0.121269 h 0.0606 c 0.22048,0 0.36931,0.08819 0.36931,0.248044 v 0.0055 c 0,0.143314 -0.12127,0.242533 -0.28112,0.242533 -0.14883,0 -0.26458,-0.05512 -0.3638,-0.154339 -0.022,-0.02204 -0.0551,-0.03859 -0.0937,-0.03859 -0.0717,0 -0.13781,0.06615 -0.13781,0.137806 0,0.03858 0.022,0.07717 0.0496,0.09922 0.12679,0.126778 0.30869,0.209463 0.5402,0.209463 z m 0,0" + id="path47996" /> + d="m 370.35474,-16.36047 c 0,0.08268 0.0661,0.126783 0.14331,0.126783 0.0606,0 0.10474,-0.02755 0.13781,-0.09371 l 0.66146,-1.26228 c 0.0275,-0.0441 0.0386,-0.09371 0.0386,-0.132291 0,-0.08268 -0.0496,-0.126783 -0.12678,-0.126783 h -0.89848 c -0.0717,0 -0.12678,0.05512 -0.12678,0.121269 0,0.07166 0.0551,0.12678 0.12678,0.12678 h 0.69453 l -0.62287,1.152038 c -0.0165,0.02755 -0.0275,0.06615 -0.0275,0.08819 z m 0,0" + id="path47992" /> + d="m 382.49792,-31.374032 c 0,0.07717 0.0606,0.132292 0.13781,0.132292 0.0772,0 0.13229,-0.05512 0.13229,-0.132292 v -0.237021 h 0.12678 c 0.0662,0 0.11576,-0.04961 0.11576,-0.115756 0,-0.06615 -0.0496,-0.115752 -0.11576,-0.115752 h -0.12678 v -0.903994 c 0,-0.07717 -0.0606,-0.132292 -0.13229,-0.132292 -0.0827,0 -0.12678,0.02755 -0.17639,0.08819 l -0.75517,0.89848 c -0.0386,0.0441 -0.0606,0.09371 -0.0606,0.148828 0,0.07717 0.0606,0.132292 0.13781,0.132292 h 0.71658 z m -0.52365,-0.468529 0.52365,-0.639411 v 0.639411 z m 0,0" + id="path47964" /> + d="m 359.67348,-35.991321 c 0,0.09922 0.0717,0.17639 0.17087,0.17639 0.0992,0 0.17639,-0.07717 0.17639,-0.17639 v -1.659157 c 0,-0.09371 -0.0772,-0.170878 -0.17639,-0.170878 -0.0992,0 -0.17087,0.07717 -0.17087,0.170878 z m 0,0" + id="path47924" /> + d="m 360.61522,-35.985807 c 0,0.0937 0.0772,0.170876 0.17088,0.170876 0.0937,0 0.17088,-0.07717 0.17088,-0.170876 v -1.251259 l 1.01423,1.311891 c 0.0496,0.06063 0.0992,0.104733 0.1819,0.104733 h 0.0165 c 0.0937,0 0.16536,-0.07717 0.16536,-0.170879 v -1.659157 c 0,-0.09371 -0.0717,-0.170878 -0.17087,-0.170878 -0.0937,0 -0.17088,0.07717 -0.17088,0.170878 v 1.212676 l -0.98667,-1.278821 c -0.0441,-0.06063 -0.0937,-0.09922 -0.1819,-0.09922 h -0.0331 c -0.0992,0 -0.17639,0.07717 -0.17639,0.170876 z m 0,0" + id="path47920" /> + d="m 362.9269,-35.991321 c 0,0.09922 0.0772,0.17639 0.17639,0.17639 0.0937,0 0.17088,-0.07717 0.17088,-0.17639 v -0.474046 h 0.39136 c 0.43546,0 0.79375,-0.23151 0.79375,-0.677992 v -0.0055 c 0,-0.396875 -0.29214,-0.655944 -0.75516,-0.655944 h -0.60083 c -0.0992,0 -0.17639,0.07166 -0.17639,0.170875 z m 0.34727,-0.788236 v -0.71107 h 0.40239 c 0.25907,0 0.42994,0.121269 0.42994,0.35278 v 0.0055 c 0,0.203946 -0.16536,0.352777 -0.42994,0.352777 z m 0,0" + id="path47908" /> + d="m 365.67888,-35.798394 c 0.51814,0 0.84887,-0.297657 0.84887,-0.887458 v -0.964626 c 0,-0.09371 -0.0772,-0.170878 -0.17088,-0.170878 -0.0992,0 -0.17638,0.07717 -0.17638,0.170878 v 0.981165 c 0,0.363802 -0.18742,0.545701 -0.4961,0.545701 -0.30868,0 -0.50161,-0.192924 -0.50161,-0.56224 v -0.964626 c 0,-0.09371 -0.0717,-0.170878 -0.17087,-0.170878 -0.0992,0 -0.17639,0.07717 -0.17639,0.170878 v 0.981165 c 0,0.573262 0.33073,0.870919 0.84336,0.870919 z m 0,0" + id="path47912" /> + d="m 367.54653,-35.991321 c 0,0.09922 0.0772,0.17639 0.17639,0.17639 0.0937,0 0.17639,-0.07717 0.17639,-0.17639 v -1.493792 h 0.47955 c 0.0882,0 0.15986,-0.07166 0.15986,-0.159853 0,-0.08819 -0.0717,-0.159851 -0.15986,-0.159851 h -1.31189 c -0.0882,0 -0.15985,0.07166 -0.15985,0.159851 0,0.08819 0.0717,0.159853 0.15985,0.159853 h 0.47956 z m 0,0" + id="path47916" /> + d="m 369.61752,-35.803908 c 0.41342,0 0.70556,-0.220485 0.70556,-0.589799 v -0.0055 c 0,-0.325215 -0.21498,-0.474044 -0.6339,-0.578774 -0.38033,-0.08819 -0.47404,-0.159853 -0.47404,-0.308681 v -0.0055 c 0,-0.132292 0.12126,-0.237019 0.32522,-0.237019 0.15433,0 0.29765,0.05512 0.45199,0.148825 0.0276,0.01654 0.0551,0.02755 0.0937,0.02755 0.0882,0 0.15985,-0.07166 0.15985,-0.159853 0,-0.06615 -0.0331,-0.115753 -0.0772,-0.137803 -0.17638,-0.121267 -0.37482,-0.187412 -0.62287,-0.187412 -0.39136,0 -0.67799,0.237021 -0.67799,0.573264 v 0.0055 c 0,0.363802 0.23702,0.490582 0.66145,0.589801 0.36381,0.08819 0.44649,0.165365 0.44649,0.303167 v 0.0055 c 0,0.148825 -0.1378,0.248044 -0.35278,0.248044 -0.21497,0 -0.39136,-0.07166 -0.55122,-0.203949 -0.022,-0.01654 -0.0551,-0.02755 -0.10473,-0.02755 -0.0882,0 -0.15985,0.07166 -0.15985,0.159854 0,0.05512 0.0276,0.10473 0.0661,0.132291 0.22049,0.165365 0.47404,0.248047 0.74414,0.248047 z m 0,0" + id="path47904" /> + d="m 347.49161,-31.379543 c 0,0.07717 0.0661,0.137803 0.1378,0.137803 0.0827,0 0.14332,-0.06063 0.14332,-0.137803 v -1.361501 c 0,-0.07717 -0.0606,-0.137803 -0.14332,-0.137803 -0.0441,0 -0.0827,0.01101 -0.1378,0.02755 l -0.24254,0.07717 c -0.0606,0.01654 -0.0992,0.06064 -0.0992,0.121267 0,0.06064 0.0606,0.115758 0.12678,0.115758 0.011,0 0.0331,0 0.0496,-0.0055 l 0.16537,-0.04961 z m 0,0" + id="path47900" /> + + + + + + + + d="m 382.33703,-16.222135 c 0.35277,0 0.61185,-0.176388 0.61185,-0.463021 v -0.0055 c 0,-0.192923 -0.11025,-0.303164 -0.28664,-0.385849 0.1323,-0.07166 0.23151,-0.17639 0.23151,-0.358289 v -0.0055 c 0,-0.248044 -0.23702,-0.429948 -0.55672,-0.429948 -0.31971,0 -0.55673,0.187413 -0.55673,0.429948 v 0.0055 c 0,0.181899 0.0992,0.286632 0.23151,0.358289 -0.17639,0.07717 -0.28663,0.198437 -0.28663,0.391363 v 0.0055 c 0,0.275608 0.25907,0.457512 0.61185,0.457512 z m 0,-0.94809 c -0.16537,0 -0.28663,-0.09922 -0.28663,-0.237024 v -0.0055 c 0,-0.121267 0.11575,-0.226 0.28663,-0.226 0.17087,0 0.28663,0.104733 0.28663,0.226 v 0.0055 c 0,0.137805 -0.12127,0.237024 -0.28663,0.237024 z m 0,0.711065 c -0.20947,0 -0.33624,-0.110241 -0.33624,-0.237019 v -0.0055 c 0,-0.148828 0.14882,-0.242536 0.33624,-0.242536 0.19292,0 0.33624,0.09371 0.33624,0.242536 v 0.0055 c 0,0.132292 -0.12678,0.237019 -0.33624,0.237019 z m 0,0" + id="path47574" /> diff --git a/src/app/AudioWidget.cpp b/src/app/AudioWidget.cpp index 106fe63d..2bb4f165 100644 --- a/src/app/AudioWidget.cpp +++ b/src/app/AudioWidget.cpp @@ -37,16 +37,16 @@ struct AudioDeviceItem : MenuItem { AudioIO *audioIO; int device; int offset; - int maxChannels; void onAction(EventAction &e) override { - audioIO->setDevice(device, offset, maxChannels); + audioIO->setDevice(device, offset); } }; struct AudioDeviceChoice : LedDisplayChoice { AudioWidget *audioWidget; - int groupChannels = 8; + /** Prevents devices with a ridiculous number of channels from being displayed */ int maxTotalChannels = 64; + void onAction(EventAction &e) override { Menu *menu = gScene->createMenu(); menu->addChild(construct(&MenuLabel::text, "Audio device")); @@ -60,21 +60,20 @@ struct AudioDeviceChoice : LedDisplayChoice { menu->addChild(item); } for (int device = 0; device < deviceCount; device++) { - int maxChannels = min(maxTotalChannels, audioWidget->audioIO->getDeviceMaxChannels(device)); - for (int offset = 0; offset < maxChannels; offset += groupChannels) { + int channels = min(maxTotalChannels, audioWidget->audioIO->getDeviceChannels(device)); + for (int offset = 0; offset < channels; offset += audioWidget->audioIO->maxChannels) { AudioDeviceItem *item = new AudioDeviceItem(); item->audioIO = audioWidget->audioIO; item->device = device; item->offset = offset; - item->maxChannels = groupChannels; - item->text = audioWidget->audioIO->getDeviceDetail(device, offset, groupChannels); + item->text = audioWidget->audioIO->getDeviceDetail(device, offset); item->rightText = CHECKMARK(item->device == audioWidget->audioIO->device && item->offset == audioWidget->audioIO->offset); menu->addChild(item); } } } void step() override { - text = audioWidget->audioIO->getDeviceDetail(audioWidget->audioIO->device, audioWidget->audioIO->offset, groupChannels); + text = audioWidget->audioIO->getDeviceDetail(audioWidget->audioIO->device, audioWidget->audioIO->offset); if (text.empty()) { text = "(No device)"; color.a = 0.5f; @@ -82,7 +81,6 @@ struct AudioDeviceChoice : LedDisplayChoice { else { color.a = 1.f; } - text = ellipsize(text, 18); } }; diff --git a/src/app/LedDisplay.cpp b/src/app/LedDisplay.cpp index c733abca..7003e1b3 100644 --- a/src/app/LedDisplay.cpp +++ b/src/app/LedDisplay.cpp @@ -38,6 +38,8 @@ LedDisplayChoice::LedDisplayChoice() { } void LedDisplayChoice::draw(NVGcontext *vg) { + nvgScissor(vg, 0, 0, box.size.x, box.size.y); + if (font->handle < 0) return; @@ -47,6 +49,8 @@ void LedDisplayChoice::draw(NVGcontext *vg) { nvgFontSize(vg, 12); nvgText(vg, textOffset.x, textOffset.y, text.c_str(), NULL); + + nvgResetScissor(vg); } void LedDisplayChoice::onMouseDown(EventMouseDown &e) { diff --git a/src/app/LightWidget.cpp b/src/app/LightWidget.cpp index 7a78f8e1..7b4443c3 100644 --- a/src/app/LightWidget.cpp +++ b/src/app/LightWidget.cpp @@ -1,15 +1,11 @@ #include "app.hpp" +#include "util/color.hpp" namespace rack { void LightWidget::draw(NVGcontext *vg) { - color.r = clamp(color.r, 0.0, 1.0); - color.g = clamp(color.g, 0.0, 1.0); - color.b = clamp(color.b, 0.0, 1.0); - color.a = clamp(color.a, 0.0, 1.0); - drawLight(vg); drawHalo(vg); } @@ -20,21 +16,14 @@ void LightWidget::drawLight(NVGcontext *vg) { nvgBeginPath(vg); nvgCircle(vg, radius, radius, radius); - // Background - nvgFillColor(vg, bgColor); + // Solid color + nvgFillColor(vg, color); nvgFill(vg); // Border - nvgStrokeWidth(vg, 1.0); - NVGcolor borderColor = bgColor; - borderColor.a *= 0.5; + nvgStrokeWidth(vg, 0.5); nvgStrokeColor(vg, borderColor); nvgStroke(vg); - - // Inner glow - nvgFillColor(vg, color); - nvgGlobalCompositeOperation(vg, NVG_LIGHTER); - nvgFill(vg); } void LightWidget::drawHalo(NVGcontext *vg) { @@ -45,10 +34,8 @@ void LightWidget::drawHalo(NVGcontext *vg) { nvgRect(vg, radius - oradius, radius - oradius, 2*oradius, 2*oradius); NVGpaint paint; - NVGcolor icol = color; - icol.a *= 0.10; - NVGcolor ocol = color; - ocol.a = 0.0; + NVGcolor icol = colorMult(color, 0.15); + NVGcolor ocol = nvgRGB(0, 0, 0); paint = nvgRadialGradient(vg, radius, radius, radius, oradius, icol, ocol); nvgFillPaint(vg, paint); nvgGlobalCompositeOperation(vg, NVG_LIGHTER); diff --git a/src/app/MidiWidget.cpp b/src/app/MidiWidget.cpp index 9e901b54..33e41daa 100644 --- a/src/app/MidiWidget.cpp +++ b/src/app/MidiWidget.cpp @@ -45,6 +45,14 @@ struct MidiDeviceChoice : LedDisplayChoice { void onAction(EventAction &e) override { Menu *menu = gScene->createMenu(); menu->addChild(construct(&MenuLabel::text, "MIDI device")); + { + MidiDeviceItem *item = new MidiDeviceItem(); + item->midiIO = midiWidget->midiIO; + item->device = -1; + item->text = "(No device)"; + item->rightText = CHECKMARK(item->device == midiWidget->midiIO->device); + menu->addChild(item); + } int driverCount = midiWidget->midiIO->getDeviceCount(); for (int device = 0; device < driverCount; device++) { MidiDeviceItem *item = new MidiDeviceItem(); @@ -57,7 +65,13 @@ struct MidiDeviceChoice : LedDisplayChoice { } void step() override { text = midiWidget->midiIO->getDeviceName(midiWidget->midiIO->device); - text = ellipsize(text, 14); + if (text.empty()) { + text = "(No device)"; + color.a = 0.5f; + } + else { + color.a = 1.f; + } } }; diff --git a/src/app/ModuleLightWidget.cpp b/src/app/ModuleLightWidget.cpp index 1982ffd8..27da8a66 100644 --- a/src/app/ModuleLightWidget.cpp +++ b/src/app/ModuleLightWidget.cpp @@ -12,7 +12,7 @@ void ModuleLightWidget::step() { for (size_t i = 0; i < baseColors.size(); i++) { float value = module->lights[firstLightId + i].getBrightness(); - value = clamp(value, 0.0, 1.0); + value = clamp(value, 0.f, 1.f); values[i] = value; } setValues(values); diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 3af3a989..9bd8a0f3 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -233,27 +233,34 @@ void ModuleWidget::onMouseMove(EventMouseMove &e) { void ModuleWidget::onHoverKey(EventHoverKey &e) { switch (e.key) { - case GLFW_KEY_I: + case GLFW_KEY_I: { if (windowIsModPressed() && !windowIsShiftPressed()) { reset(); e.consumed = true; return; } - break; - case GLFW_KEY_R: + } break; + case GLFW_KEY_R: { if (windowIsModPressed() && !windowIsShiftPressed()) { randomize(); e.consumed = true; return; } - break; - case GLFW_KEY_D: + } break; + case GLFW_KEY_D: { if (windowIsModPressed() && !windowIsShiftPressed()) { gRackWidget->cloneModule(this); e.consumed = true; return; } - break; + } break; + case GLFW_KEY_U: { + if (windowIsModPressed() && !windowIsShiftPressed()) { + disconnect(); + e.consumed = true; + return; + } + } break; } Widget::onHoverKey(e); @@ -331,6 +338,7 @@ Menu *ModuleWidget::createContextMenu() { DisconnectMenuItem *disconnectItem = new DisconnectMenuItem(); disconnectItem->text = "Disconnect cables"; + disconnectItem->rightText = WINDOW_MOD_KEY_NAME "+U"; disconnectItem->moduleWidget = this; menu->addChild(disconnectItem); diff --git a/src/app/MultiLightWidget.cpp b/src/app/MultiLightWidget.cpp index eb9ceb1f..f6249ab6 100644 --- a/src/app/MultiLightWidget.cpp +++ b/src/app/MultiLightWidget.cpp @@ -1,4 +1,5 @@ #include "app.hpp" +#include "util/color.hpp" namespace rack { @@ -10,14 +11,14 @@ void MultiLightWidget::addBaseColor(NVGcolor baseColor) { void MultiLightWidget::setValues(const std::vector &values) { assert(values.size() == baseColors.size()); - color = nvgRGBf(0, 0, 0); + color = bgColor; for (size_t i = 0; i < baseColors.size(); i++) { NVGcolor c = baseColors[i]; - float value = values[i]; - color.r += c.r * value; - color.g += c.g * value; - color.b += c.b * value; + c = colorMinus(c, bgColor); + c = colorMult(c, values[i]); + color = colorPlus(color, c); } + color = colorClip(color); } diff --git a/src/audio.cpp b/src/audio.cpp index dab5637b..bb15fd80 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -46,8 +46,8 @@ std::string AudioIO::getDriverName(int driver) { } void AudioIO::setDriver(int driver) { - // Close driver - closeStream(); + setDevice(-1, 0); + if (rtAudio) { delete rtAudio; rtAudio = NULL; @@ -100,7 +100,7 @@ bool AudioIO::getDeviceInfo(int device, RtAudio::DeviceInfo *deviceInfo) { } } -int AudioIO::getDeviceMaxChannels(int device) { +int AudioIO::getDeviceChannels(int device) { if (device < 0) return 0; @@ -130,7 +130,7 @@ std::string AudioIO::getDeviceName(int device) { return ""; } -std::string AudioIO::getDeviceDetail(int device, int offset, int maxChannels) { +std::string AudioIO::getDeviceDetail(int device, int offset) { if (device < 0) return ""; @@ -154,12 +154,10 @@ std::string AudioIO::getDeviceDetail(int device, int offset, int maxChannels) { return ""; } -void AudioIO::setDevice(int device, int offset, int maxChannels) { +void AudioIO::setDevice(int device, int offset) { closeStream(); this->device = device; this->offset = offset; - this->numOutputs = maxChannels; - this->numInputs = maxChannels; openStream(); } @@ -200,8 +198,8 @@ void AudioIO::openStream() { if (rtAudio->isStreamOpen()) return; - numOutputs = clamp((int) deviceInfo.outputChannels - offset, 0, numOutputs); - numInputs = clamp((int) deviceInfo.inputChannels - offset, 0, numInputs); + numOutputs = clamp((int) deviceInfo.outputChannels - offset, 0, maxChannels); + numInputs = clamp((int) deviceInfo.inputChannels - offset, 0, maxChannels); if (numOutputs == 0 && numInputs == 0) { warn("RtAudio device %d has 0 inputs and 0 outputs"); @@ -318,6 +316,8 @@ json_t *AudioIO::toJson() { json_object_set_new(rootJ, "driver", json_integer(driver)); std::string deviceName = getDeviceName(device); json_object_set_new(rootJ, "deviceName", json_string(deviceName.c_str())); + json_object_set_new(rootJ, "offset", json_integer(offset)); + json_object_set_new(rootJ, "maxChannels", json_integer(maxChannels)); json_object_set_new(rootJ, "sampleRate", json_integer(sampleRate)); json_object_set_new(rootJ, "blockSize", json_integer(blockSize)); return rootJ; @@ -342,6 +342,14 @@ void AudioIO::fromJson(json_t *rootJ) { } } + json_t *offsetJ = json_object_get(rootJ, "offset"); + if (offsetJ) + offset = json_integer_value(offsetJ); + + json_t *maxChannelsJ = json_object_get(rootJ, "maxChannels"); + if (maxChannelsJ) + maxChannels = json_integer_value(maxChannelsJ); + json_t *sampleRateJ = json_object_get(rootJ, "sampleRate"); if (sampleRateJ) sampleRate = json_integer_value(sampleRateJ); diff --git a/src/core/AudioInterface.cpp b/src/core/AudioInterface.cpp index 4a9c210f..f134acf6 100644 --- a/src/core/AudioInterface.cpp +++ b/src/core/AudioInterface.cpp @@ -39,7 +39,7 @@ struct AudioInterfaceIO : AudioIO { ~AudioInterfaceIO() { // Close stream here before destructing AudioInterfaceIO, so the mutexes are still valid when waiting to close. - closeStream(); + setDevice(-1, 0); } void processStream(const float *input, float *output, int length) override { @@ -97,8 +97,8 @@ struct AudioInterface : Module { NUM_OUTPUTS }; enum LightIds { - ENUMS(INPUT_LIGHT, INPUTS), - ENUMS(OUTPUT_LIGHT, OUTPUTS), + ENUMS(INPUT_LIGHT, INPUTS / 2), + ENUMS(OUTPUT_LIGHT, OUTPUTS / 2), NUM_LIGHTS }; @@ -141,7 +141,7 @@ struct AudioInterface : Module { } void onReset() override { - audioIO.closeStream(); + audioIO.setDevice(-1, 0); } }; @@ -203,72 +203,57 @@ void AudioInterface::step() { } } - for (int i = 0; i < INPUTS; i++) - lights[INPUT_LIGHT + i].value = (audioIO.numInputs > i); - for (int i = 0; i < OUTPUTS; i++) - lights[OUTPUT_LIGHT + i].value = (audioIO.numOutputs > i); + for (int i = 0; i < INPUTS / 2; i++) + lights[INPUT_LIGHT + i].value = (audioIO.numInputs >= 2*i+1); + for (int i = 0; i < OUTPUTS / 2; i++) + lights[OUTPUT_LIGHT + i].value = (audioIO.numOutputs >= 2*i+1); audioIO.audioCv.notify_all(); } struct AudioInterfaceWidget : ModuleWidget { - AudioInterfaceWidget(AudioInterface *module); + AudioInterfaceWidget(AudioInterface *module) : ModuleWidget(module) { + setPanel(SVG::load(assetGlobal("res/Core/AudioInterface.svg"))); + + addChild(Widget::create(Vec(RACK_GRID_WIDTH, 0))); + addChild(Widget::create(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); + addChild(Widget::create(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); + addChild(Widget::create(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); + + addInput(Port::create(mm2px(Vec(3.7069211, 55.530807)), Port::INPUT, module, AudioInterface::AUDIO_INPUT + 0)); + addInput(Port::create(mm2px(Vec(15.307249, 55.530807)), Port::INPUT, module, AudioInterface::AUDIO_INPUT + 1)); + addInput(Port::create(mm2px(Vec(26.906193, 55.530807)), Port::INPUT, module, AudioInterface::AUDIO_INPUT + 2)); + addInput(Port::create(mm2px(Vec(38.506519, 55.530807)), Port::INPUT, module, AudioInterface::AUDIO_INPUT + 3)); + addInput(Port::create(mm2px(Vec(3.7069209, 70.144905)), Port::INPUT, module, AudioInterface::AUDIO_INPUT + 4)); + addInput(Port::create(mm2px(Vec(15.307249, 70.144905)), Port::INPUT, module, AudioInterface::AUDIO_INPUT + 5)); + addInput(Port::create(mm2px(Vec(26.906193, 70.144905)), Port::INPUT, module, AudioInterface::AUDIO_INPUT + 6)); + addInput(Port::create(mm2px(Vec(38.506519, 70.144905)), Port::INPUT, module, AudioInterface::AUDIO_INPUT + 7)); + + addOutput(Port::create(mm2px(Vec(3.7069209, 92.143906)), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + 0)); + addOutput(Port::create(mm2px(Vec(15.307249, 92.143906)), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + 1)); + addOutput(Port::create(mm2px(Vec(26.906193, 92.143906)), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + 2)); + addOutput(Port::create(mm2px(Vec(38.506519, 92.143906)), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + 3)); + addOutput(Port::create(mm2px(Vec(3.7069209, 108.1443)), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + 4)); + addOutput(Port::create(mm2px(Vec(15.307249, 108.1443)), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + 5)); + addOutput(Port::create(mm2px(Vec(26.906193, 108.1443)), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + 6)); + addOutput(Port::create(mm2px(Vec(38.506523, 108.1443)), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + 7)); + + addChild(ModuleLightWidget::create>(mm2px(Vec(12.524985, 54.577202)), module, AudioInterface::INPUT_LIGHT + 0)); + addChild(ModuleLightWidget::create>(mm2px(Vec(35.725647, 54.577202)), module, AudioInterface::INPUT_LIGHT + 1)); + addChild(ModuleLightWidget::create>(mm2px(Vec(12.524985, 69.158226)), module, AudioInterface::INPUT_LIGHT + 2)); + addChild(ModuleLightWidget::create>(mm2px(Vec(35.725647, 69.158226)), module, AudioInterface::INPUT_LIGHT + 3)); + addChild(ModuleLightWidget::create>(mm2px(Vec(12.524985, 91.147583)), module, AudioInterface::OUTPUT_LIGHT + 0)); + addChild(ModuleLightWidget::create>(mm2px(Vec(35.725647, 91.147583)), module, AudioInterface::OUTPUT_LIGHT + 1)); + addChild(ModuleLightWidget::create>(mm2px(Vec(12.524985, 107.17003)), module, AudioInterface::OUTPUT_LIGHT + 2)); + addChild(ModuleLightWidget::create>(mm2px(Vec(35.725647, 107.17003)), module, AudioInterface::OUTPUT_LIGHT + 3)); + + AudioWidget *audioWidget = Widget::create(mm2px(Vec(3.2122073, 14.837339))); + audioWidget->box.size = mm2px(Vec(44, 28)); + audioWidget->audioIO = &module->audioIO; + addChild(audioWidget); + } }; -AudioInterfaceWidget::AudioInterfaceWidget(AudioInterface *module) : ModuleWidget(module) { - setPanel(SVG::load(assetGlobal("res/Core/AudioInterface.svg"))); - - addChild(Widget::create(Vec(RACK_GRID_WIDTH, 0))); - addChild(Widget::create(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); - addChild(Widget::create(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); - addChild(Widget::create(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); - - addInput(Port::create(mm2px(Vec(3.89433, 55.5308)), Port::INPUT, module, AudioInterface::AUDIO_INPUT + 0)); - addInput(Port::create(mm2px(Vec(15.4947, 55.5308)), Port::INPUT, module, AudioInterface::AUDIO_INPUT + 1)); - addInput(Port::create(mm2px(Vec(27.095, 55.5308)), Port::INPUT, module, AudioInterface::AUDIO_INPUT + 2)); - addInput(Port::create(mm2px(Vec(38.6953, 55.5308)), Port::INPUT, module, AudioInterface::AUDIO_INPUT + 3)); - addInput(Port::create(mm2px(Vec(3.89433, 70.1449)), Port::INPUT, module, AudioInterface::AUDIO_INPUT + 4)); - addInput(Port::create(mm2px(Vec(15.4947, 70.1449)), Port::INPUT, module, AudioInterface::AUDIO_INPUT + 5)); - addInput(Port::create(mm2px(Vec(27.095, 70.1449)), Port::INPUT, module, AudioInterface::AUDIO_INPUT + 6)); - addInput(Port::create(mm2px(Vec(38.6953, 70.1449)), Port::INPUT, module, AudioInterface::AUDIO_INPUT + 7)); - - addOutput(Port::create(mm2px(Vec(3.89295, 92.1439)), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + 0)); - addOutput(Port::create(mm2px(Vec(15.4933, 92.1439)), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + 1)); - addOutput(Port::create(mm2px(Vec(27.0936, 92.1439)), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + 2)); - addOutput(Port::create(mm2px(Vec(38.6939, 92.1439)), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + 3)); - addOutput(Port::create(mm2px(Vec(3.89433, 108.144)), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + 4)); - addOutput(Port::create(mm2px(Vec(15.4947, 108.144)), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + 5)); - addOutput(Port::create(mm2px(Vec(27.095, 108.144)), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + 6)); - addOutput(Port::create(mm2px(Vec(38.6953, 108.144)), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + 7)); - - Vec lightOffset = mm2px(Vec(7.21812, -0.1833)); - - addChild(ModuleLightWidget::create>(mm2px(Vec(3.89433, 55.5308)).plus(lightOffset), module, AudioInterface::INPUT_LIGHT + 0)); - addChild(ModuleLightWidget::create>(mm2px(Vec(15.4947, 55.5308)).plus(lightOffset), module, AudioInterface::INPUT_LIGHT + 1)); - addChild(ModuleLightWidget::create>(mm2px(Vec(27.095, 55.5308)).plus(lightOffset), module, AudioInterface::INPUT_LIGHT + 2)); - addChild(ModuleLightWidget::create>(mm2px(Vec(38.6953, 55.5308)).plus(lightOffset), module, AudioInterface::INPUT_LIGHT + 3)); - addChild(ModuleLightWidget::create>(mm2px(Vec(3.89433, 70.1449)).plus(lightOffset), module, AudioInterface::INPUT_LIGHT + 4)); - addChild(ModuleLightWidget::create>(mm2px(Vec(15.4947, 70.1449)).plus(lightOffset), module, AudioInterface::INPUT_LIGHT + 5)); - addChild(ModuleLightWidget::create>(mm2px(Vec(27.095, 70.1449)).plus(lightOffset), module, AudioInterface::INPUT_LIGHT + 6)); - addChild(ModuleLightWidget::create>(mm2px(Vec(38.6953, 70.1449)).plus(lightOffset), module, AudioInterface::INPUT_LIGHT + 7)); - - addChild(ModuleLightWidget::create>(mm2px(Vec(3.89295, 92.1439)).plus(lightOffset), module, AudioInterface::OUTPUT_LIGHT + 0)); - addChild(ModuleLightWidget::create>(mm2px(Vec(15.4933, 92.1439)).plus(lightOffset), module, AudioInterface::OUTPUT_LIGHT + 1)); - addChild(ModuleLightWidget::create>(mm2px(Vec(27.0936, 92.1439)).plus(lightOffset), module, AudioInterface::OUTPUT_LIGHT + 2)); - addChild(ModuleLightWidget::create>(mm2px(Vec(38.6939, 92.1439)).plus(lightOffset), module, AudioInterface::OUTPUT_LIGHT + 3)); - addChild(ModuleLightWidget::create>(mm2px(Vec(3.89433, 108.144)).plus(lightOffset), module, AudioInterface::OUTPUT_LIGHT + 4)); - addChild(ModuleLightWidget::create>(mm2px(Vec(15.4947, 108.144)).plus(lightOffset), module, AudioInterface::OUTPUT_LIGHT + 5)); - addChild(ModuleLightWidget::create>(mm2px(Vec(27.095, 108.144)).plus(lightOffset), module, AudioInterface::OUTPUT_LIGHT + 6)); - addChild(ModuleLightWidget::create>(mm2px(Vec(38.6953, 108.144)).plus(lightOffset), module, AudioInterface::OUTPUT_LIGHT + 7)); - - - AudioWidget *audioWidget = Widget::create(mm2px(Vec(3.401, 14.8373))); - audioWidget->box.size = mm2px(Vec(44, 28)); - audioWidget->audioIO = &module->audioIO; - addChild(audioWidget); -} - - Model *modelAudioInterface = Model::create("Core", "AudioInterface", "Audio", EXTERNAL_TAG); \ No newline at end of file