summaryrefslogtreecommitdiffstats
path: root/quantum/process_keycode
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2017-07-22 06:14:26 +0200
committerJack Humbert <jack.humb@gmail.com>2017-07-23 20:59:29 +0200
commit415d38ba9ee20424ce354ed5f8e590fae58b863f (patch)
tree663b609ace954533aff4a964b4c7cb3300bd73cd /quantum/process_keycode
parent9abbbe70890ee0a0c619411c76a2c7b82b1b49d5 (diff)
downloadqmk_firmware-415d38ba9ee20424ce354ed5f8e590fae58b863f.tar.gz
qmk_firmware-415d38ba9ee20424ce354ed5f8e590fae58b863f.tar.xz
adds music mode, music mode songs, music mask
Diffstat (limited to 'quantum/process_keycode')
-rw-r--r--quantum/process_keycode/process_audio.c16
-rw-r--r--quantum/process_keycode/process_music.c127
-rw-r--r--quantum/process_keycode/process_music.h9
3 files changed, 99 insertions, 53 deletions
diff --git a/quantum/process_keycode/process_audio.c b/quantum/process_keycode/process_audio.c
index 0b6380ed3..eb74796fa 100644
--- a/quantum/process_keycode/process_audio.c
+++ b/quantum/process_keycode/process_audio.c
@@ -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;
}
diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c
index ec2287df1..63841d1e8 100644
--- a/quantum/process_keycode/process_music.c
+++ b/quantum/process_keycode/process_music.c
@@ -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 (music_activated) {
+ if (keycode == MU_MOD && record->event.pressed) {
+ music_mode_cycle();
+ return false;
+ }
- 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 (music_activated) {
+ 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 && record->event.pressed) { // Stop recording/playing
- music_all_notes_off();
- if (music_sequence_recording) { // was recording
- music_sequence_recorded = true;
+ 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;
}
- 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_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) {
- if (record->event.pressed)
- music_sequence_interval-=10;
- return false;
- }
+ if (keycode == KC_UP) {
+ music_sequence_interval-=10;
+ return false;
+ }
- if (keycode == KC_DOWN) {
- if (record->event.pressed)
- music_sequence_interval+=10;
- return false;
+ if (keycode == KC_DOWN) {
+ 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)) {
diff --git a/quantum/process_keycode/process_music.h b/quantum/process_keycode/process_music.h
index 8dfbf041f..ee027197c 100644
--- a/quantum/process_keycode/process_music.h
+++ b/quantum/process_keycode/process_music.h
@@ -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);