forked from mirrors/qmk_userspace
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:
parent
465aabe11d
commit
0428214b90
6 changed files with 114 additions and 44 deletions
|
@ -381,11 +381,14 @@ bool is_audio_on(void) {
|
|||
void audio_toggle(void) {
|
||||
audio_config.enable ^= 1;
|
||||
eeconfig_update_audio(audio_config.raw);
|
||||
if (audio_config.enable)
|
||||
audio_on_user();
|
||||
}
|
||||
|
||||
void audio_on(void) {
|
||||
audio_config.enable = 1;
|
||||
eeconfig_update_audio(audio_config.raw);
|
||||
audio_on_user();
|
||||
}
|
||||
|
||||
void audio_off(void) {
|
||||
|
@ -484,5 +487,8 @@ __attribute__ ((weak))
|
|||
void play_goodbye_tone() {}
|
||||
|
||||
__attribute__ ((weak))
|
||||
void audio_on_callback(void) {}
|
||||
void audio_on_user() {}
|
||||
|
||||
__attribute__ ((weak))
|
||||
void play_music_scale() {}
|
||||
//------------------------------------------------------------------------------
|
||||
|
|
|
@ -29,7 +29,6 @@ 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
|
||||
|
||||
|
@ -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);
|
||||
|
||||
void play_goodbye_tone(void);
|
||||
void play_startup_tone(void);
|
||||
|
||||
|
||||
void audio_on_user(void);
|
||||
void play_music_scale(void);
|
||||
|
||||
#endif
|
|
@ -224,18 +224,20 @@ extern const uint16_t fn_actions[];
|
|||
// Audio on/off
|
||||
#define AU_ON 0x5020
|
||||
#define AU_OFF 0x5021
|
||||
#define AU_TOG 0x5022
|
||||
|
||||
// Music mode on/off
|
||||
#define MU_ON 0x5022
|
||||
#define MU_OFF 0x5023
|
||||
#define MU_ON 0x5023
|
||||
#define MU_OFF 0x5024
|
||||
#define MU_TOG 0x5025
|
||||
|
||||
// Music voice iterate
|
||||
#define MUV_IN 0x5024
|
||||
#define MUV_DE 0x5025
|
||||
#define MUV_IN 0x5026
|
||||
#define MUV_DE 0x5027
|
||||
|
||||
// Midi mode on/off
|
||||
#define MI_ON 0x5026
|
||||
#define MI_OFF 0x5027
|
||||
#define MI_ON 0x5028
|
||||
#define MI_OFF 0x5029
|
||||
|
||||
// GOTO layer - 16 layers max
|
||||
// when:
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "quantum.h"
|
||||
#include "timer.h"
|
||||
|
||||
__attribute__ ((weak))
|
||||
void matrix_init_kb(void) {}
|
||||
|
@ -17,11 +18,11 @@ void leader_start(void) {}
|
|||
__attribute__ ((weak))
|
||||
void leader_end(void) {}
|
||||
|
||||
uint8_t starting_note = 0x0C;
|
||||
int offset = 7;
|
||||
|
||||
#ifdef AUDIO_ENABLE
|
||||
uint8_t starting_note = 0x0C;
|
||||
int offset = 7;
|
||||
bool music_activated = false;
|
||||
float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
|
||||
#endif
|
||||
|
||||
#ifdef MIDI_ENABLE
|
||||
|
@ -105,7 +106,7 @@ bool process_record_quantum(keyrecord_t *record) {
|
|||
#ifdef MIDI_ENABLE
|
||||
if (keycode == MI_ON && record->event.pressed) {
|
||||
midi_activated = true;
|
||||
PLAY_NOTE_ARRAY(music_scale, false, 0);
|
||||
play_music_scale();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -181,7 +182,6 @@ bool process_record_quantum(keyrecord_t *record) {
|
|||
#ifdef AUDIO_ENABLE
|
||||
if (keycode == AU_ON && record->event.pressed) {
|
||||
audio_on();
|
||||
audio_on_callback();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -190,31 +190,53 @@ bool process_record_quantum(keyrecord_t *record) {
|
|||
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) {
|
||||
music_activated = true;
|
||||
PLAY_NOTE_ARRAY(music_scale, false, 0);
|
||||
music_on();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keycode == MU_OFF && record->event.pressed) {
|
||||
music_activated = false;
|
||||
stop_all_notes();
|
||||
music_off();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keycode == MU_TOG && record->event.pressed) {
|
||||
if (music_activated)
|
||||
{
|
||||
music_off();
|
||||
}
|
||||
else
|
||||
{
|
||||
music_on();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keycode == MUV_IN && record->event.pressed) {
|
||||
voice_iterate();
|
||||
PLAY_NOTE_ARRAY(music_scale, false, 0);
|
||||
play_music_scale();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keycode == MUV_DE && record->event.pressed) {
|
||||
voice_deiterate();
|
||||
PLAY_NOTE_ARRAY(music_scale, false, 0);
|
||||
play_music_scale();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (music_activated) {
|
||||
if (music_activated) {
|
||||
|
||||
if (keycode == KC_LCTL && record->event.pressed) { // Start recording
|
||||
stop_all_notes();
|
||||
|
@ -258,7 +280,7 @@ bool process_record_quantum(keyrecord_t *record) {
|
|||
}
|
||||
} else {
|
||||
stop_note(freq);
|
||||
}
|
||||
}
|
||||
|
||||
if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
|
||||
return false;
|
||||
|
@ -347,4 +369,29 @@ void matrix_scan_quantum() {
|
|||
#endif
|
||||
|
||||
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() {}
|
|
@ -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_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
|
Loading…
Add table
Add a link
Reference in a new issue