123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- #include <stdint.h>
- #include "system.h"
- #include "display.h"
- #include "systick.h"
- #include "button.h"
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include "ui.h"
- #include "timer.h"
- #include "led.h"
- #include "drums.h"
- #include "drone.h"
- #include "settings.h"
- #define TRACKS 8
- static struct drums_pattern *pattern = NULL;
- static uint32_t pattern_len = 8;
- static uint32_t pattern_pos = 0;
- static unsigned char *dsample[TRACKS] = {};
- static unsigned int dsample_len[TRACKS] = {};
- static void beat_cb(uint32_t b)
- {
- int i;
- uint32_t key;
- pattern = &Settings->drums[Settings->current_pattern];
- //drone_beat(pattern_pos);
- key = pattern->data[pattern_pos];
- for (i = 0; i < TRACKS; i++) {
- if ((key & (1 << i)) == (1 << i)) {
- if (dsample[i]) {
- while(dac_is_busy())
- dac_stop();
- dac_play_direct(dsample[i], dsample_len[i]);
- break;
- }
- }
- }
- pattern_pos++;
- if (pattern_pos >= pattern->len) {
- pattern_pos = 0;
- }
- led_beat((pattern_pos % 8) + 1);
- }
- void drums_oneshot(int track)
- {
- while(dac_is_busy())
- dac_stop();
- dac_play_direct(dsample[track], dsample_len[track]);
- }
- void drums_init(void)
- {
- dsample[0] = drumkit_0_au;
- dsample[1] = drumkit_1_au;
- dsample[2] = drumkit_2_au;
- dsample[3] = drumkit_3_au;
- dsample[4] = drumkit_4_au;
- dsample[5] = drumkit_5_au;
- dsample[6] = drumkit_6_au;
- dsample_len[0] = drumkit_0_au_len;
- dsample_len[1] = drumkit_1_au_len;
- dsample_len[2] = drumkit_2_au_len;
- dsample_len[3] = drumkit_3_au_len;
- dsample_len[4] = drumkit_4_au_len;
- dsample_len[5] = drumkit_5_au_len;
- dsample_len[6] = drumkit_6_au_len;
- }
- void drums_start(void)
- {
- timer_set_beat_callback(beat_cb);
- }
- void drums_stop(void)
- {
- timer_clear_beat_callback();
- }
- void drums_set(uint32_t track, int pos)
- {
- pattern = Settings->drums[Settings->current_pattern].data;
- pattern->data[pos] |= (1 << track);
- }
- void drums_clear(uint32_t track, int pos)
- {
- pattern = Settings->drums[Settings->current_pattern].data;
- pattern->data[pos] &= ~(1 << track);
- }
- int drums_get(uint32_t track, int pos)
- {
- pattern = Settings->drums[Settings->current_pattern].data;
- return (!!(pattern->data[pos] & (1 << track)));
- }
|