adds music mode, music mode songs, music mask

This commit is contained in:
Jack Humbert 2017-07-22 00:14:26 -04:00
parent 9abbbe7089
commit 415d38ba9e
10 changed files with 168 additions and 81 deletions

View file

@ -3,6 +3,18 @@
#include "../../config.h"
#ifdef AUDIO_ENABLE
#define STARTUP_SONG SONG(PLANCK_SOUND)
// #define STARTUP_SONG SONG(NO_SOUND)
#define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
SONG(COLEMAK_SOUND), \
SONG(DVORAK_SOUND) \
}
#endif
#define MUSIC_MASK (keycode != KC_NO)
/*
* MIDI options
*/
@ -13,18 +25,9 @@
/* enable basic MIDI features:
- MIDI notes can be sent when in Music mode is on
*/
#define MIDI_BASIC
#ifdef AUDIO_ENABLE
#define STARTUP_SONG SONG(PLANCK_SOUND)
// #define STARTUP_SONG SONG(NO_SOUND)
#define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
SONG(COLEMAK_SOUND), \
SONG(DVORAK_SOUND) \
}
#endif
/* enable advanced MIDI features:
- MIDI notes can be added to the keymap
- Octave shift and transpose

View file

@ -164,7 +164,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
*/
[_ADJUST] = {
{_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL },
{_______, _______, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, PLOVER, _______},
{_______, _______, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, PLOVER, _______},
{_______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______},
{_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
}

View file

@ -3,6 +3,18 @@
#include "../../config.h"
#ifdef AUDIO_ENABLE
#define STARTUP_SONG SONG(PLANCK_SOUND)
// #define STARTUP_SONG SONG(NO_SOUND)
#define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
SONG(COLEMAK_SOUND), \
SONG(DVORAK_SOUND) \
}
#endif
#define MUSIC_MASK (keycode != KC_NO)
/*
* MIDI options
*/
@ -13,18 +25,9 @@
/* enable basic MIDI features:
- MIDI notes can be sent when in Music mode is on
*/
#define MIDI_BASIC
#ifdef AUDIO_ENABLE
#define STARTUP_SONG SONG(PLANCK_SOUND)
// #define STARTUP_SONG SONG(NO_SOUND)
#define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
SONG(COLEMAK_SOUND), \
SONG(DVORAK_SOUND) \
}
#endif
/* enable advanced MIDI features:
- MIDI notes can be added to the keymap
- Octave shift and transpose

View file

@ -158,7 +158,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_ADJUST] = {
{KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12},
{_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL},
{_______, _______, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, _______, _______},
{_______, _______, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, _______, _______},
{_______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______},
{_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
}

View file

@ -100,8 +100,8 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat);
#define NOTE_ARRAY_SIZE(x) ((int16_t)(sizeof(x) / (sizeof(x[0]))))
#define PLAY_NOTE_ARRAY(note_array, note_repeat, deprecated_arg) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), (note_repeat)); \
_Pragma ("message \"'PLAY_NOTE_ARRAY' macro is deprecated\"")
#define PLAY_SONG(note_array) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), false);
#define PLAY_LOOP(note_array) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), true);
#define PLAY_SONG(note_array) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), false)
#define PLAY_LOOP(note_array) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), true)
bool is_playing_notes(void);

View file

@ -139,6 +139,38 @@
E__NOTE(_B5), \
E__NOTE(_A5 ),
#define VOICE_CHANGE_SOUND \
Q__NOTE(_A5 ), \
Q__NOTE(_CS6), \
Q__NOTE(_E6 ), \
Q__NOTE(_A6 ),
#define CHROMATIC_SOUND \
Q__NOTE(_A5 ), \
Q__NOTE(_AS5 ), \
Q__NOTE(_B5), \
Q__NOTE(_C6 ), \
Q__NOTE(_CS6 ),
#define MAJOR_SOUND \
Q__NOTE(_A5 ), \
Q__NOTE(_B5 ), \
Q__NOTE(_CS6), \
Q__NOTE(_D6 ), \
Q__NOTE(_E6 ),
#define GUITAR_SOUND \
Q__NOTE(_E5 ), \
Q__NOTE(_A5), \
Q__NOTE(_D6 ), \
Q__NOTE(_G6 ),
#define VIOLIN_SOUND \
Q__NOTE(_G5 ), \
Q__NOTE(_D6), \
Q__NOTE(_A6 ), \
Q__NOTE(_E7 ),
#define CAPS_LOCK_ON_SOUND \
E__NOTE(_A3), \
E__NOTE(_B3),

View file

@ -1,6 +1,11 @@
#include "audio.h"
#include "process_audio.h"
#ifndef VOICE_CHANGE_SONG
#define VOICE_CHANGE_SONG SONG(VOICE_CHANGE_SOUND)
#endif
float voice_change_song[][2] = VOICE_CHANGE_SONG;
static float compute_freq_for_midi_note(uint8_t note)
{
// https://en.wikipedia.org/wiki/MIDI_tuning_standard
@ -20,12 +25,9 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) {
}
if (keycode == AU_TOG && record->event.pressed) {
if (is_audio_on())
{
if (is_audio_on()) {
audio_off();
}
else
{
} else {
audio_on();
}
return false;
@ -33,13 +35,13 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) {
if (keycode == MUV_IN && record->event.pressed) {
voice_iterate();
music_scale_user();
PLAY_SONG(voice_change_song);
return false;
}
if (keycode == MUV_DE && record->event.pressed) {
voice_deiterate();
music_scale_user();
PLAY_SONG(voice_change_song);
return false;
}

View file

@ -27,6 +27,7 @@
bool music_activated = false;
uint8_t music_starting_note = 0x0C;
int music_offset = 7;
uint8_t music_mode = MUSIC_MODE_CHROMATIC;
// music sequencer
static bool music_sequence_recording = false;
@ -46,10 +47,32 @@ static uint16_t music_sequence_interval = 100;
#ifndef MUSIC_OFF_SONG
#define MUSIC_OFF_SONG SONG(MUSIC_OFF_SOUND)
#endif
#ifndef CHROMATIC_SONG
#define CHROMATIC_SONG SONG(CHROMATIC_SOUND)
#endif
#ifndef GUITAR_SONG
#define GUITAR_SONG SONG(GUITAR_SOUND)
#endif
#ifndef VIOLIN_SONG
#define VIOLIN_SONG SONG(VIOLIN_SOUND)
#endif
#ifndef MAJOR_SONG
#define MAJOR_SONG SONG(MAJOR_SOUND)
#endif
float music_mode_songs[NUMBER_OF_MODES][5][2] = {
CHROMATIC_SONG,
GUITAR_SONG,
VIOLIN_SONG,
MAJOR_SONG
};
float music_on_song[][2] = MUSIC_ON_SONG;
float music_off_song[][2] = MUSIC_OFF_SONG;
#endif
#ifndef MUSIC_MASK
#define MUSIC_MASK keycode < 0xFF
#endif
static void music_noteon(uint8_t note) {
#ifdef AUDIO_ENABLE
process_audio_noteon(note);
@ -98,59 +121,63 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
return false;
}
if (keycode == MU_MOD && record->event.pressed) {
music_mode_cycle();
return false;
}
if (music_activated) {
if (keycode == KC_LCTL && record->event.pressed) { // Start recording
music_all_notes_off();
music_sequence_recording = true;
music_sequence_recorded = false;
music_sequence_playing = false;
music_sequence_count = 0;
return false;
}
if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing
music_all_notes_off();
if (music_sequence_recording) { // was recording
music_sequence_recorded = true;
if (record->event.pressed) {
if (keycode == KC_LCTL) { // Start recording
music_all_notes_off();
music_sequence_recording = true;
music_sequence_recorded = false;
music_sequence_playing = false;
music_sequence_count = 0;
return false;
}
if (keycode == KC_LALT) { // Stop recording/playing
music_all_notes_off();
if (music_sequence_recording) { // was recording
music_sequence_recorded = true;
}
music_sequence_recording = false;
music_sequence_playing = false;
return false;
}
if (keycode == KC_LGUI && music_sequence_recorded) { // Start playing
music_all_notes_off();
music_sequence_recording = false;
music_sequence_playing = true;
music_sequence_position = 0;
music_sequence_timer = 0;
return false;
}
if (keycode == KC_UP) {
music_sequence_interval-=10;
return false;
}
if (keycode == KC_DOWN) {
music_sequence_interval+=10;
return false;
}
music_sequence_recording = false;
music_sequence_playing = false;
return false;
}
if (keycode == KC_LGUI && record->event.pressed && music_sequence_recorded) { // Start playing
music_all_notes_off();
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;
}
#define MUSIC_MODE_GUITAR
#ifdef MUSIC_MODE_CHROMATIC
uint8_t note = (music_starting_note + record->event.key.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.row);
#elif defined(MUSIC_MODE_GUITAR)
uint8_t note = (music_starting_note + record->event.key.col + music_offset + 32)+5*(MATRIX_ROWS - record->event.key.row);
#elif defined(MUSIC_MODE_VIOLIN)
uint8_t note = (music_starting_note + record->event.key.col + music_offset + 32)+7*(MATRIX_ROWS - record->event.key.row);
#else
uint8_t note = (music_starting_note + SCALE[record->event.key.col + music_offset] - 3)+12*(MATRIX_ROWS - record->event.key.row);
#endif
uint8_t note;
if (music_mode == MUSIC_MODE_CHROMATIC)
note = (music_starting_note + record->event.key.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.row);
else if (music_mode == MUSIC_MODE_GUITAR)
note = (music_starting_note + record->event.key.col + music_offset + 32)+5*(MATRIX_ROWS - record->event.key.row);
else if (music_mode == MUSIC_MODE_VIOLIN)
note = (music_starting_note + record->event.key.col + music_offset + 32)+7*(MATRIX_ROWS - record->event.key.row);
else if (music_mode == MUSIC_MODE_MAJOR)
note = (music_starting_note + SCALE[record->event.key.col + music_offset] - 3)+12*(MATRIX_ROWS - record->event.key.row);
else
note = music_starting_note;
if (record->event.pressed) {
music_noteon(note);
@ -162,7 +189,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
music_noteoff(note);
}
if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
if (MUSIC_MASK)
return false;
}
@ -197,6 +224,14 @@ void music_off(void) {
#endif
}
void music_mode_cycle(void) {
music_all_notes_off();
music_mode = (music_mode + 1) % NUMBER_OF_MODES;
#ifdef AUDIO_ENABLE
PLAY_SONG(music_mode_songs[music_mode]);
#endif
}
void matrix_scan_music(void) {
if (music_sequence_playing) {
if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {

View file

@ -21,6 +21,14 @@
#if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
enum music_modes {
MUSIC_MODE_CHROMATIC,
MUSIC_MODE_GUITAR,
MUSIC_MODE_VIOLIN,
MUSIC_MODE_MAJOR,
NUMBER_OF_MODES
};
bool process_music(uint16_t keycode, keyrecord_t *record);
bool is_music_on(void);
@ -31,6 +39,7 @@ void music_off(void);
void music_on_user(void);
void music_scale_user(void);
void music_all_notes_off(void);
void music_mode_cycle(void);
void matrix_scan_music(void);

View file

@ -132,6 +132,9 @@ enum quantum_keycodes {
MU_OFF,
MU_TOG,
// Music mode cycle
MU_MOD,
// Music voice iterate
MUV_IN,
MUV_DE,