adds music and audio toggles (#337)

* Updated personal layouts

* tweaked personal

* Nightly - Audio Cleanup

Refactored the LUTs. Abstracted some of the registers out of audio to
use more functional names. Split audio into audio and audio_pwm. WIP

* nightly - collapsed code

* Added check for note playing to LEDs

* Usability tweaks

* TWEAE

* nightly

added extra kcs to keymap common

* turned on Plank audio

* Added backlight breathing to atomic

* reverted accidental merge

* Added music and audio toggles to Quantum.c

* Redid the audio callbacks

* music/audio_on_user
This commit is contained in:
Jack Humbert 2016-05-18 23:14:00 -04:00
parent 465aabe11d
commit 0428214b90
6 changed files with 114 additions and 44 deletions

View file

@ -15,8 +15,7 @@
#define LAYER_LOWER 4 #define LAYER_LOWER 4
#define LAYER_FUNCTION 5 #define LAYER_FUNCTION 5
#define LAYER_MOUSE 6 #define LAYER_MOUSE 6
#define LAYER_MUSIC 7 #define LAYER_ADJUST 7
#define LAYER_ADJUST 8
#define MACRO_QWERTY 0 #define MACRO_QWERTY 0
#define MACRO_COLEMAK 1 #define MACRO_COLEMAK 1
@ -63,8 +62,8 @@
#define M_BDFLT M(MACRO_BREATH_DEFAULT) #define M_BDFLT M(MACRO_BREATH_DEFAULT)
#define MUS_TOG M(MACRO_MUSIC_TOGGLE) //#define MU_TOG M(MACRO_MUSIC_TOGGLE)
#define AUD_TOG M(MACRO_AUDIO_TOGGLE) //#define AU_TOG M(MACRO_AUDIO_TOGGLE)
#define VC_UP M(MACRO_INC_VOICE) #define VC_UP M(MACRO_INC_VOICE)
#define VC_DOWN M(MACRO_DEC_VOICE) #define VC_DOWN M(MACRO_DEC_VOICE)
@ -219,20 +218,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
#endif #endif
[LAYER_MUSIC] = { // MUSIC
{ XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX },
{ XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX },
{ XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX },
{ XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX },
{ XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, M_UPPER, XXXXXXX, XXXXXXX, M_LOWER, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX },
},
[LAYER_ADJUST] = { // ADJUST [LAYER_ADJUST] = { // ADJUST
{ _______, TIMBR_1, TIMBR_2, TIMBR_3, TIMBR_4, TMPO_UP, TMPO_DN, TMPO_DF, _______, _______, _______, MUS_TOG, AUD_TOG, ________________ }, { _______, TIMBR_1, TIMBR_2, TIMBR_3, TIMBR_4, TMPO_UP, TMPO_DN, TMPO_DF, _______, _______, _______, MU_TOG, AU_TOG, ________________ },
{ _______, M_QWRTY, M_COLMK, M_DVORK, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ }, { _______, M_QWRTY, M_COLMK, M_DVORK, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
{ _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, ________________, _______ }, { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, ________________, _______ },
{ _______, _______, _______, _______, M_BACKL, RESET, _______, M_MOUSE, _______, _______, _______, ________________, VC_UP, _______ }, { _______, _______, _______, _______, M_BACKL, RESET, _______, M_MOUSE, _______, _______, _______, ________________, MUV_IN, _______ },
{ _______, _______, _______, _______, _______, ________________, _______, _______, _______, _______, _______, _______, VC_DOWN, _______ }, { _______, _______, _______, _______, _______, ________________, _______, _______, _______, _______, _______, _______, MUV_DE, _______ },
}, },
@ -259,13 +250,14 @@ float tone_colemak[][2] = SONG(COLEMAK_SOUND);
float tone_audio_on[][2] = SONG(CLOSE_ENCOUNTERS_5_NOTE); float tone_audio_on[][2] = SONG(CLOSE_ENCOUNTERS_5_NOTE);
float tone_music_on[][2] = SONG(DOE_A_DEER); float tone_music_on[][2] = SONG(DOE_A_DEER);
float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
float tone_caps_on[][2] = SONG(CAPS_LOCK_ON_SOUND); float tone_caps_on[][2] = SONG(CAPS_LOCK_ON_SOUND);
float tone_caps_off[][2] = SONG(CAPS_LOCK_OFF_SOUND); float tone_caps_off[][2] = SONG(CAPS_LOCK_OFF_SOUND);
float tone_numlk_on[][2] = SONG(NUM_LOCK_ON_SOUND); float tone_numlk_on[][2] = SONG(NUM_LOCK_ON_SOUND);
float tone_numlk_off[][2] = SONG(NUM_LOCK_OFF_SOUND); float tone_numlk_off[][2] = SONG(NUM_LOCK_OFF_SOUND);
float tone_scroll_on[][2] = SONG(SCROLL_LOCK_ON_SOUND); float tone_scroll_on[][2] = SONG(SCROLL_LOCK_ON_SOUND);
float tone_scroll_off[][2] = SONG(SCROLL_LOCK_OFF_SOUND); float tone_scroll_off[][2] = SONG(SCROLL_LOCK_OFF_SOUND);
float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
#endif /* AUDIO_ENABLE */ #endif /* AUDIO_ENABLE */
@ -434,6 +426,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
} }
break; break;
/*
case MACRO_AUDIO_TOGGLE: case MACRO_AUDIO_TOGGLE:
if (record->event.pressed) if (record->event.pressed)
{ {
@ -464,7 +457,6 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
} }
} }
break; break;
case MACRO_INC_VOICE: case MACRO_INC_VOICE:
if (record->event.pressed) if (record->event.pressed)
{ {
@ -484,6 +476,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
#endif #endif
} }
break; break;
*/
#endif /* AUDIO_ENABLE */ #endif /* AUDIO_ENABLE */
@ -505,8 +498,8 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
#ifdef AUDIO_ENABLE #ifdef AUDIO_ENABLE
/*
void process_action_user(keyrecord_t *record) bool process_action_user(keyrecord_t *record)
{ {
uint8_t starting_note = 0x0C; uint8_t starting_note = 0x0C;
@ -524,7 +517,7 @@ void process_action_user(keyrecord_t *record)
} }
} }
} }
*/
void matrix_init_user(void) void matrix_init_user(void)
{ {
@ -590,4 +583,19 @@ void play_goodbye_tone()
stop_all_notes(); stop_all_notes();
} }
void play_audio_on_tone(void)
{
PLAY_NOTE_ARRAY(tone_audio_on, false, STACCATO);
}
void play_music_on_tone(void)
{
PLAY_NOTE_ARRAY(tone_music_on, false, STACCATO);
}
void play_music_scale(void)
{
PLAY_NOTE_ARRAY(music_scale, false, STACCATO);
}
#endif /* AUDIO_ENABLE */ #endif /* AUDIO_ENABLE */

View file

@ -381,11 +381,14 @@ bool is_audio_on(void) {
void audio_toggle(void) { void audio_toggle(void) {
audio_config.enable ^= 1; audio_config.enable ^= 1;
eeconfig_update_audio(audio_config.raw); eeconfig_update_audio(audio_config.raw);
if (audio_config.enable)
audio_on_user();
} }
void audio_on(void) { void audio_on(void) {
audio_config.enable = 1; audio_config.enable = 1;
eeconfig_update_audio(audio_config.raw); eeconfig_update_audio(audio_config.raw);
audio_on_user();
} }
void audio_off(void) { void audio_off(void) {
@ -484,5 +487,8 @@ __attribute__ ((weak))
void play_goodbye_tone() {} void play_goodbye_tone() {}
__attribute__ ((weak)) __attribute__ ((weak))
void audio_on_callback(void) {} void audio_on_user() {}
__attribute__ ((weak))
void play_music_scale() {}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View file

@ -29,7 +29,6 @@ bool is_audio_on(void);
void audio_toggle(void); void audio_toggle(void);
void audio_on(void); void audio_on(void);
void audio_off(void); void audio_off(void);
void audio_on_callback(void);
// Vibrato rate functions // Vibrato rate functions
@ -87,9 +86,10 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest)
bool is_playing_notes(void); bool is_playing_notes(void);
void play_goodbye_tone(void); void play_goodbye_tone(void);
void play_startup_tone(void); void play_startup_tone(void);
void audio_on_user(void);
void play_music_scale(void);
#endif #endif

View file

@ -224,18 +224,20 @@ extern const uint16_t fn_actions[];
// Audio on/off // Audio on/off
#define AU_ON 0x5020 #define AU_ON 0x5020
#define AU_OFF 0x5021 #define AU_OFF 0x5021
#define AU_TOG 0x5022
// Music mode on/off // Music mode on/off
#define MU_ON 0x5022 #define MU_ON 0x5023
#define MU_OFF 0x5023 #define MU_OFF 0x5024
#define MU_TOG 0x5025
// Music voice iterate // Music voice iterate
#define MUV_IN 0x5024 #define MUV_IN 0x5026
#define MUV_DE 0x5025 #define MUV_DE 0x5027
// Midi mode on/off // Midi mode on/off
#define MI_ON 0x5026 #define MI_ON 0x5028
#define MI_OFF 0x5027 #define MI_OFF 0x5029
// GOTO layer - 16 layers max // GOTO layer - 16 layers max
// when: // when:

View file

@ -1,4 +1,5 @@
#include "quantum.h" #include "quantum.h"
#include "timer.h"
__attribute__ ((weak)) __attribute__ ((weak))
void matrix_init_kb(void) {} void matrix_init_kb(void) {}
@ -17,11 +18,11 @@ void leader_start(void) {}
__attribute__ ((weak)) __attribute__ ((weak))
void leader_end(void) {} void leader_end(void) {}
uint8_t starting_note = 0x0C;
int offset = 7;
#ifdef AUDIO_ENABLE #ifdef AUDIO_ENABLE
uint8_t starting_note = 0x0C;
int offset = 7;
bool music_activated = false; bool music_activated = false;
float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
#endif #endif
#ifdef MIDI_ENABLE #ifdef MIDI_ENABLE
@ -105,7 +106,7 @@ bool process_record_quantum(keyrecord_t *record) {
#ifdef MIDI_ENABLE #ifdef MIDI_ENABLE
if (keycode == MI_ON && record->event.pressed) { if (keycode == MI_ON && record->event.pressed) {
midi_activated = true; midi_activated = true;
PLAY_NOTE_ARRAY(music_scale, false, 0); play_music_scale();
return false; return false;
} }
@ -181,7 +182,6 @@ bool process_record_quantum(keyrecord_t *record) {
#ifdef AUDIO_ENABLE #ifdef AUDIO_ENABLE
if (keycode == AU_ON && record->event.pressed) { if (keycode == AU_ON && record->event.pressed) {
audio_on(); audio_on();
audio_on_callback();
return false; return false;
} }
@ -190,27 +190,49 @@ bool process_record_quantum(keyrecord_t *record) {
return false; return false;
} }
if (keycode == AU_TOG && record->event.pressed) {
if (is_audio_on())
{
audio_off();
}
else
{
audio_on();
}
return false;
}
if (keycode == MU_ON && record->event.pressed) { if (keycode == MU_ON && record->event.pressed) {
music_activated = true; music_on();
PLAY_NOTE_ARRAY(music_scale, false, 0);
return false; return false;
} }
if (keycode == MU_OFF && record->event.pressed) { if (keycode == MU_OFF && record->event.pressed) {
music_activated = false; music_off();
stop_all_notes(); return false;
}
if (keycode == MU_TOG && record->event.pressed) {
if (music_activated)
{
music_off();
}
else
{
music_on();
}
return false; return false;
} }
if (keycode == MUV_IN && record->event.pressed) { if (keycode == MUV_IN && record->event.pressed) {
voice_iterate(); voice_iterate();
PLAY_NOTE_ARRAY(music_scale, false, 0); play_music_scale();
return false; return false;
} }
if (keycode == MUV_DE && record->event.pressed) { if (keycode == MUV_DE && record->event.pressed) {
voice_deiterate(); voice_deiterate();
PLAY_NOTE_ARRAY(music_scale, false, 0); play_music_scale();
return false; return false;
} }
@ -348,3 +370,28 @@ void matrix_scan_quantum() {
matrix_scan_kb(); matrix_scan_kb();
} }
bool is_music_on(void) {
return (music_activated != 0);
}
void music_toggle(void) {
if (!music_activated) {
music_on();
} else {
music_off();
}
}
void music_on(void) {
music_activated = 1;
music_on_user();
}
void music_off(void) {
music_activated = 0;
stop_all_notes();
}
__attribute__ ((weak))
void music_on_user() {}

View file

@ -46,4 +46,11 @@ void leader_end(void);
#define LEADER_EXTERNS() extern bool leading; extern uint16_t leader_time; extern uint16_t leader_sequence[3]; extern uint8_t leader_sequence_size #define LEADER_EXTERNS() extern bool leading; extern uint16_t leader_time; extern uint16_t leader_sequence[3]; extern uint8_t leader_sequence_size
#define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT) #define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT)
bool is_music_on(void);
void music_toggle(void);
void music_on(void);
void music_off(void);
void music_on_user(void);
#endif #endif