Avoid RT-unsafe allocations on HostMIDI-Map

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2022-05-22 23:47:08 +01:00
parent 21004ab183
commit d8a341be95
No known key found for this signature in database
GPG key ID: CDBAA37ABC74FBA0
3 changed files with 19 additions and 22 deletions

View file

@ -26,6 +26,7 @@
*/
#include "plugincontext.hpp"
#include "ModuleWidgets.hpp"
#include "Widgets.hpp"
#include <algorithm>
@ -34,7 +35,7 @@
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 {
enum ParamIds {
@ -93,6 +94,7 @@ struct HostMIDIMap : TerminalModule {
for (int id = 0; id < MAX_MIDI_CONTROL; ++id)
{
paramHandles[id].color = nvgRGBf(0.76f, 0.11f, 0.22f);
paramHandles[id].text.reserve(25);
pcontext->engine->addParamHandle(&paramHandles[id]);
}
@ -366,15 +368,17 @@ struct HostMIDIMap : TerminalModule {
nextLearningId = learningId = -1;
}
// FIXME this allocates string during RT!!
// this is called during RT!!
void refreshParamHandleText(const int id)
{
std::string text;
char textBuf[25];
if (ccs[id] >= 0)
text = string::f("CC%02d", ccs[id]);
std::sprintf(textBuf, "CC%02d", ccs[id]);
else
text = "MIDI-Map";
paramHandles[id].text = text;
std::strcpy(textBuf, "MIDI-Map");
paramHandles[id].text.assign(textBuf);
}
void updateMapLen()
@ -679,7 +683,7 @@ struct HostMIDIMapDisplay : Widget {
}
};
struct HostMIDIMapWidget : ModuleWidget {
struct HostMIDIMapWidget : ModuleWidgetWith11HP {
HostMIDIMap* const module;
HostMIDIMapWidget(HostMIDIMap* const m)
@ -687,11 +691,7 @@ struct HostMIDIMapWidget : ModuleWidget {
{
setModule(m);
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));
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
{
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

View file

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

View file

@ -377,8 +377,9 @@ struct OpenGlWidgetWithBrowserPreview : OpenGlWidget {
fb = nvgluCreateFramebuffer(args.vg, box.size.x * oversample, box.size.y * oversample, 0);
DISTRHO_SAFE_ASSERT_RETURN(fb != nullptr,);
// draw our special framebuffer
nvgluBindFramebuffer(fb);
// draw our special framebuffer
drawFramebufferForBrowserPreview();
// reset to regular framebuffer
@ -388,8 +389,8 @@ struct OpenGlWidgetWithBrowserPreview : OpenGlWidget {
nvgBeginPath(args.vg);
nvgRect(args.vg, 0.0f, 0.0f, box.size.x, box.size.y);
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);
nvgFill(args.vg);
}