bb-audio.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Copyright 2021 Batuhan Başerdem
  2. * <baserdem.batuhan@gmail.com> @bbaserdem
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "bb-audio.h"
  18. /* AUDIO
  19. * This contains some audio related stuff.
  20. * There is no need to wrap this up with preprocessor commands;
  21. * This is only called if audio is enabled
  22. */
  23. float tone_game_intro[][2] = GAME_ON_SONG;
  24. float tone_game_outro[][2] = GAME_OFF_SONG;
  25. // Audio playing when layer changes
  26. layer_state_t layer_state_set_audio(layer_state_t state) {
  27. // Get this layer
  28. static bool prev_game = false;
  29. // If entering the game layer; play the intro sound
  30. if (layer_state_cmp(state, _GAME) && (!prev_game)) {
  31. stop_all_notes();
  32. PLAY_SONG(tone_game_intro);
  33. prev_game = true;
  34. }
  35. // If exiting the game layer; play the outro sound
  36. if ((!layer_state_cmp(state, _GAME)) && prev_game) {
  37. stop_all_notes();
  38. PLAY_SONG(tone_game_outro);
  39. prev_game = false;
  40. }
  41. return state;
  42. }
  43. // Audio layer switch; add the music layer on top of this
  44. bool process_record_audio(uint16_t keycode, keyrecord_t *record) {
  45. switch (keycode) {
  46. case MU_TOG:
  47. if (!record->event.pressed) {
  48. // On release, exit music mode if enabled
  49. if (layer_state_is(_MUSI)) {
  50. layer_off(_MUSI);
  51. // If not enabled; turn off all layers and load music layer
  52. } else {
  53. layer_clear();
  54. layer_on(_MUSI);
  55. }
  56. }
  57. return true;
  58. break;
  59. case MU_ON:
  60. if (!record->event.pressed) {
  61. // On release, enter music mode
  62. layer_clear();
  63. layer_on(_MUSI);
  64. }
  65. return true;
  66. break;
  67. case MU_OFF:
  68. if (!record->event.pressed) {
  69. // On release, exit music mode
  70. layer_off(_MUSI);
  71. }
  72. return true;
  73. break;
  74. }
  75. return true;
  76. }