Browse Source

Avoid RT-unsafe allocations on HostMIDI-Map

Signed-off-by: falkTX <falktx@falktx.com>
tags/22.06
falkTX 3 years ago
parent
commit
d8a341be95
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
3 changed files with 19 additions and 22 deletions
  1. +14
    -19
      plugins/Cardinal/src/HostMIDI-Map.cpp
  2. +1
    -0
      plugins/Cardinal/src/ModuleWidgets.hpp
  3. +4
    -3
      plugins/Cardinal/src/Widgets.hpp

+ 14
- 19
plugins/Cardinal/src/HostMIDI-Map.cpp View File

@@ -26,6 +26,7 @@
*/ */


#include "plugincontext.hpp" #include "plugincontext.hpp"
#include "ModuleWidgets.hpp"
#include "Widgets.hpp" #include "Widgets.hpp"


#include <algorithm> #include <algorithm>
@@ -34,7 +35,7 @@


USE_NAMESPACE_DISTRHO; USE_NAMESPACE_DISTRHO;


static const int MAX_MIDI_CONTROL = 120; /* 0x77 + 1 */
static constexpr const int MAX_MIDI_CONTROL = 120; /* 0x77 + 1 */


struct HostMIDIMap : TerminalModule { struct HostMIDIMap : TerminalModule {
enum ParamIds { enum ParamIds {
@@ -93,6 +94,7 @@ struct HostMIDIMap : TerminalModule {
for (int id = 0; id < MAX_MIDI_CONTROL; ++id) for (int id = 0; id < MAX_MIDI_CONTROL; ++id)
{ {
paramHandles[id].color = nvgRGBf(0.76f, 0.11f, 0.22f); paramHandles[id].color = nvgRGBf(0.76f, 0.11f, 0.22f);
paramHandles[id].text.reserve(25);
pcontext->engine->addParamHandle(&paramHandles[id]); pcontext->engine->addParamHandle(&paramHandles[id]);
} }


@@ -366,15 +368,17 @@ struct HostMIDIMap : TerminalModule {
nextLearningId = learningId = -1; nextLearningId = learningId = -1;
} }


// FIXME this allocates string during RT!!
// this is called during RT!!
void refreshParamHandleText(const int id) void refreshParamHandleText(const int id)
{ {
std::string text;
char textBuf[25];

if (ccs[id] >= 0) if (ccs[id] >= 0)
text = string::f("CC%02d", ccs[id]);
std::sprintf(textBuf, "CC%02d", ccs[id]);
else else
text = "MIDI-Map";
paramHandles[id].text = text;
std::strcpy(textBuf, "MIDI-Map");

paramHandles[id].text.assign(textBuf);
} }


void updateMapLen() void updateMapLen()
@@ -679,7 +683,7 @@ struct HostMIDIMapDisplay : Widget {
} }
}; };


struct HostMIDIMapWidget : ModuleWidget {
struct HostMIDIMapWidget : ModuleWidgetWith11HP {
HostMIDIMap* const module; HostMIDIMap* const module;


HostMIDIMapWidget(HostMIDIMap* const m) HostMIDIMapWidget(HostMIDIMap* const m)
@@ -687,11 +691,7 @@ struct HostMIDIMapWidget : ModuleWidget {
{ {
setModule(m); setModule(m);
setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/HostMIDIMap.svg"))); setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/HostMIDIMap.svg")));

addChild(createWidget<ScrewBlack>(Vec(RACK_GRID_WIDTH, 0)));
addChild(createWidget<ScrewBlack>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
addChild(createWidget<ScrewBlack>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
addChild(createWidget<ScrewBlack>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
createAndAddScrews();


HostMIDIMapDisplay* const display = createWidget<HostMIDIMapDisplay>(Vec(1.0f, 71.0f)); HostMIDIMapDisplay* const display = createWidget<HostMIDIMapDisplay>(Vec(1.0f, 71.0f));
display->box.size = Vec(box.size.x - 2.0f, box.size.y - 89.0f); display->box.size = Vec(box.size.x - 2.0f, box.size.y - 89.0f);
@@ -701,13 +701,8 @@ struct HostMIDIMapWidget : ModuleWidget {


void draw(const DrawArgs& args) override void draw(const DrawArgs& args) override
{ {
nvgBeginPath(args.vg);
nvgRect(args.vg, 0, 0, box.size.x, box.size.y);
nvgFillPaint(args.vg, nvgLinearGradient(args.vg, 0, 0, 0, box.size.y,
nvgRGB(0x18, 0x19, 0x19), nvgRGB(0x21, 0x22, 0x22)));
nvgFill(args.vg);

ModuleWidget::draw(args);
drawBackground(args.vg);
ModuleWidgetWith11HP::draw(args);
} }


void appendContextMenu(Menu* const menu) override void appendContextMenu(Menu* const menu) override


+ 1
- 0
plugins/Cardinal/src/ModuleWidgets.hpp View File

@@ -95,3 +95,4 @@ struct ModuleWidgetWithSideScrews : ModuleWidget {
typedef ModuleWidgetWithSideScrews<3> ModuleWidgetWith3HP; typedef ModuleWidgetWithSideScrews<3> ModuleWidgetWith3HP;
typedef ModuleWidgetWithSideScrews<8> ModuleWidgetWith8HP; typedef ModuleWidgetWithSideScrews<8> ModuleWidgetWith8HP;
typedef ModuleWidgetWithSideScrews<9> ModuleWidgetWith9HP; typedef ModuleWidgetWithSideScrews<9> ModuleWidgetWith9HP;
typedef ModuleWidgetWithSideScrews<11> ModuleWidgetWith11HP;

+ 4
- 3
plugins/Cardinal/src/Widgets.hpp View File

@@ -377,8 +377,9 @@ struct OpenGlWidgetWithBrowserPreview : OpenGlWidget {
fb = nvgluCreateFramebuffer(args.vg, box.size.x * oversample, box.size.y * oversample, 0); fb = nvgluCreateFramebuffer(args.vg, box.size.x * oversample, box.size.y * oversample, 0);
DISTRHO_SAFE_ASSERT_RETURN(fb != nullptr,); DISTRHO_SAFE_ASSERT_RETURN(fb != nullptr,);


// draw our special framebuffer
nvgluBindFramebuffer(fb); nvgluBindFramebuffer(fb);

// draw our special framebuffer
drawFramebufferForBrowserPreview(); drawFramebufferForBrowserPreview();


// reset to regular framebuffer // reset to regular framebuffer
@@ -388,8 +389,8 @@ struct OpenGlWidgetWithBrowserPreview : OpenGlWidget {
nvgBeginPath(args.vg); nvgBeginPath(args.vg);
nvgRect(args.vg, 0.0f, 0.0f, box.size.x, box.size.y); nvgRect(args.vg, 0.0f, 0.0f, box.size.x, box.size.y);
NVGpaint paint = nvgImagePattern(args.vg, NVGpaint paint = nvgImagePattern(args.vg,
0.0f, 0.0f, box.size.x, box.size.y,
0.0f, fb->image, 1.0f);
0.0f, 0.0f, box.size.x, box.size.y,
0.0f, fb->image, 1.0f);
nvgFillPaint(args.vg, paint); nvgFillPaint(args.vg, paint);
nvgFill(args.vg); nvgFill(args.vg);
} }


Loading…
Cancel
Save