Custom draw function for curve to show the form and not just name

Draw the curve as well as the name of curve. Could be optimised a bit by not evaluating the curve every pixel, but something like every third pixel. Could also draw dots instead of lines if we need extra speed.
This commit is contained in:
Mikael Degerfält 2019-06-26 17:50:34 +02:00
parent 5d333432ce
commit faf4f528b3
3 changed files with 35 additions and 16 deletions

View file

@ -157,7 +157,7 @@ static const unsigned short curveM4[] = {0,4300,7000,8700,9900,10950,11900,12600
static const unsigned short curveM3[] = {0,2900,5100,6650,8200,9500,10550,11500,12300,13100,13800,14450,14950,15350,15750,16150,16383};
static const unsigned short curveM2[] = {0,2000,3600,5000,6450,7850,9000,10100,11100,12100,12900,13700,14400,14950,15500,16000,16383};
static const unsigned short curveM1[] = {0,1400,2850,4100,5300,6450,7600,8700,9800,10750,11650,12600,13350,14150,14950,15650,16383};
static const unsigned short curveIn[] = {0,1023,2047,3071,4095,5119,6143,7167,8191,9215,10239,11263,12287,13311,14335,15359,16383};
const unsigned short curveIn[] = {0,1023,2047,3071,4095,5119,6143,7167,8191,9215,10239,11263,12287,13311,14335,15359,16383};
static const unsigned short curveP1[] = {0,600,1350,2150,2900,3800,4700,5600,6650,7700,8800,9900,11100,12300,13500,14850,16383};
static const unsigned short curveP2[] = {0,400,800,1300,2000,2650,3500,4300,5300,6250,7400,8500,9600,11050,12400,14100,16383};
static const unsigned short curveP3[] = {0,200,500,900,1300,1800,2350,3100,3800,4600,5550,6550,8000,9500,11250,13400,16383};
@ -172,8 +172,8 @@ static const unsigned short curveZ2[] = {0,2000,3200,3800,4096,4800,5100,5900,66
const unsigned short* const curves[] = {
curveM4, curveM3, curveM2, curveM1, curveIn, curveP1, curveP2,
curveP3, curveP4 , curveS1, curveS2, curveZ1, curveZ2 };
curveP3, curveP4 , curveS1, curveS2, curveZ1, curveZ2
};
int vibThr; // this gets auto calibrated in setup
int vibThrLo;

View file

@ -26,6 +26,9 @@
#define DNWD 0
extern const unsigned short* const curves[];
extern const unsigned short curveIn[];
extern unsigned short breathThrVal;
extern unsigned short breathMaxVal;
extern unsigned short portamThrVal;
@ -110,4 +113,6 @@ extern byte halfPitchBendKey;
extern byte specialKey;
extern byte pinkyKey;
extern unsigned int multiMap(unsigned short val, const unsigned short * _in, const unsigned short * _out, uint8_t size);
#endif

View file

@ -1,14 +1,16 @@
#include "menu.h"
#include "hardware.h"
#include "config.h"
#include "globals.h"
#include "midi.h"
#include <EEPROM.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_MPR121.h>
#include <Arduino.h>
#include "menu.h"
#include "settings.h"
#include "hardware.h"
#include "config.h"
#include "globals.h"
#include "midi.h"
#include "numenu.h"
enum CursorIdx {
@ -600,15 +602,27 @@ const MenuEntrySub velocityMenu = {
, nullptr
};
static void curveCustomDraw(SubMenuRef __unused, char* __unused out, const char** __unused unit) {
const char* curveMenuLabels[] = {"-4", "-3", "-2", "-1", "LIN", "+1", "+2",
"+3", "+4", "S1", "S2", "Z1", "Z2" };
int y0 = 0, x0 = 0;
int scale = ((1<<14)-1)/60;
for(int x = x0; x < 60; x+=1) {
int y = multiMap(x*scale, curveIn, curves[curve], 17);
y = (y*37) / ((1<<14)-1);
display.drawLine(x0 + 65, 60 - y0, x + 65, 60 - y, WHITE);
x0 = x; y0 = y;
}
display.setCursor(125 - 3*6, 60-8 );
display.setTextSize(0);
display.print(curveMenuLabels[curve]);
}
static void curveWriteSettings(const MenuEntrySub & __unused sub){ writeSetting(BREATHCURVE_ADDR,curve); }
const MenuEntrySub curveMenu = {
MenuType::ESub, "CURVE", "CURVE", &curve, 0, 12, MenuEntryFlags::EMenuEntryWrap,
[](SubMenuRef __unused, char* out, const char** __unused unit) {
const char* curveMenuLabels[] = {"-4", "-3", "-2", "-1", "LIN", "+1", "+2",
"+3", "+4", "S1", "S2", "Z1", "Z2" };
strncpy(out, curveMenuLabels[curve], 4);
},
[](const MenuEntrySub & __unused sub){ writeSetting(BREATHCURVE_ADDR,curve); }
, nullptr
MenuType::ESub, "CURVE", "CURVE", &curve, 0, 12, MenuEntryFlags::EMenuEntryWrap | MenuEntryFlags::EMenuEntryCustom,
curveCustomDraw, curveWriteSettings, nullptr
};
const MenuEntrySub velSmpDlMenu = {