Converted audio play functions to *_user (#349)

* 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

* Adjusted default planck layout to use the user tone naming

* tabs to spaces

* Rewrote the ALL recipe to allow for faster parallel make

* tabs to spaces

* Renamed custom event functions to be 'startup_user' and 'shutdown_user'. Also moved the prototypes around.

* Tweaked pvc atomic layout to work with the pvc planck.

* updates midi scale calling
This commit is contained in:
Jack Humbert
2016-05-24 11:56:53 -04:00
parent 1ae6011cef
commit 287eb7ad14
11 changed files with 214 additions and 281 deletions
+9 -32
View File
@@ -62,8 +62,6 @@
#define M_BDFLT M(MACRO_BREATH_DEFAULT)
//#define MU_TOG M(MACRO_MUSIC_TOGGLE)
//#define AU_TOG M(MACRO_AUDIO_TOGGLE)
#define VC_UP M(MACRO_INC_VOICE)
#define VC_DOWN M(MACRO_DEC_VOICE)
@@ -156,11 +154,11 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* UPPER
* .---------------------------------------------------------------------------------------------------------------------- 2u ------------.
* | PRINT | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | NUM LK | / | * | - | NUM LK | SCR LK | XXXXXX . PAUSE |
* | PRINT | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | XXXXXX | NUM LK | / | * | | NUM LK | SCR LK | XXXXXX . PAUSE |
* |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+-----------------|
* | | F1 | F2 | F3 | F4 | | | 7 | 8 | 9 | + | ~ | | | INS |
* | | F1 | F2 | F3 | F4 | | | 7 | 8 | 9 | - | | | | INS |
* |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+- 2u ------------+--------|
* | CAP LK | F5 | F6 | F7 | F8 | | | 4 | 5 | 6 | + | ` | XXXXXX . | HOME |
* | CAP LK | F5 | F6 | F7 | F8 | | | 4 | 5 | 6 | + | | XXXXXX . | HOME |
* |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+- 2u ---------------------+--------|
* | | F9 | F10 | F11 | F12 | | | 1 | 2 | 3 | ENTER | XXXXXX . | | END |
* |--------+--------+--------+--------+--------+- 2u ------------+--------+--------+--------+--------+-----------------+--------+--------|
@@ -498,31 +496,10 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
#ifdef AUDIO_ENABLE
/*
bool process_action_user(keyrecord_t *record)
{
uint8_t starting_note = 0x0C;
int offset = 7;
if (IS_LAYER_ON(LAYER_MUSIC))
{
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)));
}
}
}
*/
void matrix_init_user(void)
{
set_voice(default_voice);
play_startup_tone();
startup_user();
println("Matrix Init");
}
@@ -570,30 +547,30 @@ void led_set_user(uint8_t usb_led)
}
void play_startup_tone()
void startup_user()
{
_delay_ms(10); // gets rid of tick
PLAY_NOTE_ARRAY(tone_my_startup, false, STACCATO);
}
void play_goodbye_tone()
void shutdown_user()
{
PLAY_NOTE_ARRAY(tone_my_goodbye, false, STACCATO);
_delay_ms(2000);
stop_all_notes();
}
void play_audio_on_tone(void)
void audio_on_user(void)
{
PLAY_NOTE_ARRAY(tone_audio_on, false, STACCATO);
}
void play_music_on_tone(void)
void music_on_user(void)
{
PLAY_NOTE_ARRAY(tone_music_on, false, STACCATO);
}
void play_music_scale(void)
void music_scale_user(void)
{
PLAY_NOTE_ARRAY(music_scale, false, STACCATO);
}
+28 -15
View File
@@ -174,21 +174,16 @@ const uint16_t PROGMEM fn_actions[] = {
};
#ifdef AUDIO_ENABLE
float tone_startup[][2] = {
{440.0*pow(2.0,(31)/12.0), 12},
{440.0*pow(2.0,(28)/12.0), 8},
{440.0*pow(2.0,(19)/12.0), 8},
{440.0*pow(2.0,(24)/12.0), 8},
{440.0*pow(2.0,(28)/12.0), 20}
};
float tone_startup[][2] = SONG(STARTUP_SOUND);
float tone_qwerty[][2] = SONG(QWERTY_SOUND);
float tone_dvorak[][2] = SONG(DVORAK_SOUND);
float tone_colemak[][2] = SONG(COLEMAK_SOUND);
float tone_plover[][2] = SONG(PLOVER_SOUND);
float tone_plover_gb[][2] = SONG(PLOVER_GOODBYE_SOUND);
float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
float goodbye[][2] = SONG(GOODBYE_SOUND);
float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
#endif
@@ -288,16 +283,34 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
};
void matrix_init_user(void) {
#ifdef AUDIO_ENABLE
_delay_ms(20); // stops the tick
PLAY_NOTE_ARRAY(tone_startup, false, 0);
#endif
#ifdef AUDIO_ENABLE
startup_user();
#endif
}
#ifdef AUDIO_ENABLE
void play_goodbye_tone()
void startup_user()
{
PLAY_NOTE_ARRAY(goodbye, false, 0);
_delay_ms(150);
_delay_ms(20); // gets rid of tick
PLAY_NOTE_ARRAY(tone_startup, false, 0);
}
void shutdown_user()
{
PLAY_NOTE_ARRAY(tone_goodbye, false, 0);
_delay_ms(150);
stop_all_notes();
}
void music_on_user(void)
{
music_scale_user();
}
void music_scale_user(void)
{
PLAY_NOTE_ARRAY(music_scale, false, 0);
}
#endif
+1 -1
View File
@@ -74,7 +74,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* disable debug print */
#define NO_DEBUG
//#define NO_DEBUG
/* disable print */
//#define NO_PRINT
File diff suppressed because it is too large Load Diff
-17
View File
@@ -475,20 +475,3 @@ void increase_tempo(uint8_t tempo_change) {
note_tempo -= tempo_change;
}
}
//------------------------------------------------------------------------------
// Override these functions in your keymap file to play different tunes on
// startup and bootloader jump
__attribute__ ((weak))
void play_startup_tone() {}
__attribute__ ((weak))
void play_goodbye_tone() {}
__attribute__ ((weak))
void audio_on_user() {}
__attribute__ ((weak))
void play_music_scale() {}
//------------------------------------------------------------------------------
+1 -5
View File
@@ -5,6 +5,7 @@
#include "musical_notes.h"
#include "song_list.h"
#include "voices.h"
#include "quantum.h"
#ifndef AUDIO_H
#define AUDIO_H
@@ -87,9 +88,4 @@ 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
+2 -1
View File
@@ -26,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "backlight.h"
#include "bootloader.h"
#include "eeconfig.h"
#include "quantum.h"
#ifdef MIDI_ENABLE
#include "keymap_midi.h"
@@ -190,7 +191,7 @@ static action_t keycode_to_action(uint16_t keycode)
clear_keyboard();
#ifdef AUDIO_ENABLE
stop_all_notes();
play_goodbye_tone();
shutdown_user();
#endif
_delay_ms(250);
#ifdef ATREUS_ASTAR
+45 -24
View File
@@ -23,17 +23,16 @@ int offset = 7;
#ifdef AUDIO_ENABLE
bool music_activated = false;
float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
// music sequencer
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;
// music sequencer
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;
static uint16_t music_sequence_timer = 0;
static uint16_t music_sequence_interval = 100;
#endif
@@ -133,7 +132,7 @@ bool process_record_quantum(keyrecord_t *record) {
#ifdef MIDI_ENABLE
if (keycode == MI_ON && record->event.pressed) {
midi_activated = true;
play_music_scale();
music_scale_user();
return false;
}
@@ -230,37 +229,37 @@ bool process_record_quantum(keyrecord_t *record) {
}
if (keycode == MU_ON && record->event.pressed) {
music_on();
return false;
music_on();
return false;
}
if (keycode == MU_OFF && record->event.pressed) {
music_off();
return false;
music_off();
return false;
}
if (keycode == MU_TOG && record->event.pressed) {
if (music_activated)
{
music_off();
music_off();
}
else
{
music_on();
music_on();
}
return false;
}
if (keycode == MUV_IN && record->event.pressed) {
voice_iterate();
play_music_scale();
return false;
voice_iterate();
music_scale_user();
return false;
}
if (keycode == MUV_DE && record->event.pressed) {
voice_deiterate();
play_music_scale();
return false;
voice_deiterate();
music_scale_user();
return false;
}
if (music_activated) {
@@ -272,12 +271,14 @@ bool process_record_quantum(keyrecord_t *record) {
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;
@@ -289,12 +290,13 @@ bool process_record_quantum(keyrecord_t *record) {
if (keycode == KC_UP) {
if (record->event.pressed)
music_sequence_interval-=10;
music_sequence_interval-=10;
return false;
}
if (keycode == KC_DOWN) {
if (record->event.pressed)
music_sequence_interval+=10;
music_sequence_interval+=10;
return false;
}
@@ -459,5 +461,24 @@ void matrix_scan_quantum() {
}
#endif
//------------------------------------------------------------------------------
// Override these functions in your keymap file to play different tunes on
// different events such as startup and bootloader jump
__attribute__ ((weak))
void startup_user() {}
__attribute__ ((weak))
void shutdown_user() {}
__attribute__ ((weak))
void music_on_user() {}
__attribute__ ((weak))
void audio_on_user() {}
__attribute__ ((weak))
void music_scale_user() {}
//------------------------------------------------------------------------------
+4
View File
@@ -67,6 +67,10 @@ void music_toggle(void);
void music_on(void);
void music_off(void);
void startup_user(void);
void shutdown_user(void);
void audio_on_user(void);
void music_on_user(void);
void music_scale_user(void);
#endif
+7 -6
View File
@@ -33,20 +33,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "led.h"
#include "command.h"
#include "backlight.h"
#include "quantum.h"
#ifdef MOUSEKEY_ENABLE
#include "mousekey.h"
#endif
#ifdef PROTOCOL_PJRC
# include "usb_keyboard.h"
# ifdef EXTRAKEY_ENABLE
# include "usb_extra.h"
# endif
#include "usb_keyboard.h"
#ifdef EXTRAKEY_ENABLE
#include "usb_extra.h"
#endif
#endif
#ifdef PROTOCOL_VUSB
# include "usbdrv.h"
#include "usbdrv.h"
#endif
#ifdef AUDIO_ENABLE
@@ -358,7 +359,7 @@ static bool command_common(uint8_t code)
print("\n\nJumping to bootloader... ");
#ifdef AUDIO_ENABLE
stop_all_notes();
play_goodbye_tone();
shutdown_user();
#else
_delay_ms(1000);
#endif
+7 -1
View File
@@ -366,7 +366,13 @@ ALL_ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
# Default target.
all: begin gccversion sizebefore build sizeafter end
all:
$(MAKE) begin
$(MAKE) gccversion
$(MAKE) sizebefore
$(MAKE) build
$(MAKE) sizeafter
$(MAKE) end
# Change the build target to build a HEX file or a library.
build: elf hex eep lss sym