You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

208 lines
5.9 KiB

  1. # Audio
  2. Your keyboard can make sounds! If you've got a Planck, Preonic, or basically any AVR keyboard that allows access to the C6 or B5 port (`#define C6_AUDIO` and/or `#define B5_AUDIO`), you can hook up a simple speaker and make it beep. You can use those beeps to indicate layer transitions, modifiers, special keys, or just to play some funky 8bit tunes.
  3. If you add `AUDIO_ENABLE = yes` to your `rules.mk`, there's a couple different sounds that will automatically be enabled without any other configuration:
  4. ```
  5. STARTUP_SONG // plays when the keyboard starts up (audio.c)
  6. GOODBYE_SONG // plays when you press the RESET key (quantum.c)
  7. AG_NORM_SONG // plays when you press AG_NORM (quantum.c)
  8. AG_SWAP_SONG // plays when you press AG_SWAP (quantum.c)
  9. MUSIC_ON_SONG // plays when music mode is activated (process_music.c)
  10. MUSIC_OFF_SONG // plays when music mode is deactivated (process_music.c)
  11. CHROMATIC_SONG // plays when the chromatic music mode is selected (process_music.c)
  12. GUITAR_SONG // plays when the guitar music mode is selected (process_music.c)
  13. VIOLIN_SONG // plays when the violin music mode is selected (process_music.c)
  14. MAJOR_SONG // plays when the major music mode is selected (process_music.c)
  15. ```
  16. You can override the default songs by doing something like this in your `config.h`:
  17. ```c
  18. #ifdef AUDIO_ENABLE
  19. #define STARTUP_SONG SONG(STARTUP_SOUND)
  20. #endif
  21. ```
  22. A full list of sounds can be found in [quantum/audio/song_list.h](https://github.com/qmk/qmk_firmware/blob/master/quantum/audio/song_list.h) - feel free to add your own to this list! All available notes can be seen in [quantum/audio/musical_notes.h](https://github.com/qmk/qmk_firmware/blob/master/quantum/audio/musical_notes.h).
  23. To play a custom sound at a particular time, you can define a song like this (near the top of the file):
  24. ```c
  25. float my_song[][2] = SONG(QWERTY_SOUND);
  26. ```
  27. And then play your song like this:
  28. ```c
  29. PLAY_SONG(my_song);
  30. ```
  31. Alternatively, you can play it in a loop like this:
  32. ```c
  33. PLAY_LOOP(my_song);
  34. ```
  35. It's advised that you wrap all audio features in `#ifdef AUDIO_ENABLE` / `#endif` to avoid causing problems when audio isn't built into the keyboard.
  36. ## Music Mode
  37. The music mode maps your columns to a chromatic scale, and your rows to octaves. This works best with ortholinear keyboards, but can be made to work with others. All keycodes less than `0xFF` get blocked, so you won't type while playing notes - if you have special keys/mods, those will still work. A work-around for this is to jump to a different layer with KC_NOs before (or after) enabling music mode.
  38. Recording is experimental due to some memory issues - if you experience some weird behavior, unplugging/replugging your keyboard will fix things.
  39. Keycodes available:
  40. * `MU_ON` - Turn music mode on
  41. * `MU_OFF` - Turn music mode off
  42. * `MU_TOG` - Toggle music mode
  43. * `MU_MOD` - Cycle through the music modes:
  44. * `CHROMATIC_MODE` - Chromatic scale, row changes the octave
  45. * `GUITAR_MODE` - Chromatic scale, but the row changes the string (+5 st)
  46. * `VIOLIN_MODE` - Chromatic scale, but the row changes the string (+7 st)
  47. * `MAJOR_MODE` - Major scale
  48. In music mode, the following keycodes work differently, and don't pass through:
  49. * `LCTL` - start a recording
  50. * `LALT` - stop recording/stop playing
  51. * `LGUI` - play recording
  52. * `KC_UP` - speed-up playback
  53. * `KC_DOWN` - slow-down playback
  54. By default, `MUSIC_MASK` is set to `keycode < 0xFF` which means keycodes less than `0xFF` are turned into notes, and don't output anything. You can change this by defining this in your `config.h` like this:
  55. #define MUSIC_MASK keycode != KC_NO
  56. Which will capture all keycodes - be careful, this will get you stuck in music mode until you restart your keyboard!
  57. The pitch standard (`PITCH_STANDARD_A`) is 440.0f by default - to change this, add something like this to your `config.h`:
  58. #define PITCH_STANDARD_A 432.0f
  59. You can completely disable Music Mode as well. This is useful, if you're pressed for space on your controller. To disable it, add this to your `config.h`:
  60. #define NO_MUSIC_MODE
  61. ## MIDI Functionality
  62. This is still a WIP, but check out `quantum/keymap_midi.c` to see what's happening. Enable from the Makefile.
  63. <!-- FIXME: this formatting needs work
  64. ## Audio
  65. ```c
  66. #ifdef AUDIO_ENABLE
  67. AU_ON,
  68. AU_OFF,
  69. AU_TOG,
  70. #ifdef FAUXCLICKY_ENABLE
  71. FC_ON,
  72. FC_OFF,
  73. FC_TOG,
  74. #endif
  75. // Music mode on/off/toggle
  76. MU_ON,
  77. MU_OFF,
  78. MU_TOG,
  79. // Music voice iterate
  80. MUV_IN,
  81. MUV_DE,
  82. #endif
  83. ```
  84. ### Midi
  85. #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
  86. MI_ON, // send midi notes when music mode is enabled
  87. MI_OFF, // don't send midi notes when music mode is enabled
  88. #endif
  89. MIDI_TONE_MIN,
  90. MIDI_TONE_MAX
  91. MI_C = MIDI_TONE_MIN,
  92. MI_Cs,
  93. MI_Db = MI_Cs,
  94. MI_D,
  95. MI_Ds,
  96. MI_Eb = MI_Ds,
  97. MI_E,
  98. MI_F,
  99. MI_Fs,
  100. MI_Gb = MI_Fs,
  101. MI_G,
  102. MI_Gs,
  103. MI_Ab = MI_Gs,
  104. MI_A,
  105. MI_As,
  106. MI_Bb = MI_As,
  107. MI_B,
  108. MIDI_TONE_KEYCODE_OCTAVES > 1
  109. where x = 1-5:
  110. MI_C_x,
  111. MI_Cs_x,
  112. MI_Db_x = MI_Cs_x,
  113. MI_D_x,
  114. MI_Ds_x,
  115. MI_Eb_x = MI_Ds_x,
  116. MI_E_x,
  117. MI_F_x,
  118. MI_Fs_x,
  119. MI_Gb_x = MI_Fs_x,
  120. MI_G_x,
  121. MI_Gs_x,
  122. MI_Ab_x = MI_Gs_x,
  123. MI_A_x,
  124. MI_As_x,
  125. MI_Bb_x = MI_As_x,
  126. MI_B_x,
  127. MI_OCT_Nx 1-2
  128. MI_OCT_x 0-7
  129. MIDI_OCTAVE_MIN = MI_OCT_N2,
  130. MIDI_OCTAVE_MAX = MI_OCT_7,
  131. MI_OCTD, // octave down
  132. MI_OCTU, // octave up
  133. MI_TRNS_Nx 1-6
  134. MI_TRNS_x 0-6
  135. MIDI_TRANSPOSE_MIN = MI_TRNS_N6,
  136. MIDI_TRANSPOSE_MAX = MI_TRNS_6,
  137. MI_TRNSD, // transpose down
  138. MI_TRNSU, // transpose up
  139. MI_VEL_x 1-10
  140. MIDI_VELOCITY_MIN = MI_VEL_1,
  141. MIDI_VELOCITY_MAX = MI_VEL_9,
  142. MI_VELD, // velocity down
  143. MI_VELU, // velocity up
  144. MI_CHx 1-16
  145. MIDI_CHANNEL_MIN = MI_CH1
  146. MIDI_CHANNEL_MAX = MI_CH16,
  147. MI_CHD, // previous channel
  148. MI_CHU, // next channel
  149. MI_ALLOFF, // all notes off
  150. MI_SUS, // sustain
  151. MI_PORT, // portamento
  152. MI_SOST, // sostenuto
  153. MI_SOFT, // soft pedal
  154. MI_LEG, // legato
  155. MI_MOD, // modulation
  156. MI_MODSD, // decrease modulation speed
  157. MI_MODSU, // increase modulation speed
  158. #endif // MIDI_ADVANCED
  159. -->