Kaynağa Gözat

fix some ui bugs

Thomas Buck 1 ay önce
ebeveyn
işleme
ff21b7393f
7 değiştirilmiş dosya ile 123 ekleme ve 87 silme
  1. 4
    0
      include/config.h
  2. 3
    3
      include/sequence.h
  3. 2
    1
      src/buttons.c
  4. 3
    2
      src/led.c
  5. 3
    2
      src/pulse.c
  6. 36
    29
      src/sequence.c
  7. 72
    50
      src/ui.c

+ 4
- 0
include/config.h Dosyayı Görüntüle

31
 //#define DISABLE_CDC_DTR_CHECK
31
 //#define DISABLE_CDC_DTR_CHECK
32
 #define DEBOUNCE_DELAY_MS 5
32
 #define DEBOUNCE_DELAY_MS 5
33
 
33
 
34
+#define BAT_FETCH_MS 66
35
+
36
+#define MAX_BPM 360
37
+
34
 // ----------------------------------------------------------------------------
38
 // ----------------------------------------------------------------------------
35
 
39
 
36
 #define STR_HELPER(x) #x
40
 #define STR_HELPER(x) #x

+ 3
- 3
include/sequence.h Dosyayı Görüntüle

44
 void sequence_set_bpm(uint32_t new_bpm);
44
 void sequence_set_bpm(uint32_t new_bpm);
45
 uint32_t sequence_get_bpm(void);
45
 uint32_t sequence_get_bpm(void);
46
 
46
 
47
-void sequence_set_ms(uint32_t new_ms);
48
-uint32_t sequence_get_ms(void);
49
-
50
 void sequence_set_beats(uint32_t new_beats);
47
 void sequence_set_beats(uint32_t new_beats);
51
 uint32_t sequence_get_beats(void);
48
 uint32_t sequence_get_beats(void);
52
 
49
 
53
 void sequence_set_bank(uint32_t new_bank);
50
 void sequence_set_bank(uint32_t new_bank);
54
 uint32_t sequence_get_bank(void);
51
 uint32_t sequence_get_bank(void);
55
 
52
 
53
+uint32_t sequence_get_max_banks(void);
54
+uint64_t sequence_get_us(void);
55
+
56
 void sequence_handle_button_loopstation(enum buttons btn, bool rec);
56
 void sequence_handle_button_loopstation(enum buttons btn, bool rec);
57
 void sequence_handle_button_drummachine(enum buttons btn);
57
 void sequence_handle_button_drummachine(enum buttons btn);
58
 
58
 

+ 2
- 1
src/buttons.c Dosyayı Görüntüle

20
 #include "pico/stdlib.h"
20
 #include "pico/stdlib.h"
21
 
21
 
22
 #include "config.h"
22
 #include "config.h"
23
+#include "log.h"
23
 #include "main.h"
24
 #include "main.h"
24
 #include "buttons.h"
25
 #include "buttons.h"
25
 
26
 
128
 
129
 
129
     if ((now - buttons[i].last_time) > DEBOUNCE_DELAY_MS) {
130
     if ((now - buttons[i].last_time) > DEBOUNCE_DELAY_MS) {
130
         if (state != buttons[i].current_state) {
131
         if (state != buttons[i].current_state) {
131
-            printf("btn %d now %s\n", i, state ? "pressed" : "released");
132
+            //debug("btn %d now %s", i, state ? "pressed" : "released");
132
 
133
 
133
             buttons[i].current_state = state;
134
             buttons[i].current_state = state;
134
             if (callback) {
135
             if (callback) {

+ 3
- 2
src/led.c Dosyayı Görüntüle

21
 #include "pico/stdlib.h"
21
 #include "pico/stdlib.h"
22
 
22
 
23
 #include "sequence.h"
23
 #include "sequence.h"
24
+#include "log.h"
24
 #include "led.h"
25
 #include "led.h"
25
 
26
 
26
 #if 0
27
 #if 0
51
 void led_set(uint32_t i, bool v) {
52
 void led_set(uint32_t i, bool v) {
52
     i %= LED_COUNT;
53
     i %= LED_COUNT;
53
     gpio_put(led_gpio_num[i], v);
54
     gpio_put(led_gpio_num[i], v);
54
-    //printf("led %"PRIu32" now %d\n", i, v);
55
+    //debug("led %"PRIu32" now %d", i, v);
55
 }
56
 }
56
 
57
 
57
 void ch_set(uint32_t i, bool v) {
58
 void ch_set(uint32_t i, bool v) {
58
     i %= NUM_CHANNELS;
59
     i %= NUM_CHANNELS;
59
     gpio_put(ch_gpio_num[i], v);
60
     gpio_put(ch_gpio_num[i], v);
60
-    //printf("ch %"PRIu32" now %d\n", i, v);
61
+    //debug("ch %"PRIu32" now %d", i, v);
61
 }
62
 }

+ 3
- 2
src/pulse.c Dosyayı Görüntüle

21
 #include "pico/stdlib.h"
21
 #include "pico/stdlib.h"
22
 
22
 
23
 #include "led.h"
23
 #include "led.h"
24
+#include "log.h"
24
 #include "sequence.h"
25
 #include "sequence.h"
25
 #include "pulse.h"
26
 #include "pulse.h"
26
 
27
 
35
         if (out_time[i % NUM_CHANNELS] == 0) {
36
         if (out_time[i % NUM_CHANNELS] == 0) {
36
             out_time[i % NUM_CHANNELS] = off_t;
37
             out_time[i % NUM_CHANNELS] = off_t;
37
         } else {
38
         } else {
38
-            printf("%s: skip retrigger out %"PRIu32"\n", __func__, i);
39
+            debug("skip retrigger out %"PRIu32, i);
39
         }
40
         }
40
     } else {
41
     } else {
41
         led_set(i, true);
42
         led_set(i, true);
42
         if (led_time[i % LED_COUNT] == 0) {
43
         if (led_time[i % LED_COUNT] == 0) {
43
             led_time[i % LED_COUNT] = off_t;
44
             led_time[i % LED_COUNT] = off_t;
44
         } else {
45
         } else {
45
-            printf("%s: skip retrigger led %"PRIu32"\n", __func__, i);
46
+            debug("skip retrigger led %"PRIu32, i);
46
         }
47
         }
47
     }
48
     }
48
 }
49
 }

+ 36
- 29
src/sequence.c Dosyayı Görüntüle

21
 #include "pico/stdlib.h"
21
 #include "pico/stdlib.h"
22
 
22
 
23
 #include "led.h"
23
 #include "led.h"
24
+#include "log.h"
24
 #include "pulse.h"
25
 #include "pulse.h"
25
 #include "ui.h"
26
 #include "ui.h"
26
 #include "sequence.h"
27
 #include "sequence.h"
27
 
28
 
28
 static const uint32_t channel_times[NUM_CHANNELS] = CH_GPIO_TIMINGS;
29
 static const uint32_t channel_times[NUM_CHANNELS] = CH_GPIO_TIMINGS;
29
 
30
 
30
-static uint32_t ms_per_beat = 0;
31
+static uint64_t us_per_beat = 0;
32
+static uint64_t last_t = 0;
33
+static uint64_t beattimer_start = 0;
34
+
31
 static uint32_t beats = MAX_BEATS;
35
 static uint32_t beats = MAX_BEATS;
32
-static uint32_t last_t = 0;
33
 static uint32_t last_i = 0;
36
 static uint32_t last_i = 0;
34
 static uint32_t bank = 0;
37
 static uint32_t bank = 0;
35
-static uint32_t beattimer_start = 0;
38
+static uint32_t max_banks_currently = 0;
36
 
39
 
37
 static enum channels sequence[MAX_BEATS] = {0};
40
 static enum channels sequence[MAX_BEATS] = {0};
38
 
41
 
39
 void sequence_init(void) {
42
 void sequence_init(void) {
40
-    ms_per_beat = 0;
43
+    us_per_beat = 0;
41
     beats = MAX_BEATS;
44
     beats = MAX_BEATS;
42
     last_t = to_ms_since_boot(get_absolute_time());
45
     last_t = to_ms_since_boot(get_absolute_time());
43
     last_i = 0;
46
     last_i = 0;
47
+    max_banks_currently = (beats + (NUM_BTNS - 1)) / NUM_BTNS;
44
 
48
 
45
     for (uint i = 0; i < MAX_BEATS; i++) {
49
     for (uint i = 0; i < MAX_BEATS; i++) {
46
         sequence[i] = 0;
50
         sequence[i] = 0;
47
     }
51
     }
48
 }
52
 }
49
 
53
 
50
-void sequence_set_bpm(uint32_t new_bpm) {
51
-    ms_per_beat = 60000 / new_bpm / beats;
52
-    printf("bpm now %"PRIu32" = %"PRIu32"ms\n", new_bpm, ms_per_beat);
53
-}
54
-
55
-uint32_t sequence_get_bpm(void) {
56
-    return 60000 / (ms_per_beat * beats);
54
+uint32_t sequence_get_max_banks(void) {
55
+    return max_banks_currently;
57
 }
56
 }
58
 
57
 
59
-void sequence_set_ms(uint32_t new_ms) {
60
-    ms_per_beat = new_ms;
58
+void sequence_set_bpm(uint32_t new_bpm) {
59
+    us_per_beat = (60UL * 1000UL * 1000UL) / new_bpm;
60
+    debug("bpm @ %"PRIu64"us = %"PRIu64"us", us_per_beat, us_per_beat / beats);
61
 }
61
 }
62
 
62
 
63
-uint32_t sequence_get_ms(void) {
64
-    return ms_per_beat;
63
+uint32_t sequence_get_bpm(void) {
64
+    if (us_per_beat == 0) {
65
+        return 0;
66
+    }
67
+    return (60UL * 1000UL * 1000UL) / us_per_beat;
65
 }
68
 }
66
 
69
 
67
 void sequence_set_beats(uint32_t new_beats) {
70
 void sequence_set_beats(uint32_t new_beats) {
68
     beats = (new_beats <= MAX_BEATS) ? new_beats : MAX_BEATS;
71
     beats = (new_beats <= MAX_BEATS) ? new_beats : MAX_BEATS;
72
+    debug("beats @ %"PRIu64"us = %"PRIu64"us", us_per_beat, us_per_beat / beats);
69
 
73
 
70
-    uint32_t max_banks_currently = (beats + (NUM_BTNS - 1)) / NUM_BTNS;
71
-    bank = (bank < max_banks_currently) ? bank : max_banks_currently;
74
+    max_banks_currently = (beats + (NUM_BTNS - 1)) / NUM_BTNS;
75
+    bank = (bank < max_banks_currently) ? bank : 0;
72
 }
76
 }
73
 
77
 
74
 uint32_t sequence_get_beats(void) {
78
 uint32_t sequence_get_beats(void) {
77
 
81
 
78
 void sequence_set_bank(uint32_t new_bank) {
82
 void sequence_set_bank(uint32_t new_bank) {
79
     uint32_t b = (new_bank < MAX_BANKS) ? new_bank : MAX_BANKS;
83
     uint32_t b = (new_bank < MAX_BANKS) ? new_bank : MAX_BANKS;
80
-
81
-    uint32_t max_banks_currently = (beats + (NUM_BTNS - 1)) / NUM_BTNS;
82
-    bank = (b < max_banks_currently) ? b : max_banks_currently;
84
+    bank = (b < max_banks_currently) ? b : 0;
83
 }
85
 }
84
 
86
 
85
 uint32_t sequence_get_bank(void) {
87
 uint32_t sequence_get_bank(void) {
86
     return bank;
88
     return bank;
87
 }
89
 }
88
 
90
 
91
+uint64_t sequence_get_us(void) {
92
+    return us_per_beat;
93
+}
94
+
89
 static void sequence_set(uint32_t beat, enum channels ch, bool value) {
95
 static void sequence_set(uint32_t beat, enum channels ch, bool value) {
90
     if (beat < MAX_BEATS) {
96
     if (beat < MAX_BEATS) {
91
         if (value) {
97
         if (value) {
194
 
200
 
195
 void sequence_looptime(bool fin) {
201
 void sequence_looptime(bool fin) {
196
     if (!fin) {
202
     if (!fin) {
197
-        beattimer_start = to_ms_since_boot(get_absolute_time());
203
+        beattimer_start = to_us_since_boot(get_absolute_time());
198
     } else {
204
     } else {
199
-        if (ms_per_beat == 0) {
200
-            uint32_t now = to_ms_since_boot(get_absolute_time());
201
-            uint32_t diff = now - beattimer_start;
202
-            ms_per_beat = diff / beats;
203
-            printf("looptime: diff=%"PRIu32"ms per_beat=%"PRIu32"ms\n", diff, ms_per_beat);
205
+        if (us_per_beat == 0) {
206
+            uint64_t now = to_us_since_boot(get_absolute_time());
207
+            uint64_t diff = now - beattimer_start;
208
+            us_per_beat = diff;
209
+            debug("looptime @ %"PRIu64"us = %"PRIu64"us", us_per_beat, us_per_beat / beats);
204
         }
210
         }
205
     }
211
     }
206
 }
212
 }
207
 
213
 
208
 void sequence_run(void) {
214
 void sequence_run(void) {
209
-    uint32_t now = to_ms_since_boot(get_absolute_time());
215
+    uint64_t now = to_us_since_boot(get_absolute_time());
216
+    uint64_t us = us_per_beat / beats;
210
 
217
 
211
-    if ((ms_per_beat > 0) && (now >= (last_t + ms_per_beat))) {
212
-        //printf("trigger\n");
218
+    if ((us > 0) && (now >= (last_t + us))) {
219
+        //debug("trigger");
213
 
220
 
214
         uint32_t i = last_i + 1;
221
         uint32_t i = last_i + 1;
215
         if (i >= beats) i = 0;
222
         if (i >= beats) i = 0;

+ 72
- 50
src/ui.c Dosyayı Görüntüle

21
 #include <math.h>
21
 #include <math.h>
22
 #include "pico/stdlib.h"
22
 #include "pico/stdlib.h"
23
 
23
 
24
+#include "config.h"
24
 #include "adc.h"
25
 #include "adc.h"
25
 #include "buttons.h"
26
 #include "buttons.h"
26
 #include "lcd.h"
27
 #include "lcd.h"
27
 #include "led.h"
28
 #include "led.h"
29
+#include "log.h"
28
 #include "pulse.h"
30
 #include "pulse.h"
29
 #include "sequence.h"
31
 #include "sequence.h"
30
 #include "usb.h"
32
 #include "usb.h"
31
 #include "usb_midi.h"
33
 #include "usb_midi.h"
32
 #include "ui.h"
34
 #include "ui.h"
33
 
35
 
34
-#define BAT_FETCH_MS 66
36
+#define KEEP_IN_RANGE(val, min, len) { \
37
+    while (val > (len - min)) {        \
38
+        val -= len;                    \
39
+    }                                  \
40
+    while (val < min) {                \
41
+        val += len;                    \
42
+    }                                  \
43
+}
35
 
44
 
36
 enum ui_settings {
45
 enum ui_settings {
37
     SETTING_MODE = 0,
46
     SETTING_MODE = 0,
41
 
50
 
42
     // drum machine
51
     // drum machine
43
     SETTING_BPM,
52
     SETTING_BPM,
44
-    SETTING_BANK,
45
     SETTING_LENGTH,
53
     SETTING_LENGTH,
54
+    SETTING_BANK,
55
+    SETTING_CHANNEL,
46
 
56
 
47
     // midi
57
     // midi
48
     SETTING_CH_RX,
58
     SETTING_CH_RX,
54
 static bool allowed_settings[MACHINE_NUM_MODES][SETTING_NUM_MODES] = {
64
 static bool allowed_settings[MACHINE_NUM_MODES][SETTING_NUM_MODES] = {
55
     // MODE_LOOPSTATION
65
     // MODE_LOOPSTATION
56
     {
66
     {
57
-        true, true,
58
-        false, false, false,
67
+        true, // SETTING_MODE
68
+        true,
69
+        false, false, false, false,
59
         false, false,
70
         false, false,
60
     },
71
     },
61
 
72
 
62
     // MODE_DRUMMACHINE
73
     // MODE_DRUMMACHINE
63
     {
74
     {
64
-        true, false,
65
-        true, true, true,
75
+        true, // SETTING_MODE
76
+        false,
77
+        true, true, true, true,
66
         false, false,
78
         false, false,
67
     },
79
     },
68
 
80
 
69
     // MODE_MIDI
81
     // MODE_MIDI
70
     {
82
     {
71
-        true, false,
72
-        false, false, false,
83
+        true, // SETTING_MODE
84
+        false,
85
+        false, false, false, false,
73
         true, true,
86
         true, true,
74
     },
87
     },
75
 };
88
 };
94
     char bat[64] = {0};
107
     char bat[64] = {0};
95
 
108
 
96
     switch (ui_setting) {
109
     switch (ui_setting) {
97
-        case SETTING_BPM: {
98
-            snprintf(mode, sizeof(mode) - 1, "BPM:");
99
-            snprintf(val, sizeof(val) - 1, "%"PRIu32, sequence_get_bpm());
100
-            break;
101
-        }
102
-
103
         case SETTING_MODE: {
110
         case SETTING_MODE: {
104
-            if ((machine_mode == MODE_LOOPSTATION) && (sequence_get_ms() != 0)) {
105
-                snprintf(mode, sizeof(mode) - 1, "Mode: %"PRIu32"ms", sequence_get_ms());
111
+            if ((machine_mode == MODE_LOOPSTATION) && (sequence_get_us() != 0)) {
112
+                snprintf(mode, sizeof(mode) - 1, "Mode: %"PRIu64"ms", sequence_get_us() / 1000);
106
             } else {
113
             } else {
107
                 snprintf(mode, sizeof(mode) - 1, "Mode:");
114
                 snprintf(mode, sizeof(mode) - 1, "Mode:");
108
             }
115
             }
134
             break;
141
             break;
135
         }
142
         }
136
 
143
 
144
+        case SETTING_SPEED:
145
+        case SETTING_BPM: {
146
+            if ((machine_mode == MODE_LOOPSTATION) && (sequence_get_us() != 0)) {
147
+                snprintf(mode, sizeof(mode) - 1, "BPM: %"PRIu64"ms", sequence_get_us() / 1000);
148
+            } else {
149
+                snprintf(mode, sizeof(mode) - 1, "BPM:");
150
+            }
151
+            snprintf(val, sizeof(val) - 1, "%"PRIu32, sequence_get_bpm());
152
+            break;
153
+        }
154
+
137
         case SETTING_LENGTH: {
155
         case SETTING_LENGTH: {
138
             snprintf(mode, sizeof(mode) - 1, "Length:");
156
             snprintf(mode, sizeof(mode) - 1, "Length:");
139
             snprintf(val, sizeof(val) - 1, "%"PRIu32, sequence_get_beats());
157
             snprintf(val, sizeof(val) - 1, "%"PRIu32, sequence_get_beats());
142
 
160
 
143
         case SETTING_BANK: {
161
         case SETTING_BANK: {
144
             snprintf(mode, sizeof(mode) - 1, "Bank:");
162
             snprintf(mode, sizeof(mode) - 1, "Bank:");
145
-            snprintf(val, sizeof(val) - 1, "%"PRIu32, sequence_get_bank());
146
-            break;
147
-        }
148
-
149
-        case SETTING_SPEED: {
150
-            snprintf(mode, sizeof(mode) - 1, "Speed:");
151
-            snprintf(val, sizeof(val) - 1, "%"PRIu32, sequence_get_ms());
163
+            snprintf(val, sizeof(val) - 1, "%"PRIu32, sequence_get_bank() + 1);
152
             break;
164
             break;
153
         }
165
         }
154
 
166
 
164
             break;
176
             break;
165
         }
177
         }
166
 
178
 
179
+        case SETTING_CHANNEL: {
180
+            snprintf(mode, sizeof(mode) - 1, "Channel:");
181
+            snprintf(val, sizeof(val) - 1, "todo");
182
+            break;
183
+        }
184
+
167
         default: {
185
         default: {
168
-            printf("%s: invalid setting: %d\n", __func__, ui_setting);
186
+            debug("invalid setting: %d", ui_setting);
169
             ui_setting = 0;
187
             ui_setting = 0;
170
             ui_redraw();
188
             ui_redraw();
171
             return;
189
             return;
208
         }
226
         }
209
 
227
 
210
         default: {
228
         default: {
211
-            printf("%s: invalid btn: %d\n", __func__, btn);
229
+            debug("invalid btn: %d", btn);
212
             break;
230
             break;
213
         }
231
         }
214
     }
232
     }
232
         }
250
         }
233
 
251
 
234
         default: {
252
         default: {
235
-            printf("%s: invalid btn: %d\n", __func__, btn);
253
+            debug("invalid btn: %d", btn);
236
             break;
254
             break;
237
         }
255
         }
238
     }
256
     }
291
                 }
309
                 }
292
 
310
 
293
                 default: {
311
                 default: {
294
-                    printf("%s: invalid mode: %d\n", __func__, machine_mode);
312
+                    debug("invalid mode: %d", machine_mode);
295
                     machine_mode = 0;
313
                     machine_mode = 0;
296
                     ui_buttons(btn, val);
314
                     ui_buttons(btn, val);
297
                     break;
315
                     break;
308
     }
326
     }
309
 
327
 
310
     switch (ui_setting) {
328
     switch (ui_setting) {
311
-        case SETTING_BPM: {
312
-            sequence_set_bpm(sequence_get_bpm() + val);
313
-            break;
314
-        }
315
-
316
         case SETTING_MODE: {
329
         case SETTING_MODE: {
317
             int32_t tmp = machine_mode + val;
330
             int32_t tmp = machine_mode + val;
318
-
319
-            while (tmp < 0) {
320
-                tmp += MACHINE_NUM_MODES;
321
-            }
322
-            while (tmp >= MACHINE_NUM_MODES) {
323
-                tmp -= MACHINE_NUM_MODES;
324
-            }
331
+            KEEP_IN_RANGE(tmp, 0, MACHINE_NUM_MODES);
325
 
332
 
326
             // midi only when connected to pc
333
             // midi only when connected to pc
327
             if ((tmp == MODE_MIDI) && !usb_is_connected()) {
334
             if ((tmp == MODE_MIDI) && !usb_is_connected()) {
331
             enum machine_modes prev_mode = machine_mode;
338
             enum machine_modes prev_mode = machine_mode;
332
             machine_mode = tmp;
339
             machine_mode = tmp;
333
 
340
 
334
-            printf("mode add %"PRIi32" now %d\n", val, machine_mode);
335
-
336
             if (prev_mode != machine_mode) {
341
             if (prev_mode != machine_mode) {
337
                 // reset sequence
342
                 // reset sequence
338
                 sequence_init();
343
                 sequence_init();
350
                     led_set(NUM_CHANNELS + 4, true);
355
                     led_set(NUM_CHANNELS + 4, true);
351
                 } else if (machine_mode == MODE_DRUMMACHINE) {
356
                 } else if (machine_mode == MODE_DRUMMACHINE) {
352
                     sequence_set_beats(LED_COUNT);
357
                     sequence_set_beats(LED_COUNT);
358
+                    sequence_set_bpm(120);
353
                 }
359
                 }
354
             }
360
             }
355
             break;
361
             break;
356
         }
362
         }
357
 
363
 
358
-        case SETTING_LENGTH: {
359
-            sequence_set_beats(sequence_get_beats() + val);
364
+        case SETTING_SPEED:
365
+        case SETTING_BPM: {
366
+            int32_t tmp = sequence_get_bpm() + val;
367
+            KEEP_IN_RANGE(tmp, 1, MAX_BPM);
368
+            sequence_set_bpm(tmp);
360
             break;
369
             break;
361
         }
370
         }
362
 
371
 
363
-        case SETTING_BANK: {
364
-            sequence_set_bank(sequence_get_bank() + val);
372
+        case SETTING_LENGTH: {
373
+            int32_t tmp = sequence_get_beats() + val;
374
+            KEEP_IN_RANGE(tmp, 1, MAX_BEATS);
375
+            sequence_set_beats(tmp);
365
             break;
376
             break;
366
         }
377
         }
367
 
378
 
368
-        case SETTING_SPEED: {
369
-            sequence_set_ms(sequence_get_ms() + val);
379
+        case SETTING_BANK: {
380
+            int32_t tmp = sequence_get_bank() + val;
381
+            KEEP_IN_RANGE(tmp, 0, (int32_t)sequence_get_max_banks());
382
+            sequence_set_bank(tmp);
370
             break;
383
             break;
371
         }
384
         }
372
 
385
 
373
         case SETTING_CH_RX: {
386
         case SETTING_CH_RX: {
374
-            midi_rx = (uint8_t)(midi_rx + val) % MIDI_MAX_CH;
387
+            int32_t tmp = midi_rx + val;
388
+            KEEP_IN_RANGE(tmp, 0, MIDI_MAX_CH);
389
+            midi_rx = tmp;
375
             break;
390
             break;
376
         }
391
         }
377
 
392
 
378
         case SETTING_CH_TX: {
393
         case SETTING_CH_TX: {
379
-            midi_tx = (uint8_t)(midi_tx + val) % MIDI_MAX_CH;
394
+            int32_t tmp = midi_tx + val;
395
+            KEEP_IN_RANGE(tmp, 0, MIDI_MAX_CH);
396
+            midi_tx = tmp;
397
+            break;
398
+        }
399
+
400
+        case SETTING_CHANNEL: {
401
+            // TODO
380
             break;
402
             break;
381
         }
403
         }
382
 
404
 
383
         default: {
405
         default: {
384
-            printf("%s: invalid setting: %d\n", __func__, ui_setting);
406
+            debug("invalid setting: %d", ui_setting);
385
             ui_setting = 0;
407
             ui_setting = 0;
386
             ui_encoder(val);
408
             ui_encoder(val);
387
             return;
409
             return;

Loading…
İptal
Kaydet