First iteration of menu cleanup

* Broke up the code into more general functions instead of duplicating code
 * Made stuff const and removed variables no longer used
 * Use defines for menu button values
 * Changed the order or things to avoid forward declarations
 * Use array lookup instead of switch-case on some menu options
 * Adjust menu functionification
 * Cleaned up sensor rendering
This commit is contained in:
Mikael Degerfält 2019-06-09 16:47:13 +02:00
parent 435ad106d8
commit e362546e3c
6 changed files with 831 additions and 1428 deletions

View file

@ -86,28 +86,23 @@ int parallel = 7; // semitones
byte gateOpen = 0; // setting for gate always open, note on sent for every time fingering changes, no matter the breath status
int breathLoLimit = 0;
int breathHiLimit = 4095;
int portamLoLimit = 700;
int portamHiLimit = 4700;
int pitchbLoLimit = 500;
int pitchbHiLimit = 4000;
int extracLoLimit = 500;
int extracHiLimit = 4000;
int ctouchLoLimit = 50;
int ctouchHiLimit = 350;
int ttouchLoLimit = 50;
int ttouchHiLimit = 1900;
// MAybe move these to config.h (as defines?)
const int breathLoLimit = 0;
const int breathHiLimit = 4095;
const int portamLoLimit = 700;
const int portamHiLimit = 4700;
const int pitchbLoLimit = 500;
const int pitchbHiLimit = 4000;
const int extracLoLimit = 500;
const int extracHiLimit = 4000;
const int ctouchLoLimit = 50;
const int ctouchHiLimit = 350;
const int ttouchLoLimit = 50;
const int ttouchHiLimit = 1900;
int touch_Thr = 1300;
int breathStep;
int portamStep;
int pitchbStep;
int extracStep;
int ctouchStep;
byte ccList[11] = {0,1,2,7,11,1,2,7,11,74,20}; // OFF, Modulation, Breath, Volume, Expression (then same sent in hires), CC74 (cutoff/brightness), CC20
int pbDepthList[13] = {8192,8192,4096,2731,2048,1638,1365,1170,1024,910,819,744,683};
@ -371,12 +366,6 @@ void setup() {
slowMidi = dipSwBits & (1<<3);
activePatch = patch;
breathStep = (breathHiLimit - breathLoLimit)/92; // 92 is the number of pixels in the settings bar
portamStep = (portamHiLimit - portamLoLimit)/92;
pitchbStep = (pitchbHiLimit - pitchbLoLimit)/92;
extracStep = (extracHiLimit - extracLoLimit)/92;
ctouchStep = (ctouchHiLimit - ctouchLoLimit)/92;
touch_Thr = map(ctouchThrVal,ctouchHiLimit,ctouchLoLimit,ttouchLoLimit,ttouchHiLimit);
if (!touchSensor.begin(0x5A)) {

View file

@ -40,25 +40,20 @@ extern byte currentRotation;
extern int rotations[4];
extern int parallel; // semitones
extern int breathLoLimit;
extern int breathHiLimit;
extern int portamLoLimit;
extern int portamHiLimit;
extern int pitchbLoLimit;
extern int pitchbHiLimit;
extern int extracLoLimit;
extern int extracHiLimit;
extern int ctouchLoLimit;
extern int ctouchHiLimit;
extern int ttouchLoLimit;
extern int ttouchHiLimit;
extern const int breathLoLimit;
extern const int breathHiLimit;
extern const int portamLoLimit;
extern const int portamHiLimit;
extern const int pitchbLoLimit;
extern const int pitchbHiLimit;
extern const int extracLoLimit;
extern const int extracHiLimit;
extern const int ctouchLoLimit;
extern const int ctouchHiLimit;
extern const int ttouchLoLimit;
extern const int ttouchHiLimit;
extern int touch_Thr;
extern int breathStep;
extern int portamStep;
extern int pitchbStep;
extern int extracStep;
extern int ctouchStep;
extern unsigned long cursorBlinkTime; // the last time the cursor was toggled

File diff suppressed because it is too large Load diff

View file

@ -5,7 +5,7 @@
#define MENU_ROW_HEIGHT 9
#define MENU_HEADER_OFFSET 3
#define MENU_NUM_ROWS 5
//display states
#define DISPLAYOFF_IDL 0

115
NuEVI/numenu.cpp Normal file
View file

@ -0,0 +1,115 @@
/*
Notes on the original menu implementation
# Menus
## Main Menu
### Transpose
Sub menu with values -12 to 12.
### Octave
Sub menu with values -3 to +3
### MIDI CH
Sub menu with values 0 to 16. Should be 1 to 16, but there might be a bug
either in my simulation code, my changes to the menu or a bug in the original
menu.
### Adjust
This is a special option where the Adjust menu mode is entered. It take over
the display and draw horizontal indicators for threshold and such. More on
this in a later section.
### SETUP BR
Breath setup. Opens a new menu with breath specific stuff.
### SETUP CTL
Controls setup. Opens a new menu.
*/
#include <cstring>
#include <Adafruit_SSD1306.h>
#include "numenu.h"
#include "menu.h"
NuMenu::NuMenu(Adafruit_SSD1306& display)
: _display(display)
{
}
bool NuMenu::init()
{
// memset(_pageStack, 0, sizeof(_pageStack));
// _rootMenu = MenuPageState(root, 0, 0);
_enabled = false;
return true;
}
void NuMenu::update(uint16_t buttonState)
{
if(_enabled)
{
// int
}
}
extern Adafruit_SSD1306 display;
void NuMenu::drawMenuItems(const char* title, const char* entries[], int count, int selection, int offset)
{
//Initialize display and draw menu header + line
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println(title);
display.drawLine(0,MENU_ROW_HEIGHT,127,MENU_ROW_HEIGHT, WHITE);
int rowPixel = MENU_HEADER_OFFSET + MENU_ROW_HEIGHT;
for(int index = offset, count = 0; ((index-offset) < MENU_NUM_ROWS) && index < count; index++ )
{
// int rowPixel = (row+1)*MENU_ROW_HEIGHT + MENU_HEADER_OFFSET;
const char* lineText = entries[index];
display.setCursor(0,rowPixel);
rowPixel += (MENU_ROW_HEIGHT+1);
display.println(lineText);
}
// TODO: Fix cursor
// if(selection>=0)
// drawMenuCursor(selection, WHITE);
}
// This is for the SUB MENU
// void NuMenu::drawSelection(const char* title, const char* entries[], int count, int* selection)
// {
// _display.fillRect(63,11,64,52,BLACK);
// _display.drawRect(63,11,64,52,WHITE);
// _display.setTextColor(WHITE);
// _display.setTextSize(1);
// _display.setCursor(68,15);
// _display.println(title);
// const char* entryTxt = entries[*selection];
// int len = strlen(entryTxt);
// _display.setTextSize(2);
// _display.setCursor(91 - 4*len,33);
// _display.println(entryTxt);
// _display.display();
// }

31
NuEVI/numenu.h Normal file
View file

@ -0,0 +1,31 @@
#ifndef __NUMENU_H
#define __NUMENU_H
#include <cstdint>
#include <functional>
#define MAX_DEPTH 16
class Adafruit_SSD1306;
class NuMenu
{
public:
NuMenu(Adafruit_SSD1306 &gfx);
bool init();
void update(uint16_t buttonState);
void setEnabled(bool state) { _enabled = state; }
static void drawMenuItems(const char* title, const char* entries[], int count, int selection, int offset = 0);
private:
bool _enabled;
// MenuPageState _rootMenu;
// MenuPageState _pageStack[MAX_DEPTH];
Adafruit_SSD1306 &_display;
};
#endif