diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2015-08-31 12:39:53 -0400 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2015-08-31 12:39:53 -0400 |
| commit | ed384bd4376398887a95942b7d6750d5bc4833e8 (patch) | |
| tree | 004cdce88ebd1967a4abe53b53cc04b31d42cbae | |
| parent | 91176d854b8c9e49e88d494ba02c8e9c54fec914 (diff) | |
| download | qmk_firmware-ed384bd4376398887a95942b7d6750d5bc4833e8.tar.gz qmk_firmware-ed384bd4376398887a95942b7d6750d5bc4833e8.zip | |
beeps update
| -rw-r--r-- | keyboard/planck/Makefile | 2 | ||||
| -rw-r--r-- | keyboard/planck/beeps.c | 204 | ||||
| -rw-r--r-- | keyboard/planck/beeps.h | 3 | ||||
| -rw-r--r-- | keyboard/planck/keymap_midi.c | 66 | ||||
| -rw-r--r-- | keyboard/planck/keymap_midi.h | 6 | ||||
| -rw-r--r-- | keyboard/planck/keymaps/keymap_lock.c | 2 | ||||
| -rw-r--r-- | protocol/lufa/lufa.c | 13 |
7 files changed, 197 insertions, 99 deletions
diff --git a/keyboard/planck/Makefile b/keyboard/planck/Makefile index be9f04267..ad0c82437 100644 --- a/keyboard/planck/Makefile +++ b/keyboard/planck/Makefile | |||
| @@ -117,7 +117,7 @@ OPT_DEFS += -DBOOTLOADER_SIZE=4096 | |||
| 117 | # comment out to disable the options. | 117 | # comment out to disable the options. |
| 118 | # | 118 | # |
| 119 | BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) | 119 | BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) |
| 120 | # MOUSEKEY_ENABLE = yes # Mouse keys(+4700) | 120 | MOUSEKEY_ENABLE = yes # Mouse keys(+4700) |
| 121 | EXTRAKEY_ENABLE = yes # Audio control and System control(+450) | 121 | EXTRAKEY_ENABLE = yes # Audio control and System control(+450) |
| 122 | CONSOLE_ENABLE = yes # Console for debug(+400) | 122 | CONSOLE_ENABLE = yes # Console for debug(+400) |
| 123 | COMMAND_ENABLE = yes # Commands for debug and configuration | 123 | COMMAND_ENABLE = yes # Commands for debug and configuration |
diff --git a/keyboard/planck/beeps.c b/keyboard/planck/beeps.c index 335bfa7d4..a1e697be4 100644 --- a/keyboard/planck/beeps.c +++ b/keyboard/planck/beeps.c | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | #include <avr/io.h> | 5 | #include <avr/io.h> |
| 6 | 6 | ||
| 7 | #define PI 3.14159265 | 7 | #define PI 3.14159265 |
| 8 | #define CHANNEL OCR1C | ||
| 9 | 8 | ||
| 10 | void delay_us(int count) { | 9 | void delay_us(int count) { |
| 11 | while(count--) { | 10 | while(count--) { |
| @@ -16,91 +15,17 @@ void delay_us(int count) { | |||
| 16 | int voices = 0; | 15 | int voices = 0; |
| 17 | double frequency = 0; | 16 | double frequency = 0; |
| 18 | int volume = 0; | 17 | int volume = 0; |
| 18 | int position = 0; | ||
| 19 | 19 | ||
| 20 | double frequencies[8] = {0, 0, 0, 0, 0, 0, 0, 0}; | 20 | double frequencies[8] = {0, 0, 0, 0, 0, 0, 0, 0}; |
| 21 | int volumes[8] = {0, 0, 0, 0, 0, 0, 0, 0}; | 21 | int volumes[8] = {0, 0, 0, 0, 0, 0, 0, 0}; |
| 22 | 22 | bool sliding = false; | |
| 23 | void beeps() { | 23 | #define RANGE 1000 |
| 24 | // DDRB |= (1<<7); | 24 | volatile int i=0; //elements of the wave |
| 25 | // PORTB &= ~(1<<7); | ||
| 26 | |||
| 27 | // // Use full 16-bit resolution. | ||
| 28 | // ICR1 = 0xFFFF; | ||
| 29 | |||
| 30 | // // I could write a wall of text here to explain... but TL;DW | ||
| 31 | // // Go read the ATmega32u4 datasheet. | ||
| 32 | // // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on | ||
| 33 | |||
| 34 | // // Pin PB7 = OCR1C (Timer 1, Channel C) | ||
| 35 | // // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0 | ||
| 36 | // // (i.e. start high, go low when counter matches.) | ||
| 37 | // // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0 | ||
| 38 | // // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1 | ||
| 39 | |||
| 40 | // TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010; | ||
| 41 | // TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; | ||
| 42 | |||
| 43 | |||
| 44 | // // Turn off PWM control on PB7, revert to output low. | ||
| 45 | // // TCCR1A &= ~(_BV(COM1C1)); | ||
| 46 | // // CHANNEL = ((1 << level) - 1); | ||
| 47 | |||
| 48 | // // Turn on PWM control of PB7 | ||
| 49 | // TCCR1A |= _BV(COM1C1); | ||
| 50 | // // CHANNEL = level << OFFSET | 0x0FFF; | ||
| 51 | // // CHANNEL = 0b1010101010101010; | ||
| 52 | |||
| 53 | // float x = 12; | ||
| 54 | // float y = 24; | ||
| 55 | // float length = 50; | ||
| 56 | // float scale = 1; | ||
| 57 | |||
| 58 | // // int f1 = 1000000/440; | ||
| 59 | // // int f2 = 1000000/880; | ||
| 60 | // // for (uint32_t i = 0; i < length * 1000; i++) { | ||
| 61 | // // // int frequency = 1/((sin(PI*2*i*scale*pow(2, x/12.0))*.5+1 + sin(PI*2*i*scale*pow(2, y/12.0))*.5+1) / 2); | ||
| 62 | |||
| 63 | // // ICR1 = f1; // Set max to the period | ||
| 64 | // // OCR1C = f1 >> 1; // Set compare to half the period | ||
| 65 | // // // _delay_us(10); | ||
| 66 | // // } | ||
| 67 | // int frequency = 1000000/440; | ||
| 68 | // ICR1 = frequency; // Set max to the period | ||
| 69 | // OCR1C = frequency >> 1; // Set compare to half the period | ||
| 70 | // _delay_us(500000); | ||
| 71 | |||
| 72 | // TCCR1A &= ~(_BV(COM1C1)); | ||
| 73 | // CHANNEL = 0; | ||
| 74 | play_notes(); | ||
| 75 | |||
| 76 | |||
| 77 | // play_note(55*pow(2, 0/12.0), 1); | ||
| 78 | // play_note(55*pow(2, 12/12.0), 1); | ||
| 79 | // play_note(55*pow(2, 24/12.0), 1); | ||
| 80 | // play_note(55*pow(2, 0/12.0), 1); | ||
| 81 | // play_note(55*pow(2, 12/12.0), 1); | ||
| 82 | // play_note(55*pow(2, 24/12.0), 1); | ||
| 83 | |||
| 84 | // play_note(0, 4); | ||
| 85 | |||
| 86 | // play_note(55*pow(2, 0/12.0), 8); | ||
| 87 | // play_note(55*pow(2, 12/12.0), 4); | ||
| 88 | // play_note(55*pow(2, 10/12.0), 4); | ||
| 89 | // play_note(55*pow(2, 12/12.0), 8); | ||
| 90 | // play_note(55*pow(2, 10/12.0), 4); | ||
| 91 | // play_note(55*pow(2, 7/12.0), 2); | ||
| 92 | // play_note(55*pow(2, 8/12.0), 2); | ||
| 93 | // play_note(55*pow(2, 7/12.0), 16); | ||
| 94 | // play_note(0, 4); | ||
| 95 | // play_note(55*pow(2, 3/12.0), 8); | ||
| 96 | // play_note(55*pow(2, 5/12.0), 4); | ||
| 97 | // play_note(55*pow(2, 7/12.0), 4); | ||
| 98 | // play_note(55*pow(2, 7/12.0), 8); | ||
| 99 | // play_note(55*pow(2, 5/12.0), 4); | ||
| 100 | // play_note(55*pow(2, 3/12.0), 4); | ||
| 101 | // play_note(55*pow(2, 2/12.0), 16); | ||
| 102 | 25 | ||
| 103 | 26 | ||
| 27 | void beeps() { | ||
| 28 | play_notes(); | ||
| 104 | } | 29 | } |
| 105 | 30 | ||
| 106 | void send_freq(double freq, int vol) { | 31 | void send_freq(double freq, int vol) { |
| @@ -114,6 +39,7 @@ void stop_all_notes() { | |||
| 114 | TCCR3A = 0; | 39 | TCCR3A = 0; |
| 115 | TCCR3B = 0; | 40 | TCCR3B = 0; |
| 116 | frequency = 0; | 41 | frequency = 0; |
| 42 | volume = 0; | ||
| 117 | 43 | ||
| 118 | for (int i = 0; i < 8; i++) { | 44 | for (int i = 0; i < 8; i++) { |
| 119 | frequencies[i] = 0; | 45 | frequencies[i] = 0; |
| @@ -135,21 +61,28 @@ void stop_note(double freq) { | |||
| 135 | } | 61 | } |
| 136 | } | 62 | } |
| 137 | voices--; | 63 | voices--; |
| 64 | if (voices < 0) | ||
| 65 | voices = 0; | ||
| 138 | if (voices == 0) { | 66 | if (voices == 0) { |
| 139 | TCCR3A = 0; | 67 | TCCR3A = 0; |
| 140 | TCCR3B = 0; | 68 | TCCR3B = 0; |
| 141 | frequency = 0; | 69 | frequency = 0; |
| 70 | volume = 0; | ||
| 142 | } else { | 71 | } else { |
| 143 | double freq = frequencies[voices - 1]; | 72 | double freq = frequencies[voices - 1]; |
| 144 | int vol = volumes[voices - 1]; | 73 | int vol = volumes[voices - 1]; |
| 145 | if (frequency < freq) { | 74 | if (frequency < freq) { |
| 75 | sliding = true; | ||
| 146 | for (double f = frequency; f <= freq; f += ((freq - frequency) / 500.0)) { | 76 | for (double f = frequency; f <= freq; f += ((freq - frequency) / 500.0)) { |
| 147 | send_freq(f, vol); | 77 | send_freq(f, vol); |
| 148 | } | 78 | } |
| 79 | sliding = false; | ||
| 149 | } else if (frequency > freq) { | 80 | } else if (frequency > freq) { |
| 81 | sliding = true; | ||
| 150 | for (double f = frequency; f >= freq; f -= ((frequency - freq) / 500.0)) { | 82 | for (double f = frequency; f >= freq; f -= ((frequency - freq) / 500.0)) { |
| 151 | send_freq(f, vol); | 83 | send_freq(f, vol); |
| 152 | } | 84 | } |
| 85 | sliding = false; | ||
| 153 | } | 86 | } |
| 154 | send_freq(freq, vol); | 87 | send_freq(freq, vol); |
| 155 | frequency = freq; | 88 | frequency = freq; |
| @@ -157,6 +90,115 @@ void stop_note(double freq) { | |||
| 157 | } | 90 | } |
| 158 | } | 91 | } |
| 159 | 92 | ||
| 93 | void init_notes() { | ||
| 94 | // TCCR1A = (1 << COM1A1) | (0 << COM1A0) | (1 << WGM11) | (1 << WGM10); | ||
| 95 | // TCCR1B = (1 << COM1B1) | (0 << COM1A0) | (1 << WGM13) | (1 << WGM12) | (0 << CS12) | (0 << CS11) | (1 << CS10); | ||
| 96 | |||
| 97 | // DDRC |= (1<<6); | ||
| 98 | |||
| 99 | // TCCR3A = (1 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30); | ||
| 100 | // TCCR3B = (1 << WGM33) | (1 << WGM32) | (0 << CS32) | (0 << CS31) | (1 << CS30); | ||
| 101 | |||
| 102 | // ICR3 = 0xFFFF; | ||
| 103 | // OCR3A = (int)((float)wave[i]*ICR3/RANGE); //go to next array element | ||
| 104 | |||
| 105 | |||
| 106 | // cli(); | ||
| 107 | |||
| 108 | // /* Enable interrupt on timer2 == 127, with clk/8 prescaler. At 16MHz, | ||
| 109 | // this gives a timer interrupt at 15625Hz. */ | ||
| 110 | // TIMSK3 = (1 << OCIE3A); | ||
| 111 | |||
| 112 | // /* clear/reset timer on match */ | ||
| 113 | // // TCCR3A = 1<<WGM31 | 0<<WGM30; CTC mode, reset on match | ||
| 114 | // // TCCR3B = 0<<CS32 | 1<<CS31 | 0<<CS30; /* clk, /8 prescaler */ | ||
| 115 | |||
| 116 | // TCCR3A = (1 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30); | ||
| 117 | // TCCR3B = (0 << WGM33) | (0 << WGM32) | (0 << CS32) | (0 << CS31) | (1 << CS30); | ||
| 118 | |||
| 119 | |||
| 120 | // TCCR1A = (1 << COM1A1) | (0 << COM1A0) | (1 << WGM11) | (0 << WGM10); | ||
| 121 | // TCCR1B = (1 << WGM12) | (0 << CS12) | (0 << CS11) | (1 << CS10); | ||
| 122 | // // SPCR = 0x50; | ||
| 123 | // // SPSR = 0x01; | ||
| 124 | // DDRC |= (1<<6); | ||
| 125 | // // ICR3 = 0xFFFF; | ||
| 126 | // // OCR3A=80; | ||
| 127 | // PORTC |= (1<<6); | ||
| 128 | |||
| 129 | // sei(); | ||
| 130 | } | ||
| 131 | |||
| 132 | // #define highByte(c) ((c >> 8) & 0x00FF) | ||
| 133 | // #define lowByte(c) (c & 0x00FF) | ||
| 134 | |||
| 135 | ISR(TIMER3_COMPA_vect) { | ||
| 136 | |||
| 137 | if (ICR3 > 0 && !sliding) { | ||
| 138 | switch (position) { | ||
| 139 | case 0: { | ||
| 140 | int duty = (((double)F_CPU) / (frequency)); | ||
| 141 | ICR3 = duty; // Set max to the period | ||
| 142 | OCR3A = duty >> 1; // Set compare to half the period | ||
| 143 | break; | ||
| 144 | } | ||
| 145 | case 1: { | ||
| 146 | int duty = (((double)F_CPU) / (frequency*2)); | ||
| 147 | ICR3 = duty; // Set max to the period | ||
| 148 | OCR3A = duty >> 1; // Set compare to half the period | ||
| 149 | break; | ||
| 150 | } | ||
| 151 | case 2: { | ||
| 152 | int duty = (((double)F_CPU) / (frequency*3)); | ||
| 153 | ICR3 = duty; // Set max to the period | ||
| 154 | OCR3A = duty >> 1; // Set compare to half the period | ||
| 155 | break; | ||
| 156 | } | ||
| 157 | } | ||
| 158 | position = (position + 1) % 3; | ||
| 159 | } | ||
| 160 | // /* OCR2A has been cleared, per TCCR2A above */ | ||
| 161 | // // OCR3A = 127; | ||
| 162 | |||
| 163 | // // pos1 += incr1; | ||
| 164 | // // pos2 += incr2; | ||
| 165 | // // pos3 += incr3; | ||
| 166 | |||
| 167 | // // sample = sinewave[highByte(pos1)] + sinewave[highByte(pos2)] + sinewave[highByte(pos3)]; | ||
| 168 | |||
| 169 | // // OCR3A = sample; | ||
| 170 | |||
| 171 | |||
| 172 | // OCR3A=pgm_read_byte(&sinewave[pos1]); | ||
| 173 | // pos1++; | ||
| 174 | // // PORTC &= ~(1<<6); | ||
| 175 | |||
| 176 | // /* buffered, 1x gain, active mode */ | ||
| 177 | // // SPDR = highByte(sample) | 0x70; | ||
| 178 | // // while (!(SPSR & (1<<SPIF))); | ||
| 179 | |||
| 180 | // // SPDR = lowByte(sample); | ||
| 181 | // // while (!(SPSR & (1<<SPIF))); | ||
| 182 | |||
| 183 | // // PORTC |= (1<<6); | ||
| 184 | } | ||
| 185 | |||
| 186 | void loop() { | ||
| 187 | } | ||
| 188 | // ISR(TIMER1_COMPA_vect) | ||
| 189 | // { | ||
| 190 | // // if (i<(sizeof(wave)/sizeof(int))) //don't exceed ends of vector... sizeof(wave) | ||
| 191 | // if (i<pow(2, 10)) //don't exceed ends of vector... sizeof(wave) | ||
| 192 | // { | ||
| 193 | // OCR3A = (int)((float)wave[i]*ICR3/RANGE); //go to next array element | ||
| 194 | // // int x = 1; | ||
| 195 | // // int y = 5; | ||
| 196 | // // OCR3A = (int) (round(sin(i*440*pow(2, x/12.0))*.5+.5 + sin(i*440*pow(2, y/12.0))*.5+.5) / 2 * ICR3); | ||
| 197 | // i++; //increment | ||
| 198 | // } | ||
| 199 | // else i=0; //reset | ||
| 200 | // } | ||
| 201 | |||
| 160 | void play_note(double freq, int vol) { | 202 | void play_note(double freq, int vol) { |
| 161 | 203 | ||
| 162 | if (freq > 0) { | 204 | if (freq > 0) { |
diff --git a/keyboard/planck/beeps.h b/keyboard/planck/beeps.h index ec1d349d8..378983c60 100644 --- a/keyboard/planck/beeps.h +++ b/keyboard/planck/beeps.h | |||
| @@ -8,4 +8,5 @@ void beeps(); | |||
| 8 | void true_note(float x, float y, float length); | 8 | void true_note(float x, float y, float length); |
| 9 | void play_note(double freq, int vol); | 9 | void play_note(double freq, int vol); |
| 10 | void stop_note(double freq); | 10 | void stop_note(double freq); |
| 11 | void stop_all_notes(); \ No newline at end of file | 11 | void stop_all_notes(); |
| 12 | void init_notes(); \ No newline at end of file | ||
diff --git a/keyboard/planck/keymap_midi.c b/keyboard/planck/keymap_midi.c index ddd8a4b68..60ad6d53a 100644 --- a/keyboard/planck/keymap_midi.c +++ b/keyboard/planck/keymap_midi.c | |||
| @@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 20 | #include <lufa.h> | 20 | #include <lufa.h> |
| 21 | 21 | ||
| 22 | uint8_t starting_note = 0x0C; | 22 | uint8_t starting_note = 0x0C; |
| 23 | int offset = 7; | ||
| 23 | 24 | ||
| 24 | void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) | 25 | void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) |
| 25 | { | 26 | { |
| @@ -31,28 +32,77 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) | |||
| 31 | } | 32 | } |
| 32 | } | 33 | } |
| 33 | 34 | ||
| 34 | if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) { | 35 | if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) { |
| 35 | starting_note++; | 36 | if (record->event.pressed) { |
| 37 | 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); | ||
| 39 | midi_send_cc(&midi_device, 0, 0x7B, 0); | ||
| 40 | midi_send_cc(&midi_device, 1, 0x7B, 0); | ||
| 41 | midi_send_cc(&midi_device, 2, 0x7B, 0); | ||
| 42 | midi_send_cc(&midi_device, 3, 0x7B, 0); | ||
| 43 | midi_send_cc(&midi_device, 4, 0x7B, 0); | ||
| 44 | return; | ||
| 45 | } 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))); | ||
| 47 | // stop_all_notes(); | ||
| 48 | return; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) { | ||
| 52 | if (record->event.pressed) { | ||
| 53 | 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); | ||
| 55 | midi_send_cc(&midi_device, 0, 0x7B, 0); | ||
| 56 | midi_send_cc(&midi_device, 1, 0x7B, 0); | ||
| 57 | midi_send_cc(&midi_device, 2, 0x7B, 0); | ||
| 58 | midi_send_cc(&midi_device, 3, 0x7B, 0); | ||
| 59 | midi_send_cc(&midi_device, 4, 0x7B, 0); | ||
| 60 | return; | ||
| 61 | } 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))); | ||
| 63 | // stop_all_notes(); | ||
| 64 | return; | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) { | ||
| 69 | offset++; | ||
| 36 | midi_send_cc(&midi_device, 0, 0x7B, 0); | 70 | midi_send_cc(&midi_device, 0, 0x7B, 0); |
| 37 | midi_send_cc(&midi_device, 1, 0x7B, 0); | 71 | midi_send_cc(&midi_device, 1, 0x7B, 0); |
| 38 | midi_send_cc(&midi_device, 2, 0x7B, 0); | 72 | midi_send_cc(&midi_device, 2, 0x7B, 0); |
| 39 | midi_send_cc(&midi_device, 3, 0x7B, 0); | 73 | midi_send_cc(&midi_device, 3, 0x7B, 0); |
| 40 | midi_send_cc(&midi_device, 4, 0x7B, 0); | 74 | midi_send_cc(&midi_device, 4, 0x7B, 0); |
| 75 | // stop_all_notes(); | ||
| 76 | 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); | ||
| 78 | _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))); | ||
| 80 | _delay_us(8000); | ||
| 81 | } | ||
| 82 | return; | ||
| 41 | } | 83 | } |
| 42 | if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) { | 84 | if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) { |
| 43 | starting_note--; | 85 | offset--; |
| 44 | midi_send_cc(&midi_device, 0, 0x7B, 0); | 86 | midi_send_cc(&midi_device, 0, 0x7B, 0); |
| 45 | midi_send_cc(&midi_device, 1, 0x7B, 0); | 87 | midi_send_cc(&midi_device, 1, 0x7B, 0); |
| 46 | midi_send_cc(&midi_device, 2, 0x7B, 0); | 88 | midi_send_cc(&midi_device, 2, 0x7B, 0); |
| 47 | midi_send_cc(&midi_device, 3, 0x7B, 0); | 89 | midi_send_cc(&midi_device, 3, 0x7B, 0); |
| 48 | midi_send_cc(&midi_device, 4, 0x7B, 0); | 90 | midi_send_cc(&midi_device, 4, 0x7B, 0); |
| 91 | // stop_all_notes(); | ||
| 92 | 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); | ||
| 94 | _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))); | ||
| 96 | _delay_us(8000); | ||
| 97 | } | ||
| 98 | return; | ||
| 49 | } | 99 | } |
| 50 | 100 | ||
| 51 | if (record->event.pressed) { | 101 | if (record->event.pressed) { |
| 52 | midi_send_noteon(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127); | 102 | // midi_send_noteon(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127); |
| 53 | play_note(((double)261.6)*pow(2.0, 2.0)*pow(2.0,SCALE[record->event.key.col]/12.0+(record->event.key.row)), 0xF); | 103 | 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); |
| 54 | } else { | 104 | } else { |
| 55 | 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); |
| 56 | stop_note(((double)261.6)*pow(2.0, 2.0)*pow(2.0,SCALE[record->event.key.col]/12.0+(record->event.key.row))); | 106 | 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))); |
| 57 | } | 107 | } |
| 58 | } \ No newline at end of file | 108 | } \ No newline at end of file |
diff --git a/keyboard/planck/keymap_midi.h b/keyboard/planck/keymap_midi.h index 02bf35c24..c5917f884 100644 --- a/keyboard/planck/keymap_midi.h +++ b/keyboard/planck/keymap_midi.h | |||
| @@ -23,7 +23,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 23 | 23 | ||
| 24 | #define CHNL(note, channel) (note + (channel << 8)) | 24 | #define CHNL(note, channel) (note + (channel << 8)) |
| 25 | 25 | ||
| 26 | #define SCALE (int []){ 0, 2, 4, 5, 7, 9, 11, 12, 14, 16, 17, 19, 21, 23, 24, 26, 28, 29, 31, 33, 35, 36} | 26 | #define SCALE (int []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \ |
| 27 | 0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \ | ||
| 28 | 0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \ | ||
| 29 | 0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \ | ||
| 30 | 0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), } | ||
| 27 | 31 | ||
| 28 | #define N_CN1 (0x600C + (12 * -1) + 0 ) | 32 | #define N_CN1 (0x600C + (12 * -1) + 0 ) |
| 29 | #define N_CN1S (0x600C + (12 * -1) + 1 ) | 33 | #define N_CN1S (0x600C + (12 * -1) + 1 ) |
diff --git a/keyboard/planck/keymaps/keymap_lock.c b/keyboard/planck/keymaps/keymap_lock.c index 4c4845963..4fe2e0a2b 100644 --- a/keyboard/planck/keymaps/keymap_lock.c +++ b/keyboard/planck/keymaps/keymap_lock.c | |||
| @@ -40,7 +40,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 40 | { MIDI12 }, | 40 | { MIDI12 }, |
| 41 | { MIDI12 }, | 41 | { MIDI12 }, |
| 42 | { MIDI12 }, | 42 | { MIDI12 }, |
| 43 | {M(0), KC_LCTL, KC_LALT, KC_LGUI, FUNC(2), KC_SPC, KC_SPC, FUNC(1), MIDI, MIDI, MIDI, MIDI} | 43 | {M(0), KC_MS_L, KC_MS_D, KC_MS_U, KC_MS_R, KC_SPC, KC_SPC, FUNC(1), MIDI, MIDI, MIDI, MIDI} |
| 44 | } | 44 | } |
| 45 | }; | 45 | }; |
| 46 | 46 | ||
diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index 3ec476928..c6e6e9505 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c | |||
| @@ -829,6 +829,7 @@ int main(void) | |||
| 829 | midi_register_cc_callback(&midi_device, cc_callback); | 829 | midi_register_cc_callback(&midi_device, cc_callback); |
| 830 | midi_register_sysex_callback(&midi_device, sysex_callback); | 830 | midi_register_sysex_callback(&midi_device, sysex_callback); |
| 831 | 831 | ||
| 832 | init_notes(); | ||
| 832 | // midi_send_cc(&midi_device, 0, 1, 2); | 833 | // midi_send_cc(&midi_device, 0, 1, 2); |
| 833 | // midi_send_cc(&midi_device, 15, 1, 0); | 834 | // midi_send_cc(&midi_device, 15, 1, 0); |
| 834 | // midi_send_noteon(&midi_device, 0, 64, 127); | 835 | // midi_send_noteon(&midi_device, 0, 64, 127); |
| @@ -837,13 +838,13 @@ int main(void) | |||
| 837 | 838 | ||
| 838 | 839 | ||
| 839 | /* wait for USB startup & debug output */ | 840 | /* wait for USB startup & debug output */ |
| 840 | while (USB_DeviceState != DEVICE_STATE_Configured) { | 841 | // while (USB_DeviceState != DEVICE_STATE_Configured) { |
| 841 | #if defined(INTERRUPT_CONTROL_ENDPOINT) | 842 | // #if defined(INTERRUPT_CONTROL_ENDPOINT) |
| 842 | ; | 843 | // ; |
| 843 | #else | 844 | // #else |
| 844 | USB_USBTask(); | 845 | USB_USBTask(); |
| 845 | #endif | 846 | // #endif |
| 846 | } | 847 | // } |
| 847 | print("USB configured.\n"); | 848 | print("USB configured.\n"); |
| 848 | 849 | ||
| 849 | /* init modules */ | 850 | /* init modules */ |
