aboutsummaryrefslogtreecommitdiff
path: root/docs/feature_midi.md
diff options
context:
space:
mode:
authorwxyangf <2058629+wxyangf@users.noreply.github.com>2021-06-07 02:53:20 -0400
committerGitHub <noreply@github.com>2021-06-06 23:53:20 -0700
commitb10728edc1ce897939833ccca447640804888854 (patch)
tree81775c467ec8b59bd59415fa85659537e5edae15 /docs/feature_midi.md
parent94e80912a4cda3a92f6865cf0b5a199fd97ae95b (diff)
downloadqmk_firmware-b10728edc1ce897939833ccca447640804888854.tar.gz
qmk_firmware-b10728edc1ce897939833ccca447640804888854.zip
[Docs] added basic midi documention of common features (#13113)
Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> Co-authored-by: Ryan <fauxpark@gmail.com> Co-authored-by: Joel Challis <git@zvecr.com>
Diffstat (limited to 'docs/feature_midi.md')
-rw-r--r--docs/feature_midi.md260
1 files changed, 260 insertions, 0 deletions
diff --git a/docs/feature_midi.md b/docs/feature_midi.md
new file mode 100644
index 000000000..ab29d89db
--- /dev/null
+++ b/docs/feature_midi.md
@@ -0,0 +1,260 @@
1# MIDI
2
3## Usage
4
5First, enable MIDI by adding the following to your `rules.mk`:
6
7```makefile
8MIDI_ENABLE = yes
9```
10
11There are two MIDI systems in QMK: basic and advanced. With basic MIDI you will only be able to send Note On and Note Off messages using the note keycodes, meaning that keycodes like `MI_OCTU` and `MI_OCTD` will not work. Advanced MIDI allows you to do things like octave shifts, channel changes, velocity changes, modulation, and more.
12
13### Basic MIDI
14
15To enable basic MIDI, add the following to your `config.h`:
16
17```c
18#define MIDI_BASIC
19```
20
21### Advanced MIDI
22
23To enable advanced MIDI, add the following to your `config.h`:
24
25```c
26#define MIDI_ADVANCED
27```
28
29#### Sending Control Change (CC) Messages
30
31If you're aiming to emulate the features of something like a Launchpad or other MIDI controller you'll need to access the internal MIDI device directly.
32
33Because there are so many possible CC messages, not all of them are implemented as keycodes. Additionally, you might need to provide more than just two values that you would get from a keycode (pressed and released) - for example, the analog values from a fader or a potentiometer. So, you will need to implement [custom keycodes](feature_macros.md) if you want to use them in your keymap directly using `process_record_user()`.
34
35
36For reference of all the possible control code numbers see [MIDI Specification](#midi-specification)
37
38#### Example code for using Generic On Off Switches as per MIDI Specification.
39```c
40#include QMK_KEYBOARD_H
41
42extern MidiDevice midi_device;
43
44// MIDI CC codes for generic on/off switches (80, 81, 82, 83)
45// Off: 0-63
46// On: 64-127
47
48#define MIDI_CC_OFF 0
49#define MIDI_CC_ON 127
50
51enum custom_keycodes {
52 MIDI_CC80 = SAFE_RANGE,
53};
54
55bool process_record_user(uint16_t keycode, keyrecord_t *record) {
56 switch (keycode) {
57 case MIDI_CC80:
58 if (record->event.pressed) {
59 midi_send_cc(&midi_device, midi_config.channel, 80, ON);
60 } else {
61 midi_send_cc(&midi_device, midi_config.channel, 80, OFF);
62 }
63 return true;
64 }
65 return true;
66};
67
68const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
69 LAYOUT(
70 // ...
71 MIDI_CC80,
72 // ...
73 )
74};
75```
76
77### Keycodes
78
79|Keycode |Aliases |Description |
80|------------|---------|---------------------------------|
81|`MI_ON` | |Turn MIDI on |
82|`MI_OFF` | |Turn MIDI off |
83|`MI_TOG` | |Toggle MIDI enabled |
84|`MI_C` | |C octave 0 |
85|`MI_Cs` |`MI_Db` |C♯/D♭ octave 0 |
86|`MI_D` | |D octave 0 |
87|`MI_Ds` |`MI_Eb` |D♯/E♭ octave 0 |
88|`MI_E` | |E octave 0 |
89|`MI_F` | |F octave 0 |
90|`MI_Fs` |`MI_Gb` |F♯/G♭ octave 0 |
91|`MI_G` | |G octave 0 |
92|`MI_Gs` |`MI_Gs` |G♯/A♭ octave 0 |
93|`MI_A` | |A octave 0 |
94|`MI_As` |`MI_Bb` |A♯/B♭ octave 0 |
95|`MI_B` | |B octave 0 |
96|`MI_C_1` | |C octave 1 |
97|`MI_Cs_1` |`MI_Db_1`|C♯/D♭ octave 1 |
98|`MI_D_1` | |D octave 1 |
99|`MI_Ds_1` |`MI_Eb_1`|D♯/E♭ octave 1 |
100|`MI_E_1` | |E octave 1 |
101|`MI_F_1` | |F octave 1 |
102|`MI_Fs_1` |`MI_Gb_1`|F♯/G♭ octave 1 |
103|`MI_G_1` | |G octave 1 |
104|`MI_Gs_1` |`MI_Ab_1`|G♯/A♭ octave 1 |
105|`MI_A_1` | |A octave 1 |
106|`MI_As_1` |`MI_Bb_1`|A♯/B♭ octave 1 |
107|`MI_B_1` | |B octave 1 |
108|`MI_C_2` | |C octave 2 |
109|`MI_Cs_2` |`MI_Db_2`|C♯/D♭ octave 2 |
110|`MI_D_2` | |D octave 2 |
111|`MI_Ds_2` |`MI_Eb_2`|D♯/E♭ octave 2 |
112|`MI_E_2` | |E octave 2 |
113|`MI_F_2` | |F octave 2 |
114|`MI_Fs_2` |`MI_Gb_2`|F♯/G♭ octave 2 |
115|`MI_G_2` | |G octave 2 |
116|`MI_Gs_2` |`MI_Ab_2`|G♯/A♭ octave 2 |
117|`MI_A_2` | |A octave 2 |
118|`MI_As_2` |`MI_Bb_2`|A♯/B♭ octave 2 |
119|`MI_B_2` | |B octave 2 |
120|`MI_C_3` | |C octave 3 |
121|`MI_Cs_3` |`MI_Db_3`|C♯/D♭ octave 3 |
122|`MI_D_3` | |D octave 3 |
123|`MI_Ds_3` |`MI_Eb_3`|D♯/E♭ octave 3 |
124|`MI_E_3` | |E octave 3 |
125|`MI_F_3` | |F octave 3 |
126|`MI_Fs_3` |`MI_Gb_3`|F♯/G♭ octave 3 |
127|`MI_G_3` | |G octave 3 |
128|`MI_Gs_3` |`MI_Ab_3`|G♯/A♭ octave 3 |
129|`MI_A_3` | |A octave 3 |
130|`MI_As_3` |`MI_Bb_3`|A♯/B♭ octave 3 |
131|`MI_B_3` | |B octave 3 |
132|`MI_C_4` | |C octave 4 |
133|`MI_Cs_4` |`MI_Db_4`|C♯/D♭ octave 4 |
134|`MI_D_4` | |D octave 4 |
135|`MI_Ds_4` |`MI_Eb_4`|D♯/E♭ octave 4 |
136|`MI_E_4` | |E octave 4 |
137|`MI_F_4` | |F octave 4 |
138|`MI_Fs_4` |`MI_Gb_4`|F♯/G♭ octave 4 |
139|`MI_G_4` | |G octave 4 |
140|`MI_Gs_4` |`MI_Ab_4`|G♯/A♭ octave 4 |
141|`MI_A_4` | |A octave 4 |
142|`MI_As_4` |`MI_Bb_4`|A♯/B♭ octave 4 |
143|`MI_B_4` | |B octave 4 |
144|`MI_C_5` | |C octave 5 |
145|`MI_Cs_5` |`MI_Db_5`|C♯/D♭ octave 5 |
146|`MI_D_5` | |D octave 5 |
147|`MI_Ds_5` |`MI_Eb_5`|D♯/E♭ octave 5 |
148|`MI_E_5` | |E octave 5 |
149|`MI_F_5` | |F octave 5 |
150|`MI_Fs_5` |`MI_Gb_5`|F♯/G♭ octave 5 |
151|`MI_G_5` | |G octave 5 |
152|`MI_Gs_5` |`MI_Ab_5`|G♯/A♭ octave 5 |
153|`MI_A_5` | |A octave 5 |
154|`MI_As_5` |`MI_Bb_5`|A♯/B♭ octave 5 |
155|`MI_B_5` | |B octave 5 |
156|`MI_OCT_N2` | |Set octave to -2 |
157|`MI_OCT_N1` | |Set octave to -1 |
158|`MI_OCT_0` | |Set octave to 0 |
159|`MI_OCT_1` | |Set octave to 1 |
160|`MI_OCT_2` | |Set octave to 2 |
161|`MI_OCT_3` | |Set octave to 3 |
162|`MI_OCT_4` | |Set octave to 4 |
163|`MI_OCT_5` | |Set octave to 5 |
164|`MI_OCT_6` | |Set octave to 6 |
165|`MI_OCT_7` | |Set octave to 7 |
166|`MI_OCTD` | |Move down an octave |
167|`MI_OCTU` | |Move up an octave |
168|`MI_TRNS_N6`| |Set transposition to -6 semitones|
169|`MI_TRNS_N5`| |Set transposition to -5 semitones|
170|`MI_TRNS_N4`| |Set transposition to -4 semitones|
171|`MI_TRNS_N3`| |Set transposition to -3 semitones|
172|`MI_TRNS_N2`| |Set transposition to -2 semitones|
173|`MI_TRNS_N1`| |Set transposition to -1 semitone |
174|`MI_TRNS_0` | |No transposition |
175|`MI_TRNS_1` | |Set transposition to +1 semitone |
176|`MI_TRNS_2` | |Set transposition to +2 semitones|
177|`MI_TRNS_3` | |Set transposition to +3 semitones|
178|`MI_TRNS_4` | |Set transposition to +4 semitones|
179|`MI_TRNS_5` | |Set transposition to +5 semitones|
180|`MI_TRNS_6` | |Set transposition to +6 semitones|
181|`MI_TRNSD` | |Decrease transposition |
182|`MI_TRNSU` | |Increase transposition |
183|`MI_VEL_0` | |Set velocity to 0 |
184|`MI_VEL_1` | |Set velocity to 12 |
185|`MI_VEL_2` | |Set velocity to 25 |
186|`MI_VEL_3` | |Set velocity to 38 |
187|`MI_VEL_4` | |Set velocity to 51 |
188|`MI_VEL_5` | |Set velocity to 64 |
189|`MI_VEL_6` | |Set velocity to 76 |
190|`MI_VEL_7` | |Set velocity to 89 |
191|`MI_VEL_8` | |Set velocity to 102 |
192|`MI_VEL_9` | |Set velocity to 114 |
193|`MI_VEL_10` | |Set velocity to 127 |
194|`MI_VELD` | |Decrease velocity |
195|`MI_VELU` | |Increase velocity |
196|`MI_CH1` | |Set channel to 1 |
197|`MI_CH2` | |Set channel to 2 |
198|`MI_CH3` | |Set channel to 3 |
199|`MI_CH4` | |Set channel to 4 |
200|`MI_CH5` | |Set channel to 5 |
201|`MI_CH6` | |Set channel to 6 |
202|`MI_CH7` | |Set channel to 7 |
203|`MI_CH8` | |Set channel to 8 |
204|`MI_CH9` | |Set channel to 9 |
205|`MI_CH10` | |Set channel to 10 |
206|`MI_CH11` | |Set channel to 11 |
207|`MI_CH12` | |Set channel to 12 |
208|`MI_CH13` | |Set channel to 13 |
209|`MI_CH14` | |Set channel to 14 |
210|`MI_CH15` | |Set channel to 15 |
211|`MI_CH16` | |Set channel to 16 |
212|`MI_CHD` | |Decrease channel |
213|`MI_CHU` | |Increase channel |
214|`MI_ALLOFF` | |Stop all notes |
215|`MI_SUS` | |Sustain |
216|`MI_PORT` | |Portmento |
217|`MI_SOST` | |Sostenuto |
218|`MI_SOFT` | |Soft Pedal |
219|`MI_LEG` | |Legato |
220|`MI_MOD` | |Modulation |
221|`MI_MODSD` | |Decrease modulation speed |
222|`MI_MODSU` | |Increase modulation speed |
223|`MI_BENDD` | |Bend pitch down |
224|`MI_BENDU` | |Bend pitch up |
225
226### Configuration
227
228Certain values are stored in the `midi_config` struct. This configuration is not persisted to EEPROM. By default, these values are:
229
230|Configuration |Value|Comments |
231|-------------------|-----|-------------------------|
232|Octave |`4` |Corresponds to `MI_OCT_2`|
233|Transposition |`0` | |
234|Velocity |`127`| |
235|Channel |`0` | |
236|Modulation Interval|`8` | |
237
238For the above, the `MI_C` keycode will produce a C3 (note number 48), and so on.
239
240### References
241#### MIDI Specification
242
243 * [MIDI.org](https://www.midi.org/specifications-old/item/table-1-summary-of-midi-message)
244 * [CMU MIDI Programmer's Reference](https://www.cs.cmu.edu/~music/cmsip/readings/MIDI%20tutorial%20for%20programmers.html)
245#### QMK C Files
246
247 * `quantum/process_keycode/process_midi.c`
248 * `quantum/quantum_keycodes.h`
249 * `tmk_core/protocol/midi.h`
250 * `tmk_core/protocol/midi.c`
251 * `tmk_core/protocol/qmk_midi.c`
252 * `tmk_core/protocol/midi_device.h`
253
254<!--
255#### QMK Internals (Autogenerated)
256
257 * [Internals/MIDI Device Setup Process](internals_midi_device_setup_process.md)
258 * [Internals/MIDI Device](internals_midi_device.md)
259 * [Internals/MIDI Util](internals_midi_util.md)
260-->