upload
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

quantum.c 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. #include "quantum.h"
  2. #include "timer.h"
  3. __attribute__ ((weak))
  4. void matrix_init_kb(void) {}
  5. __attribute__ ((weak))
  6. void matrix_scan_kb(void) {}
  7. __attribute__ ((weak))
  8. bool process_action_kb(keyrecord_t *record) {
  9. return true;
  10. }
  11. __attribute__ ((weak))
  12. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  13. return process_record_user(keycode, record);
  14. }
  15. __attribute__ ((weak))
  16. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  17. return true;
  18. }
  19. __attribute__ ((weak))
  20. void leader_start(void) {}
  21. __attribute__ ((weak))
  22. void leader_end(void) {}
  23. uint8_t starting_note = 0x0C;
  24. int offset = 7;
  25. #ifdef AUDIO_ENABLE
  26. bool music_activated = false;
  27. // music sequencer
  28. static bool music_sequence_recording = false;
  29. static bool music_sequence_playing = false;
  30. static float music_sequence[16] = {0};
  31. static uint8_t music_sequence_count = 0;
  32. static uint8_t music_sequence_position = 0;
  33. static uint16_t music_sequence_timer = 0;
  34. static uint16_t music_sequence_interval = 100;
  35. #endif
  36. #ifdef MIDI_ENABLE
  37. bool midi_activated = false;
  38. #endif
  39. // Leader key stuff
  40. bool leading = false;
  41. uint16_t leader_time = 0;
  42. uint16_t leader_sequence[3] = {0, 0, 0};
  43. uint8_t leader_sequence_size = 0;
  44. // Chording stuff
  45. #define CHORDING_MAX 4
  46. bool chording = false;
  47. uint8_t chord_keys[CHORDING_MAX] = {0};
  48. uint8_t chord_key_count = 0;
  49. uint8_t chord_key_down = 0;
  50. #ifdef UNICODE_ENABLE
  51. static uint8_t input_mode;
  52. #endif
  53. static bool shift_interrupted[2] = {0, 0};
  54. bool keys_chord(uint8_t keys[]) {
  55. uint8_t keys_size = sizeof(keys)/sizeof(keys[0]);
  56. bool pass = true;
  57. uint8_t in = 0;
  58. for (uint8_t i = 0; i < chord_key_count; i++) {
  59. bool found = false;
  60. for (uint8_t j = 0; j < keys_size; j++) {
  61. if (chord_keys[i] == (keys[j] & 0xFF)) {
  62. in++; // detects key in chord
  63. found = true;
  64. break;
  65. }
  66. }
  67. if (found)
  68. continue;
  69. if (chord_keys[i] != 0) {
  70. pass = false; // makes sure rest are blank
  71. }
  72. }
  73. return (pass && (in == keys_size));
  74. }
  75. #ifdef UNICODE_ENABLE
  76. uint16_t hex_to_keycode(uint8_t hex)
  77. {
  78. if (hex == 0x0) {
  79. return KC_0;
  80. } else if (hex < 0xA) {
  81. return KC_1 + (hex - 0x1);
  82. } else {
  83. return KC_A + (hex - 0xA);
  84. }
  85. }
  86. void set_unicode_mode(uint8_t os_target)
  87. {
  88. input_mode = os_target;
  89. }
  90. #endif
  91. bool process_record_quantum(keyrecord_t *record) {
  92. /* This gets the keycode from the key pressed */
  93. keypos_t key = record->event.key;
  94. uint16_t keycode;
  95. #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
  96. uint8_t layer;
  97. if (record->event.pressed) {
  98. layer = layer_switch_get_layer(key);
  99. update_source_layers_cache(key, layer);
  100. } else {
  101. layer = read_source_layers_cache(key);
  102. }
  103. keycode = keymap_key_to_keycode(layer, key);
  104. #else
  105. keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key);
  106. #endif
  107. if (!process_record_kb(keycode, record))
  108. return false;
  109. // This is how you use actions here
  110. // if (keycode == KC_LEAD) {
  111. // action_t action;
  112. // action.code = ACTION_DEFAULT_LAYER_SET(0);
  113. // process_action(record, action);
  114. // return false;
  115. // }
  116. #ifdef MIDI_ENABLE
  117. if (keycode == MI_ON && record->event.pressed) {
  118. midi_activated = true;
  119. music_scale_user();
  120. return false;
  121. }
  122. if (keycode == MI_OFF && record->event.pressed) {
  123. midi_activated = false;
  124. midi_send_cc(&midi_device, 0, 0x7B, 0);
  125. return false;
  126. }
  127. if (midi_activated) {
  128. if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) {
  129. if (record->event.pressed) {
  130. starting_note++; // Change key
  131. midi_send_cc(&midi_device, 0, 0x7B, 0);
  132. // midi_send_cc(&midi_device, 1, 0x7B, 0);
  133. // midi_send_cc(&midi_device, 2, 0x7B, 0);
  134. // midi_send_cc(&midi_device, 3, 0x7B, 0);
  135. // midi_send_cc(&midi_device, 4, 0x7B, 0);
  136. }
  137. return false;
  138. }
  139. if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) {
  140. if (record->event.pressed) {
  141. starting_note--; // Change key
  142. midi_send_cc(&midi_device, 0, 0x7B, 0);
  143. // midi_send_cc(&midi_device, 1, 0x7B, 0);
  144. // midi_send_cc(&midi_device, 2, 0x7B, 0);
  145. // midi_send_cc(&midi_device, 3, 0x7B, 0);
  146. // midi_send_cc(&midi_device, 4, 0x7B, 0);
  147. }
  148. return false;
  149. }
  150. if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
  151. offset++; // Change scale
  152. midi_send_cc(&midi_device, 0, 0x7B, 0);
  153. // midi_send_cc(&midi_device, 1, 0x7B, 0);
  154. // midi_send_cc(&midi_device, 2, 0x7B, 0);
  155. // midi_send_cc(&midi_device, 3, 0x7B, 0);
  156. // midi_send_cc(&midi_device, 4, 0x7B, 0);
  157. return false;
  158. }
  159. if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
  160. offset--; // Change scale
  161. midi_send_cc(&midi_device, 0, 0x7B, 0);
  162. // midi_send_cc(&midi_device, 1, 0x7B, 0);
  163. // midi_send_cc(&midi_device, 2, 0x7B, 0);
  164. // midi_send_cc(&midi_device, 3, 0x7B, 0);
  165. // midi_send_cc(&midi_device, 4, 0x7B, 0);
  166. return false;
  167. }
  168. // basic
  169. // uint8_t note = (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row);
  170. // advanced
  171. // uint8_t note = (starting_note + record->event.key.col + offset)+12*(MATRIX_ROWS - record->event.key.row);
  172. // guitar
  173. uint8_t note = (starting_note + record->event.key.col + offset)+5*(MATRIX_ROWS - record->event.key.row);
  174. // violin
  175. // uint8_t note = (starting_note + record->event.key.col + offset)+7*(MATRIX_ROWS - record->event.key.row);
  176. if (record->event.pressed) {
  177. // midi_send_noteon(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
  178. midi_send_noteon(&midi_device, 0, note, 127);
  179. } else {
  180. // midi_send_noteoff(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
  181. midi_send_noteoff(&midi_device, 0, note, 127);
  182. }
  183. if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
  184. return false;
  185. }
  186. #endif
  187. #ifdef AUDIO_ENABLE
  188. if (keycode == AU_ON && record->event.pressed) {
  189. audio_on();
  190. return false;
  191. }
  192. if (keycode == AU_OFF && record->event.pressed) {
  193. audio_off();
  194. return false;
  195. }
  196. if (keycode == AU_TOG && record->event.pressed) {
  197. if (is_audio_on())
  198. {
  199. audio_off();
  200. }
  201. else
  202. {
  203. audio_on();
  204. }
  205. return false;
  206. }
  207. if (keycode == MU_ON && record->event.pressed) {
  208. music_on();
  209. return false;
  210. }
  211. if (keycode == MU_OFF && record->event.pressed) {
  212. music_off();
  213. return false;
  214. }
  215. if (keycode == MU_TOG && record->event.pressed) {
  216. if (music_activated)
  217. {
  218. music_off();
  219. }
  220. else
  221. {
  222. music_on();
  223. }
  224. return false;
  225. }
  226. if (keycode == MUV_IN && record->event.pressed) {
  227. voice_iterate();
  228. music_scale_user();
  229. return false;
  230. }
  231. if (keycode == MUV_DE && record->event.pressed) {
  232. voice_deiterate();
  233. music_scale_user();
  234. return false;
  235. }
  236. if (music_activated) {
  237. if (keycode == KC_LCTL && record->event.pressed) { // Start recording
  238. stop_all_notes();
  239. music_sequence_recording = true;
  240. music_sequence_playing = false;
  241. music_sequence_count = 0;
  242. return false;
  243. }
  244. if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing
  245. stop_all_notes();
  246. music_sequence_recording = false;
  247. music_sequence_playing = false;
  248. return false;
  249. }
  250. if (keycode == KC_LGUI && record->event.pressed) { // Start playing
  251. stop_all_notes();
  252. music_sequence_recording = false;
  253. music_sequence_playing = true;
  254. music_sequence_position = 0;
  255. music_sequence_timer = 0;
  256. return false;
  257. }
  258. if (keycode == KC_UP) {
  259. if (record->event.pressed)
  260. music_sequence_interval-=10;
  261. return false;
  262. }
  263. if (keycode == KC_DOWN) {
  264. if (record->event.pressed)
  265. music_sequence_interval+=10;
  266. return false;
  267. }
  268. float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row));
  269. if (record->event.pressed) {
  270. play_note(freq, 0xF);
  271. if (music_sequence_recording) {
  272. music_sequence[music_sequence_count] = freq;
  273. music_sequence_count++;
  274. }
  275. } else {
  276. stop_note(freq);
  277. }
  278. if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
  279. return false;
  280. }
  281. #endif
  282. #ifndef DISABLE_LEADER
  283. // Leader key set-up
  284. if (record->event.pressed) {
  285. if (!leading && keycode == KC_LEAD) {
  286. leader_start();
  287. leading = true;
  288. leader_time = timer_read();
  289. leader_sequence_size = 0;
  290. leader_sequence[0] = 0;
  291. leader_sequence[1] = 0;
  292. leader_sequence[2] = 0;
  293. return false;
  294. }
  295. if (leading && timer_elapsed(leader_time) < LEADER_TIMEOUT) {
  296. leader_sequence[leader_sequence_size] = keycode;
  297. leader_sequence_size++;
  298. return false;
  299. }
  300. }
  301. #endif
  302. #define DISABLE_CHORDING
  303. #ifndef DISABLE_CHORDING
  304. if (keycode >= 0x5700 && keycode <= 0x57FF) {
  305. if (record->event.pressed) {
  306. if (!chording) {
  307. chording = true;
  308. for (uint8_t i = 0; i < CHORDING_MAX; i++)
  309. chord_keys[i] = 0;
  310. chord_key_count = 0;
  311. chord_key_down = 0;
  312. }
  313. chord_keys[chord_key_count] = (keycode & 0xFF);
  314. chord_key_count++;
  315. chord_key_down++;
  316. return false;
  317. } else {
  318. if (chording) {
  319. chord_key_down--;
  320. if (chord_key_down == 0) {
  321. chording = false;
  322. // Chord Dictionary
  323. if (keys_chord((uint8_t[]){KC_ENTER, KC_SPACE})) {
  324. register_code(KC_A);
  325. unregister_code(KC_A);
  326. return false;
  327. }
  328. for (uint8_t i = 0; i < chord_key_count; i++) {
  329. register_code(chord_keys[i]);
  330. unregister_code(chord_keys[i]);
  331. return false;
  332. }
  333. }
  334. }
  335. }
  336. }
  337. #endif
  338. #ifdef UNICODE_ENABLE
  339. if (keycode > UNICODE(0) && record->event.pressed) {
  340. uint16_t unicode = keycode & 0x7FFF;
  341. switch(input_mode) {
  342. case UC_OSX:
  343. register_code(KC_LALT);
  344. break;
  345. case UC_LNX:
  346. register_code(KC_LCTL);
  347. register_code(KC_LSFT);
  348. register_code(KC_U);
  349. unregister_code(KC_U);
  350. break;
  351. case UC_WIN:
  352. register_code(KC_LALT);
  353. register_code(KC_PPLS);
  354. unregister_code(KC_PPLS);
  355. break;
  356. }
  357. for(int i = 3; i >= 0; i--) {
  358. uint8_t digit = ((unicode >> (i*4)) & 0xF);
  359. register_code(hex_to_keycode(digit));
  360. unregister_code(hex_to_keycode(digit));
  361. }
  362. switch(input_mode) {
  363. case UC_OSX:
  364. case UC_WIN:
  365. unregister_code(KC_LALT);
  366. break;
  367. case UC_LNX:
  368. unregister_code(KC_LCTL);
  369. unregister_code(KC_LSFT);
  370. break;
  371. }
  372. }
  373. #endif
  374. switch(keycode) {
  375. case KC_LSPO: {
  376. if (record->event.pressed) {
  377. shift_interrupted[0] = false;
  378. register_mods(MOD_BIT(KC_LSFT));
  379. }
  380. else {
  381. if (!shift_interrupted[0]) {
  382. register_code(KC_9);
  383. unregister_code(KC_9);
  384. }
  385. unregister_mods(MOD_BIT(KC_LSFT));
  386. }
  387. return false;
  388. break;
  389. }
  390. case KC_RSPC: {
  391. if (record->event.pressed) {
  392. shift_interrupted[1] = false;
  393. register_mods(MOD_BIT(KC_RSFT));
  394. }
  395. else {
  396. if (!shift_interrupted[1]) {
  397. register_code(KC_0);
  398. unregister_code(KC_0);
  399. }
  400. unregister_mods(MOD_BIT(KC_RSFT));
  401. }
  402. return false;
  403. break;
  404. }
  405. default: {
  406. shift_interrupted[0] = true;
  407. shift_interrupted[1] = true;
  408. break;
  409. }
  410. }
  411. return process_action_kb(record);
  412. }
  413. const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = {
  414. 0, 0, 0, 0, 0, 0, 0, 0,
  415. 0, 0, 0, 0, 0, 0, 0, 0,
  416. 0, 0, 0, 0, 0, 0, 0, 0,
  417. 0, 0, 0, 0, 0, 0, 0, 0,
  418. 0, 1, 1, 1, 1, 1, 1, 0,
  419. 1, 1, 1, 1, 0, 0, 0, 0,
  420. 0, 0, 0, 0, 0, 0, 0, 0,
  421. 0, 0, 1, 0, 1, 0, 1, 1,
  422. 1, 1, 1, 1, 1, 1, 1, 1,
  423. 1, 1, 1, 1, 1, 1, 1, 1,
  424. 1, 1, 1, 1, 1, 1, 1, 1,
  425. 1, 1, 1, 0, 0, 0, 1, 1,
  426. 0, 0, 0, 0, 0, 0, 0, 0,
  427. 0, 0, 0, 0, 0, 0, 0, 0,
  428. 0, 0, 0, 0, 0, 0, 0, 0,
  429. 0, 0, 0, 1, 1, 1, 1, 0
  430. };
  431. const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = {
  432. 0, 0, 0, 0, 0, 0, 0, 0,
  433. KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
  434. 0, 0, 0, 0, 0, 0, 0, 0,
  435. 0, 0, 0, KC_ESC, 0, 0, 0, 0,
  436. KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
  437. KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
  438. KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
  439. KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
  440. KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
  441. KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
  442. KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
  443. KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
  444. KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
  445. KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
  446. KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
  447. KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
  448. };
  449. /* for users whose OSes are set to Colemak */
  450. #if 0
  451. #include "keymap_colemak.h"
  452. const bool ascii_to_colemak_shift_lut[0x80] PROGMEM = {
  453. 0, 0, 0, 0, 0, 0, 0, 0,
  454. 0, 0, 0, 0, 0, 0, 0, 0,
  455. 0, 0, 0, 0, 0, 0, 0, 0,
  456. 0, 0, 0, 0, 0, 0, 0, 0,
  457. 0, 1, 1, 1, 1, 1, 1, 0,
  458. 1, 1, 1, 1, 0, 0, 0, 0,
  459. 0, 0, 0, 0, 0, 0, 0, 0,
  460. 0, 0, 1, 0, 1, 0, 1, 1,
  461. 1, 1, 1, 1, 1, 1, 1, 1,
  462. 1, 1, 1, 1, 1, 1, 1, 1,
  463. 1, 1, 1, 1, 1, 1, 1, 1,
  464. 1, 1, 1, 0, 0, 0, 1, 1,
  465. 0, 0, 0, 0, 0, 0, 0, 0,
  466. 0, 0, 0, 0, 0, 0, 0, 0,
  467. 0, 0, 0, 0, 0, 0, 0, 0,
  468. 0, 0, 0, 1, 1, 1, 1, 0
  469. };
  470. const uint8_t ascii_to_colemak_keycode_lut[0x80] PROGMEM = {
  471. 0, 0, 0, 0, 0, 0, 0, 0,
  472. KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
  473. 0, 0, 0, 0, 0, 0, 0, 0,
  474. 0, 0, 0, KC_ESC, 0, 0, 0, 0,
  475. KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
  476. KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
  477. KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
  478. KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
  479. KC_2, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
  480. CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
  481. CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
  482. CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
  483. KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
  484. CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
  485. CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
  486. CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
  487. };
  488. #endif
  489. void send_string(const char *str) {
  490. while (1) {
  491. uint8_t keycode;
  492. uint8_t ascii_code = pgm_read_byte(str);
  493. if (!ascii_code) break;
  494. keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]);
  495. if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) {
  496. register_code(KC_LSFT);
  497. register_code(keycode);
  498. unregister_code(keycode);
  499. unregister_code(KC_LSFT);
  500. }
  501. else {
  502. register_code(keycode);
  503. unregister_code(keycode);
  504. }
  505. ++str;
  506. }
  507. }
  508. void matrix_init_quantum() {
  509. matrix_init_kb();
  510. }
  511. void matrix_scan_quantum() {
  512. #ifdef AUDIO_ENABLE
  513. if (music_sequence_playing) {
  514. if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
  515. music_sequence_timer = timer_read();
  516. stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]);
  517. play_note(music_sequence[music_sequence_position], 0xF);
  518. music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
  519. }
  520. }
  521. #endif
  522. matrix_scan_kb();
  523. }
  524. #ifdef AUDIO_ENABLE
  525. bool is_music_on(void) {
  526. return (music_activated != 0);
  527. }
  528. void music_toggle(void) {
  529. if (!music_activated) {
  530. music_on();
  531. } else {
  532. music_off();
  533. }
  534. }
  535. void music_on(void) {
  536. music_activated = 1;
  537. music_on_user();
  538. }
  539. void music_off(void) {
  540. music_activated = 0;
  541. stop_all_notes();
  542. }
  543. #endif
  544. //------------------------------------------------------------------------------
  545. // Override these functions in your keymap file to play different tunes on
  546. // different events such as startup and bootloader jump
  547. __attribute__ ((weak))
  548. void startup_user() {}
  549. __attribute__ ((weak))
  550. void shutdown_user() {}
  551. __attribute__ ((weak))
  552. void music_on_user() {}
  553. __attribute__ ((weak))
  554. void audio_on_user() {}
  555. __attribute__ ((weak))
  556. void music_scale_user() {}
  557. //------------------------------------------------------------------------------