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.

204 lines
5.7 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. ## MIDI Functionality
  60. This is still a WIP, but check out `quantum/keymap_midi.c` to see what's happening. Enable from the Makefile.
  61. <!-- FIXME: this formatting needs work
  62. ## Audio
  63. ```c
  64. #ifdef AUDIO_ENABLE
  65. AU_ON,
  66. AU_OFF,
  67. AU_TOG,
  68. #ifdef FAUXCLICKY_ENABLE
  69. FC_ON,
  70. FC_OFF,
  71. FC_TOG,
  72. #endif
  73. // Music mode on/off/toggle
  74. MU_ON,
  75. MU_OFF,
  76. MU_TOG,
  77. // Music voice iterate
  78. MUV_IN,
  79. MUV_DE,
  80. #endif
  81. ```
  82. ### Midi
  83. #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
  84. MI_ON, // send midi notes when music mode is enabled
  85. MI_OFF, // don't send midi notes when music mode is enabled
  86. #endif
  87. MIDI_TONE_MIN,
  88. MIDI_TONE_MAX
  89. MI_C = MIDI_TONE_MIN,
  90. MI_Cs,
  91. MI_Db = MI_Cs,
  92. MI_D,
  93. MI_Ds,
  94. MI_Eb = MI_Ds,
  95. MI_E,
  96. MI_F,
  97. MI_Fs,
  98. MI_Gb = MI_Fs,
  99. MI_G,
  100. MI_Gs,
  101. MI_Ab = MI_Gs,
  102. MI_A,
  103. MI_As,
  104. MI_Bb = MI_As,
  105. MI_B,
  106. MIDI_TONE_KEYCODE_OCTAVES > 1
  107. where x = 1-5:
  108. MI_C_x,
  109. MI_Cs_x,
  110. MI_Db_x = MI_Cs_x,
  111. MI_D_x,
  112. MI_Ds_x,
  113. MI_Eb_x = MI_Ds_x,
  114. MI_E_x,
  115. MI_F_x,
  116. MI_Fs_x,
  117. MI_Gb_x = MI_Fs_x,
  118. MI_G_x,
  119. MI_Gs_x,
  120. MI_Ab_x = MI_Gs_x,
  121. MI_A_x,
  122. MI_As_x,
  123. MI_Bb_x = MI_As_x,
  124. MI_B_x,
  125. MI_OCT_Nx 1-2
  126. MI_OCT_x 0-7
  127. MIDI_OCTAVE_MIN = MI_OCT_N2,
  128. MIDI_OCTAVE_MAX = MI_OCT_7,
  129. MI_OCTD, // octave down
  130. MI_OCTU, // octave up
  131. MI_TRNS_Nx 1-6
  132. MI_TRNS_x 0-6
  133. MIDI_TRANSPOSE_MIN = MI_TRNS_N6,
  134. MIDI_TRANSPOSE_MAX = MI_TRNS_6,
  135. MI_TRNSD, // transpose down
  136. MI_TRNSU, // transpose up
  137. MI_VEL_x 1-10
  138. MIDI_VELOCITY_MIN = MI_VEL_1,
  139. MIDI_VELOCITY_MAX = MI_VEL_9,
  140. MI_VELD, // velocity down
  141. MI_VELU, // velocity up
  142. MI_CHx 1-16
  143. MIDI_CHANNEL_MIN = MI_CH1
  144. MIDI_CHANNEL_MAX = MI_CH16,
  145. MI_CHD, // previous channel
  146. MI_CHU, // next channel
  147. MI_ALLOFF, // all notes off
  148. MI_SUS, // sustain
  149. MI_PORT, // portamento
  150. MI_SOST, // sostenuto
  151. MI_SOFT, // soft pedal
  152. MI_LEG, // legato
  153. MI_MOD, // modulation
  154. MI_MODSD, // decrease modulation speed
  155. MI_MODSU, // increase modulation speed
  156. #endif // MIDI_ADVANCED
  157. -->