Advertisement
Antyos

Modutar 2 - Menu System Issues

Jul 3rd, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 24.68 KB | None | 0 0
  1. /** MenuStructure.h
  2.  * Provides the structure of the menu system. It uses a system of #define statements to create
  3.  * a menu structure. This system is based on the menu system found in the Marlin firmware in
  4.  * ultralcd.h file.
  5.  *
  6.  * Written by Andrew Glick (12/31/2018).
  7.  *
  8.  *
  9.  */
  10.  
  11. #ifndef menustructure_h_
  12. #define menustructure_h_
  13.  
  14. #include "Menus.h"
  15. #include "Display.h"
  16. #include "lang.h"
  17. #include "config.h"
  18. #include <Adafruit_GFX.h>
  19. #include <Adafruit_SSD1306.h>
  20. #include "SerialDebug.h"
  21.  
  22. #define ROW_SELECTED '>'
  23. #define ROW_NORMAL   ' '
  24.  
  25. typedef __uint8_t uint8_t;
  26. typedef void (*menuFunc_t)(); //Function pointer to menu functions.
  27.  
  28. uint8_t cursorPos;
  29. // uint8_t lastCursorPos;
  30. bool cvFwd;
  31. bool redrawMenu;
  32. uint8_t currentViewOffset;
  33.  
  34. static char str[16];
  35. const  int  strLen = 16;
  36. static char buffer[8];
  37.  
  38. inline int numDigits8(uint8_t n) { return ((n < 10) ? 1 : (n < 100) ? 2 : 3); } // Returns the number of digits in an 8-bit number
  39.  
  40. //*******************************************************************
  41. // Function to draw a standard menu line with a value on the right
  42. void draw_menu_generic(uint8_t row, const char* label, char preChar, const char* value, uint8_t valCharOffset, bool cv)
  43. {
  44.     oled.setCursor(0, row * CHAR_HEIGHT);
  45.     if (!cv) oled.print(preChar);
  46.     else     oled.print(" ");
  47.     oled.print(" ");
  48.     oled.print(label);
  49.     oled.print(":");
  50.     //Serial.print(label);
  51.    
  52.     oled.setCursor(valCharOffset * CHAR_WIDTH, row * CHAR_HEIGHT);
  53.     if (cv) oled.print(preChar);
  54.     else    oled.print(" ");
  55.     oled.print(value);
  56. }
  57.  
  58. //*******************************************************************
  59. // Function to draw a menu line with a specific character on the right
  60. void draw_menu_char(uint8_t row, const char* label, char preChar, int value, uint8_t valCharOffset)
  61. {
  62.     oled.setCursor(0, row * CHAR_HEIGHT);
  63.     oled.print(preChar);
  64.     oled.print(" ");
  65.     oled.print(label);
  66.     //oled.print(":");
  67.        
  68.     oled.setCursor(valCharOffset * CHAR_WIDTH, row * CHAR_HEIGHT);
  69.     oled.write(value);
  70. }
  71.  
  72. //*******************************************************************//
  73. //                      Get string functions                         //
  74. //*******************************************************************//
  75.  
  76. // Clear the str buffer by filling it with spaces
  77. void clrStr() { for(int i = 0; i < strLen - 1; i++) str[i] = 0; }
  78.  
  79. char* uiToStr(uint8_t x) // unsigned int to string
  80. {
  81.     clrStr();
  82.     (x >= 100) ? str[0] = (x / 100) % 10 + '0' : str[0] = ' '; // set the 100's place if x >= 100
  83.     (x >= 10)  ? str[1] = (x / 10)  % 10 + '0' : str[1] = ' '; // set the 10's place if x >= 10
  84.                  str[2] = (x % 10) + '0';                      // set the 1's place
  85.                  str[3] = ' ';
  86.     return str;
  87. }
  88.  
  89. char* siToStr(int8_t x) // signed int to string
  90. {
  91.     clrStr();
  92.     int xx = abs(x);
  93.     int digits = numDigits8(xx);                                          // Get the number of digits to place the negative sign
  94.                   str[0] = ' ';                                           // Clear the first character
  95.     (xx >= 100) ? str[1] = (char) ((xx / 100) % 10) + '0' : str[1] = ' '; // set the 100's place if x >= 100
  96.     (xx >= 10)  ? str[2] = (char) ((xx / 10)  % 10) + '0' : str[2] = ' '; // set the 10's place if x >= 10
  97.                   str[3] = (char) (xx % 10) + '0';                        // set the 1's place
  98.     if (x < 0)    str[3 - digits] = '-';                                  // set the appropriate character to '-' if the number is negative
  99.     return str;
  100. }
  101.  
  102. char* cuiToStr(uint8_t x, const char* c) // character + unsigned int to char
  103. {
  104.     clrStr();
  105.     strcpy(buffer, c);
  106.     if (x == 0) return buffer;
  107.     else return uiToStr(x);
  108. }
  109.  
  110. char* percentToStr(uint8_t x) // unsigned int (as percent) to string
  111. {
  112.     clrStr();
  113.     (x >= 100) ? str[0] = (x / 100) % 10 + '0' : str[0] = ' '; // set the 100's place if x >= 100
  114.     (x >= 10)  ? str[1] = (x / 10)  % 10 + '0' : str[1] = ' '; // set the 10's place if x >= 10
  115.                  str[2] = (x % 10) + '0';                        // set the 1's place
  116.                  str[3] = '%';
  117.     return str;
  118. }
  119.  
  120. char* noteToStr(uint8_t note)
  121. {
  122.     static const char* noNote = "    None";
  123.     if (note >= 128) return (char*) noNote;      // If the note is too large, return "None";
  124.  
  125.     clrStr();
  126.     strcpy(str, note_table[note % 12]); // Copy over the note name
  127.     str[6] = ' ';                       // Add a space
  128.     str[7] = (note / 12) + 1 + '0';     // Set the octave
  129.  
  130.     return str;
  131. }
  132.  
  133.  
  134. // Definitions for each row type
  135. #define draw_menu(row, label, value, cursor)             draw_menu_generic(row, label, cursor, value, 10, cvFwd)
  136. #define draw_menu_submenu(row, label, value, cursor)     draw_menu_char(row, label, cursor, 26, DISPLAY_MENU_OFFSET)
  137. #define draw_menu_back(row, label, value, cursor)        draw_menu_char(row, label, cursor, 27, DISPLAY_MENU_OFFSET)
  138. #define draw_menu_toggle(row, label, value, cursor)      draw_menu_char(row, label, cursor, ' ', 17)
  139. #define draw_menu_function(row, label, value, cursor)    draw_menu_char(row, label, cursor, '*', DISPLAY_MENU_OFFSET)
  140.  
  141. #define draw_menu_value(row, label, value, cursor)       draw_menu_generic(row, label, cursor, uiToStr(value), DISPLAY_VALUE_OFFSET, cvFwd)
  142. #define draw_menu_tf(row, label, value, cursor)          draw_menu_generic(row, label, cursor, tf_table[value], DISPLAY_TF_OFFSET, cvFwd)
  143. #define draw_menu_percent(row, label, value, cursor)     draw_menu_generic(row, label, cursor, percentToStr(value), DISPLAY_PERCENT_OFFSET, cvFwd)
  144. #define draw_menu_off8(row, label, value, cursor)        draw_menu_generic(row, label, cursor, cuiToStr(value, str_off), DISPLAY_OFF8_OFFSET, cvFwd)
  145. #define draw_menu_off24(row, label, value, cursor)       draw_menu_generic(row, label, cursor, cuiToStr(value, str_off), DISPLAY_OFF24_OFFSET, cvFwd)
  146. #define draw_menu_u64(row, label, value, cursor)         draw_menu_generic(row, label, cursor, uiToStr(value), DISPLAY_U6_OFFSET, cvFwd)
  147. #define draw_menu_u127(row, label, value, cursor)        draw_menu_generic(row, label, cursor, uiToStr(value), DISPLAY_U6_OFFSET, cvFwd)
  148. #define draw_menu_u255(row, label, value, cursor)        draw_menu_generic(row, label, cursor, uiToStr(value), DISPLAY_U8_OFFSET, cvFwd)
  149. #define draw_menu_s127(row, label, value, cursor)        draw_menu_generic(row, label, cursor, siToStr(value), DISPLAY_S8_OFFSET, cvFwd)
  150. #define draw_menu_note(row, label, value, cursor)        draw_menu_generic(row, label, cursor, note_table[value], DISPLAY_NOTE_OFFSET, cvFwd)
  151. #define draw_menu_noteVal(row, label, value, cursor)     draw_menu_generic(row, label, cursor, noteToStr(value), DISPLAY_NOTE_OFFSET - 2, cvFwd)
  152. #define draw_menu_noteDiv(row, label, value, cursor)     draw_menu_generic(row, label, cursor, noteDiv_table[value], DISPLAY_NOTEDIV_OFFSET, cvFwd)
  153. #define draw_menu_mode(row, label, value, cursor)        draw_menu_generic(row, label, cursor, mode_table[value], DISPLAY_MODE_OFFSET, cvFwd)
  154. #define draw_menu_wave(row, label, value, cursor)        draw_menu_generic(row, label, cursor, wave_table[value], DISPLAY_WAVE_OFFSET, cvFwd)
  155.  
  156. // Menu Type declerations for MENU_ITEM_EDIT_NEW
  157. //                                            -------- display --------
  158. //                   min,   max,   rate,       display,   type,  width
  159. #define __value_t      0,   255,      1,       uiToStr,   func,      3
  160. #define __tf_t         0,     1       1,      tf_table,  array,      6
  161. #define __off8_t       0,     8,      1,       uiToStr,   func,      3
  162. #define __off24_t      0,    24,      1,       uiToStr,   func,      3
  163. #define __percent_t    0,   100,      5,  percentToStr,   func,      4
  164. #define __u64_t        0,    64,      1,       uiToStr,   func,      3
  165. #define __u127_t       0,   127,      4,       uiToStr,   func,      3
  166. #define __u255_t       0,   255,      5,       uiToStr,   func,      3
  167. #define __s127_t    -128,   127,      5,       siToStr,   func,      4
  168. #define __noteVal_t    0,   127,      1,     noteToStr,   func,      8
  169. #define __noteDiv_t    0,     7,      1, noteDiv_table,  array,      noteDivLen
  170. #define __note_t       0,    11,      1,    note_table,  array,      6
  171. #define __mode_t       0, numModes-1, 1,    mode_table,  array,     11
  172. #define __wave_t       0,     6,      1,    wave_table,  array,      7
  173.  
  174. // For off8: (x == 0) ? "Off" : uiToStr(x);
  175.  
  176. /* Types of menu actions */
  177. #define toggle_cvFwd cvFwd = !cvFwd
  178. #define menu_action_function(function) function();
  179. void menu_action_toggle(bool b) { b = !b; }
  180. void menu_action_back(menuFunc_t data);
  181. void menu_action_submenu(menuFunc_t data);
  182.  
  183. // Menu system macros based on menu system macros from Marlin firmware in ultralcd.h
  184. // Insert at end of 'if(!cvFwd)' for cursorPos debug:   Serial.print("cP: "); Serial.print(cursorPos);
  185. #define START_MENU()  do { \
  186.     oled.clearDisplay(); \
  187.     oled.setTextSize(1); \
  188.     oled.setTextColor(WHITE); \
  189.     if (cursorPos < currentViewOffset) { currentViewOffset = cursorPos; } /* Scroll up */ \
  190.     uint8_t lineNr = currentViewOffset, menuItemNr, cursorSkip = 0; \
  191.     bool buttonPressed = re.switchPressed(); \
  192.     redrawMenu |= buttonPressed; \
  193.     if (!cvFwd) { \
  194.         cursorPos += changeValue(cursorPos, range_value);\
  195.     } \
  196.     for(uint8_t drawLineNr = 0; drawLineNr < OLED_HEIGHT; drawLineNr++, lineNr++) { \
  197.         menuItemNr = 0; \
  198.         cursorSkip = 0; /* Disable cursor skip functionality*/ \
  199.         // debugPrint("Start");
  200.  
  201. #define MENU_ITEM(type, label, args) do { \
  202.         if(lineNr == menuItemNr) { \
  203.             debugPrint2("Ln#",lineNr);\
  204.             if (lineNr == cursorPos + cursorSkip) { \
  205.                 draw_menu_ ## type(drawLineNr, label, value, ROW_SELECTED);\
  206.             } \
  207.             else \
  208.                 draw_menu_ ## type(drawLineNr, label, value, ROW_NORMAL); \
  209.             if (buttonPressed && cursorPos + cursorSkip == lineNr) menu_action_ ## type(args); \
  210.         }\
  211.         menuItemNr++; \
  212.     } while (0)
  213.  
  214. // New MENU_ITEM_EDIT macro:
  215. /* Notes:
  216.  *  draw_menu_generic(row, value, selected_bool, VALUE, VALUE OFFSET, cv )
  217.  *  changeValue(value, min, max, (rate))
  218.  *  Maybe have a struct for each type instead of a lot of function arguments
  219.  *  Offset should be from right
  220.  */
  221.  
  222. // Definitions for types of displays
  223. // Note: Move these elsewhere when done
  224. #define disp_array(display, value)  display[value]
  225. #define disp_func(display, value)   display(value)
  226. #define disp_char(display, value)   display
  227.  
  228. #define MENU_ITEM_EDIT_NEW(min, max, rate, display, displayType, width, label, value) do { \
  229.         if(lineNr == menuItemNr) \
  230.         { \
  231.         /*debugPrint2("Ln#",lineNr);*/\
  232.         /*min + max + rate + display + displayType + width + label + value; */\
  233.             if (lineNr == cursorPos + cursorSkip) \
  234.             { \
  235.                 draw_menu_generic(drawLineNr, label, ROW_SELECTED, disp_ ## displayType(display, value), OLED_WIDTH - width, cvFwd); \
  236.                 if (cvFwd) value += changeValue(value, min, max, rate);\
  237.             } \
  238.             else \
  239.                 draw_menu_generic(drawLineNr, label, ROW_NORMAL,   disp_ ## displayType(display, value), OLED_WIDTH - width, cvFwd); \
  240.             if (buttonPressed && cursorPos + cursorSkip == lineNr) toggle_cvFwd; \
  241.         }\
  242.         menuItemNr++; \
  243.     } while (0)
  244.  
  245. #define MENU_ITEM_EDIT(type, label, value) do { \
  246.         if(lineNr == menuItemNr) { \
  247.         /*debugPrint2("Ln#",lineNr);*/\
  248.             if (lineNr == cursorPos + cursorSkip) { \
  249.                 draw_menu_ ## type(drawLineNr, label, value, ROW_SELECTED);\
  250.                 if (cvFwd) value += changeValue(value, range_ ## type);\
  251.             } \
  252.             else \
  253.                 draw_menu_ ## type(drawLineNr, label, value, ROW_NORMAL); \
  254.             if (buttonPressed && cursorPos + cursorSkip == lineNr) toggle_cvFwd; \
  255.         }\
  256.         menuItemNr++; \
  257.     } while (0)
  258.  
  259. // Need to remove eventually
  260. #define MENU_ITEM_EDITS(type, label, value) do { \
  261.         if(lineNr == menuItemNr) { \
  262.         /*debugPrint2("Ln#",lineNr);*/\
  263.             if (lineNr == cursorPos + cursorSkip) { \
  264.                 draw_menu_ ## type(drawLineNr, label, value, ROW_SELECTED);\
  265.                 if (cvFwd) value += changeValueS(value, range_ ## type);\
  266.             } \
  267.             else \
  268.                 draw_menu_ ## type(drawLineNr, label, value, ROW_NORMAL); \
  269.             if (buttonPressed && cursorPos + cursorSkip == lineNr) toggle_cvFwd; \
  270.         }\
  271.         menuItemNr++; \
  272.     } while (0)
  273.  
  274. #define MENU_ITEM_DUMMY() do { if (lineNr == menuItemNr) { cursorSkip++; } menuItemNr++; } while (0)
  275. #define END_MENU() \
  276.         if (cursorPos >= menuItemNr) cursorPos = menuItemNr - 1; \
  277.         if (cursorPos + cursorSkip >= currentViewOffset + OLED_HEIGHT) { /* Scroll down */ \
  278.             currentViewOffset = cursorPos + cursorSkip - OLED_HEIGHT + 1; \
  279.             lineNr = currentViewOffset - 1; \
  280.             drawLineNr = -1; \
  281.         } \
  282.     } } while (0); \
  283.     oled.display()
  284.     //if (redrawMenu) { oled.display(); redrawMenu = false; }
  285. //End of Marlin based menu system macros
  286.  
  287. #endif
  288.  
  289. /** Menus.cpp
  290.  *
  291.  * Written by Andrew Glick (8/2/2018).
  292.  *
  293.  *
  294.  */
  295.  
  296. #include "Menus.h"
  297. #include "MenuStructure.h"
  298. #include "MenuVariables.h"
  299.  
  300. #include <Wire.h>
  301. #include <Adafruit_GFX.h>
  302. #include <Adafruit_SSD1306.h>
  303. #include "RotaryEncoder.h"
  304.  
  305. void (*cMenu)(void); // Pointer to function for active menu
  306.  
  307. RotaryEncoder re = RotaryEncoder();
  308.  
  309. /* Menus */
  310. void menu_splash();
  311. void menu_simple();
  312. void menu_main();
  313. void menu_voice1();
  314. void menu_presets();
  315. void menu_presets_key();
  316. void menu_presets_mode();
  317. void menu_sequence();
  318. void menu_settings();
  319.  
  320. //*******************************************************************
  321. // Equivalent of void setup() for the menu objects and such
  322. void beginMenus()
  323. {
  324.     oled.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR); // initialize with the I2C addr 0x3D (for the 128x64)
  325.     bl.attach(BUTTON_L_PIN, INPUT_PULLUP); // attach the lower buttons
  326.     bm.attach(BUTTON_M_PIN, INPUT_PULLUP);
  327.     br.attach(BUTTON_R_PIN, INPUT_PULLUP);
  328.  
  329.     re.begin(ROTENC_ADDR); // begin the rotarty encoder
  330.  
  331.     cMenu = menu_main; // set the current menu to menu_main
  332.  
  333.     menu_splash(); // splash the OLED
  334. }
  335.  
  336. //*******************************************************************
  337. // Function to change a value in a menu - For unsigned char
  338. int changeValue(int val, int boundMin, int boundMax, int rate)
  339. {
  340.     // Change 'val' based on how much the rotary encoder has changed
  341.     int change = re.getEncoderRotation() * rate;                // get how much the encoder has changed
  342.    
  343.     // Constrain "change" to bonuds
  344.     change = max(change, boundMin - val);
  345.     change = min(change, boundMax - val);
  346.  
  347.     // if (change != 0) redrawMenu = true; // If there is a change, redraw the menu
  348.  
  349.     // debugPrint(change);
  350.     return change;
  351. }
  352.  
  353. //*******************************************************************
  354. // Function to change a value in a menu - for signed char
  355. int8_t changeValueS(int8_t val, int boundMin, int boundMax, int rate)
  356. {
  357.     // Change 'val' based on how much the rotary encoder has changed
  358.     int change = re.getEncoderRotation();                // get how much the encoder has changed
  359.    
  360.     // Constrain "change"
  361.     change = max(change, boundMin - val);
  362.     change = min(change, boundMax - val);
  363.  
  364.     // debugPrint(change);
  365.     return change;
  366. }
  367.  
  368. //*******************************************************************
  369. // Function to change values | Uses buttons
  370. uint8_t changeValueB(uint8_t val, int boundMin, int boundMax, int rate)
  371. {
  372.     // Change 'val' based on button input
  373.     int change = 0;
  374.     if (bl.isPressed()) change -= rate;
  375.     if (br.isPressed()) change += rate;
  376.  
  377.     if (val + change < boundMin || val + change > boundMax) change = 0; // constrain it to bounds
  378.  
  379.     // debugPrint2("c:", change);
  380.  
  381.     return change;    
  382. }
  383.  
  384. //*******************************************************************
  385. //    MENUS
  386. //*******************************************************************
  387.  
  388. //*******************************************************************
  389. // Displays the menu
  390. void displayMenu() { (*cMenu)(); }
  391.  
  392. //*******************************************************************
  393. // Gets the user input from buttons
  394. void getButtonInput()
  395. {
  396.     if (bm.isPressed()) seq1.togglePlayback(); // if the middle button is pressed
  397. }
  398.  
  399. //*******************************************************************
  400. // Splash screen at startup
  401. void menu_splash()
  402. {
  403.     // splash the OLED with the adafruit logo
  404.     oled.display();
  405.     delay(1000);
  406.     oled.clearDisplay();
  407.  
  408.     // spash the screen with the program info
  409.     oled.setTextSize(2);
  410.     oled.setTextColor(WHITE);
  411.     oled.setCursor(4 * CHAR_WIDTH, 2 * CHAR_HEIGHT);
  412.     oled.print("Modutar");
  413.     oled.setCursor(7 * CHAR_WIDTH, 4 * CHAR_HEIGHT);
  414.     oled.print(VERSION_NUMBER);
  415.     oled.display();
  416.     delay(750);
  417. }
  418.  
  419. //*******************************************************************
  420. // Simple view of the menu
  421. void menu_simple()
  422. {
  423.     START_MENU();
  424.       MENU_ITEM_EDIT(note, "Key:", cKey);
  425.       MENU_ITEM_EDIT(mode, "Mode:", cMode);
  426.     END_MENU();
  427. }
  428.  
  429. //*******************************************************************
  430. // Main menu
  431. void menu_main()
  432. {
  433.     START_MENU();
  434.       //Serial.print(" :) ");
  435.       MENU_ITEM_EDIT(note, "Key",          cKey);
  436.       MENU_ITEM_EDIT(mode, "Mode",         cMode);
  437.       MENU_ITEM_EDIT(value,"Octave",       cOctave);
  438.       MENU_ITEM_EDIT(off8, "Pressure",     cPressure);
  439.       MENU_ITEM_EDIT(tf,   "Slide Enable", slideEnabled);
  440.       MENU_ITEM_DUMMY();
  441.       MENU_ITEM(submenu, "Voice 1",   menu_voice1);
  442.       MENU_ITEM(submenu, "Presets",   menu_presets);
  443.       MENU_ITEM(submenu, "Sequencer", menu_sequence);
  444.       MENU_ITEM(submenu, "Settings",  menu_settings);
  445.     END_MENU();
  446.  
  447.     //blink.refresh();
  448. }
  449.  
  450. //*******************************************************************
  451. // Menu for voice 1
  452. void menu_voice1()
  453. {
  454.     START_MENU();
  455.         // MENU_ITEM_EDIT(u255, "Current Voice",    currentVoice); // Uncomment when multiple voices are a thing
  456.        
  457.         // Oscillators
  458.         MENU_ITEM_EDIT(wave,  "o1-Wave",       voice1.osc[0].wave);
  459.         if (voice1.osc[0].wave == 6)           // Show PWM option if the wave is set to "Pulse"
  460.           MENU_ITEM_EDIT(u255,"o1-PWM",        voice1.osc[0].pwm);
  461.         MENU_ITEM_EDIT(off8, "o1-Voume",       voice1.osc[0].volume);
  462.  
  463.         MENU_ITEM_EDIT(wave,  "o2-Wave",       voice1.osc[1].wave);
  464.         if (voice1.osc[1].wave == 6)           // Show PWM option if the wave is set to "Pulse"
  465.           MENU_ITEM_EDIT(u255,"o2-PWM",        voice1.osc[1].pwm);
  466.         MENU_ITEM_EDIT(value, "o2-Octave",     voice1.osc[1].octave);
  467.         MENU_ITEM_EDITS(s127, "o2-Detune",     voice1.osc[1].detune);
  468.         MENU_ITEM_EDITS(s127, "o2-Offset",     voice1.osc[1].offset);
  469.         MENU_ITEM_EDIT(off8,  "o2-Volume",     voice1.osc[1].volume);
  470.  
  471.         MENU_ITEM_EDIT(wave,  "o3-Wave",       voice1.osc[2].wave);
  472.         if (voice1.osc[2].wave == 6)           // Show PWM option if the wave is set to "Pulse"
  473.           MENU_ITEM_EDIT(u255,"o3-PWM",        voice1.osc[2].pwm);
  474.         MENU_ITEM_EDIT(value, "o3-Octave",     voice1.osc[2].octave);
  475.         MENU_ITEM_EDITS(s127, "o3-Detune",     voice1.osc[2].detune);
  476.         MENU_ITEM_EDITS(s127, "o3-Offset",     voice1.osc[2].offset);
  477.         MENU_ITEM_EDIT(off8,  "o3-Volume",     voice1.osc[2].volume);
  478.  
  479.         MENU_ITEM_EDIT(off8,  "Noise Volume",  voice1.noiseVolume);
  480.         MENU_ITEM_DUMMY();
  481.  
  482.         // LFO
  483.         MENU_ITEM_EDIT(wave, "LFO-Wave",  voice1.lfoWave);
  484.         MENU_ITEM_EDIT(u255, "LFO-Rate",  voice1.lfoRate);
  485.         MENU_ITEM_EDIT(u255, "LFO-Delay", voice1.lfoDelay);
  486.         MENU_ITEM_EDIT(u255, "LFO-Depth", voice1.lfoDepth);
  487.         MENU_ITEM_DUMMY();
  488.  
  489.         // ADSR EG
  490.         MENU_ITEM_EDIT(u255, "Attack",  voice1.egAttack);
  491.         MENU_ITEM_EDIT(u255, "Decay",   voice1.egDecay);
  492.         MENU_ITEM_EDIT(u255, "Sustain", voice1.egSustain);
  493.         MENU_ITEM_EDIT(u255, "Release", voice1.egRelease);
  494.         MENU_ITEM_DUMMY();
  495.  
  496.         // Filter
  497.         MENU_ITEM_EDIT(off8, "Filter Mix",        voice1.filterMix);
  498.         MENU_ITEM_EDIT(u255, "Filter Cutoff",     voice1.filterCutoff);
  499.         MENU_ITEM_EDIT(u255, "Filter Resonance",  voice1.filterResonance);
  500.  
  501.         // Add: Glide
  502.  
  503.         // Back
  504.         MENU_ITEM(back, "Back", menu_main);
  505.     END_MENU();
  506. }
  507.  
  508. /* This doesn't work yet
  509. void menu_voice1_new()
  510. {
  511.     START_MENU();
  512.         // Oscillators
  513.         MENU_ITEM_EDIT_NEW(__wave_t,  "o1-Wave",       voice1.osc[0].wave);
  514.         if (voice1.osc[0].wave == 6)           // Show PWM option if the wave is set to "Pulse"
  515.           MENU_ITEM_EDIT_NEW(__u255_t,"o1-PWM",        voice1.osc[0].pwm);
  516.         MENU_ITEM_EDIT_NEW(__off8_t, "o1-Voume",       voice1.osc[0].volume);
  517.  
  518.         MENU_ITEM_EDIT_NEW(off8,  "Noise Volume",  voice1.noiseVolume);
  519.         MENU_ITEM_DUMMY();
  520.  
  521.         // Back
  522.         MENU_ITEM(back, "Back", menu_main);
  523.     END_MENU();
  524. }//*/
  525.  
  526.  
  527. //*******************************************************************
  528. // Menu for changing presets
  529. void menu_presets()
  530. {
  531.     START_MENU();
  532.         MENU_ITEM(submenu, "Keys", menu_presets_key);
  533.         MENU_ITEM(submenu, "Modes", menu_presets_mode);
  534.         MENU_ITEM_EDIT(off8, "Current Preset", cPreset);
  535.         MENU_ITEM_EDIT(off8, "Preset Count", presetCount);
  536.         MENU_ITEM(back, "Back", menu_main);
  537.     END_MENU();
  538. }
  539.  
  540. // Changes the presets' key
  541. void menu_presets_key()
  542. {
  543.     START_MENU();
  544.         MENU_ITEM_EDIT(note, "Key 1", presetKeys[0]);
  545.         MENU_ITEM_EDIT(note, "Key 2", presetKeys[1]);
  546.         MENU_ITEM_EDIT(note, "Key 3", presetKeys[2]);
  547.         MENU_ITEM_EDIT(note, "Key 4", presetKeys[3]);
  548.         MENU_ITEM_EDIT(note, "Key 5", presetKeys[4]);
  549.         MENU_ITEM_EDIT(note, "Key 6", presetKeys[5]);
  550.         MENU_ITEM_EDIT(note, "Key 7", presetKeys[6]);
  551.         MENU_ITEM_EDIT(note, "Key 8", presetKeys[7]);
  552.         MENU_ITEM(back, "Back", menu_presets);
  553.     END_MENU();
  554. }
  555.  
  556. // Changes the presets' mode
  557. void menu_presets_mode()
  558. {
  559.     START_MENU();
  560.         MENU_ITEM_EDIT(note, "Mode 1", presetMode[0]);
  561.         MENU_ITEM_EDIT(note, "Mode 2", presetMode[1]);
  562.         MENU_ITEM_EDIT(note, "Mode 3", presetMode[2]);
  563.         MENU_ITEM_EDIT(note, "Mode 4", presetMode[3]);
  564.         MENU_ITEM_EDIT(note, "Mode 5", presetMode[4]);
  565.         MENU_ITEM_EDIT(note, "Mode 6", presetMode[5]);
  566.         MENU_ITEM_EDIT(note, "Mode 7", presetMode[6]);
  567.         MENU_ITEM_EDIT(note, "Mode 8", presetMode[7]);
  568.         MENU_ITEM(back, "Back", menu_presets);
  569.     END_MENU();
  570. }
  571.  
  572. //*******************************************************************
  573. // Menu for adjusting the sequence
  574. void menu_sequence()
  575. {
  576.     // Note: Consider changing first argument in MENU_ITEM_EDIT(<THIS ONE> , <Tag>, <Value>) to be: ( (min, max, displayString), , )
  577.     START_MENU();
  578.         MENU_ITEM_EDIT(u64, "Edit Sequence", seq1.seqPos);
  579.         MENU_ITEM_EDIT(noteVal, "Note", seq1.notes[seq1.seqPos][0]);
  580.         MENU_ITEM_EDIT(u64, "Seq-Length", seq1.seqLen);
  581.         MENU_ITEM_EDIT(u255, "BPM", seq1.bpm);
  582.         MENU_ITEM_EDIT(noteDiv, "Beat Unit", seq1.noteType); // Crashes when value decreases
  583.         // MENU_ITEM_EDIT(percent, "Swing", seq1.swing); // To-do
  584.         MENU_ITEM(function, "Trim", seq1.trim);
  585.         MENU_ITEM(function, "Clear", seq1.clearSequence);
  586.         MENU_ITEM(back, "Back", menu_main);
  587.  
  588.         // Additional lines to be run when the menu is active
  589.         seqEdit = (cvFwd && cursorPos == 0); // If the user is editing the sequence (in the menu)
  590.         seqCursorView = (cvFwd && cursorPos == 2) ? 1 : 0; // Get the view mode for the cursor on the 8x8 LED matrix
  591.  
  592.         if (br.isPressed() && bl.isPressed()) seq1.eraseNote(); // If button L and R are pressed, erase current note
  593.     END_MENU();
  594. }
  595.  
  596. //*******************************************************************
  597. // Menu for settings
  598. void menu_settings()
  599. {
  600.     START_MENU();
  601.         MENU_ITEM_EDIT(u255, "Volume", displayVolume);
  602.         MENU_ITEM_EDIT(off24, "Ribbon Overide", ribbonOveride);
  603.         MENU_ITEM_EDIT(tf, "Flip Control", invertRibbonController);
  604.         MENU_ITEM(back, "Back", menu_main);
  605.     END_MENU();
  606. }
  607.  
  608. //*******************************************************************
  609. //    MENU ACTIONS
  610. //*******************************************************************
  611.  
  612. // Goes back a menu
  613. void menu_action_back(menuFunc_t data)
  614. {
  615.     cMenu = data;
  616.     // cursorPos = lastCursorPos;
  617.     cursorPos = 0;
  618. }
  619.  
  620. // Goes to a sub menu
  621. void menu_action_submenu(menuFunc_t data)
  622. {
  623.     cMenu = data;
  624.     // lastCursorPos = cursorPos;
  625.     cursorPos = 0;
  626. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement