暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * ui.c
  3. *
  4. * Copyright (c) 2024 Thomas Buck (thomas@xythobuz.de)
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * See <http://www.gnu.org/licenses/>.
  17. */
  18. #include <stdio.h>
  19. #include "pico/stdlib.h"
  20. #include "buttons.h"
  21. #include "sequence.h"
  22. #include "ui.h"
  23. static bool rec_held_down = false;
  24. static enum ui_modes ui_mode = 0;
  25. static enum machine_modes machine_mode = 0;
  26. static void ui_redraw(void) {
  27. switch (ui_mode) {
  28. case UI_BPM: {
  29. // TODO
  30. break;
  31. }
  32. case UI_MODE: {
  33. // TODO
  34. break;
  35. }
  36. case UI_LENGTH: {
  37. // TODO
  38. break;
  39. }
  40. case UI_BANK: {
  41. // TODO
  42. break;
  43. }
  44. default: {
  45. printf("%s: invalid mode: %d\n", __func__, ui_mode);
  46. ui_mode = 0;
  47. ui_redraw();
  48. break;
  49. }
  50. }
  51. }
  52. static void ui_buttons_loopstation(enum buttons btn, bool val) {
  53. switch (btn) {
  54. case BTN_A:
  55. case BTN_B:
  56. case BTN_C: {
  57. if (val) {
  58. sequence_handle_button_loopstation(btn, rec_held_down);
  59. }
  60. break;
  61. }
  62. case BTN_REC: {
  63. rec_held_down = val;
  64. break;
  65. }
  66. default: {
  67. printf("%s: invalid btn: %d\n", __func__, btn);
  68. break;
  69. }
  70. }
  71. }
  72. static void ui_buttons_drummachine(enum buttons btn, bool val) {
  73. switch (btn) {
  74. case BTN_A:
  75. case BTN_B:
  76. case BTN_C:
  77. case BTN_REC: {
  78. if (val) {
  79. sequence_handle_button_drummachine(btn);
  80. }
  81. break;
  82. }
  83. default: {
  84. printf("%s: invalid btn: %d\n", __func__, btn);
  85. break;
  86. }
  87. }
  88. }
  89. static void ui_buttons(enum buttons btn, bool val) {
  90. switch (btn) {
  91. case BTN_CLICK: {
  92. ui_mode = (ui_mode + 1) % UI_NUM_MODES;
  93. ui_redraw();
  94. break;
  95. }
  96. default: {
  97. switch (machine_mode) {
  98. case MODE_LOOPSTATION: {
  99. ui_buttons_loopstation(btn, val);
  100. break;
  101. }
  102. case MODE_DRUMMACHINE: {
  103. ui_buttons_drummachine(btn, val);
  104. break;
  105. }
  106. default: {
  107. printf("%s: invalid mode: %d\n", __func__, machine_mode);
  108. machine_mode = 0;
  109. ui_buttons(btn, val);
  110. break;
  111. }
  112. }
  113. break;
  114. }
  115. }
  116. }
  117. void ui_encoder(int32_t val) {
  118. if (val == 0) {
  119. return;
  120. }
  121. switch (ui_mode) {
  122. case UI_BPM: {
  123. // TODO
  124. break;
  125. }
  126. case UI_MODE: {
  127. // TODO
  128. break;
  129. }
  130. case UI_LENGTH: {
  131. // TODO
  132. break;
  133. }
  134. case UI_BANK: {
  135. // TODO
  136. break;
  137. }
  138. default: {
  139. printf("%s: invalid mode: %d\n", __func__, ui_mode);
  140. ui_mode = 0;
  141. ui_encoder(val);
  142. break;
  143. }
  144. }
  145. }
  146. void ui_init(void) {
  147. buttons_callback(ui_buttons);
  148. ui_redraw();
  149. }