aboutsummaryrefslogtreecommitdiff
path: root/quantum/keymap_midi.c
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2016-01-11 16:53:33 -0500
committerJack Humbert <jack.humb@gmail.com>2016-01-11 16:53:33 -0500
commit29de37d5c0ea9fc6b5539ce4493c7b10a2a7f33f (patch)
treececb16f2969a1d250b45d828df1e700bce1d8c40 /quantum/keymap_midi.c
parent11ce694557389bdde2b5ae15af38fdad3fe77a27 (diff)
downloadqmk_firmware-29de37d5c0ea9fc6b5539ce4493c7b10a2a7f33f.tar.gz
qmk_firmware-29de37d5c0ea9fc6b5539ce4493c7b10a2a7f33f.zip
pwm audio
Diffstat (limited to 'quantum/keymap_midi.c')
-rw-r--r--quantum/keymap_midi.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/quantum/keymap_midi.c b/quantum/keymap_midi.c
index b7eba3ab7..3a1408e22 100644
--- a/quantum/keymap_midi.c
+++ b/quantum/keymap_midi.c
@@ -17,7 +17,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18#include "keymap_common.h" 18#include "keymap_common.h"
19#include "keymap_midi.h" 19#include "keymap_midi.h"
20#include <lufa.h>
21 20
22uint8_t starting_note = 0x0C; 21uint8_t starting_note = 0x0C;
23int offset = 7; 22int offset = 7;
@@ -35,7 +34,7 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
35 if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) { 34 if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) {
36 if (record->event.pressed) { 35 if (record->event.pressed) {
37 starting_note++; 36 starting_note++;
38 play_note(((double)261.6)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[0 + offset])/12.0+(MATRIX_ROWS - 1)), 0xC); 37 play_note(((double)261.626)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[0 + offset])/12.0+(MATRIX_ROWS - 1)), 0xC);
39 midi_send_cc(&midi_device, 0, 0x7B, 0); 38 midi_send_cc(&midi_device, 0, 0x7B, 0);
40 midi_send_cc(&midi_device, 1, 0x7B, 0); 39 midi_send_cc(&midi_device, 1, 0x7B, 0);
41 midi_send_cc(&midi_device, 2, 0x7B, 0); 40 midi_send_cc(&midi_device, 2, 0x7B, 0);
@@ -43,7 +42,7 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
43 midi_send_cc(&midi_device, 4, 0x7B, 0); 42 midi_send_cc(&midi_device, 4, 0x7B, 0);
44 return; 43 return;
45 } else { 44 } else {
46 stop_note(((double)261.6)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[0 + offset])/12.0+(MATRIX_ROWS - 1))); 45 stop_note(((double)261.626)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[0 + offset])/12.0+(MATRIX_ROWS - 1)));
47 stop_all_notes(); 46 stop_all_notes();
48 return; 47 return;
49 } 48 }
@@ -51,7 +50,7 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
51 if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) { 50 if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) {
52 if (record->event.pressed) { 51 if (record->event.pressed) {
53 starting_note--; 52 starting_note--;
54 play_note(((double)261.6)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[0 + offset])/12.0+(MATRIX_ROWS - 1)), 0xC); 53 play_note(((double)261.626)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[0 + offset])/12.0+(MATRIX_ROWS - 1)), 0xC);
55 midi_send_cc(&midi_device, 0, 0x7B, 0); 54 midi_send_cc(&midi_device, 0, 0x7B, 0);
56 midi_send_cc(&midi_device, 1, 0x7B, 0); 55 midi_send_cc(&midi_device, 1, 0x7B, 0);
57 midi_send_cc(&midi_device, 2, 0x7B, 0); 56 midi_send_cc(&midi_device, 2, 0x7B, 0);
@@ -59,7 +58,7 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
59 midi_send_cc(&midi_device, 4, 0x7B, 0); 58 midi_send_cc(&midi_device, 4, 0x7B, 0);
60 return; 59 return;
61 } else { 60 } else {
62 stop_note(((double)261.6)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[0 + offset])/12.0+(MATRIX_ROWS - 1))); 61 stop_note(((double)261.626)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[0 + offset])/12.0+(MATRIX_ROWS - 1)));
63 stop_all_notes(); 62 stop_all_notes();
64 return; 63 return;
65 } 64 }
@@ -74,9 +73,9 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
74 midi_send_cc(&midi_device, 4, 0x7B, 0); 73 midi_send_cc(&midi_device, 4, 0x7B, 0);
75 stop_all_notes(); 74 stop_all_notes();
76 for (int i = 0; i <= 7; i++) { 75 for (int i = 0; i <= 7; i++) {
77 play_note(((double)261.6)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[i + offset])/12.0+(MATRIX_ROWS - 1)), 0xC); 76 play_note(((double)261.626)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[i + offset])/12.0+(MATRIX_ROWS - 1)), 0xC);
78 _delay_us(80000); 77 _delay_us(80000);
79 stop_note(((double)261.6)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[i + offset])/12.0+(MATRIX_ROWS - 1))); 78 stop_note(((double)261.626)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[i + offset])/12.0+(MATRIX_ROWS - 1)));
80 _delay_us(8000); 79 _delay_us(8000);
81 } 80 }
82 return; 81 return;
@@ -90,9 +89,9 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
90 midi_send_cc(&midi_device, 4, 0x7B, 0); 89 midi_send_cc(&midi_device, 4, 0x7B, 0);
91 stop_all_notes(); 90 stop_all_notes();
92 for (int i = 0; i <= 7; i++) { 91 for (int i = 0; i <= 7; i++) {
93 play_note(((double)261.6)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[i + offset])/12.0+(MATRIX_ROWS - 1)), 0xC); 92 play_note(((double)261.626)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[i + offset])/12.0+(MATRIX_ROWS - 1)), 0xC);
94 _delay_us(80000); 93 _delay_us(80000);
95 stop_note(((double)261.6)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[i + offset])/12.0+(MATRIX_ROWS - 1))); 94 stop_note(((double)261.626)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[i + offset])/12.0+(MATRIX_ROWS - 1)));
96 _delay_us(8000); 95 _delay_us(8000);
97 } 96 }
98 return; 97 return;
@@ -101,10 +100,10 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
101 if (record->event.pressed) { 100 if (record->event.pressed) {
102 // midi_send_noteon(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127); 101 // midi_send_noteon(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
103 midi_send_noteon(&midi_device, 0, (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row), 127); 102 midi_send_noteon(&midi_device, 0, (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row), 127);
104 play_note(((double)261.6)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)), 0xF); 103 play_note(((double)261.626)*pow(2.0, 0.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)), 0xF);
105 } else { 104 } else {
106 // midi_send_noteoff(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127); 105 // midi_send_noteoff(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
107 midi_send_noteoff(&midi_device, 0, (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row), 127); 106 midi_send_noteoff(&midi_device, 0, (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row), 127);
108 stop_note(((double)261.6)*pow(2.0, -1.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row))); 107 stop_note(((double)261.626)*pow(2.0, 0.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)));
109 } 108 }
110} \ No newline at end of file 109} \ No newline at end of file