Kaynağa Gözat

drum machine mode now kinda usable

Thomas Buck 6 ay önce
ebeveyn
işleme
314bf218ca
3 değiştirilmiş dosya ile 29 ekleme ve 22 silme
  1. 3
    0
      include/sequence.h
  2. 20
    20
      src/sequence.c
  3. 6
    2
      src/ui.c

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

@@ -48,6 +48,9 @@ uint32_t sequence_get_beats(void);
48 48
 void sequence_set_bank(uint32_t new_bank);
49 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 54
 uint32_t sequence_get_max_banks(void);
52 55
 uint64_t sequence_get_us(void);
53 56
 

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

@@ -35,6 +35,7 @@ static uint32_t beats = MAX_BEATS;
35 35
 static uint32_t last_i = 0;
36 36
 static uint32_t bank = 0;
37 37
 static uint32_t max_banks_currently = 0;
38
+static uint32_t channel = 0;
38 39
 
39 40
 static enum channels sequence[MAX_BEATS] = {0};
40 41
 
@@ -87,6 +88,14 @@ uint32_t sequence_get_bank(void) {
87 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 99
 uint64_t sequence_get_us(void) {
91 100
     return us_per_beat;
92 101
 }
@@ -167,27 +176,18 @@ void sequence_handle_button_loopstation(enum buttons btn, bool rec) {
167 176
 }
168 177
 
169 178
 void sequence_handle_button_drummachine(enum buttons btn) {
170
-    uint32_t beat = 42; // TODO!!
171
-
172 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 191
             break;
192 192
         }
193 193
 

+ 6
- 2
src/ui.c Dosyayı Görüntüle

@@ -168,7 +168,7 @@ static void ui_redraw(void) {
168 168
 
169 169
         case SETTING_CHANNEL: {
170 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 172
             break;
173 173
         }
174 174
 
@@ -347,6 +347,8 @@ void ui_encoder(int32_t val) {
347 347
                 } else if (machine_mode == MODE_DRUMMACHINE) {
348 348
                     sequence_set_beats(LED_COUNT);
349 349
                     sequence_set_bpm(120);
350
+                    sequence_set_bank(0);
351
+                    sequence_set_channel(0);
350 352
                 }
351 353
             }
352 354
             break;
@@ -389,7 +391,9 @@ void ui_encoder(int32_t val) {
389 391
         }
390 392
 
391 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 397
             break;
394 398
         }
395 399
 

Loading…
İptal
Kaydet