#include #include "system.h" #include "display.h" #include "systick.h" #include "button.h" #include #include #include #include "ui.h" #include "timer.h" #include "led.h" #include "drums.h" #include "drone.h" #include "settings.h" #define TRACKS 8 //static uint32_t pattern[MAX_PATTERN_LEN] = { DRUMS_KICK, DRUMS_HIHAT, DRUMS_SNARE, DRUMS_HIHAT, DRUMS_KICK, DRUMS_KICK, DRUMS_SNARE, DRUMS_HIHAT }; static uint32_t pattern[MAX_PATTERN_LEN] = { DRUMS_KICK, DRUMS_KICK, DRUMS_CLAP, 0, 0, DRUMS_KICK, 0}; 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) { uint32_t key = pattern[pattern_pos]; int i; drone_beat(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 >= Settings.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_pattern_len(int l) { Settings.pattern_len = l; timer_set_beat(1); } void drums_set(uint32_t track, int pos) { pattern[pos] |= (1 << track); } void drums_clear(uint32_t track, int pos) { pattern[pos] &= ~(1 << track); } int drums_get(uint32_t track, int pos) { return (!!(pattern[pos] & (1 << track))); }