From 1145822a2e160fe44f521f2050ea678a0b72c3db Mon Sep 17 00:00:00 2001 From: David Huss <dh@atoav.com> Date: Sun, 12 Nov 2023 21:22:24 +0100 Subject: [PATCH] Make show description generic --- code/daisy-looper/button_grid.h | 60 +++++++++------- code/daisy-looper/ui.h | 123 +++++++++++++++----------------- 2 files changed, 91 insertions(+), 92 deletions(-) diff --git a/code/daisy-looper/button_grid.h b/code/daisy-looper/button_grid.h index d844d6a..d183739 100644 --- a/code/daisy-looper/button_grid.h +++ b/code/daisy-looper/button_grid.h @@ -31,7 +31,7 @@ class GridButton { public: const char* name; const char* description; - GridButton(const char* name, Button& button, bool is_home=false, ButtonType type=BUTTON_TYPE_SIMPLE, int default_value=0, const char* description="") + GridButton(const char* name, Button *button, bool is_home=false, ButtonType type=BUTTON_TYPE_SIMPLE, int default_value=0, const char* description="") : name(name), button(button), @@ -46,7 +46,7 @@ class GridButton { ++lines; } } - Button button; + Button *button; ButtonType type; bool is_home; bool should_render_description = false; @@ -90,30 +90,38 @@ class ButtonGrid { GridButton grid_buttons_[6]; int ui_mode; - // void setup(Ui ui) { - // for (int n=0; n<6; n++) { - // // If this is the home button setup callbacks - // if (grid_buttons_[n].is_home) { - // // When homebutton is held switch to this UI Mode - // grid_buttons_[n].button.onHold([ui, n](){ ui->setMode(ui_mode); }); - // // When homebutton is released hide ALL button descriptions - // grid_buttons_[n].button.onReleased([ui, n](){ - // ui->setMode(UI_MODE_DEFAULT); - // for (int i=0; i<6; i++) { - // grid_buttons_[i].should_render_description = false; - // } - // }); - // } else { - // // Not a home button, display help on long hold and hide on release - // grid_buttons_[n].button.onLongHold([ui, n](){ - // grid_buttons_[n].should_render_description = true; - // }); - // grid_buttons_[n].button.onReleased([ui, n](){ - // grid_buttons_[n].should_render_description = false; - // }); - // } - // } - // } + void setup() { + Serial.println("Running Setup for ButtonGrid"); + for (int n=0; n<6; n++) { + // If this is the home button setup callbacks + if (grid_buttons_[n].is_home) { + Serial.print("Home button "); + Serial.println(n); + // // When homebutton is held switch to this UI Mode + // grid_buttons_[n].button.onHold([ui, n](){ ui->setMode(ui_mode); }); + // // When homebutton is released hide ALL button descriptions + // grid_buttons_[n].button.onReleased([ui, n](){ + // ui->setMode(UI_MODE_DEFAULT); + // for (int i=0; i<6; i++) { + // grid_buttons_[i].should_render_description = false; + // } + // }); + } else { + Serial.println(n); + // Not a home button, display help on long hold and hide on release + grid_buttons_[n].button->onLongHold([this, n](){ + // TODO: Doesn't register for some reason? + Serial.println("Show DESCROOOTT"); + grid_buttons_[n].should_render_description = true; + }); + grid_buttons_[n].button->onReleased([this, n](){ + // TODO: Doesn't register for some reason? + Serial.println("NOPE"); + grid_buttons_[n].should_render_description = false; + }); + } + } + } void render(int button_enum) { int width = display.width(); diff --git a/code/daisy-looper/ui.h b/code/daisy-looper/ui.h index 0e1e3ea..0cceec3 100644 --- a/code/daisy-looper/ui.h +++ b/code/daisy-looper/ui.h @@ -66,36 +66,36 @@ class Ui { public: Ui() : button_grids { ButtonGrid((int) UI_MODE_REC_MENU, { - GridButton("REC\nMENU", button_1, true), - GridButton("MOM\nTOGGLE", button_2, false, BUTTON_TYPE_TOGGLE, 0, "REC/OVERDUB BUTTONS\n\nMOM->Record while \n Button is held\n\nTOGGLE->Press once to\n start, press \n again to stop"), - GridButton("PRE\nPOST\nOUT\nNOISE", button_3, false, BUTTON_TYPE_MULTITOGGLE, 0, "REC/OVERDUB SOURCE\n\nPRE----->Direct Input\nPOST---->With Effects\nOUT---->Looper Output\nNOISE--->Noise Source"), - GridButton("FULL\nLOOP\nSHOT", button_4, false, BUTTON_TYPE_MULTITOGGLE, 1, "RECORDING REGION\n\nFULL---->Whole Buffer\nLOOP----->Loop Bounds\nSHOT->Full Buffer but\n stop at the end"), - GridButton("NORMAL\nPITCHD\nUNPTCH", button_5, false, BUTTON_TYPE_MULTITOGGLE, 0, "SPEED OF THE REC HEAD\n\nNORMAL--->Fixed Speed\nPITCHD->Inverse Playh\nUNPITCH----->Playhead\n Speed"), - GridButton("START\nLOOPST\nPLAYHD", button_6, false, BUTTON_TYPE_MULTITOGGLE, 0, "START RECORDING AT\n\nSTART--->Start of the\n Buffer\nLOOP---->Start of the\n Loop\nPLAYH--->Position of\n the Playhead"), + GridButton("REC\nMENU", &button_1, true), + GridButton("MOM\nTOGGLE", &button_2, false, BUTTON_TYPE_TOGGLE, 0, "REC/OVERDUB BUTTONS\n\nMOM->Record while \n Button is held\n\nTOGGLE->Press once to\n start, press \n again to stop"), + GridButton("PRE\nPOST\nOUT\nNOISE", &button_3, false, BUTTON_TYPE_MULTITOGGLE, 0, "REC/OVERDUB SOURCE\n\nPRE----->Direct Input\nPOST---->With Effects\nOUT---->Looper Output\nNOISE--->Noise Source"), + GridButton("FULL\nLOOP\nSHOT", &button_4, false, BUTTON_TYPE_MULTITOGGLE, 1, "RECORDING REGION\n\nFULL---->Whole Buffer\nLOOP----->Loop Bounds\nSHOT->Full Buffer but\n stop at the end"), + GridButton("NORMAL\nPITCHD\nUNPTCH", &button_5, false, BUTTON_TYPE_MULTITOGGLE, 0, "SPEED OF THE REC HEAD\n\nNORMAL--->Fixed Speed\nPITCHD->Inverse Playh\nUNPITCH----->Playhead\n Speed"), + GridButton("START\nLOOPST\nPLAYHD", &button_6, false, BUTTON_TYPE_MULTITOGGLE, 0, "START RECORDING AT\n\nSTART--->Start of the\n Buffer\nLOOP---->Start of the\n Loop\nPLAYH--->Position of\n the Playhead"), }), ButtonGrid((int) UI_MODE_PLAY_MENU, { - GridButton("LOOP", button_1, false), - GridButton("PLAY\nMENU", button_2, true), - GridButton("WINDOW", button_3, false), - GridButton("DRUNK", button_4, false), - GridButton("GRAIN", button_5, false), - GridButton("SHOT", button_6, false), + GridButton("LOOP", &button_1, false), + GridButton("PLAY\nMENU", &button_2, true), + GridButton("WINDOW", &button_3, false), + GridButton("DRUNK", &button_4, false), + GridButton("GRAIN", &button_5, false), + GridButton("SHOT", &button_6, false), }), ButtonGrid((int) UI_MODE_TRIGGER_MENU, { - GridButton("MIDI\nTRIG.", button_1, false), - GridButton("MIDI\nUNMUTE", button_2, false), - GridButton("TRIG.\nMENU", button_3, true), - GridButton("MANUAL\nTRIG.", button_4, false), - GridButton("MANUAL\nUNMUTE", button_5, false), - GridButton("AUTO", button_6, false), + GridButton("MIDI\nTRIG.", &button_1, false), + GridButton("MIDI\nUNMUTE", &button_2, false), + GridButton("TRIG.\nMENU", &button_3, true), + GridButton("MANUAL\nTRIG.", &button_4, false), + GridButton("MANUAL\nUNMUTE", &button_5, false), + GridButton("AUTO", &button_6, false), }), ButtonGrid((int) UI_MODE_FX_MENU, { - GridButton("DELAY", button_1, false), - GridButton("REVERB", button_2, false), - GridButton("-", button_3, false), - GridButton("-", button_4, false), - GridButton("-", button_5, false), - GridButton("FX\nMENU", button_6, true), + GridButton("DELAY", &button_1, false), + GridButton("REVERB", &button_2, false), + GridButton("-", &button_3, false), + GridButton("-", &button_4, false), + GridButton("-", &button_5, false), + GridButton("FX\nMENU", &button_6, true), }), } {}; @@ -234,17 +234,8 @@ class Ui { // Reset controls resetControls(); - // Stay in this menu as long as the button is pressed, otherwise return - button_1.onHold([this, n](){ this->setMode(UI_MODE_REC_MENU); }); - button_1.onReleased([this, n](){ - this->setMode(UI_MODE_DEFAULT); - button_grids[n].grid_buttons_[0].should_render_description = false; - button_grids[n].grid_buttons_[1].should_render_description = false; - button_grids[n].grid_buttons_[2].should_render_description = false; - button_grids[n].grid_buttons_[3].should_render_description = false; - button_grids[n].grid_buttons_[4].should_render_description = false; - button_grids[n].grid_buttons_[5].should_render_description = false; - }); + // Setup + button_grids[n].setup(); // Toggle between momentary and toggle recording modes button_2.onPress([this, n](){ @@ -289,46 +280,46 @@ class Ui { looper.setRecStartMode((atoav::RecStartMode) button_grids[n].grid_buttons_[5].active); }); - // Display descriptions on Long Hold: - button_2.onLongHold([this, n](){ - button_grids[n].grid_buttons_[1].should_render_description = true; - }); + // // Display descriptions on Long Hold: + // button_2.onLongHold([this, n](){ + // button_grids[n].grid_buttons_[1].should_render_description = true; + // }); - button_2.onReleased([this, n](){ - button_grids[n].grid_buttons_[1].should_render_description = false; - }); + // button_2.onReleased([this, n](){ + // button_grids[n].grid_buttons_[1].should_render_description = false; + // }); - button_3.onLongHold([this, n](){ - button_grids[n].grid_buttons_[2].should_render_description = true; - }); + // button_3.onLongHold([this, n](){ + // button_grids[n].grid_buttons_[2].should_render_description = true; + // }); - button_3.onReleased([this, n](){ - button_grids[n].grid_buttons_[2].should_render_description = false; - }); + // button_3.onReleased([this, n](){ + // button_grids[n].grid_buttons_[2].should_render_description = false; + // }); - button_4.onLongHold([this, n](){ - button_grids[n].grid_buttons_[3].should_render_description = true; - }); + // button_4.onLongHold([this, n](){ + // button_grids[n].grid_buttons_[3].should_render_description = true; + // }); - button_4.onReleased([this, n](){ - button_grids[n].grid_buttons_[3].should_render_description = false; - }); + // button_4.onReleased([this, n](){ + // button_grids[n].grid_buttons_[3].should_render_description = false; + // }); - button_5.onLongHold([this, n](){ - button_grids[n].grid_buttons_[4].should_render_description = true; - }); + // button_5.onLongHold([this, n](){ + // button_grids[n].grid_buttons_[4].should_render_description = true; + // }); - button_5.onReleased([this, n](){ - button_grids[n].grid_buttons_[4].should_render_description = false; - }); + // button_5.onReleased([this, n](){ + // button_grids[n].grid_buttons_[4].should_render_description = false; + // }); - button_6.onLongHold([this, n](){ - button_grids[n].grid_buttons_[5].should_render_description = true; - }); + // button_6.onLongHold([this, n](){ + // button_grids[n].grid_buttons_[5].should_render_description = true; + // }); - button_6.onReleased([this, n](){ - button_grids[n].grid_buttons_[5].should_render_description = false; - }); + // button_6.onReleased([this, n](){ + // button_grids[n].grid_buttons_[5].should_render_description = false; + // }); // Store the last ui mode, for the check on top -- GitLab