Hello!
I could use some help on a fairly trivial C++ problem. I’ve never really dealt with enum arrays before, but I want to learn. I’m working on my groovebox module, which has a virtual LCD screen. I want to track which state the LCD screen is in. It might display track name, or perhaps other stuff.
My current code is horrible. It looked like:
bool show_sample_visualizer = false;
bool show_ratchet_visualizer = false;
bool show_updates_visualizer = false;
I would use these variables to decide what to display.
I would prefer to have a single variable called something like “lcd_mode”.
That might look like:
if(lcd_mode == 0) then {{ show default }}
if(lcd_mode == 1) then {{ show sample visualizer }}
if(lcd_mode == 2) then {{ show ratchet visualizer }}
I could use defines to change the above to…
#define LCD_MODE_DEFAULT 0
#define LCD_MODE_SAMPLE_VISUALIZER 1
#define LCD_MODE_RATCHET_VISUALIZER 2
if(lcd_mode == LCD_MODE_DEFAULT) then {{ show default }}
if(lcd_mode == LCD_MODE_SAMPLE_VISUALIZER) then {{ show sample visualizer }}
if(lcd_mode == LCD_MODE_RATCHET_VISUALIZER) then {{ show ratchet visualizer }}
This is a step in the right direction.
Would it be better if I did something like…
enum lcd_modes {
DEFAULT,
SAMPLE,
RATCHET,
};
if(lcd_mode == lcd_modes[DEFAULT]) then {{ show default }}
if(lcd_mode == lcd_modes[SAMPLE]) then {{ show sample visualizer }}
if(lcd_mode == lcd_modes[RATCHET]) then {{ show ratchet visualizer }}
?? If so, I could use some help with the syntax, as I’m getting errors like:
src/GrooveBox/GrooveBox.hpp:197:32: error: expected primary-expression before ‘[’ token 197 | lcd_screen_mode = lcd_modes [DEFAULT];
Thanks!