Browse Source

drum machine mode now kinda usable

Thomas Buck 6 months ago
parent
commit
314bf218ca
3 changed files with 29 additions and 22 deletions
  1. 3
    0
      include/sequence.h
  2. 20
    20
      src/sequence.c
  3. 6
    2
      src/ui.c

+ 3
- 0
include/sequence.h View File

48
 void sequence_set_bank(uint32_t new_bank);
48
 void sequence_set_bank(uint32_t new_bank);
49
 uint32_t sequence_get_bank(void);
49
 uint32_t sequence_get_bank(void);
50
 
50
 
51
+void sequence_set_channel(uint32_t new_channel);
52
+uint32_t sequence_get_channel(void);
53
+
51
 uint32_t sequence_get_max_banks(void);
54
 uint32_t sequence_get_max_banks(void);
52
 uint64_t sequence_get_us(void);
55
 uint64_t sequence_get_us(void);
53
 
56
 

+ 20
- 20
src/sequence.c View File

35
 static uint32_t last_i = 0;
35
 static uint32_t last_i = 0;
36
 static uint32_t bank = 0;
36
 static uint32_t bank = 0;
37
 static uint32_t max_banks_currently = 0;
37
 static uint32_t max_banks_currently = 0;
38
+static uint32_t channel = 0;
38
 
39
 
39
 static enum channels sequence[MAX_BEATS] = {0};
40
 static enum channels sequence[MAX_BEATS] = {0};
40
 
41
 
87
     return bank;
88
     return bank;
88
 }
89
 }
89
 
90
 
91
+void sequence_set_channel(uint32_t new_channel) {
92
+    channel = (new_channel < NUM_CHANNELS) ? new_channel : 0;
93
+}
94
+
95
+uint32_t sequence_get_channel(void) {
96
+    return channel;
97
+}
98
+
90
 uint64_t sequence_get_us(void) {
99
 uint64_t sequence_get_us(void) {
91
     return us_per_beat;
100
     return us_per_beat;
92
 }
101
 }
167
 }
176
 }
168
 
177
 
169
 void sequence_handle_button_drummachine(enum buttons btn) {
178
 void sequence_handle_button_drummachine(enum buttons btn) {
170
-    uint32_t beat = 42; // TODO!!
171
-
172
     switch (btn) {
179
     switch (btn) {
173
-        case BTN_A: {
174
-            // TODO kick is wrong here
175
-            bool val = !sequence_get(beat, CH_KICK);
176
-            sequence_set(beat, CH_KICK, val);
177
-            break;
178
-        }
179
-
180
-        case BTN_B: {
181
-            // TODO snare is wrong here
182
-            bool val = !sequence_get(beat, CH_SNARE);
183
-            sequence_set(beat, CH_SNARE, val);
184
-            break;
185
-        }
186
-
187
-        case BTN_C: {
188
-            // TODO hihat is wrong here
189
-            bool val = !sequence_get(beat, CH_HIHAT);
190
-            sequence_set(beat, CH_HIHAT, val);
180
+        case BTN_A:
181
+        case BTN_B:
182
+        case BTN_C:
183
+        case BTN_D:
184
+        case BTN_E:
185
+        case BTN_F:
186
+        case BTN_G:
187
+        case BTN_H: {
188
+            uint32_t beat = (btn - BTN_A) + bank * LED_COUNT;
189
+            bool val = !sequence_get(beat, 1 << channel);
190
+            sequence_set(beat, 1 << channel, val);
191
             break;
191
             break;
192
         }
192
         }
193
 
193
 

+ 6
- 2
src/ui.c View File

168
 
168
 
169
         case SETTING_CHANNEL: {
169
         case SETTING_CHANNEL: {
170
             snprintf(mode, sizeof(mode) - 1, "Channel:");
170
             snprintf(mode, sizeof(mode) - 1, "Channel:");
171
-            snprintf(val, sizeof(val) - 1, "todo");
171
+            snprintf(val, sizeof(val) - 1, "%"PRIu32, sequence_get_channel() + 1);
172
             break;
172
             break;
173
         }
173
         }
174
 
174
 
347
                 } else if (machine_mode == MODE_DRUMMACHINE) {
347
                 } else if (machine_mode == MODE_DRUMMACHINE) {
348
                     sequence_set_beats(LED_COUNT);
348
                     sequence_set_beats(LED_COUNT);
349
                     sequence_set_bpm(120);
349
                     sequence_set_bpm(120);
350
+                    sequence_set_bank(0);
351
+                    sequence_set_channel(0);
350
                 }
352
                 }
351
             }
353
             }
352
             break;
354
             break;
389
         }
391
         }
390
 
392
 
391
         case SETTING_CHANNEL: {
393
         case SETTING_CHANNEL: {
392
-            // TODO
394
+            int32_t tmp = sequence_get_channel() + val;
395
+            KEEP_IN_RANGE(tmp, 0, NUM_CHANNELS);
396
+            sequence_set_channel(tmp);
393
             break;
397
             break;
394
         }
398
         }
395
 
399
 

Loading…
Cancel
Save