1
0
Fork 0

adds a sequencer to the music mode (#330)

* implements leader key for planck experimental

* allows override of leader timeout

* adds ability to use the leader key in seq

* fixes leader keycode

* adds chording prototype

* fixes keycode detection

* moves music mode to quantum.c

* disables chording by default

* adds music sequencer functionality

* implements audio/music functions in quantum.c

* Merge branch 'master' into process-record
This commit is contained in:
Jack Humbert 2016-05-15 00:40:59 -04:00
parent 1a8c0dd22d
commit 15719f3574
5 changed files with 123 additions and 82 deletions

View file

@ -478,12 +478,11 @@ void increase_tempo(uint8_t tempo_change) {
// Override these functions in your keymap file to play different tunes on
// startup and bootloader jump
__attribute__ ((weak))
void play_startup_tone()
{
}
void play_startup_tone() {}
__attribute__ ((weak))
void play_goodbye_tone()
{
}
void play_goodbye_tone() {}
__attribute__ ((weak))
void audio_on_callback(void) {}
//------------------------------------------------------------------------------

View file

@ -29,6 +29,7 @@ bool is_audio_on(void);
void audio_toggle(void);
void audio_on(void);
void audio_off(void);
void audio_on_callback(void);
// Vibrato rate functions

View file

@ -191,8 +191,6 @@ extern const uint16_t fn_actions[];
#define RESET 0x5000
#define DEBUG 0x5001
#define KC_LEAD 0x5014
// MAGIC keycodes
#define MAGIC_SWAP_CONTROL_CAPSLOCK 0x5002
@ -217,6 +215,19 @@ extern const uint16_t fn_actions[];
#define AG_SWAP MAGIC_SWAP_ALT_GUI
#define AG_NORM MAGIC_UNSWAP_ALT_GUI
#define KC_LEAD 0x5014
// Audio on/off
#define AU_ON 0x5020
#define AU_OFF 0x5021
// Music mode on/off
#define MU_ON 0x5022
#define MU_OFF 0x5023
// Music voice iterate
#define MUV_IN 0x5024
#define MUV_DE 0x5025
// GOTO layer - 16 layers max
// when:

View file

@ -21,6 +21,7 @@ void leader_end(void) {}
uint8_t starting_note = 0x0C;
int offset = 0;
bool music_activated = false;
float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
#endif
// Leader key stuff
@ -60,6 +61,15 @@ bool keys_chord(uint8_t keys[]) {
return (pass && (in == keys_size));
}
static bool music_sequence_recording = false;
static bool music_sequence_playing = false;
static float music_sequence[16] = {0};
static uint8_t music_sequence_count = 0;
static uint8_t music_sequence_position = 0;
static uint16_t music_sequence_timer = 0;
static uint16_t music_sequence_interval = 100;
bool process_action_quantum(keyrecord_t *record) {
/* This gets the keycode from the key pressed */
@ -81,12 +91,87 @@ bool process_action_quantum(keyrecord_t *record) {
#endif
#ifdef AUDIO_ENABLE
if (music_activated) {
if (record->event.pressed) {
play_note(((double)220.0)*pow(2.0, -4.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)), 0xF);
} else {
stop_note(((double)220.0)*pow(2.0, -4.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)));
if (keycode == AU_ON && record->event.pressed) {
audio_on();
audio_on_callback();
return false;
}
if (keycode == AU_OFF && record->event.pressed) {
audio_off();
return false;
}
if (keycode == MU_ON && record->event.pressed) {
music_activated = true;
PLAY_NOTE_ARRAY(music_scale, false, 0);
return false;
}
if (keycode == MU_OFF && record->event.pressed) {
music_activated = false;
stop_all_notes();
return false;
}
if (keycode == MUV_IN && record->event.pressed) {
voice_iterate();
PLAY_NOTE_ARRAY(music_scale, false, 0);
return false;
}
if (keycode == MUV_DE && record->event.pressed) {
voice_deiterate();
PLAY_NOTE_ARRAY(music_scale, false, 0);
return false;
}
if (music_activated) {
if (keycode == KC_LCTL && record->event.pressed) { // Start recording
stop_all_notes();
music_sequence_recording = true;
music_sequence_playing = false;
music_sequence_count = 0;
return false;
}
if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing
stop_all_notes();
music_sequence_recording = false;
music_sequence_playing = false;
return false;
}
if (keycode == KC_LGUI && record->event.pressed) { // Start playing
stop_all_notes();
music_sequence_recording = false;
music_sequence_playing = true;
music_sequence_position = 0;
music_sequence_timer = 0;
return false;
}
if (keycode == KC_UP) {
if (record->event.pressed)
music_sequence_interval-=10;
return false;
}
if (keycode == KC_DOWN) {
if (record->event.pressed)
music_sequence_interval+=10;
return false;
}
float freq = ((float)220.0)*pow(2.0, -4.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row));
if (record->event.pressed) {
play_note(freq, 0xF);
if (music_sequence_recording) {
music_sequence[music_sequence_count] = freq;
music_sequence_count++;
}
} else {
stop_note(freq);
}
if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
return false;
}
@ -163,5 +248,16 @@ void matrix_init_quantum() {
}
void matrix_scan_quantum() {
#ifdef AUDIO_ENABLE
if (music_sequence_playing) {
if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
music_sequence_timer = timer_read();
stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]);
play_note(music_sequence[music_sequence_position], 0xF);
music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
}
}
#endif
matrix_scan_kb();
}