aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Young <gabeplaysdrums@live.com>2017-02-25 15:02:43 -0800
committerGabriel Young <gabeplaysdrums@live.com>2017-02-25 15:02:43 -0800
commit525be99ee938aa6e48448d7dd6ea6e6fe50bb36d (patch)
tree8842033e455e5a2546894d03b701ae8fe2f565a7
parent64eecfc5303788bd82bf2fb466ec4a6f1bd0c028 (diff)
downloadqmk_firmware-525be99ee938aa6e48448d7dd6ea6e6fe50bb36d.tar.gz
qmk_firmware-525be99ee938aa6e48448d7dd6ea6e6fe50bb36d.zip
Split MIDI functionality into MIDI_BASIC and MIDI_ADVANCED
MIDI_ENABLE = no text data bss dec hex filename 0 17080 0 17080 42b8 satan_midi.hex MIDI_ENABLE = yes MIDI_BASIC undefined MIDI_ADVANCED undefined text data bss dec hex filename 0 19494 0 19494 4c26 satan_midi.hex MIDI_ENABLE = yes #define MIDI_BASIC MIDI_ADVANCED undefined text data bss dec hex filename 0 19788 0 19788 4d4c satan_midi.hex MIDI_ENABLE = yes MIDI_BASIC undefined #define MIDI_ADVANCED text data bss dec hex filename 0 20846 0 20846 516e satan_midi.hex MIDI_ENABLE = yes #define MIDI_BASIC #define MIDI_ADVANCED text data bss dec hex filename 0 21140 0 21140 5294 satan_midi.hex
-rw-r--r--build_keyboard.mk1
-rw-r--r--keyboards/satan/keymaps/midi/config.h17
-rw-r--r--keyboards/satan/keymaps/midi/keymap.c4
-rw-r--r--quantum/process_keycode/process_midi.c9
-rw-r--r--quantum/process_keycode/process_music.c22
-rw-r--r--quantum/quantum.c4
-rw-r--r--quantum/quantum_keycodes.h13
-rw-r--r--quantum/template/config.h17
-rw-r--r--tmk_core/protocol/lufa/lufa.c4
9 files changed, 80 insertions, 11 deletions
diff --git a/build_keyboard.mk b/build_keyboard.mk
index 4a6fc0980..eea8d5919 100644
--- a/build_keyboard.mk
+++ b/build_keyboard.mk
@@ -141,6 +141,7 @@ endif
141 141
142ifeq ($(strip $(MIDI_ENABLE)), yes) 142ifeq ($(strip $(MIDI_ENABLE)), yes)
143 OPT_DEFS += -DMIDI_ENABLE 143 OPT_DEFS += -DMIDI_ENABLE
144 SRC += $(QUANTUM_DIR)/process_keycode/process_music.c
144 SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c 145 SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c
145endif 146endif
146 147
diff --git a/keyboards/satan/keymaps/midi/config.h b/keyboards/satan/keymaps/midi/config.h
index 0dbdb5cbc..59250b49e 100644
--- a/keyboards/satan/keymaps/midi/config.h
+++ b/keyboards/satan/keymaps/midi/config.h
@@ -3,7 +3,22 @@
3 3
4#include "../../config.h" 4#include "../../config.h"
5 5
6// place overrides here 6/*
7 * MIDI options
8 */
9
10/* enable basic MIDI features:
11 - MIDI notes can be sent when in Music mode is on
12*/
13#define MIDI_BASIC
14
15/* enable advanced MIDI features:
16 - MIDI notes can be added to the keymap
17 - Octave shift and transpose
18 - Virtual sustain, portamento, and modulation wheel
19 - etc.
20*/
21#define MIDI_ADVANCED
7 22
8/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ 23/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
9#define MIDI_TONE_KEYCODE_OCTAVES 2 24#define MIDI_TONE_KEYCODE_OCTAVES 2
diff --git a/keyboards/satan/keymaps/midi/keymap.c b/keyboards/satan/keymaps/midi/keymap.c
index 397fe097b..349391c3b 100644
--- a/keyboards/satan/keymaps/midi/keymap.c
+++ b/keyboards/satan/keymaps/midi/keymap.c
@@ -32,7 +32,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
32 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT, \ 32 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT, \
33 KC_LCTL, KC_LGUI,KC_LALT, KC_SPC, KC_RALT,KC_RGUI, TG(_ML), KC_RCTL), 33 KC_LCTL, KC_LGUI,KC_LALT, KC_SPC, KC_RALT,KC_RGUI, TG(_ML), KC_RCTL),
34 34
35#ifdef MIDI_ENABLE 35#if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
36/* Keymap _ML: MIDI Layer 36/* Keymap _ML: MIDI Layer
37 * ,------------------------------------------------------------------------. 37 * ,------------------------------------------------------------------------.
38 * | Exit | | | | | | | | | | | | | | 38 * | Exit | | | | | | | | | | | | | |
@@ -51,6 +51,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
51 MI_CHU, XXXXXXX, MI_Cs, MI_Ds, XXXXXXX, MI_Fs, MI_Gs, MI_As, XXXXXXX, MI_Cs_1, MI_Ds_1, XXXXXXX, XXXXXXX, XXXXXXX, \ 51 MI_CHU, XXXXXXX, MI_Cs, MI_Ds, XXXXXXX, MI_Fs, MI_Gs, MI_As, XXXXXXX, MI_Cs_1, MI_Ds_1, XXXXXXX, XXXXXXX, XXXXXXX, \
52 MI_MOD, MI_C, MI_D, MI_E, MI_F, MI_G, MI_A, MI_B, MI_C_1, MI_D_1, MI_E_1, MI_F_1, _______, \ 52 MI_MOD, MI_C, MI_D, MI_E, MI_F, MI_G, MI_A, MI_B, MI_C_1, MI_D_1, MI_E_1, MI_F_1, _______, \
53 MI_SUS, MI_OCTD, MI_OCTU, MI_MODSD, MI_MODSU, XXXXXXX, XXXXXXX, XXXXXXX, MI_TRNSD, MI_TRNSU, MI_TRNS_0, MI_SUS, \ 53 MI_SUS, MI_OCTD, MI_OCTU, MI_MODSD, MI_MODSU, XXXXXXX, XXXXXXX, XXXXXXX, MI_TRNSD, MI_TRNSU, MI_TRNS_0, MI_SUS, \
54 _______, _______, _______, MI_OFF, _______, _______, _______, _______), 54 _______, _______, _______, MI_ALLOFF, _______, _______, _______, _______),
55#endif 55#endif
56}; \ No newline at end of file 56}; \ No newline at end of file
diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c
index 5530ea97c..161f04a24 100644
--- a/quantum/process_keycode/process_midi.c
+++ b/quantum/process_keycode/process_midi.c
@@ -1,6 +1,7 @@
1#define MIDI_TONE_KEYCODE_OCTAVES 2
2
3#include "process_midi.h" 1#include "process_midi.h"
2
3#if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
4
4#include "timer.h" 5#include "timer.h"
5 6
6static uint8_t tone_status[MIDI_TONE_COUNT]; 7static uint8_t tone_status[MIDI_TONE_COUNT];
@@ -161,7 +162,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
161 dprintf("midi channel %d\n", midi_config.channel); 162 dprintf("midi channel %d\n", midi_config.channel);
162 } 163 }
163 return false; 164 return false;
164 case MI_OFF: 165 case MI_ALLOFF:
165 if (record->event.pressed) { 166 if (record->event.pressed) {
166 midi_send_cc(&midi_device, midi_config.channel, 0x7B, 0); 167 midi_send_cc(&midi_device, midi_config.channel, 0x7B, 0);
167 dprintf("midi off\n"); 168 dprintf("midi off\n");
@@ -209,3 +210,5 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
209 210
210 return true; 211 return true;
211} 212}
213
214#endif // MIDI_ADVANCED
diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c
index 1e2648bff..ac906b628 100644
--- a/quantum/process_keycode/process_music.c
+++ b/quantum/process_keycode/process_music.c
@@ -17,6 +17,7 @@ static uint16_t music_sequence_interval = 100;
17 17
18bool process_music(uint16_t keycode, keyrecord_t *record) { 18bool process_music(uint16_t keycode, keyrecord_t *record) {
19 19
20 #ifdef AUDIO_ENABLE
20 if (keycode == AU_ON && record->event.pressed) { 21 if (keycode == AU_ON && record->event.pressed) {
21 audio_on(); 22 audio_on();
22 return false; 23 return false;
@@ -38,6 +39,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
38 } 39 }
39 return false; 40 return false;
40 } 41 }
42 #endif // AUDIO_ENABLE
41 43
42 if (keycode == MU_ON && record->event.pressed) { 44 if (keycode == MU_ON && record->event.pressed) {
43 music_on(); 45 music_on();
@@ -61,6 +63,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
61 return false; 63 return false;
62 } 64 }
63 65
66 #ifdef AUDIO_ENABLE
64 if (keycode == MUV_IN && record->event.pressed) { 67 if (keycode == MUV_IN && record->event.pressed) {
65 voice_iterate(); 68 voice_iterate();
66 music_scale_user(); 69 music_scale_user();
@@ -72,11 +75,14 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
72 music_scale_user(); 75 music_scale_user();
73 return false; 76 return false;
74 } 77 }
78 #endif // AUDIO_ENABLE
75 79
76 if (music_activated) { 80 if (music_activated) {
77 81
78 if (keycode == KC_LCTL && record->event.pressed) { // Start recording 82 if (keycode == KC_LCTL && record->event.pressed) { // Start recording
83 #ifdef AUDIO_ENABLE
79 stop_all_notes(); 84 stop_all_notes();
85 #endif
80 music_sequence_recording = true; 86 music_sequence_recording = true;
81 music_sequence_recorded = false; 87 music_sequence_recorded = false;
82 music_sequence_playing = false; 88 music_sequence_playing = false;
@@ -85,7 +91,9 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
85 } 91 }
86 92
87 if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing 93 if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing
94 #ifdef AUDIO_ENABLE
88 stop_all_notes(); 95 stop_all_notes();
96 #endif
89 if (music_sequence_recording) { // was recording 97 if (music_sequence_recording) { // was recording
90 music_sequence_recorded = true; 98 music_sequence_recorded = true;
91 } 99 }
@@ -95,7 +103,9 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
95 } 103 }
96 104
97 if (keycode == KC_LGUI && record->event.pressed && music_sequence_recorded) { // Start playing 105 if (keycode == KC_LGUI && record->event.pressed && music_sequence_recorded) { // Start playing
106 #ifdef AUDIO_ENABLE
98 stop_all_notes(); 107 stop_all_notes();
108 #endif
99 music_sequence_recording = false; 109 music_sequence_recording = false;
100 music_sequence_playing = true; 110 music_sequence_playing = true;
101 music_sequence_position = 0; 111 music_sequence_position = 0;
@@ -116,6 +126,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
116 } 126 }
117 #define MUSIC_MODE_GUITAR 127 #define MUSIC_MODE_GUITAR
118 128
129 #ifdef AUDIO_ENABLE
119 #ifdef MUSIC_MODE_CHROMATIC 130 #ifdef MUSIC_MODE_CHROMATIC
120 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(MATRIX_ROWS - record->event.key.row)); 131 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(MATRIX_ROWS - record->event.key.row));
121 #elif defined(MUSIC_MODE_GUITAR) 132 #elif defined(MUSIC_MODE_GUITAR)
@@ -125,15 +136,20 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
125 #else 136 #else
126 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + SCALE[record->event.key.col + music_offset])/12.0+(MATRIX_ROWS - record->event.key.row)); 137 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + SCALE[record->event.key.col + music_offset])/12.0+(MATRIX_ROWS - record->event.key.row));
127 #endif 138 #endif
139 #endif // AUDIO_ENABLE
128 140
129 if (record->event.pressed) { 141 if (record->event.pressed) {
142 #ifdef AUDIO_ENABLE
130 play_note(freq, 0xF); 143 play_note(freq, 0xF);
131 if (music_sequence_recording) { 144 if (music_sequence_recording) {
132 music_sequence[music_sequence_count] = freq; 145 music_sequence[music_sequence_count] = freq;
133 music_sequence_count++; 146 music_sequence_count++;
134 } 147 }
148 #endif
135 } else { 149 } else {
150 #ifdef AUDIO_ENABLE
136 stop_note(freq); 151 stop_note(freq);
152 #endif
137 } 153 }
138 154
139 if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through 155 if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
@@ -161,15 +177,19 @@ void music_on(void) {
161 177
162void music_off(void) { 178void music_off(void) {
163 music_activated = 0; 179 music_activated = 0;
180 #ifdef AUDIO_ENABLE
164 stop_all_notes(); 181 stop_all_notes();
182 #endif
165} 183}
166 184
167 185
168__attribute__ ((weak)) 186__attribute__ ((weak))
169void music_on_user() {} 187void music_on_user() {}
170 188
189#ifdef AUDIO_ENABLE
171__attribute__ ((weak)) 190__attribute__ ((weak))
172void audio_on_user() {} 191void audio_on_user() {}
192#endif
173 193
174__attribute__ ((weak)) 194__attribute__ ((weak))
175void music_scale_user() {} 195void music_scale_user() {}
@@ -178,8 +198,10 @@ void matrix_scan_music(void) {
178 if (music_sequence_playing) { 198 if (music_sequence_playing) {
179 if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) { 199 if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
180 music_sequence_timer = timer_read(); 200 music_sequence_timer = timer_read();
201 #ifdef AUDIO_ENABLE
181 stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]); 202 stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]);
182 play_note(music_sequence[music_sequence_position], 0xF); 203 play_note(music_sequence[music_sequence_position], 0xF);
204 #endif
183 music_sequence_position = (music_sequence_position + 1) % music_sequence_count; 205 music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
184 } 206 }
185 } 207 }
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 4a6d0355f..83fa87708 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -150,10 +150,10 @@ bool process_record_quantum(keyrecord_t *record) {
150 150
151 if (!( 151 if (!(
152 process_record_kb(keycode, record) && 152 process_record_kb(keycode, record) &&
153 #ifdef MIDI_ENABLE 153 #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
154 process_midi(keycode, record) && 154 process_midi(keycode, record) &&
155 #endif 155 #endif
156 #ifdef AUDIO_ENABLE 156 #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
157 process_music(keycode, record) && 157 process_music(keycode, record) &&
158 #endif 158 #endif
159 #ifdef TAP_DANCE_ENABLE 159 #ifdef TAP_DANCE_ENABLE
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index 6d1438051..3b82b7208 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -2,7 +2,7 @@
2#ifndef QUANTUM_KEYCODES_H 2#ifndef QUANTUM_KEYCODES_H
3#define QUANTUM_KEYCODES_H 3#define QUANTUM_KEYCODES_H
4 4
5#ifdef MIDI_ENABLE 5#if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
6#ifndef MIDI_TONE_KEYCODE_OCTAVES 6#ifndef MIDI_TONE_KEYCODE_OCTAVES
7#define MIDI_TONE_KEYCODE_OCTAVES 3 7#define MIDI_TONE_KEYCODE_OCTAVES 3
8#endif 8#endif
@@ -116,6 +116,12 @@ enum quantum_keycodes {
116#ifdef MIDI_ENABLE 116#ifdef MIDI_ENABLE
117 // Midi 117 // Midi
118 118
119#ifdef MIDI_BASIC
120 MI_ON, // send midi notes when music mode is enabled
121 MI_OFF, // don't send midi notes when music mode is enabled
122#endif
123
124#ifdef MIDI_ADVANCED
119 MIDI_TONE_MIN, 125 MIDI_TONE_MIN,
120 126
121#if MIDI_TONE_KEYCODE_OCTAVES > 0 127#if MIDI_TONE_KEYCODE_OCTAVES > 0
@@ -321,7 +327,7 @@ enum quantum_keycodes {
321 MI_CHD, // previous channel 327 MI_CHD, // previous channel
322 MI_CHU, // next channel 328 MI_CHU, // next channel
323 329
324 MI_OFF, // all notes off 330 MI_ALLOFF, // all notes off
325 331
326 MI_SUS, // sustain 332 MI_SUS, // sustain
327 MI_PORT, // portamento 333 MI_PORT, // portamento
@@ -332,7 +338,8 @@ enum quantum_keycodes {
332 MI_MOD, // modulation 338 MI_MOD, // modulation
333 MI_MODSD, // decrease modulation speed 339 MI_MODSD, // decrease modulation speed
334 MI_MODSU, // increase modulation speed 340 MI_MODSU, // increase modulation speed
335#endif 341#endif // MIDI_ADVANCED
342#endif // MIDI_ENABLE
336 343
337 // Backlight functionality 344 // Backlight functionality
338 BL_0, 345 BL_0,
diff --git a/quantum/template/config.h b/quantum/template/config.h
index cd6dfa2c6..54db4f242 100644
--- a/quantum/template/config.h
+++ b/quantum/template/config.h
@@ -159,6 +159,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
159//#define NO_ACTION_MACRO 159//#define NO_ACTION_MACRO
160//#define NO_ACTION_FUNCTION 160//#define NO_ACTION_FUNCTION
161 161
162/*
163 * MIDI options
164 */
165
166/* enable basic MIDI features:
167 - MIDI notes can be sent when in Music mode is on
168*/
169//#define MIDI_BASIC
170
171/* enable advanced MIDI features:
172 - MIDI notes can be added to the keymap
173 - Octave shift and transpose
174 - Virtual sustain, portamento, and modulation wheel
175 - etc.
176*/
177//#define MIDI_ADVANCED
178
162/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ 179/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
163//#define MIDI_TONE_KEYCODE_OCTAVES 1 180//#define MIDI_TONE_KEYCODE_OCTAVES 1
164 181
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index bd2498057..651a0f347 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -1104,7 +1104,9 @@ void sysex_callback(MidiDevice * device,
1104 1104
1105void setup_midi(void) 1105void setup_midi(void)
1106{ 1106{
1107#ifdef MIDI_ADVANCED
1107 midi_init(); 1108 midi_init();
1109#endif
1108 midi_device_init(&midi_device); 1110 midi_device_init(&midi_device);
1109 midi_device_set_send_func(&midi_device, usb_send_func); 1111 midi_device_set_send_func(&midi_device, usb_send_func);
1110 midi_device_set_pre_input_process_func(&midi_device, usb_get_midi); 1112 midi_device_set_pre_input_process_func(&midi_device, usb_get_midi);
@@ -1180,8 +1182,10 @@ int main(void)
1180 1182
1181#ifdef MIDI_ENABLE 1183#ifdef MIDI_ENABLE
1182 midi_device_process(&midi_device); 1184 midi_device_process(&midi_device);
1185#ifdef MIDI_ADVANCED
1183 midi_task(); 1186 midi_task();
1184#endif 1187#endif
1188#endif
1185 1189
1186#if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE) 1190#if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE)
1187 rgblight_task(); 1191 rgblight_task();