diff options
Diffstat (limited to 'quantum/quantum.c')
| -rw-r--r-- | quantum/quantum.c | 104 |
1 files changed, 100 insertions, 4 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c index e274d846f..cd7fdbb7f 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
| @@ -21,6 +21,7 @@ void leader_end(void) {} | |||
| 21 | uint8_t starting_note = 0x0C; | 21 | uint8_t starting_note = 0x0C; |
| 22 | int offset = 0; | 22 | int offset = 0; |
| 23 | bool music_activated = false; | 23 | bool music_activated = false; |
| 24 | float music_scale[][2] = SONG(MUSIC_SCALE_SOUND); | ||
| 24 | #endif | 25 | #endif |
| 25 | 26 | ||
| 26 | // Leader key stuff | 27 | // Leader key stuff |
| @@ -60,6 +61,15 @@ bool keys_chord(uint8_t keys[]) { | |||
| 60 | return (pass && (in == keys_size)); | 61 | return (pass && (in == keys_size)); |
| 61 | } | 62 | } |
| 62 | 63 | ||
| 64 | static bool music_sequence_recording = false; | ||
| 65 | static bool music_sequence_playing = false; | ||
| 66 | static float music_sequence[16] = {0}; | ||
| 67 | static uint8_t music_sequence_count = 0; | ||
| 68 | static uint8_t music_sequence_position = 0; | ||
| 69 | |||
| 70 | static uint16_t music_sequence_timer = 0; | ||
| 71 | static uint16_t music_sequence_interval = 100; | ||
| 72 | |||
| 63 | bool process_action_quantum(keyrecord_t *record) { | 73 | bool process_action_quantum(keyrecord_t *record) { |
| 64 | 74 | ||
| 65 | /* This gets the keycode from the key pressed */ | 75 | /* This gets the keycode from the key pressed */ |
| @@ -81,12 +91,87 @@ bool process_action_quantum(keyrecord_t *record) { | |||
| 81 | #endif | 91 | #endif |
| 82 | 92 | ||
| 83 | #ifdef AUDIO_ENABLE | 93 | #ifdef AUDIO_ENABLE |
| 84 | if (music_activated) { | 94 | if (keycode == AU_ON && record->event.pressed) { |
| 95 | audio_on(); | ||
| 96 | audio_on_callback(); | ||
| 97 | return false; | ||
| 98 | } | ||
| 99 | |||
| 100 | if (keycode == AU_OFF && record->event.pressed) { | ||
| 101 | audio_off(); | ||
| 102 | return false; | ||
| 103 | } | ||
| 104 | |||
| 105 | if (keycode == MU_ON && record->event.pressed) { | ||
| 106 | music_activated = true; | ||
| 107 | PLAY_NOTE_ARRAY(music_scale, false, 0); | ||
| 108 | return false; | ||
| 109 | } | ||
| 110 | |||
| 111 | if (keycode == MU_OFF && record->event.pressed) { | ||
| 112 | music_activated = false; | ||
| 113 | stop_all_notes(); | ||
| 114 | return false; | ||
| 115 | } | ||
| 116 | |||
| 117 | if (keycode == MUV_IN && record->event.pressed) { | ||
| 118 | voice_iterate(); | ||
| 119 | PLAY_NOTE_ARRAY(music_scale, false, 0); | ||
| 120 | return false; | ||
| 121 | } | ||
| 122 | |||
| 123 | if (keycode == MUV_DE && record->event.pressed) { | ||
| 124 | voice_deiterate(); | ||
| 125 | PLAY_NOTE_ARRAY(music_scale, false, 0); | ||
| 126 | return false; | ||
| 127 | } | ||
| 128 | |||
| 129 | if (music_activated) { | ||
| 130 | |||
| 131 | if (keycode == KC_LCTL && record->event.pressed) { // Start recording | ||
| 132 | stop_all_notes(); | ||
| 133 | music_sequence_recording = true; | ||
| 134 | music_sequence_playing = false; | ||
| 135 | music_sequence_count = 0; | ||
| 136 | return false; | ||
| 137 | } | ||
| 138 | if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing | ||
| 139 | stop_all_notes(); | ||
| 140 | music_sequence_recording = false; | ||
| 141 | music_sequence_playing = false; | ||
| 142 | return false; | ||
| 143 | } | ||
| 144 | if (keycode == KC_LGUI && record->event.pressed) { // Start playing | ||
| 145 | stop_all_notes(); | ||
| 146 | music_sequence_recording = false; | ||
| 147 | music_sequence_playing = true; | ||
| 148 | music_sequence_position = 0; | ||
| 149 | music_sequence_timer = 0; | ||
| 150 | return false; | ||
| 151 | } | ||
| 152 | |||
| 153 | if (keycode == KC_UP) { | ||
| 154 | if (record->event.pressed) | ||
| 155 | music_sequence_interval-=10; | ||
| 156 | return false; | ||
| 157 | } | ||
| 158 | if (keycode == KC_DOWN) { | ||
| 159 | if (record->event.pressed) | ||
| 160 | music_sequence_interval+=10; | ||
| 161 | return false; | ||
| 162 | } | ||
| 163 | |||
| 164 | 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)); | ||
| 85 | if (record->event.pressed) { | 165 | if (record->event.pressed) { |
| 86 | 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); | 166 | play_note(freq, 0xF); |
| 167 | if (music_sequence_recording) { | ||
| 168 | music_sequence[music_sequence_count] = freq; | ||
| 169 | music_sequence_count++; | ||
| 170 | } | ||
| 87 | } else { | 171 | } else { |
| 88 | 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))); | 172 | stop_note(freq); |
| 89 | } | 173 | } |
| 174 | |||
| 90 | if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through | 175 | if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through |
| 91 | return false; | 176 | return false; |
| 92 | } | 177 | } |
| @@ -163,5 +248,16 @@ void matrix_init_quantum() { | |||
| 163 | } | 248 | } |
| 164 | 249 | ||
| 165 | void matrix_scan_quantum() { | 250 | void matrix_scan_quantum() { |
| 251 | #ifdef AUDIO_ENABLE | ||
| 252 | if (music_sequence_playing) { | ||
| 253 | if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) { | ||
| 254 | music_sequence_timer = timer_read(); | ||
| 255 | stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]); | ||
| 256 | play_note(music_sequence[music_sequence_position], 0xF); | ||
| 257 | music_sequence_position = (music_sequence_position + 1) % music_sequence_count; | ||
| 258 | } | ||
| 259 | } | ||
| 260 | |||
| 261 | #endif | ||
| 166 | matrix_scan_kb(); | 262 | matrix_scan_kb(); |
| 167 | } \ No newline at end of file | 263 | } \ No newline at end of file |
