mirror of
				https://github.com/AquaMorph/Droplets.git
				synced 2025-10-30 16:13:20 +00:00 
			
		
		
		
	Spinner based menu
This commit is contained in:
		 Submodule lib/libDaisy updated: 504f10264c...2cfc8f7f39
									
								
							
							
								
								
									
										59
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										59
									
								
								src/main.cpp
									
									
									
									
									
								
							| @@ -1,6 +1,7 @@ | |||||||
| #include "daisysp.h" | #include "daisysp.h" | ||||||
| #include "daisy_patch.h" | #include "daisy_patch.h" | ||||||
|  |  | ||||||
|  | #include <algorithm> | ||||||
| #include <string> | #include <string> | ||||||
|  |  | ||||||
| #include "main.h" | #include "main.h" | ||||||
| @@ -10,18 +11,33 @@ using namespace daisysp; | |||||||
|  |  | ||||||
| DaisyPatch patch; | DaisyPatch patch; | ||||||
|  |  | ||||||
| const int MENU_SIZE = 7; | const int MENU_SIZE = 8; | ||||||
|  | const int MAX_CHAR_LENGTH = 15; | ||||||
| std::string menuItems[MENU_SIZE]; | std::string menuItems[MENU_SIZE]; | ||||||
|  | const int MENU_X[] = {0,  5,  10,  5,  0}; | ||||||
|  | const int MENU_Y[] = {0, 11, 22, 41, 52}; | ||||||
| int selectedMenuItem = 0; | int selectedMenuItem = 0; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | void DrawSolidRect(uint8_t x1, | ||||||
|  | 		   uint8_t y1, | ||||||
|  | 		   uint8_t x2, | ||||||
|  | 		   uint8_t y2, | ||||||
|  | 		   bool on) { | ||||||
|  |   for (int i = std::min(y1, y2); i <= std::max(y1, y2); i++) { | ||||||
|  |     patch.display.DrawLine(x1, i, x2, i, on); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
| void SetupMenu() { | void SetupMenu() { | ||||||
|   menuItems[0] = "VCO"; |   menuItems[0] = "VCO"; | ||||||
|   menuItems[1] = "VCA"; |   menuItems[1] = "VCA"; | ||||||
|   menuItems[2] = "Envelope"; |   menuItems[2] = "Envelope"; | ||||||
|   menuItems[3] = "LFO"; |   menuItems[3] = "LFO"; | ||||||
|   menuItems[4] = "Logic"; |   menuItems[4] = "Logic"; | ||||||
|   menuItems[5] = "Delay"; |   menuItems[5] = "Noise"; | ||||||
|   menuItems[6] = "Reverb"; |   menuItems[6] = "Delay"; | ||||||
|  |   menuItems[7] = "Reverb"; | ||||||
| } | } | ||||||
|  |  | ||||||
| int main(void) { | int main(void) { | ||||||
| @@ -35,39 +51,50 @@ int main(void) { | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| void FilterMenu() { | void FilterMenuSelection() { | ||||||
|   if (selectedMenuItem >= MENU_SIZE) { |   if (selectedMenuItem >= MENU_SIZE) { | ||||||
|     selectedMenuItem = 0; |  | ||||||
|   } else if (selectedMenuItem < 0) { |  | ||||||
|     selectedMenuItem = MENU_SIZE - 1; |     selectedMenuItem = MENU_SIZE - 1; | ||||||
|  |   } else if (selectedMenuItem < 0) { | ||||||
|  |     selectedMenuItem = 0; | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | std::string FilterMenuText(int position) { | ||||||
|  |   if (position >= MENU_SIZE || position < 0) { | ||||||
|  |     return ""; | ||||||
|  |   } else { | ||||||
|  |     return menuItems[position]; | ||||||
|  |   } | ||||||
|  | } | ||||||
| void ProcessControls() { | void ProcessControls() { | ||||||
|   patch.UpdateAnalogControls(); |   patch.UpdateAnalogControls(); | ||||||
|   patch.DebounceControls(); |   patch.DebounceControls(); | ||||||
|   selectedMenuItem += patch.encoder.Increment(); |   selectedMenuItem -= patch.encoder.Increment(); | ||||||
|   FilterMenu(); |   FilterMenuSelection(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void ProcessOutputs() {} | void ProcessOutputs() {} | ||||||
|  |  | ||||||
| void CreateMenuItem(std::string text, int position, bool highlighted) { | void CreateMenuItem(std::string text, int position, bool highlighted) { | ||||||
|   char* cstr = &text[0]; |   char* cstr = &text[0]; | ||||||
|   patch.display.SetCursor(0, (position-1)*10); |   text.insert(text.end(), MAX_CHAR_LENGTH-text.size(), ' '); | ||||||
|  |   patch.display.SetCursor(MENU_X[position-1], MENU_Y[position-1]); | ||||||
|  |   if (highlighted) { | ||||||
|  |     patch.display.WriteString(cstr, Font_11x18, !highlighted); | ||||||
|  |   } else { | ||||||
|     patch.display.WriteString(cstr, Font_7x10, !highlighted); |     patch.display.WriteString(cstr, Font_7x10, !highlighted); | ||||||
|   } |   } | ||||||
|  |   //DrawSolidRect(text.size()*7, (position-1)*10, text.size()*7+21, position*10, false); | ||||||
|  | } | ||||||
|  |  | ||||||
| void ProcessOled() { | void ProcessOled() { | ||||||
|   patch.display.Fill(false); |   patch.display.Fill(false); | ||||||
|  |  | ||||||
|   CreateMenuItem(std::to_string(selectedMenuItem) + " " + |   CreateMenuItem(FilterMenuText(selectedMenuItem-2), 1, false); | ||||||
| 		 menuItems[selectedMenuItem], 1, false); |   CreateMenuItem(FilterMenuText(selectedMenuItem-1), 2, false); | ||||||
|   CreateMenuItem("Item 2", 2, false); |   CreateMenuItem(FilterMenuText(selectedMenuItem), 3, true); | ||||||
|   CreateMenuItem("Item 3", 3, false); |   CreateMenuItem(FilterMenuText(selectedMenuItem+1), 4, false); | ||||||
|   CreateMenuItem("Item 4", 4, false); |   CreateMenuItem(FilterMenuText(selectedMenuItem+2), 5, false); | ||||||
|   CreateMenuItem("Item 5", 5, false); |  | ||||||
|   CreateMenuItem("Item 6", 6, false); |  | ||||||
|    |    | ||||||
|   patch.display.Update(); |   patch.display.Update(); | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user