diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2016-05-15 00:51:06 -0400 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2016-05-15 00:51:06 -0400 |
| commit | fde477a927edc6b4207a6968d44aeed021e8b300 (patch) | |
| tree | 89a52f005d7d119af31b03261607792aa1f459ff /quantum/quantum.c | |
| parent | bf5c2ccee5497523c214dae7aacdc27fdbb0f235 (diff) | |
| download | qmk_firmware-fde477a927edc6b4207a6968d44aeed021e8b300.tar.gz qmk_firmware-fde477a927edc6b4207a6968d44aeed021e8b300.zip | |
updates midi functionality (#331)
* implements leader key for planck experimental
* allows override of leader timeout
* adds ability to use the leader key in seq
* fixes leader keycode
* adds chording prototype
* fixes keycode detection
* moves music mode to quantum.c
* disables chording by default
* adds music sequencer functionality
* implements audio/music functions in quantum.c
* splits up process_action to allow independent processing of actions
* moves midi stuff to quantum.c
* adds additional scales for midi
Diffstat (limited to 'quantum/quantum.c')
| -rw-r--r-- | quantum/quantum.c | 88 |
1 files changed, 83 insertions, 5 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c index dd5d84f82..5a978d332 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
| @@ -19,11 +19,15 @@ void leader_end(void) {} | |||
| 19 | 19 | ||
| 20 | #ifdef AUDIO_ENABLE | 20 | #ifdef AUDIO_ENABLE |
| 21 | uint8_t starting_note = 0x0C; | 21 | uint8_t starting_note = 0x0C; |
| 22 | int offset = 0; | 22 | int offset = 7; |
| 23 | bool music_activated = false; | 23 | bool music_activated = false; |
| 24 | float music_scale[][2] = SONG(MUSIC_SCALE_SOUND); | 24 | float music_scale[][2] = SONG(MUSIC_SCALE_SOUND); |
| 25 | #endif | 25 | #endif |
| 26 | 26 | ||
| 27 | #ifdef MIDI_ENABLE | ||
| 28 | bool midi_activated = false; | ||
| 29 | #endif | ||
| 30 | |||
| 27 | // Leader key stuff | 31 | // Leader key stuff |
| 28 | bool leading = false; | 32 | bool leading = false; |
| 29 | uint16_t leader_time = 0; | 33 | uint16_t leader_time = 0; |
| @@ -98,6 +102,82 @@ bool process_record_quantum(keyrecord_t *record) { | |||
| 98 | // return false; | 102 | // return false; |
| 99 | // } | 103 | // } |
| 100 | 104 | ||
| 105 | #ifdef MIDI_ENABLE | ||
| 106 | if (keycode == MI_ON && record->event.pressed) { | ||
| 107 | midi_activated = true; | ||
| 108 | PLAY_NOTE_ARRAY(music_scale, false, 0); | ||
| 109 | return false; | ||
| 110 | } | ||
| 111 | |||
| 112 | if (keycode == MI_OFF && record->event.pressed) { | ||
| 113 | midi_activated = false; | ||
| 114 | midi_send_cc(&midi_device, 0, 0x7B, 0); | ||
| 115 | return false; | ||
| 116 | } | ||
| 117 | |||
| 118 | if (midi_activated) { | ||
| 119 | if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) { | ||
| 120 | if (record->event.pressed) { | ||
| 121 | starting_note++; // Change key | ||
| 122 | midi_send_cc(&midi_device, 0, 0x7B, 0); | ||
| 123 | // midi_send_cc(&midi_device, 1, 0x7B, 0); | ||
| 124 | // midi_send_cc(&midi_device, 2, 0x7B, 0); | ||
| 125 | // midi_send_cc(&midi_device, 3, 0x7B, 0); | ||
| 126 | // midi_send_cc(&midi_device, 4, 0x7B, 0); | ||
| 127 | } | ||
| 128 | return false; | ||
| 129 | } | ||
| 130 | if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) { | ||
| 131 | if (record->event.pressed) { | ||
| 132 | starting_note--; // Change key | ||
| 133 | midi_send_cc(&midi_device, 0, 0x7B, 0); | ||
| 134 | // midi_send_cc(&midi_device, 1, 0x7B, 0); | ||
| 135 | // midi_send_cc(&midi_device, 2, 0x7B, 0); | ||
| 136 | // midi_send_cc(&midi_device, 3, 0x7B, 0); | ||
| 137 | // midi_send_cc(&midi_device, 4, 0x7B, 0); | ||
| 138 | } | ||
| 139 | return false; | ||
| 140 | } | ||
| 141 | if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) { | ||
| 142 | offset++; // Change scale | ||
| 143 | midi_send_cc(&midi_device, 0, 0x7B, 0); | ||
| 144 | // midi_send_cc(&midi_device, 1, 0x7B, 0); | ||
| 145 | // midi_send_cc(&midi_device, 2, 0x7B, 0); | ||
| 146 | // midi_send_cc(&midi_device, 3, 0x7B, 0); | ||
| 147 | // midi_send_cc(&midi_device, 4, 0x7B, 0); | ||
| 148 | return false; | ||
| 149 | } | ||
| 150 | if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) { | ||
| 151 | offset--; // Change scale | ||
| 152 | midi_send_cc(&midi_device, 0, 0x7B, 0); | ||
| 153 | // midi_send_cc(&midi_device, 1, 0x7B, 0); | ||
| 154 | // midi_send_cc(&midi_device, 2, 0x7B, 0); | ||
| 155 | // midi_send_cc(&midi_device, 3, 0x7B, 0); | ||
| 156 | // midi_send_cc(&midi_device, 4, 0x7B, 0); | ||
| 157 | return false; | ||
| 158 | } | ||
| 159 | // basic | ||
| 160 | // uint8_t note = (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row); | ||
| 161 | // advanced | ||
| 162 | // uint8_t note = (starting_note + record->event.key.col + offset)+12*(MATRIX_ROWS - record->event.key.row); | ||
| 163 | // guitar | ||
| 164 | uint8_t note = (starting_note + record->event.key.col + offset)+5*(MATRIX_ROWS - record->event.key.row); | ||
| 165 | // violin | ||
| 166 | // uint8_t note = (starting_note + record->event.key.col + offset)+7*(MATRIX_ROWS - record->event.key.row); | ||
| 167 | |||
| 168 | if (record->event.pressed) { | ||
| 169 | // midi_send_noteon(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127); | ||
| 170 | midi_send_noteon(&midi_device, 0, note, 127); | ||
| 171 | } else { | ||
| 172 | // midi_send_noteoff(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127); | ||
| 173 | midi_send_noteoff(&midi_device, 0, note, 127); | ||
| 174 | } | ||
| 175 | |||
| 176 | if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through | ||
| 177 | return false; | ||
| 178 | } | ||
| 179 | #endif | ||
| 180 | |||
| 101 | #ifdef AUDIO_ENABLE | 181 | #ifdef AUDIO_ENABLE |
| 102 | if (keycode == AU_ON && record->event.pressed) { | 182 | if (keycode == AU_ON && record->event.pressed) { |
| 103 | audio_on(); | 183 | audio_on(); |
| @@ -169,7 +249,7 @@ bool process_record_quantum(keyrecord_t *record) { | |||
| 169 | return false; | 249 | return false; |
| 170 | } | 250 | } |
| 171 | 251 | ||
| 172 | 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)); | 252 | float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)); |
| 173 | if (record->event.pressed) { | 253 | if (record->event.pressed) { |
| 174 | play_note(freq, 0xF); | 254 | play_note(freq, 0xF); |
| 175 | if (music_sequence_recording) { | 255 | if (music_sequence_recording) { |
| @@ -185,8 +265,6 @@ bool process_record_quantum(keyrecord_t *record) { | |||
| 185 | } | 265 | } |
| 186 | #endif | 266 | #endif |
| 187 | 267 | ||
| 188 | |||
| 189 | |||
| 190 | #ifndef DISABLE_LEADER | 268 | #ifndef DISABLE_LEADER |
| 191 | // Leader key set-up | 269 | // Leader key set-up |
| 192 | if (record->event.pressed) { | 270 | if (record->event.pressed) { |
| @@ -267,6 +345,6 @@ void matrix_scan_quantum() { | |||
| 267 | } | 345 | } |
| 268 | 346 | ||
| 269 | #endif | 347 | #endif |
| 270 | 348 | ||
| 271 | matrix_scan_kb(); | 349 | matrix_scan_kb(); |
| 272 | } \ No newline at end of file | 350 | } \ No newline at end of file |
