Няма описание
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. break;
  30. }
  31. case UI_MODE: {
  32. break;
  33. }
  34. case UI_LENGTH: {
  35. break;
  36. }
  37. case UI_BANK: {
  38. break;
  39. }
  40. default: {
  41. printf("%s: invalid mode: %d\n", __func__, ui_mode);
  42. ui_mode = 0;
  43. ui_redraw();
  44. break;
  45. }
  46. }
  47. }
  48. static void ui_buttons_loopstation(enum buttons btn, bool val) {
  49. switch (btn) {
  50. case BTN_A:
  51. case BTN_B:
  52. case BTN_C: {
  53. if (val) {
  54. sequence_handle_button_loopstation(btn, rec_held_down);
  55. }
  56. break;
  57. }
  58. case BTN_REC: {
  59. rec_held_down = val;
  60. break;
  61. }
  62. default: {
  63. printf("%s: invalid btn: %d\n", __func__, btn);
  64. break;
  65. }
  66. }
  67. }
  68. static void ui_buttons_drummachine(enum buttons btn, bool val) {
  69. switch (btn) {
  70. case BTN_A:
  71. case BTN_B:
  72. case BTN_C:
  73. case BTN_REC: {
  74. if (val) {
  75. sequence_handle_button_drummachine(btn);
  76. }
  77. break;
  78. }
  79. default: {
  80. printf("%s: invalid btn: %d\n", __func__, btn);
  81. break;
  82. }
  83. }
  84. }
  85. static void ui_buttons(enum buttons btn, bool val) {
  86. switch (btn) {
  87. case BTN_CLICK: {
  88. ui_mode = (ui_mode + 1) % UI_NUM_MODES;
  89. ui_redraw();
  90. break;
  91. }
  92. default: {
  93. switch (machine_mode) {
  94. case MODE_LOOPSTATION: {
  95. ui_buttons_loopstation(btn, val);
  96. break;
  97. }
  98. case MODE_DRUMMACHINE: {
  99. ui_buttons_drummachine(btn, val);
  100. break;
  101. }
  102. default: {
  103. printf("%s: invalid mode: %d\n", __func__, machine_mode);
  104. machine_mode = 0;
  105. ui_buttons(btn, val);
  106. break;
  107. }
  108. }
  109. break;
  110. }
  111. }
  112. }
  113. void ui_init(void) {
  114. buttons_callback(ui_buttons);
  115. ui_redraw();
  116. }