summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/audio/audio.c11
-rw-r--r--quantum/audio/audio.h1
-rw-r--r--quantum/keymap_common.h15
-rw-r--r--quantum/quantum.c104
4 files changed, 119 insertions, 12 deletions
diff --git a/quantum/audio/audio.c b/quantum/audio/audio.c
index 27b64f8c96..243f49f0ee 100644
--- a/quantum/audio/audio.c
+++ b/quantum/audio/audio.c
@@ -478,12 +478,11 @@ void increase_tempo(uint8_t tempo_change) {
// Override these functions in your keymap file to play different tunes on
// startup and bootloader jump
__attribute__ ((weak))
-void play_startup_tone()
-{
-}
+void play_startup_tone() {}
__attribute__ ((weak))
-void play_goodbye_tone()
-{
-}
+void play_goodbye_tone() {}
+
+__attribute__ ((weak))
+void audio_on_callback(void) {}
//------------------------------------------------------------------------------
diff --git a/quantum/audio/audio.h b/quantum/audio/audio.h
index 4ba879bbb1..fe85061318 100644
--- a/quantum/audio/audio.h
+++ b/quantum/audio/audio.h
@@ -29,6 +29,7 @@ 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
diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h
index 2ad1ba6c60..4107d575be 100644
--- a/quantum/keymap_common.h
+++ b/quantum/keymap_common.h
@@ -191,8 +191,6 @@ extern const uint16_t fn_actions[];
#define RESET 0x5000
#define DEBUG 0x5001
-#define KC_LEAD 0x5014
-
// MAGIC keycodes
#define MAGIC_SWAP_CONTROL_CAPSLOCK 0x5002
@@ -217,6 +215,19 @@ extern const uint16_t fn_actions[];
#define AG_SWAP MAGIC_SWAP_ALT_GUI
#define AG_NORM MAGIC_UNSWAP_ALT_GUI
+#define KC_LEAD 0x5014
+
+// Audio on/off
+#define AU_ON 0x5020
+#define AU_OFF 0x5021
+
+// Music mode on/off
+#define MU_ON 0x5022
+#define MU_OFF 0x5023
+
+// Music voice iterate
+#define MUV_IN 0x5024
+#define MUV_DE 0x5025
// GOTO layer - 16 layers max
// when:
diff --git a/quantum/quantum.c b/quantum/quantum.c
index e274d846f2..cd7fdbb7fe 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -21,6 +21,7 @@ void leader_end(void) {}
uint8_t starting_note = 0x0C;
int offset = 0;
bool music_activated = false;
+ float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
#endif
// Leader key stuff
@@ -60,6 +61,15 @@ bool keys_chord(uint8_t keys[]) {
return (pass && (in == keys_size));
}
+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;
+
bool process_action_quantum(keyrecord_t *record) {
/* This gets the keycode from the key pressed */
@@ -81,12 +91,87 @@ bool process_action_quantum(keyrecord_t *record) {
#endif
#ifdef AUDIO_ENABLE
- if (music_activated) {
+ if (keycode == AU_ON && record->event.pressed) {
+ audio_on();
+ audio_on_callback();
+ return false;
+ }
+
+ if (keycode == AU_OFF && record->event.pressed) {
+ audio_off();
+ return false;
+ }
+
+ if (keycode == MU_ON && record->event.pressed) {
+ music_activated = true;
+ PLAY_NOTE_ARRAY(music_scale, false, 0);
+ return false;
+ }
+
+ if (keycode == MU_OFF && record->event.pressed) {
+ music_activated = false;
+ stop_all_notes();
+ return false;
+ }
+
+ if (keycode == MUV_IN && record->event.pressed) {
+ voice_iterate();
+ PLAY_NOTE_ARRAY(music_scale, false, 0);
+ return false;
+ }
+
+ if (keycode == MUV_DE && record->event.pressed) {
+ voice_deiterate();
+ PLAY_NOTE_ARRAY(music_scale, false, 0);
+ return false;
+ }
+
+ if (music_activated) {
+
+ if (keycode == KC_LCTL && record->event.pressed) { // Start recording
+ stop_all_notes();
+ music_sequence_recording = true;
+ music_sequence_playing = false;
+ 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;
+ 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;
+ }
+
+ float freq = ((float)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));
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);
+ play_note(freq, 0xF);
+ if (music_sequence_recording) {
+ music_sequence[music_sequence_count] = freq;
+ music_sequence_count++;
+ }
} 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)));
- }
+ stop_note(freq);
+ }
+
if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
return false;
}
@@ -163,5 +248,16 @@ void matrix_init_quantum() {
}
void matrix_scan_quantum() {
+ #ifdef AUDIO_ENABLE
+ if (music_sequence_playing) {
+ if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
+ music_sequence_timer = timer_read();
+ stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]);
+ play_note(music_sequence[music_sequence_position], 0xF);
+ music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
+ }
+ }
+
+ #endif
matrix_scan_kb();
} \ No newline at end of file