123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- /*
- * ui.c
- *
- * Copyright (c) 2024 Thomas Buck (thomas@xythobuz.de)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * See <http://www.gnu.org/licenses/>.
- */
-
- #include <stdio.h>
- #include "pico/stdlib.h"
-
- #include "buttons.h"
- #include "sequence.h"
- #include "ui.h"
-
- static bool rec_held_down = false;
- static enum ui_modes ui_mode = 0;
- static enum machine_modes machine_mode = 0;
-
- static void ui_redraw(void) {
- switch (ui_mode) {
- case UI_BPM: {
- // TODO
- break;
- }
-
- case UI_MODE: {
- // TODO
- break;
- }
-
- case UI_LENGTH: {
- // TODO
- break;
- }
-
- case UI_BANK: {
- // TODO
- break;
- }
-
- default: {
- printf("%s: invalid mode: %d\n", __func__, ui_mode);
- ui_mode = 0;
- ui_redraw();
- break;
- }
- }
- }
-
- static void ui_buttons_loopstation(enum buttons btn, bool val) {
- switch (btn) {
- case BTN_A:
- case BTN_B:
- case BTN_C: {
- if (val) {
- sequence_handle_button_loopstation(btn, rec_held_down);
- }
- break;
- }
-
- case BTN_REC: {
- rec_held_down = val;
- break;
- }
-
- default: {
- printf("%s: invalid btn: %d\n", __func__, btn);
- break;
- }
- }
- }
-
- static void ui_buttons_drummachine(enum buttons btn, bool val) {
- switch (btn) {
- case BTN_A:
- case BTN_B:
- case BTN_C:
- case BTN_REC: {
- if (val) {
- sequence_handle_button_drummachine(btn);
- }
- break;
- }
-
- default: {
- printf("%s: invalid btn: %d\n", __func__, btn);
- break;
- }
- }
- }
-
- static void ui_buttons(enum buttons btn, bool val) {
- switch (btn) {
- case BTN_CLICK: {
- ui_mode = (ui_mode + 1) % UI_NUM_MODES;
- ui_redraw();
- break;
- }
-
- default: {
- switch (machine_mode) {
- case MODE_LOOPSTATION: {
- ui_buttons_loopstation(btn, val);
- break;
- }
-
- case MODE_DRUMMACHINE: {
- ui_buttons_drummachine(btn, val);
- break;
- }
-
- default: {
- printf("%s: invalid mode: %d\n", __func__, machine_mode);
- machine_mode = 0;
- ui_buttons(btn, val);
- break;
- }
- }
- break;
- }
- }
- }
-
- void ui_encoder(int32_t val) {
- if (val == 0) {
- return;
- }
-
- switch (ui_mode) {
- case UI_BPM: {
- // TODO
- break;
- }
-
- case UI_MODE: {
- // TODO
- break;
- }
-
- case UI_LENGTH: {
- // TODO
- break;
- }
-
- case UI_BANK: {
- // TODO
- break;
- }
-
- default: {
- printf("%s: invalid mode: %d\n", __func__, ui_mode);
- ui_mode = 0;
- ui_encoder(val);
- break;
- }
- }
- }
-
- void ui_init(void) {
- buttons_callback(ui_buttons);
- ui_redraw();
- }
|