summary refs log tree commit diff
path: root/quantum
diff options
context:
space:
mode:
authorIBNobody <ibnobody@gmail.com>2016-05-24 17:55:46 -0500
committerIBNobody <ibnobody@gmail.com>2016-05-24 17:55:46 -0500
commit76e36a787a58ad0e72fac579e4a02aa66ce26be1 (patch)
tree22eb10d93b95cfb52560a91450a29bd9aabdbc61 /quantum
parent35d7081899df3a486b9b5785c7e8ec9481195848 (diff)
parentd66aa0abf96b5e887250cf0a7fa5e575f18c5a91 (diff)
Merge remote-tracking branch 'remotes/jackhumbert/master'
Diffstat (limited to 'quantum')
-rw-r--r--quantum/audio/audio.c783
-rw-r--r--quantum/audio/audio.h18
-rw-r--r--quantum/audio/audio_pwm.c643
-rw-r--r--quantum/audio/frequency_lut.h357
-rw-r--r--quantum/audio/luts.c382
-rw-r--r--quantum/audio/luts.h15
-rw-r--r--quantum/audio/vibrato_lut.h28
-rw-r--r--quantum/audio/voices.c8
-rw-r--r--quantum/audio/voices.h3
-rw-r--r--quantum/keymap_common.c43
-rw-r--r--quantum/keymap_common.h126
-rw-r--r--quantum/keymap_extras/keymap_german_ch.h102
-rw-r--r--quantum/keymap_midi.h10
-rw-r--r--quantum/keymap_unicode.c61
-rw-r--r--quantum/matrix.c25
-rw-r--r--quantum/quantum.c463
-rw-r--r--quantum/quantum.h72
-rw-r--r--quantum/quantum.mk17
-rw-r--r--quantum/template/template.c7
-rw-r--r--quantum/template/template.h2
-rw-r--r--quantum/tools/README.md4
-rw-r--r--quantum/unicode.h128
22 files changed, 2307 insertions, 990 deletions
diff --git a/quantum/audio/audio.c b/quantum/audio/audio.c
index e85370d958..32f64417ed 100644
--- a/quantum/audio/audio.c
+++ b/quantum/audio/audio.c
@@ -1,6 +1,6 @@
 #include <stdio.h>
 #include <string.h>
-#include <math.h>
+//#include <math.h>
 #include <avr/pgmspace.h>
 #include <avr/interrupt.h>
 #include <avr/io.h>
@@ -10,30 +10,28 @@
 
 #include "eeconfig.h"
 
-#ifdef VIBRATO_ENABLE
-    #include "vibrato_lut.h"
-#endif
+#define CPU_PRESCALER 8
 
-#define PI 3.14159265
+// -----------------------------------------------------------------------------
+// Timer Abstractions
+// -----------------------------------------------------------------------------
 
-#define CPU_PRESCALER 8
+// TIMSK3 - Timer/Counter #3 Interrupt Mask Register
+// Turn on/off 3A interputs, stopping/enabling the ISR calls
+#define ENABLE_AUDIO_COUNTER_3_ISR TIMSK3 |= _BV(OCIE3A)
+#define DISABLE_AUDIO_COUNTER_3_ISR TIMSK3 &= ~_BV(OCIE3A)
 
-#ifdef PWM_AUDIO
-    #include "wave.h"
-    #define SAMPLE_DIVIDER 39
-    #define SAMPLE_RATE (2000000.0/SAMPLE_DIVIDER/2048)
-    // Resistor value of 1/ (2 * PI * 10nF * (2000000 hertz / SAMPLE_DIVIDER / 10)) for 10nF cap
+// TCCR3A: Timer/Counter #3 Control Register
+// Compare Output Mode (COM3An) = 0b00 = Normal port operation, OC3A disconnected from PC6
+#define ENABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A |= _BV(COM3A1);
+#define DISABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A &= ~(_BV(COM3A1) | _BV(COM3A0));
 
-    float places[8] = {0, 0, 0, 0, 0, 0, 0, 0};
-    uint16_t place_int = 0;
-    bool repeat = true;
-#endif
+// Fast PWM Mode Controls
+#define TIMER_3_PERIOD     ICR3
+#define TIMER_3_DUTY_CYCLE OCR3A
+
+// -----------------------------------------------------------------------------
 
-void delay_us(int count) {
-  while(count--) {
-    _delay_us(1);
-  }
-}
 
 int voices = 0;
 int voice_place = 0;
@@ -45,26 +43,23 @@ float frequencies[8] = {0, 0, 0, 0, 0, 0, 0, 0};
 int volumes[8] = {0, 0, 0, 0, 0, 0, 0, 0};
 bool sliding = false;
 
-int max = 0xFF;
-float sum = 0;
 float place = 0;
 
 uint8_t * sample;
 uint16_t sample_length = 0;
-// float freq = 0;
-
-bool notes = false;
-bool note = false;
-float note_frequency = 0;
-float note_length = 0;
-float note_tempo = TEMPO_DEFAULT;
-float note_timbre = TIMBRE_DEFAULT;
+
+bool     playing_notes = false;
+bool     playing_note = false;
+float    note_frequency = 0;
+float    note_length = 0;
+uint8_t  note_tempo = TEMPO_DEFAULT;
+float    note_timbre = TIMBRE_DEFAULT;
 uint16_t note_position = 0;
 float (* notes_pointer)[][2];
 uint16_t notes_count;
-bool notes_repeat;
-float notes_rest;
-bool note_resting = false;
+bool     notes_repeat;
+float    notes_rest;
+bool     note_resting = false;
 
 uint8_t current_note = 0;
 uint8_t rest_counter = 0;
@@ -77,175 +72,65 @@ float vibrato_rate = 0.125;
 
 float polyphony_rate = 0;
 
-bool inited = false;
+static bool audio_initialized = false;
 
 audio_config_t audio_config;
 
 uint16_t envelope_index = 0;
 
-void audio_toggle(void) {
-    audio_config.enable ^= 1;
-    eeconfig_update_audio(audio_config.raw);
-}
-
-void audio_on(void) {
-    audio_config.enable = 1;
-    eeconfig_update_audio(audio_config.raw);
-}
-
-void audio_off(void) {
-    audio_config.enable = 0;
-    eeconfig_update_audio(audio_config.raw);
-}
-
-#ifdef VIBRATO_ENABLE
-// Vibrato rate functions
-
-void set_vibrato_rate(float rate) {
-    vibrato_rate = rate;
-}
-
-void increase_vibrato_rate(float change) {
-    vibrato_rate *= change;
-}
-
-void decrease_vibrato_rate(float change) {
-    vibrato_rate /= change;
-}
-
-#ifdef VIBRATO_STRENGTH_ENABLE
-
-void set_vibrato_strength(float strength) {
-    vibrato_strength = strength;
-}
-
-void increase_vibrato_strength(float change) {
-    vibrato_strength *= change;
-}
-
-void decrease_vibrato_strength(float change) {
-    vibrato_strength /= change;
-}
-
-#endif
-
-#endif
-
-// Polyphony functions
-
-void set_polyphony_rate(float rate) {
-    polyphony_rate = rate;
-}
-
-void enable_polyphony() {
-    polyphony_rate = 5;
-}
-
-void disable_polyphony() {
-    polyphony_rate = 0;
-}
-
-void increase_polyphony_rate(float change) {
-    polyphony_rate *= change;
-}
-
-void decrease_polyphony_rate(float change) {
-    polyphony_rate /= change;
-}
-
-// Timbre function
-
-void set_timbre(float timbre) {
-    note_timbre = timbre;
-}
-
-// Tempo functions
-
-void set_tempo(float tempo) {
-    note_tempo = tempo;
-}
-
-void decrease_tempo(uint8_t tempo_change) {
-    note_tempo += (float) tempo_change;
-}
-
-void increase_tempo(uint8_t tempo_change) {
-    if (note_tempo - (float) tempo_change < 10) {
-        note_tempo = 10;
-    } else {
-        note_tempo -= (float) tempo_change;
-    }
-}
-
-void audio_init() {
+void audio_init()
+{
 
-    /* check signature */
-    if (!eeconfig_is_enabled()) {
+    // Check EEPROM
+    if (!eeconfig_is_enabled())
+    {
         eeconfig_init();
     }
     audio_config.raw = eeconfig_read_audio();
 
-    #ifdef PWM_AUDIO
-        PLLFRQ = _BV(PDIV2);
-        PLLCSR = _BV(PLLE);
-        while(!(PLLCSR & _BV(PLOCK)));
-        PLLFRQ |= _BV(PLLTM0); /* PCK 48MHz */
+	// Set port PC6 (OC3A and /OC4A) as output
+    DDRC |= _BV(PORTC6);
 
-        /* Init a fast PWM on Timer4 */
-        TCCR4A = _BV(COM4A0) | _BV(PWM4A); /* Clear OC4A on Compare Match */
-        TCCR4B = _BV(CS40); /* No prescaling => f = PCK/256 = 187500Hz */
-        OCR4A = 0;
+    DISABLE_AUDIO_COUNTER_3_ISR;
 
-        /* Enable the OC4A output */
-        DDRC |= _BV(PORTC6);
+	// TCCR3A / TCCR3B: Timer/Counter #3 Control Registers
+	// Compare Output Mode (COM3An) = 0b00 = Normal port operation, OC3A disconnected from PC6
+	// Waveform Generation Mode (WGM3n) = 0b1110 = Fast PWM Mode 14 (Period = ICR3, Duty Cycle = OCR3A)
+	// Clock Select (CS3n) = 0b010 = Clock / 8
+    TCCR3A = (0 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30);
+    TCCR3B = (1 << WGM33)  | (1 << WGM32)  | (0 << CS32)  | (1 << CS31) | (0 << CS30);
 
-        TIMSK3 &= ~_BV(OCIE3A); // Turn off 3A interputs
-
-        TCCR3A = 0x0; // Options not needed
-        TCCR3B = _BV(CS31) | _BV(CS30) | _BV(WGM32); // 64th prescaling and CTC
-        OCR3A = SAMPLE_DIVIDER - 1; // Correct count/compare, related to sample playback
-    #else
-        DDRC |= _BV(PORTC6);
-
-        TIMSK3 &= ~_BV(OCIE3A); // Turn off 3A interputs
-
-        TCCR3A = (0 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30);
-        TCCR3B = (1 << WGM33) | (1 << WGM32) | (0 << CS32) | (1 << CS31) | (0 << CS30);
-    #endif
-
-    inited = true;
+    audio_initialized = true;
 }
 
-void stop_all_notes() {
-    if (!inited) {
+void stop_all_notes()
+{
+    if (!audio_initialized) {
         audio_init();
     }
     voices = 0;
-    #ifdef PWM_AUDIO
-        TIMSK3 &= ~_BV(OCIE3A);
-    #else
-        TIMSK3 &= ~_BV(OCIE3A);
-        TCCR3A &= ~_BV(COM3A1);
-    #endif
-    notes = false;
-    note = false;
+
+    DISABLE_AUDIO_COUNTER_3_ISR;
+    DISABLE_AUDIO_COUNTER_3_OUTPUT;
+
+    playing_notes = false;
+    playing_note = false;
     frequency = 0;
     volume = 0;
 
-    for (int i = 0; i < 8; i++) {
+    for (uint8_t i = 0; i < 8; i++)
+    {
         frequencies[i] = 0;
         volumes[i] = 0;
     }
 }
 
-void stop_note(float freq) {
-    if (note) {
-        if (!inited) {
+void stop_note(float freq)
+{
+    if (playing_note) {
+        if (!audio_initialized) {
             audio_init();
         }
-        #ifdef PWM_AUDIO
-            freq = freq / SAMPLE_RATE;
-        #endif
         for (int i = 7; i >= 0; i--) {
             if (frequencies[i] == freq) {
                 frequencies[i] = 0;
@@ -266,15 +151,11 @@ void stop_note(float freq) {
             voice_place = 0;
         }
         if (voices == 0) {
-            #ifdef PWM_AUDIO
-                TIMSK3 &= ~_BV(OCIE3A);
-            #else
-                TIMSK3 &= ~_BV(OCIE3A);
-                TCCR3A &= ~_BV(COM3A1);
-            #endif
+            DISABLE_AUDIO_COUNTER_3_ISR;
+            DISABLE_AUDIO_COUNTER_3_OUTPUT;
             frequency = 0;
             volume = 0;
-            note = false;
+            playing_note = false;
         }
     }
 }
@@ -289,9 +170,9 @@ float mod(float a, int b)
 
 float vibrato(float average_freq) {
     #ifdef VIBRATO_STRENGTH_ENABLE
-        float vibrated_freq = average_freq * pow(VIBRATO_LUT[(int)vibrato_counter], vibrato_strength);
+        float vibrated_freq = average_freq * pow(vibrato_lut[(int)vibrato_counter], vibrato_strength);
     #else
-        float vibrated_freq = average_freq * VIBRATO_LUT[(int)vibrato_counter];
+        float vibrated_freq = average_freq * vibrato_lut[(int)vibrato_counter];
     #endif
     vibrato_counter = mod((vibrato_counter + vibrato_rate * (1.0 + 440.0/average_freq)), VIBRATO_LUT_LENGTH);
     return vibrated_freq;
@@ -299,309 +180,315 @@ float vibrato(float average_freq) {
 
 #endif
 
-ISR(TIMER3_COMPA_vect) {
-    if (note) {
-        #ifdef PWM_AUDIO
-            if (voices == 1) {
-                // SINE
-                OCR4A = pgm_read_byte(&sinewave[(uint16_t)place]) >> 2;
-
-                // SQUARE
-                // if (((int)place) >= 1024){
-                //     OCR4A = 0xFF >> 2;
-                // } else {
-                //     OCR4A = 0x00;
-                // }
-
-                // SAWTOOTH
-                // OCR4A = (int)place / 4;
-
-                // TRIANGLE
-                // if (((int)place) >= 1024) {
-                //     OCR4A = (int)place / 2;
-                // } else {
-                //     OCR4A = 2048 - (int)place / 2;
-                // }
-
-                place += frequency;
-
-                if (place >= SINE_LENGTH)
-                    place -= SINE_LENGTH;
-
-            } else {
-                int sum = 0;
-                for (int i = 0; i < voices; i++) {
-                    // SINE
-                    sum += pgm_read_byte(&sinewave[(uint16_t)places[i]]) >> 2;
-
-                    // SQUARE
-                    // if (((int)places[i]) >= 1024){
-                    //     sum += 0xFF >> 2;
-                    // } else {
-                    //     sum += 0x00;
-                    // }
-
-                    places[i] += frequencies[i];
-
-                    if (places[i] >= SINE_LENGTH)
-                        places[i] -= SINE_LENGTH;
-                }
-                OCR4A = sum;
-            }
-        #else
-            if (voices > 0) {
-                float freq;
-                if (polyphony_rate > 0) {                
-                    if (voices > 1) {
-                        voice_place %= voices;
-                        if (place++ > (frequencies[voice_place] / polyphony_rate / CPU_PRESCALER)) {
-                            voice_place = (voice_place + 1) % voices;
-                            place = 0.0;
-                        }
-                    }
-                    #ifdef VIBRATO_ENABLE
-                    if (vibrato_strength > 0) {
-                        freq = vibrato(frequencies[voice_place]);
-                    } else {
-                    #else
-                    {
-                    #endif
-                        freq = frequencies[voice_place];
-                    } 
-                } else {
-                    if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440/frequencies[voices - 1]/12/2)) {
-                        frequency = frequency * pow(2, 440/frequency/12/2);
-                    } else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440/frequencies[voices - 1]/12/2)) {
-                        frequency = frequency * pow(2, -440/frequency/12/2);
-                    } else {
-                        frequency = frequencies[voices - 1];
-                    }
-
-
-                    #ifdef VIBRATO_ENABLE
-                    if (vibrato_strength > 0) {
-                        freq = vibrato(frequency);
-                    } else {
-                    #else
-                    {
-                    #endif
-                        freq = frequency;
-                    } 
-                }
+ISR(TIMER3_COMPA_vect)
+{
+	float freq;
+
+	if (playing_note) {
+		if (voices > 0) {
+			if (polyphony_rate > 0) {
+				if (voices > 1) {
+					voice_place %= voices;
+					if (place++ > (frequencies[voice_place] / polyphony_rate / CPU_PRESCALER)) {
+						voice_place = (voice_place + 1) % voices;
+						place = 0.0;
+					}
+				}
+
+				#ifdef VIBRATO_ENABLE
+					if (vibrato_strength > 0) {
+						freq = vibrato(frequencies[voice_place]);
+					} else {
+						freq = frequencies[voice_place];
+					}
+				#else
+					freq = frequencies[voice_place];
+				#endif
+			} else {
+				if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440/frequencies[voices - 1]/12/2)) {
+					frequency = frequency * pow(2, 440/frequency/12/2);
+				} else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440/frequencies[voices - 1]/12/2)) {
+					frequency = frequency * pow(2, -440/frequency/12/2);
+				} else {
+					frequency = frequencies[voices - 1];
+				}
+
+				#ifdef VIBRATO_ENABLE
+					if (vibrato_strength > 0) {
+						freq = vibrato(frequency);
+					} else {
+						freq = frequency;
+					}
+				#else
+					freq = frequency;
+				#endif
+			}
+
+			if (envelope_index < 65535) {
+				envelope_index++;
+			}
+
+			freq = voice_envelope(freq);
+
+			if (freq < 30.517578125) {
+				freq = 30.52;
+			}
+
+			TIMER_3_PERIOD = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER));
+			TIMER_3_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre);
+		}
+	}
+
+	if (playing_notes) {
+		if (note_frequency > 0) {
+			#ifdef VIBRATO_ENABLE
+				if (vibrato_strength > 0) {
+					freq = vibrato(note_frequency);
+				} else {
+					freq = note_frequency;
+				}
+			#else
+					freq = note_frequency;
+			#endif
+
+			if (envelope_index < 65535) {
+				envelope_index++;
+			}
+			freq = voice_envelope(freq);
+
+			TIMER_3_PERIOD = (uint16_t)(((float)F_CPU) / (freq * CPU_PRESCALER));
+			TIMER_3_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre);
+		} else {
+			TIMER_3_PERIOD = 0;
+			TIMER_3_DUTY_CYCLE = 0;
+		}
+
+		note_position++;
+		bool end_of_note = false;
+		if (TIMER_3_PERIOD > 0) {
+			end_of_note = (note_position >= (note_length / TIMER_3_PERIOD * 0xFFFF));
+		} else {
+			end_of_note = (note_position >= (note_length * 0x7FF));
+		}
+
+		if (end_of_note) {
+			current_note++;
+			if (current_note >= notes_count) {
+				if (notes_repeat) {
+					current_note = 0;
+				} else {
+					DISABLE_AUDIO_COUNTER_3_ISR;
+					DISABLE_AUDIO_COUNTER_3_OUTPUT;
+					playing_notes = false;
+					return;
+				}
+			}
+			if (!note_resting && (notes_rest > 0)) {
+				note_resting = true;
+				note_frequency = 0;
+				note_length = notes_rest;
+				current_note--;
+			} else {
+				note_resting = false;
+				envelope_index = 0;
+				note_frequency = (*notes_pointer)[current_note][0];
+				note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
+			}
+
+			note_position = 0;
+		}
+	}
+
+	if (!audio_config.enable) {
+		playing_notes = false;
+		playing_note = false;
+	}
+}
 
-                if (envelope_index < 65535) {
-                    envelope_index++;
-                }
-                freq = voice_envelope(freq);
+void play_note(float freq, int vol) {
 
-                if (freq < 30.517578125)
-                    freq = 30.52;
-                ICR3 = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period
-                OCR3A = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
-            }
-        #endif
+    if (!audio_initialized) {
+        audio_init();
     }
 
-    // SAMPLE
-    // OCR4A = pgm_read_byte(&sample[(uint16_t)place_int]);
-
-    // place_int++;
-
-    // if (place_int >= sample_length)
-    //     if (repeat)
-    //         place_int -= sample_length;
-    //     else
-    //         TIMSK3 &= ~_BV(OCIE3A);
-
-
-    if (notes) {
-        #ifdef PWM_AUDIO
-            OCR4A = pgm_read_byte(&sinewave[(uint16_t)place]) >> 0;
-
-            place += note_frequency;
-            if (place >= SINE_LENGTH)
-                place -= SINE_LENGTH;
-        #else
-            if (note_frequency > 0) {
-                float freq;
-
-                #ifdef VIBRATO_ENABLE
-                if (vibrato_strength > 0) {
-                    freq = vibrato(note_frequency);
-                } else {
-                #else
-                {
-                #endif
-                    freq = note_frequency;
-                }
+	if (audio_config.enable && voices < 8) {
+	    DISABLE_AUDIO_COUNTER_3_ISR;
 
-                if (envelope_index < 65535) {
-                    envelope_index++;
-                }
-                freq = voice_envelope(freq);
+	    // Cancel notes if notes are playing
+	    if (playing_notes)
+	        stop_all_notes();
 
-                ICR3 = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period
-                OCR3A = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
-            } else {
-                ICR3 = 0;
-                OCR3A = 0;
-            }
-        #endif
-
-
-        note_position++;
-        bool end_of_note = false;
-        if (ICR3 > 0)
-            end_of_note = (note_position >= (note_length / ICR3 * 0xFFFF));
-        else
-            end_of_note = (note_position >= (note_length * 0x7FF));
-        if (end_of_note) {
-            current_note++;
-            if (current_note >= notes_count) {
-                if (notes_repeat) {
-                    current_note = 0;
-                } else {
-                    #ifdef PWM_AUDIO
-                        TIMSK3 &= ~_BV(OCIE3A);
-                    #else
-                        TIMSK3 &= ~_BV(OCIE3A);
-                        TCCR3A &= ~_BV(COM3A1);
-                    #endif
-                    notes = false;
-                    return;
-                }
-            }
-            if (!note_resting && (notes_rest > 0)) {
-                note_resting = true;
-                note_frequency = 0;
-                note_length = notes_rest;
-                current_note--;
-            } else {
-                note_resting = false;
-                #ifdef PWM_AUDIO
-                    note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
-                    note_length = (*notes_pointer)[current_note][1] * (note_tempo / 100);
-                #else
-                    envelope_index = 0;
-                    note_frequency = (*notes_pointer)[current_note][0];
-                    note_length = ((*notes_pointer)[current_note][1] / 4) * (note_tempo / 100);
-                #endif
-            }
-            note_position = 0;
-        }
+	    playing_note = true;
 
-    }
+	    envelope_index = 0;
+
+	    if (freq > 0) {
+	        frequencies[voices] = freq;
+	        volumes[voices] = vol;
+	        voices++;
+	    }
+
+        ENABLE_AUDIO_COUNTER_3_ISR;
+        ENABLE_AUDIO_COUNTER_3_OUTPUT;
+	}
 
-    if (!audio_config.enable) {
-        notes = false;
-        note = false;
-    }
 }
 
-void play_note(float freq, int vol) {
+void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest)
+{
 
-    if (!inited) {
+    if (!audio_initialized) {
         audio_init();
     }
 
-if (audio_config.enable && voices < 8) {
-    TIMSK3 &= ~_BV(OCIE3A);
-    // Cancel notes if notes are playing
-    if (notes)
-        stop_all_notes();
-    note = true;
-    envelope_index = 0;
-    #ifdef PWM_AUDIO
-        freq = freq / SAMPLE_RATE;
-    #endif
-    if (freq > 0) {
-        frequencies[voices] = freq;
-        volumes[voices] = vol;
-        voices++;
-    }
+	if (audio_config.enable) {
+
+	    DISABLE_AUDIO_COUNTER_3_ISR;
+
+		// Cancel note if a note is playing
+	    if (playing_note)
+	        stop_all_notes();
+
+	    playing_notes = true;
+
+	    notes_pointer = np;
+	    notes_count = n_count;
+	    notes_repeat = n_repeat;
+	    notes_rest = n_rest;
+
+	    place = 0;
+	    current_note = 0;
+
+        note_frequency = (*notes_pointer)[current_note][0];
+        note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
+	    note_position = 0;
+
+
+        ENABLE_AUDIO_COUNTER_3_ISR;
+        ENABLE_AUDIO_COUNTER_3_OUTPUT;
+	}
 
-    #ifdef PWM_AUDIO
-        TIMSK3 |= _BV(OCIE3A);
-    #else
-        TIMSK3 |= _BV(OCIE3A);
-        TCCR3A |= _BV(COM3A1);
-    #endif
 }
 
+bool is_playing_notes(void) {
+	return playing_notes;
 }
 
-void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest) {
+bool is_audio_on(void) {
+    return (audio_config.enable != 0);
+}
 
-    if (!inited) {
-        audio_init();
-    }
+void audio_toggle(void) {
+    audio_config.enable ^= 1;
+    eeconfig_update_audio(audio_config.raw);
+    if (audio_config.enable)
+        audio_on_user();
+}
 
-if (audio_config.enable) {
-    TIMSK3 &= ~_BV(OCIE3A);
-	// Cancel note if a note is playing
-    if (note)
-        stop_all_notes();
-    notes = true;
-
-    notes_pointer = np;
-    notes_count = n_count;
-    notes_repeat = n_repeat;
-    notes_rest = n_rest;
-
-    place = 0;
-    current_note = 0;
-    #ifdef PWM_AUDIO
-        note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
-        note_length = (*notes_pointer)[current_note][1] * (note_tempo / 100);
-    #else
-        note_frequency = (*notes_pointer)[current_note][0];
-        note_length = ((*notes_pointer)[current_note][1] / 4) * (note_tempo / 100);
-    #endif
-    note_position = 0;
+void audio_on(void) {
+    audio_config.enable = 1;
+    eeconfig_update_audio(audio_config.raw);
+    audio_on_user();
+}
 
+void audio_off(void) {
+    audio_config.enable = 0;
+    eeconfig_update_audio(audio_config.raw);
+}
 
-    #ifdef PWM_AUDIO
-        TIMSK3 |= _BV(OCIE3A);
-    #else
-        TIMSK3 |= _BV(OCIE3A);
-        TCCR3A |= _BV(COM3A1);
-    #endif
+#ifdef VIBRATO_ENABLE
+
+// Vibrato rate functions
+
+void set_vibrato_rate(float rate) {
+    vibrato_rate = rate;
 }
 
+void increase_vibrato_rate(float change) {
+    vibrato_rate *= change;
 }
 
-#ifdef PWM_AUDIO
-void play_sample(uint8_t * s, uint16_t l, bool r) {
-    if (!inited) {
-        audio_init();
-    }
+void decrease_vibrato_rate(float change) {
+    vibrato_rate /= change;
+}
 
-    if (audio_config.enable) {
-        TIMSK3 &= ~_BV(OCIE3A);
-        stop_all_notes();
-        place_int = 0;
-        sample = s;
-        sample_length = l;
-        repeat = r;
+#ifdef VIBRATO_STRENGTH_ENABLE
 
-        TIMSK3 |= _BV(OCIE3A);
+void set_vibrato_strength(float strength) {
+    vibrato_strength = strength;
+}
+
+void increase_vibrato_strength(float change) {
+    vibrato_strength *= change;
+}
+
+void decrease_vibrato_strength(float change) {
+    vibrato_strength /= change;
+}
+
+#endif  /* VIBRATO_STRENGTH_ENABLE */
+
+#endif /* VIBRATO_ENABLE */
+
+// Polyphony functions
+
+void set_polyphony_rate(float rate) {
+    polyphony_rate = rate;
+}
+
+void enable_polyphony() {
+    polyphony_rate = 5;
+}
+
+void disable_polyphony() {
+    polyphony_rate = 0;
+}
+
+void increase_polyphony_rate(float change) {
+    polyphony_rate *= change;
+}
+
+void decrease_polyphony_rate(float change) {
+    polyphony_rate /= change;
+}
+
+// Timbre function
+
+void set_timbre(float timbre) {
+    note_timbre = timbre;
+}
+
+// Tempo functions
+
+void set_tempo(uint8_t tempo) {
+    note_tempo = tempo;
+}
+
+void decrease_tempo(uint8_t tempo_change) {
+    note_tempo += tempo_change;
+}
+
+void increase_tempo(uint8_t tempo_change) {
+    if (note_tempo - tempo_change < 10) {
+        note_tempo = 10;
+    } else {
+        note_tempo -= tempo_change;
     }
 }
-#endif
+
 
 //------------------------------------------------------------------------------
 // Override these functions in your keymap file to play different tunes on
 // startup and bootloader jump
 __attribute__ ((weak))
-void play_startup_tone()
-{
-}
-
+void play_startup_tone() {}
 
+__attribute__ ((weak))
+void play_goodbye_tone() {}
 
 __attribute__ ((weak))
-void play_goodbye_tone()
-{
+void audio_on_user() {}
 
-}
+__attribute__ ((weak))
+void play_music_scale() {}
 //------------------------------------------------------------------------------
diff --git a/quantum/audio/audio.h b/quantum/audio/audio.h
index 89769507e1..b46f587bb4 100644
--- a/quantum/audio/audio.h
+++ b/quantum/audio/audio.h
@@ -25,6 +25,7 @@ typedef union {
     };
 } audio_config_t;
 
+bool is_audio_on(void);
 void audio_toggle(void);
 void audio_on(void);
 void audio_off(void);
@@ -56,7 +57,7 @@ void increase_polyphony_rate(float change);
 void decrease_polyphony_rate(float change);
 
 void set_timbre(float timbre);
-void set_tempo(float tempo);
+void set_tempo(uint8_t tempo);
 
 void increase_tempo(uint8_t tempo_change);
 void decrease_tempo(uint8_t tempo_change);
@@ -71,11 +72,11 @@ void stop_note(float freq);
 void stop_all_notes(void);
 void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest);
 
-#define SCALE (int []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \
-						0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \
-						0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \
-						0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \
-						0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), }
+#define SCALE (int8_t []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \
+                           0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \
+                           0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \
+                           0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \
+                           0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), }
 
 // These macros are used to allow play_notes to play an array of indeterminate
 // length. This works around the limitation of C's sizeof operation on pointers.
@@ -83,7 +84,12 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest)
 #define NOTE_ARRAY_SIZE(x) ((int16_t)(sizeof(x) / (sizeof(x[0]))))
 #define PLAY_NOTE_ARRAY(note_array, note_repeat, note_rest_style) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), (note_repeat), (note_rest_style));
 
+
+bool is_playing_notes(void);
+
 void play_goodbye_tone(void);
 void play_startup_tone(void);
+void audio_on_user(void);
+void play_music_scale(void);
 
 #endif
\ No newline at end of file
diff --git a/quantum/audio/audio_pwm.c b/quantum/audio/audio_pwm.c
new file mode 100644
index 0000000000..328a253a7e
--- /dev/null
+++ b/quantum/audio/audio_pwm.c
@@ -0,0 +1,643 @@
+#include <stdio.h>
+#include <string.h>
+//#include <math.h>
+#include <avr/pgmspace.h>
+#include <avr/interrupt.h>
+#include <avr/io.h>
+#include "print.h"
+#include "audio.h"
+#include "keymap_common.h"
+
+#include "eeconfig.h"
+
+#define PI 3.14159265
+
+#define CPU_PRESCALER 8
+
+
+// Timer Abstractions
+
+// TIMSK3 - Timer/Counter #3 Interrupt Mask Register
+// Turn on/off 3A interputs, stopping/enabling the ISR calls
+#define ENABLE_AUDIO_COUNTER_3_ISR TIMSK3 |= _BV(OCIE3A)
+#define DISABLE_AUDIO_COUNTER_3_ISR TIMSK3 &= ~_BV(OCIE3A)
+
+
+// TCCR3A: Timer/Counter #3 Control Register
+// Compare Output Mode (COM3An) = 0b00 = Normal port operation, OC3A disconnected from PC6
+#define ENABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A |= _BV(COM3A1);
+#define DISABLE_AUDIO_COUNTER_3_OUTPUT TCCR3A &= ~(_BV(COM3A1) | _BV(COM3A0));
+
+
+#define NOTE_PERIOD ICR3
+#define NOTE_DUTY_CYCLE OCR3A
+
+
+#ifdef PWM_AUDIO
+    #include "wave.h"
+    #define SAMPLE_DIVIDER 39
+    #define SAMPLE_RATE (2000000.0/SAMPLE_DIVIDER/2048)
+    // Resistor value of 1/ (2 * PI * 10nF * (2000000 hertz / SAMPLE_DIVIDER / 10)) for 10nF cap
+
+    float places[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+    uint16_t place_int = 0;
+    bool repeat = true;
+#endif
+
+void delay_us(int count) {
+  while(count--) {
+    _delay_us(1);
+  }
+}
+
+int voices = 0;
+int voice_place = 0;
+float frequency = 0;
+int volume = 0;
+long position = 0;
+
+float frequencies[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+int volumes[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+bool sliding = false;
+
+float place = 0;
+
+uint8_t * sample;
+uint16_t sample_length = 0;
+// float freq = 0;
+
+bool     playing_notes = false;
+bool     playing_note = false;
+float    note_frequency = 0;
+float    note_length = 0;
+uint8_t  note_tempo = TEMPO_DEFAULT;
+float    note_timbre = TIMBRE_DEFAULT;
+uint16_t note_position = 0;
+float (* notes_pointer)[][2];
+uint16_t notes_count;
+bool     notes_repeat;
+float    notes_rest;
+bool     note_resting = false;
+
+uint8_t current_note = 0;
+uint8_t rest_counter = 0;
+
+#ifdef VIBRATO_ENABLE
+float vibrato_counter = 0;
+float vibrato_strength = .5;
+float vibrato_rate = 0.125;
+#endif
+
+float polyphony_rate = 0;
+
+static bool audio_initialized = false;
+
+audio_config_t audio_config;
+
+uint16_t envelope_index = 0;
+
+void audio_init() {
+
+    // Check EEPROM
+    if (!eeconfig_is_enabled())
+    {
+        eeconfig_init();
+    }
+    audio_config.raw = eeconfig_read_audio();
+
+    #ifdef PWM_AUDIO
+
+        PLLFRQ = _BV(PDIV2);
+        PLLCSR = _BV(PLLE);
+        while(!(PLLCSR & _BV(PLOCK)));
+        PLLFRQ |= _BV(PLLTM0); /* PCK 48MHz */
+
+        /* Init a fast PWM on Timer4 */
+        TCCR4A = _BV(COM4A0) | _BV(PWM4A); /* Clear OC4A on Compare Match */
+        TCCR4B = _BV(CS40); /* No prescaling => f = PCK/256 = 187500Hz */
+        OCR4A = 0;
+
+        /* Enable the OC4A output */
+        DDRC |= _BV(PORTC6);
+
+        DISABLE_AUDIO_COUNTER_3_ISR; // Turn off 3A interputs
+
+        TCCR3A = 0x0; // Options not needed
+        TCCR3B = _BV(CS31) | _BV(CS30) | _BV(WGM32); // 64th prescaling and CTC
+        OCR3A = SAMPLE_DIVIDER - 1; // Correct count/compare, related to sample playback
+
+    #else
+
+    	// Set port PC6 (OC3A and /OC4A) as output
+        DDRC |= _BV(PORTC6);
+
+        DISABLE_AUDIO_COUNTER_3_ISR;
+
+		// TCCR3A / TCCR3B: Timer/Counter #3 Control Registers
+		// Compare Output Mode (COM3An) = 0b00 = Normal port operation, OC3A disconnected from PC6
+		// Waveform Generation Mode (WGM3n) = 0b1110 = Fast PWM Mode 14 (Period = ICR3, Duty Cycle = OCR3A)
+		// Clock Select (CS3n) = 0b010 = Clock / 8
+        TCCR3A = (0 << COM3A1) | (0 << COM3A0) | (1 << WGM31) | (0 << WGM30);
+        TCCR3B = (1 << WGM33)  | (1 << WGM32)  | (0 << CS32)  | (1 << CS31) | (0 << CS30);
+
+    #endif
+
+    audio_initialized = true;
+}
+
+void stop_all_notes() {
+    if (!audio_initialized) {
+        audio_init();
+    }
+    voices = 0;
+    #ifdef PWM_AUDIO
+	    DISABLE_AUDIO_COUNTER_3_ISR;
+    #else
+        DISABLE_AUDIO_COUNTER_3_ISR;
+        DISABLE_AUDIO_COUNTER_3_OUTPUT;
+    #endif
+
+    playing_notes = false;
+    playing_note = false;
+    frequency = 0;
+    volume = 0;
+
+    for (uint8_t i = 0; i < 8; i++)
+    {
+        frequencies[i] = 0;
+        volumes[i] = 0;
+    }
+}
+
+void stop_note(float freq)
+{
+    if (playing_note) {
+        if (!audio_initialized) {
+            audio_init();
+        }
+        #ifdef PWM_AUDIO
+            freq = freq / SAMPLE_RATE;
+        #endif
+        for (int i = 7; i >= 0; i--) {
+            if (frequencies[i] == freq) {
+                frequencies[i] = 0;
+                volumes[i] = 0;
+                for (int j = i; (j < 7); j++) {
+                    frequencies[j] = frequencies[j+1];
+                    frequencies[j+1] = 0;
+                    volumes[j] = volumes[j+1];
+                    volumes[j+1] = 0;
+                }
+                break;
+            }
+        }
+        voices--;
+        if (voices < 0)
+            voices = 0;
+        if (voice_place >= voices) {
+            voice_place = 0;
+        }
+        if (voices == 0) {
+            #ifdef PWM_AUDIO
+                DISABLE_AUDIO_COUNTER_3_ISR;
+            #else
+                DISABLE_AUDIO_COUNTER_3_ISR;
+                DISABLE_AUDIO_COUNTER_3_OUTPUT;
+            #endif
+            frequency = 0;
+            volume = 0;
+            playing_note = false;
+        }
+    }
+}
+
+#ifdef VIBRATO_ENABLE
+
+float mod(float a, int b)
+{
+    float r = fmod(a, b);
+    return r < 0 ? r + b : r;
+}
+
+float vibrato(float average_freq) {
+    #ifdef VIBRATO_STRENGTH_ENABLE
+        float vibrated_freq = average_freq * pow(vibrato_lut[(int)vibrato_counter], vibrato_strength);
+    #else
+        float vibrated_freq = average_freq * vibrato_lut[(int)vibrato_counter];
+    #endif
+    vibrato_counter = mod((vibrato_counter + vibrato_rate * (1.0 + 440.0/average_freq)), VIBRATO_LUT_LENGTH);
+    return vibrated_freq;
+}
+
+#endif
+
+ISR(TIMER3_COMPA_vect)
+{
+    if (playing_note) {
+        #ifdef PWM_AUDIO
+            if (voices == 1) {
+                // SINE
+                OCR4A = pgm_read_byte(&sinewave[(uint16_t)place]) >> 2;
+
+                // SQUARE
+                // if (((int)place) >= 1024){
+                //     OCR4A = 0xFF >> 2;
+                // } else {
+                //     OCR4A = 0x00;
+                // }
+
+                // SAWTOOTH
+                // OCR4A = (int)place / 4;
+
+                // TRIANGLE
+                // if (((int)place) >= 1024) {
+                //     OCR4A = (int)place / 2;
+                // } else {
+                //     OCR4A = 2048 - (int)place / 2;
+                // }
+
+                place += frequency;
+
+                if (place >= SINE_LENGTH)
+                    place -= SINE_LENGTH;
+
+            } else {
+                int sum = 0;
+                for (int i = 0; i < voices; i++) {
+                    // SINE
+                    sum += pgm_read_byte(&sinewave[(uint16_t)places[i]]) >> 2;
+
+                    // SQUARE
+                    // if (((int)places[i]) >= 1024){
+                    //     sum += 0xFF >> 2;
+                    // } else {
+                    //     sum += 0x00;
+                    // }
+
+                    places[i] += frequencies[i];
+
+                    if (places[i] >= SINE_LENGTH)
+                        places[i] -= SINE_LENGTH;
+                }
+                OCR4A = sum;
+            }
+        #else
+            if (voices > 0) {
+                float freq;
+                if (polyphony_rate > 0) {
+                    if (voices > 1) {
+                        voice_place %= voices;
+                        if (place++ > (frequencies[voice_place] / polyphony_rate / CPU_PRESCALER)) {
+                            voice_place = (voice_place + 1) % voices;
+                            place = 0.0;
+                        }
+                    }
+                    #ifdef VIBRATO_ENABLE
+                    if (vibrato_strength > 0) {
+                        freq = vibrato(frequencies[voice_place]);
+                    } else {
+                    #else
+                    {
+                    #endif
+                        freq = frequencies[voice_place];
+                    }
+                } else {
+                    if (frequency != 0 && frequency < frequencies[voices - 1] && frequency < frequencies[voices - 1] * pow(2, -440/frequencies[voices - 1]/12/2)) {
+                        frequency = frequency * pow(2, 440/frequency/12/2);
+                    } else if (frequency != 0 && frequency > frequencies[voices - 1] && frequency > frequencies[voices - 1] * pow(2, 440/frequencies[voices - 1]/12/2)) {
+                        frequency = frequency * pow(2, -440/frequency/12/2);
+                    } else {
+                        frequency = frequencies[voices - 1];
+                    }
+
+
+                    #ifdef VIBRATO_ENABLE
+                    if (vibrato_strength > 0) {
+                        freq = vibrato(frequency);
+                    } else {
+                    #else
+                    {
+                    #endif
+                        freq = frequency;
+                    }
+                }
+
+                if (envelope_index < 65535) {
+                    envelope_index++;
+                }
+                freq = voice_envelope(freq);
+
+                if (freq < 30.517578125)
+                    freq = 30.52;
+                NOTE_PERIOD = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period
+                NOTE_DUTY_CYCLE = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
+            }
+        #endif
+    }
+
+    // SAMPLE
+    // OCR4A = pgm_read_byte(&sample[(uint16_t)place_int]);
+
+    // place_int++;
+
+    // if (place_int >= sample_length)
+    //     if (repeat)
+    //         place_int -= sample_length;
+    //     else
+    //         DISABLE_AUDIO_COUNTER_3_ISR;
+
+
+    if (playing_notes) {
+        #ifdef PWM_AUDIO
+            OCR4A = pgm_read_byte(&sinewave[(uint16_t)place]) >> 0;
+
+            place += note_frequency;
+            if (place >= SINE_LENGTH)
+                place -= SINE_LENGTH;
+        #else
+            if (note_frequency > 0) {
+                float freq;
+
+                #ifdef VIBRATO_ENABLE
+                if (vibrato_strength > 0) {
+                    freq = vibrato(note_frequency);
+                } else {
+                #else
+                {
+                #endif
+                    freq = note_frequency;
+                }
+
+                if (envelope_index < 65535) {
+                    envelope_index++;
+                }
+                freq = voice_envelope(freq);
+
+                NOTE_PERIOD = (int)(((double)F_CPU) / (freq * CPU_PRESCALER)); // Set max to the period
+                NOTE_DUTY_CYCLE = (int)((((double)F_CPU) / (freq * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
+            } else {
+                NOTE_PERIOD = 0;
+                NOTE_DUTY_CYCLE = 0;
+            }
+        #endif
+
+
+        note_position++;
+        bool end_of_note = false;
+        if (NOTE_PERIOD > 0)
+            end_of_note = (note_position >= (note_length / NOTE_PERIOD * 0xFFFF));
+        else
+            end_of_note = (note_position >= (note_length * 0x7FF));
+        if (end_of_note) {
+            current_note++;
+            if (current_note >= notes_count) {
+                if (notes_repeat) {
+                    current_note = 0;
+                } else {
+                    #ifdef PWM_AUDIO
+                        DISABLE_AUDIO_COUNTER_3_ISR;
+                    #else
+                        DISABLE_AUDIO_COUNTER_3_ISR;
+                        DISABLE_AUDIO_COUNTER_3_OUTPUT;
+                    #endif
+                    playing_notes = false;
+                    return;
+                }
+            }
+            if (!note_resting && (notes_rest > 0)) {
+                note_resting = true;
+                note_frequency = 0;
+                note_length = notes_rest;
+                current_note--;
+            } else {
+                note_resting = false;
+                #ifdef PWM_AUDIO
+                    note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
+                    note_length = (*notes_pointer)[current_note][1] * (((float)note_tempo) / 100);
+                #else
+                    envelope_index = 0;
+                    note_frequency = (*notes_pointer)[current_note][0];
+                    note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
+                #endif
+            }
+            note_position = 0;
+        }
+
+    }
+
+    if (!audio_config.enable) {
+        playing_notes = false;
+        playing_note = false;
+    }
+}
+
+void play_note(float freq, int vol) {
+
+    if (!audio_initialized) {
+        audio_init();
+    }
+
+	if (audio_config.enable && voices < 8) {
+	    DISABLE_AUDIO_COUNTER_3_ISR;
+
+	    // Cancel notes if notes are playing
+	    if (playing_notes)
+	        stop_all_notes();
+
+	    playing_note = true;
+
+	    envelope_index = 0;
+
+	    #ifdef PWM_AUDIO
+	        freq = freq / SAMPLE_RATE;
+	    #endif
+	    if (freq > 0) {
+	        frequencies[voices] = freq;
+	        volumes[voices] = vol;
+	        voices++;
+	    }
+
+	    #ifdef PWM_AUDIO
+	        ENABLE_AUDIO_COUNTER_3_ISR;
+	    #else
+	        ENABLE_AUDIO_COUNTER_3_ISR;
+	        ENABLE_AUDIO_COUNTER_3_OUTPUT;
+	    #endif
+	}
+
+}
+
+void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest)
+{
+
+    if (!audio_initialized) {
+        audio_init();
+    }
+
+	if (audio_config.enable) {
+
+	    DISABLE_AUDIO_COUNTER_3_ISR;
+
+		// Cancel note if a note is playing
+	    if (playing_note)
+	        stop_all_notes();
+
+	    playing_notes = true;
+
+	    notes_pointer = np;
+	    notes_count = n_count;
+	    notes_repeat = n_repeat;
+	    notes_rest = n_rest;
+
+	    place = 0;
+	    current_note = 0;
+
+	    #ifdef PWM_AUDIO
+	        note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
+	        note_length = (*notes_pointer)[current_note][1] * (((float)note_tempo) / 100);
+	    #else
+	        note_frequency = (*notes_pointer)[current_note][0];
+	        note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
+	    #endif
+	    note_position = 0;
+
+
+	    #ifdef PWM_AUDIO
+	        ENABLE_AUDIO_COUNTER_3_ISR;
+	    #else
+	        ENABLE_AUDIO_COUNTER_3_ISR;
+	        ENABLE_AUDIO_COUNTER_3_OUTPUT;
+	    #endif
+	}
+
+}
+
+#ifdef PWM_AUDIO
+void play_sample(uint8_t * s, uint16_t l, bool r) {
+    if (!audio_initialized) {
+        audio_init();
+    }
+
+    if (audio_config.enable) {
+        DISABLE_AUDIO_COUNTER_3_ISR;
+        stop_all_notes();
+        place_int = 0;
+        sample = s;
+        sample_length = l;
+        repeat = r;
+
+        ENABLE_AUDIO_COUNTER_3_ISR;
+    }
+}
+#endif
+
+
+void audio_toggle(void) {
+    audio_config.enable ^= 1;
+    eeconfig_update_audio(audio_config.raw);
+}
+
+void audio_on(void) {
+    audio_config.enable = 1;
+    eeconfig_update_audio(audio_config.raw);
+}
+
+void audio_off(void) {
+    audio_config.enable = 0;
+    eeconfig_update_audio(audio_config.raw);
+}
+
+#ifdef VIBRATO_ENABLE
+
+// Vibrato rate functions
+
+void set_vibrato_rate(float rate) {
+    vibrato_rate = rate;
+}
+
+void increase_vibrato_rate(float change) {
+    vibrato_rate *= change;
+}
+
+void decrease_vibrato_rate(float change) {
+    vibrato_rate /= change;
+}
+
+#ifdef VIBRATO_STRENGTH_ENABLE
+
+void set_vibrato_strength(float strength) {
+    vibrato_strength = strength;
+}
+
+void increase_vibrato_strength(float change) {
+    vibrato_strength *= change;
+}
+
+void decrease_vibrato_strength(float change) {
+    vibrato_strength /= change;
+}
+
+#endif  /* VIBRATO_STRENGTH_ENABLE */
+
+#endif /* VIBRATO_ENABLE */
+
+// Polyphony functions
+
+void set_polyphony_rate(float rate) {
+    polyphony_rate = rate;
+}
+
+void enable_polyphony() {
+    polyphony_rate = 5;
+}
+
+void disable_polyphony() {
+    polyphony_rate = 0;
+}
+
+void increase_polyphony_rate(float change) {
+    polyphony_rate *= change;
+}
+
+void decrease_polyphony_rate(float change) {
+    polyphony_rate /= change;
+}
+
+// Timbre function
+
+void set_timbre(float timbre) {
+    note_timbre = timbre;
+}
+
+// Tempo functions
+
+void set_tempo(uint8_t tempo) {
+    note_tempo = tempo;
+}
+
+void decrease_tempo(uint8_t tempo_change) {
+    note_tempo += tempo_change;
+}
+
+void increase_tempo(uint8_t tempo_change) {
+    if (note_tempo - tempo_change < 10) {
+        note_tempo = 10;
+    } else {
+        note_tempo -= tempo_change;
+    }
+}
+
+
+//------------------------------------------------------------------------------
+// Override these functions in your keymap file to play different tunes on
+// startup and bootloader jump
+__attribute__ ((weak))
+void play_startup_tone()
+{
+}
+
+__attribute__ ((weak))
+void play_goodbye_tone()
+{
+}
+//------------------------------------------------------------------------------
diff --git a/quantum/audio/frequency_lut.h b/quantum/audio/frequency_lut.h
deleted file mode 100644
index e62da5be4e..0000000000
--- a/quantum/audio/frequency_lut.h
+++ /dev/null
@@ -1,357 +0,0 @@
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <avr/pgmspace.h>
-
-#define FREQUENCY_LUT_LENGTH 349
-
-const uint16_t FREQUENCY_LUT[FREQUENCY_LUT_LENGTH] = {
-0x8E0B,
-0x8C02,
-0x8A00,
-0x8805,
-0x8612,
-0x8426,
-0x8241,
-0x8063,
-0x7E8C,
-0x7CBB,
-0x7AF2,
-0x792E,
-0x7772,
-0x75BB,
-0x740B,
-0x7261,
-0x70BD,
-0x6F20,
-0x6D88,
-0x6BF6,
-0x6A69,
-0x68E3,
-0x6762,
-0x65E6,
-0x6470,
-0x6300,
-0x6194,
-0x602E,
-0x5ECD,
-0x5D71,
-0x5C1A,
-0x5AC8,
-0x597B,
-0x5833,
-0x56EF,
-0x55B0,
-0x5475,
-0x533F,
-0x520E,
-0x50E1,
-0x4FB8,
-0x4E93,
-0x4D73,
-0x4C57,
-0x4B3E,
-0x4A2A,
-0x491A,
-0x480E,
-0x4705,
-0x4601,
-0x4500,
-0x4402,
-0x4309,
-0x4213,
-0x4120,
-0x4031,
-0x3F46,
-0x3E5D,
-0x3D79,
-0x3C97,
-0x3BB9,
-0x3ADD,
-0x3A05,
-0x3930,
-0x385E,
-0x3790,
-0x36C4,
-0x35FB,
-0x3534,
-0x3471,
-0x33B1,
-0x32F3,
-0x3238,
-0x3180,
-0x30CA,
-0x3017,
-0x2F66,
-0x2EB8,
-0x2E0D,
-0x2D64,
-0x2CBD,
-0x2C19,
-0x2B77,
-0x2AD8,
-0x2A3A,
-0x299F,
-0x2907,
-0x2870,
-0x27DC,
-0x2749,
-0x26B9,
-0x262B,
-0x259F,
-0x2515,
-0x248D,
-0x2407,
-0x2382,
-0x2300,
-0x2280,
-0x2201,
-0x2184,
-0x2109,
-0x2090,
-0x2018,
-0x1FA3,
-0x1F2E,
-0x1EBC,
-0x1E4B,
-0x1DDC,
-0x1D6E,
-0x1D02,
-0x1C98,
-0x1C2F,
-0x1BC8,
-0x1B62,
-0x1AFD,
-0x1A9A,
-0x1A38,
-0x19D8,
-0x1979,
-0x191C,
-0x18C0,
-0x1865,
-0x180B,
-0x17B3,
-0x175C,
-0x1706,
-0x16B2,
-0x165E,
-0x160C,
-0x15BB,
-0x156C,
-0x151D,
-0x14CF,
-0x1483,
-0x1438,
-0x13EE,
-0x13A4,
-0x135C,
-0x1315,
-0x12CF,
-0x128A,
-0x1246,
-0x1203,
-0x11C1,
-0x1180,
-0x1140,
-0x1100,
-0x10C2,
-0x1084,
-0x1048,
-0x100C,
-0xFD1,
-0xF97,
-0xF5E,
-0xF25,
-0xEEE,
-0xEB7,
-0xE81,
-0xE4C,
-0xE17,
-0xDE4,
-0xDB1,
-0xD7E,
-0xD4D,
-0xD1C,
-0xCEC,
-0xCBC,
-0xC8E,
-0xC60,
-0xC32,
-0xC05,
-0xBD9,
-0xBAE,
-0xB83,
-0xB59,
-0xB2F,
-0xB06,
-0xADD,
-0xAB6,
-0xA8E,
-0xA67,
-0xA41,
-0xA1C,
-0x9F7,
-0x9D2,
-0x9AE,
-0x98A,
-0x967,
-0x945,
-0x923,
-0x901,
-0x8E0,
-0x8C0,
-0x8A0,
-0x880,
-0x861,
-0x842,
-0x824,
-0x806,
-0x7E8,
-0x7CB,
-0x7AF,
-0x792,
-0x777,
-0x75B,
-0x740,
-0x726,
-0x70B,
-0x6F2,
-0x6D8,
-0x6BF,
-0x6A6,
-0x68E,
-0x676,
-0x65E,
-0x647,
-0x630,
-0x619,
-0x602,
-0x5EC,
-0x5D7,
-0x5C1,
-0x5AC,
-0x597,
-0x583,
-0x56E,
-0x55B,
-0x547,
-0x533,
-0x520,
-0x50E,
-0x4FB,
-0x4E9,
-0x4D7,
-0x4C5,
-0x4B3,
-0x4A2,
-0x491,
-0x480,
-0x470,
-0x460,
-0x450,
-0x440,
-0x430,
-0x421,
-0x412,
-0x403,
-0x3F4,
-0x3E5,
-0x3D7,
-0x3C9,
-0x3BB,
-0x3AD,
-0x3A0,
-0x393,
-0x385,
-0x379,
-0x36C,
-0x35F,
-0x353,
-0x347,
-0x33B,
-0x32F,
-0x323,
-0x318,
-0x30C,
-0x301,
-0x2F6,
-0x2EB,
-0x2E0,
-0x2D6,
-0x2CB,
-0x2C1,
-0x2B7,
-0x2AD,
-0x2A3,
-0x299,
-0x290,
-0x287,
-0x27D,
-0x274,
-0x26B,
-0x262,
-0x259,
-0x251,
-0x248,
-0x240,
-0x238,
-0x230,
-0x228,
-0x220,
-0x218,
-0x210,
-0x209,
-0x201,
-0x1FA,
-0x1F2,
-0x1EB,
-0x1E4,
-0x1DD,
-0x1D6,
-0x1D0,
-0x1C9,
-0x1C2,
-0x1BC,
-0x1B6,
-0x1AF,
-0x1A9,
-0x1A3,
-0x19D,
-0x197,
-0x191,
-0x18C,
-0x186,
-0x180,
-0x17B,
-0x175,
-0x170,
-0x16B,
-0x165,
-0x160,
-0x15B,
-0x156,
-0x151,
-0x14C,
-0x148,
-0x143,
-0x13E,
-0x13A,
-0x135,
-0x131,
-0x12C,
-0x128,
-0x124,
-0x120,
-0x11C,
-0x118,
-0x114,
-0x110,
-0x10C,
-0x108,
-0x104,
-0x100,
-0xFD,
-0xF9,
-0xF5,
-0xF2,
-0xEE
-};
\ No newline at end of file
diff --git a/quantum/audio/luts.c b/quantum/audio/luts.c
new file mode 100644
index 0000000000..9f3de9a05c
--- /dev/null
+++ b/quantum/audio/luts.c
@@ -0,0 +1,382 @@
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <avr/pgmspace.h>
+#include "luts.h"
+
+const float vibrato_lut[VIBRATO_LUT_LENGTH] =
+{
+	1.0022336811487,
+	1.0042529943610,
+	1.0058584256028,
+	1.0068905285205,
+	1.0072464122237,
+	1.0068905285205,
+	1.0058584256028,
+	1.0042529943610,
+	1.0022336811487,
+	1.0000000000000,
+	0.9977712970630,
+	0.9957650169978,
+	0.9941756956510,
+	0.9931566259436,
+	0.9928057204913,
+	0.9931566259436,
+	0.9941756956510,
+	0.9957650169978,
+	0.9977712970630,
+	1.0000000000000,
+};
+
+const uint16_t frequency_lut[FREQUENCY_LUT_LENGTH] =
+{
+	0x8E0B,
+	0x8C02,
+	0x8A00,
+	0x8805,
+	0x8612,
+	0x8426,
+	0x8241,
+	0x8063,
+	0x7E8C,
+	0x7CBB,
+	0x7AF2,
+	0x792E,
+	0x7772,
+	0x75BB,
+	0x740B,
+	0x7261,
+	0x70BD,
+	0x6F20,
+	0x6D88,
+	0x6BF6,
+	0x6A69,
+	0x68E3,
+	0x6762,
+	0x65E6,
+	0x6470,
+	0x6300,
+	0x6194,
+	0x602E,
+	0x5ECD,
+	0x5D71,
+	0x5C1A,
+	0x5AC8,
+	0x597B,
+	0x5833,
+	0x56EF,
+	0x55B0,
+	0x5475,
+	0x533F,
+	0x520E,
+	0x50E1,
+	0x4FB8,
+	0x4E93,
+	0x4D73,
+	0x4C57,
+	0x4B3E,
+	0x4A2A,
+	0x491A,
+	0x480E,
+	0x4705,
+	0x4601,
+	0x4500,
+	0x4402,
+	0x4309,
+	0x4213,
+	0x4120,
+	0x4031,
+	0x3F46,
+	0x3E5D,
+	0x3D79,
+	0x3C97,
+	0x3BB9,
+	0x3ADD,
+	0x3A05,
+	0x3930,
+	0x385E,
+	0x3790,
+	0x36C4,
+	0x35FB,
+	0x3534,
+	0x3471,
+	0x33B1,
+	0x32F3,
+	0x3238,
+	0x3180,
+	0x30CA,
+	0x3017,
+	0x2F66,
+	0x2EB8,
+	0x2E0D,
+	0x2D64,
+	0x2CBD,
+	0x2C19,
+	0x2B77,
+	0x2AD8,
+	0x2A3A,
+	0x299F,
+	0x2907,
+	0x2870,
+	0x27DC,
+	0x2749,
+	0x26B9,
+	0x262B,
+	0x259F,
+	0x2515,
+	0x248D,
+	0x2407,
+	0x2382,
+	0x2300,
+	0x2280,
+	0x2201,
+	0x2184,
+	0x2109,
+	0x2090,
+	0x2018,
+	0x1FA3,
+	0x1F2E,
+	0x1EBC,
+	0x1E4B,
+	0x1DDC,
+	0x1D6E,
+	0x1D02,
+	0x1C98,
+	0x1C2F,
+	0x1BC8,
+	0x1B62,
+	0x1AFD,
+	0x1A9A,
+	0x1A38,
+	0x19D8,
+	0x1979,
+	0x191C,
+	0x18C0,
+	0x1865,
+	0x180B,
+	0x17B3,
+	0x175C,
+	0x1706,
+	0x16B2,
+	0x165E,
+	0x160C,
+	0x15BB,
+	0x156C,
+	0x151D,
+	0x14CF,
+	0x1483,
+	0x1438,
+	0x13EE,
+	0x13A4,
+	0x135C,
+	0x1315,
+	0x12CF,
+	0x128A,
+	0x1246,
+	0x1203,
+	0x11C1,
+	0x1180,
+	0x1140,
+	0x1100,
+	0x10C2,
+	0x1084,
+	0x1048,
+	0x100C,
+	0xFD1,
+	0xF97,
+	0xF5E,
+	0xF25,
+	0xEEE,
+	0xEB7,
+	0xE81,
+	0xE4C,
+	0xE17,
+	0xDE4,
+	0xDB1,
+	0xD7E,
+	0xD4D,
+	0xD1C,
+	0xCEC,
+	0xCBC,
+	0xC8E,
+	0xC60,
+	0xC32,
+	0xC05,
+	0xBD9,
+	0xBAE,
+	0xB83,
+	0xB59,
+	0xB2F,
+	0xB06,
+	0xADD,
+	0xAB6,
+	0xA8E,
+	0xA67,
+	0xA41,
+	0xA1C,
+	0x9F7,
+	0x9D2,
+	0x9AE,
+	0x98A,
+	0x967,
+	0x945,
+	0x923,
+	0x901,
+	0x8E0,
+	0x8C0,
+	0x8A0,
+	0x880,
+	0x861,
+	0x842,
+	0x824,
+	0x806,
+	0x7E8,
+	0x7CB,
+	0x7AF,
+	0x792,
+	0x777,
+	0x75B,
+	0x740,
+	0x726,
+	0x70B,
+	0x6F2,
+	0x6D8,
+	0x6BF,
+	0x6A6,
+	0x68E,
+	0x676,
+	0x65E,
+	0x647,
+	0x630,
+	0x619,
+	0x602,
+	0x5EC,
+	0x5D7,
+	0x5C1,
+	0x5AC,
+	0x597,
+	0x583,
+	0x56E,
+	0x55B,
+	0x547,
+	0x533,
+	0x520,
+	0x50E,
+	0x4FB,
+	0x4E9,
+	0x4D7,
+	0x4C5,
+	0x4B3,
+	0x4A2,
+	0x491,
+	0x480,
+	0x470,
+	0x460,
+	0x450,
+	0x440,
+	0x430,
+	0x421,
+	0x412,
+	0x403,
+	0x3F4,
+	0x3E5,
+	0x3D7,
+	0x3C9,
+	0x3BB,
+	0x3AD,
+	0x3A0,
+	0x393,
+	0x385,
+	0x379,
+	0x36C,
+	0x35F,
+	0x353,
+	0x347,
+	0x33B,
+	0x32F,
+	0x323,
+	0x318,
+	0x30C,
+	0x301,
+	0x2F6,
+	0x2EB,
+	0x2E0,
+	0x2D6,
+	0x2CB,
+	0x2C1,
+	0x2B7,
+	0x2AD,
+	0x2A3,
+	0x299,
+	0x290,
+	0x287,
+	0x27D,
+	0x274,
+	0x26B,
+	0x262,
+	0x259,
+	0x251,
+	0x248,
+	0x240,
+	0x238,
+	0x230,
+	0x228,
+	0x220,
+	0x218,
+	0x210,
+	0x209,
+	0x201,
+	0x1FA,
+	0x1F2,
+	0x1EB,
+	0x1E4,
+	0x1DD,
+	0x1D6,
+	0x1D0,
+	0x1C9,
+	0x1C2,
+	0x1BC,
+	0x1B6,
+	0x1AF,
+	0x1A9,
+	0x1A3,
+	0x19D,
+	0x197,
+	0x191,
+	0x18C,
+	0x186,
+	0x180,
+	0x17B,
+	0x175,
+	0x170,
+	0x16B,
+	0x165,
+	0x160,
+	0x15B,
+	0x156,
+	0x151,
+	0x14C,
+	0x148,
+	0x143,
+	0x13E,
+	0x13A,
+	0x135,
+	0x131,
+	0x12C,
+	0x128,
+	0x124,
+	0x120,
+	0x11C,
+	0x118,
+	0x114,
+	0x110,
+	0x10C,
+	0x108,
+	0x104,
+	0x100,
+	0xFD,
+	0xF9,
+	0xF5,
+	0xF2,
+	0xEE,
+};
+
diff --git a/quantum/audio/luts.h b/quantum/audio/luts.h
new file mode 100644
index 0000000000..7df3078a7f
--- /dev/null
+++ b/quantum/audio/luts.h
@@ -0,0 +1,15 @@
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <avr/pgmspace.h>
+
+#ifndef LUTS_H
+#define LUTS_H
+
+#define VIBRATO_LUT_LENGTH 20
+
+#define FREQUENCY_LUT_LENGTH 349
+
+extern const float vibrato_lut[VIBRATO_LUT_LENGTH];
+extern const uint16_t frequency_lut[FREQUENCY_LUT_LENGTH];
+
+#endif /* LUTS_H */
\ No newline at end of file
diff --git a/quantum/audio/vibrato_lut.h b/quantum/audio/vibrato_lut.h
deleted file mode 100644
index a2b1f3e5ce..0000000000
--- a/quantum/audio/vibrato_lut.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <avr/pgmspace.h>
-
-#define VIBRATO_LUT_LENGTH 20
-
-const float VIBRATO_LUT[VIBRATO_LUT_LENGTH] = { \
-1.00223368114872,
-1.00425299436105,
-1.00585842560279,
-1.00689052852052,
-1.0072464122237,
-1.00689052852052,
-1.00585842560279,
-1.00425299436105,
-1.00223368114872,
-1,
-0.99777129706302,
-0.99576501699778,
-0.994175695650927,
-0.993156625943589,
-0.992805720491269,
-0.993156625943589,
-0.994175695650927,
-0.99576501699778,
-0.99777129706302,
-1
-};
\ No newline at end of file
diff --git a/quantum/audio/voices.c b/quantum/audio/voices.c
index d2316ba1b3..6d4172a06c 100644
--- a/quantum/audio/voices.c
+++ b/quantum/audio/voices.c
@@ -1,6 +1,6 @@
 #include "voices.h"
+#include "audio.h"
 #include "stdlib.h"
-#include "vibrato_lut.h"
 
 // these are imported from audio.c
 extern uint16_t envelope_index;
@@ -109,7 +109,7 @@ float voice_envelope(float frequency) {
                 case 0 ... VOICE_VIBRATO_DELAY:
                     break;
                 default:
-                    frequency = frequency * VIBRATO_LUT[(int)fmod((((float)compensated_index - (VOICE_VIBRATO_DELAY + 1))/1000*VOICE_VIBRATO_SPEED), VIBRATO_LUT_LENGTH)];
+                    frequency = frequency * vibrato_lut[(int)fmod((((float)compensated_index - (VOICE_VIBRATO_DELAY + 1))/1000*VOICE_VIBRATO_SPEED), VIBRATO_LUT_LENGTH)];
                     break;
             }
             break;
@@ -160,4 +160,6 @@ float voice_envelope(float frequency) {
     }
 
     return frequency;
-}
\ No newline at end of file
+}
+
+
diff --git a/quantum/audio/voices.h b/quantum/audio/voices.h
index 74c873f42f..b2495b23b5 100644
--- a/quantum/audio/voices.h
+++ b/quantum/audio/voices.h
@@ -2,8 +2,7 @@
 #include <stdbool.h>
 #include <avr/io.h>
 #include <util/delay.h>
-#include "musical_notes.h"
-#include "song_list.h"
+#include "luts.h"
 
 #ifndef VOICES_H
 #define VOICES_H
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 4b4bd62109..1d9ab2e05c 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -24,10 +24,13 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "action_macro.h"
 #include "debug.h"
 #include "backlight.h"
-#include "keymap_midi.h"
 #include "bootloader.h"
 #include "eeconfig.h"
 
+#ifdef MIDI_ENABLE
+	#include "keymap_midi.h"
+#endif
+
 extern keymap_config_t keymap_config;
 
 #include <stdio.h>
@@ -150,20 +153,22 @@ static action_t keycode_to_action(uint16_t keycode)
         case KC_TRNS:
             action.code = ACTION_TRANSPARENT;
             break;
-        case 0x0100 ... 0x1FFF: ;
+        case LCTL(0) ... 0x1FFF: ;
             // Has a modifier
             // Split it up
             action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key
             break;
-        case 0x2000 ... 0x2FFF:
+        case FUNC(0) ... FUNC(0xFFF): ;
             // Is a shortcut for function layer, pull last 12bits
             // This means we have 4,096 FN macros at our disposal
             return keymap_func_to_action(keycode & 0xFFF);
             break;
-        case 0x3000 ... 0x3FFF: ;
-            // When the code starts with 3, it's an action macro.
+        case M(0) ... M(0xFF):
             action.code = ACTION_MACRO(keycode & 0xFF);
             break;
+        case LT(0, 0) ... LT(0xFF, 0xF):
+            action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
+            break;
     #ifdef BACKLIGHT_ENABLE
         case BL_0 ... BL_15:
             action.code = ACTION_BACKLIGHT_LEVEL(keycode & 0x000F);
@@ -197,7 +202,7 @@ static action_t keycode_to_action(uint16_t keycode)
             print("\nDEBUG: enabled.\n");
             debug_enable = true;
             break;
-        case 0x5002 ... 0x50FF:
+        case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_UNSWAP_ALT_GUI:
             // MAGIC actions (BOOTMAGIC without the boot)
             if (!eeconfig_is_enabled()) {
                 eeconfig_init();
@@ -247,7 +252,7 @@ static action_t keycode_to_action(uint16_t keycode)
             }
             eeconfig_update_keymap(keymap_config.raw);
             break;
-        case 0x5100 ... 0x5FFF: ;
+        case TO(0, 1) ... OSM(0xFF): ;
             // Layer movement shortcuts
             // See .h to see constraints/usage
             int type = (keycode >> 0x8) & 0xF;
@@ -268,25 +273,19 @@ static action_t keycode_to_action(uint16_t keycode)
                 // Set default layer
                 int layer = keycode & 0xFF;
                 action.code = ACTION_LAYER_TOGGLE(layer);
+            } else if (type == 0x5) {
+                // OSL(layer) - One-shot layer
+                int layer = keycode & 0xFF;
+                action.code = ACTION_LAYER_ONESHOT(layer);
+            } else if (type == 0x6) {
+                // OSM(mod) - One-shot mod
+                int mod = keycode & 0xFF;
+                action.code = ACTION_MODS_ONESHOT(mod);
             }
             break;
-    #ifdef MIDI_ENABLE
-        case 0x6000 ... 0x6FFF:
-            action.code =  ACTION_FUNCTION_OPT(keycode & 0xFF, (keycode & 0x0F00) >> 8);
-            break;
-    #endif
-        case 0x7000 ... 0x7FFF:
+        case MT(0, 0) ... MT(0xF, 0xFF):
             action.code = ACTION_MODS_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
             break;
-        case 0x8000 ... 0x8FFF:
-            action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
-            break;
-    #ifdef UNICODE_ENABLE
-        case 0x8000000 ... 0x8FFFFFF:
-            uint16_t unicode = keycode & ~(0x8000);
-            action.code =  ACTION_FUNCTION_OPT(unicode & 0xFF, (unicode & 0xFF00) >> 8);
-            break;
-    #endif
         default:
             action.code = ACTION_NO;
             break;
diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h
index 0ede0296b9..91d5c09c1c 100644
--- a/quantum/keymap_common.h
+++ b/quantum/keymap_common.h
@@ -67,6 +67,9 @@ extern const uint16_t fn_actions[];
 #define MEH(kc) kc  | 0x0700
 #define LCAG(kc) kc  | 0x0D00 // Modifier Ctrl Alt and GUI
 
+#define MOD_HYPR 0xf
+#define MOD_MEH 0x7
+
 #define RCTL(kc) kc | 0x1100
 #define RSFT(kc) kc | 0x1200
 #define RALT(kc) kc | 0x1400
@@ -84,8 +87,11 @@ extern const uint16_t fn_actions[];
 #define KC_EXCLAIM  KC_EXLM
 
 #define KC_AT   LSFT(KC_2)      // @
+
+
 #define KC_HASH LSFT(KC_3)      // #
 
+
 #define KC_DLR  LSFT(KC_4)      // $
 #define KC_DOLLAR   KC_DLR
 
@@ -107,22 +113,43 @@ extern const uint16_t fn_actions[];
 #define KC_RPRN LSFT(KC_0)      // )
 #define KC_RIGHT_PAREN  KC_RPRN
 
+
 #define KC_UNDS LSFT(KC_MINS)   // _
 #define KC_UNDERSCORE   KC_UNDS
 
 #define KC_PLUS LSFT(KC_EQL)    // +
 
+
 #define KC_LCBR LSFT(KC_LBRC)   // {
 #define KC_LEFT_CURLY_BRACE KC_LCBR
 
 #define KC_RCBR LSFT(KC_RBRC)   // }
 #define KC_RIGHT_CURLY_BRACE    KC_RCBR
 
+#define KC_LABK LSFT(KC_COMM)   // <
+#define KC_LEFT_ANGLE_BRACKET   KC_LABK
+
+#define KC_RABK LSFT(KC_DOT)    // >
+#define KC_RIGHT_ANGLE_BRACKET  KC_RABK
+
 #define KC_COLN LSFT(KC_SCLN)   // :
 #define KC_COLON    KC_COLN
 
 #define KC_PIPE LSFT(KC_BSLS)   // |
 
+#define KC_LT LSFT(KC_COMM)     // <
+
+
+#define KC_GT LSFT(KC_DOT)      // >
+
+
+#define KC_QUES LSFT(KC_SLSH)   // ?
+#define KC_QUESTION KC_QUES
+
+
+#define KC_DQT LSFT(KC_QUOT)   // "
+#define KC_DOUBLE_QUOTE KC_DQT
+
 #define KC_DELT KC_DELETE // Del key (four letter code)
 
 // Alias for function layers than expand past FN31
@@ -132,35 +159,14 @@ extern const uint16_t fn_actions[];
 #define S(kc) LSFT(kc)
 #define F(kc) FUNC(kc)
 
-#define M(kc) kc | 0x3000
+#define M(kc) (kc | 0x3000)
 
 #define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE)
 
-// These affect the backlight (if your keyboard has one).
-// We don't need to comment them out if your keyboard doesn't have a backlight,
-// since they don't take up any space.
-#define BL_ON 0x4009
-#define BL_OFF 0x4000
-#define BL_0 0x4000
-#define BL_1 0x4001
-#define BL_2 0x4002
-#define BL_3 0x4003
-#define BL_4 0x4004
-#define BL_5 0x4005
-#define BL_6 0x4006
-#define BL_7 0x4007
-#define BL_8 0x4008
-#define BL_9 0x4009
-#define BL_10 0x400A
-#define BL_11 0x400B
-#define BL_12 0x400C
-#define BL_13 0x400D
-#define BL_14 0x400E
-#define BL_15 0x400F
-#define BL_DEC 0x4010
-#define BL_INC 0x4011
-#define BL_TOGG 0x4012
-#define BL_STEP 0x4013
+// 0x3100+ is free
+
+// L-ayer, T-ap - 256 keycode max, 16 layer max
+#define LT(layer, kc) (kc | 0x4000 | ((layer & 0xF) << 8))
 
 #define RESET 0x5000
 #define DEBUG 0x5001
@@ -188,6 +194,51 @@ extern const uint16_t fn_actions[];
 #define AG_SWAP MAGIC_SWAP_ALT_GUI
 #define AG_NORM MAGIC_UNSWAP_ALT_GUI
 
+#define KC_LEAD 0x5014
+
+// Audio on/off
+#define AU_ON  0x5020
+#define AU_OFF 0x5021
+#define AU_TOG 0x5022
+
+// Music mode on/off
+#define MU_ON  0x5023
+#define MU_OFF 0x5024
+#define MU_TOG 0x5025
+
+// Music voice iterate
+#define MUV_IN 0x5026
+#define MUV_DE 0x5027
+
+// Midi mode on/off
+#define MI_ON  0x5028
+#define MI_OFF 0x5029
+
+// These affect the backlight (if your keyboard has one).
+// We don't need to comment them out if your keyboard doesn't have a backlight,
+// since they don't take up any space.
+#define BL_ON 0x5079
+#define BL_OFF 0x5070
+#define BL_0 0x5070
+#define BL_1 0x5071
+#define BL_2 0x5072
+#define BL_3 0x5073
+#define BL_4 0x5074
+#define BL_5 0x5075
+#define BL_6 0x5076
+#define BL_7 0x5077
+#define BL_8 0x5078
+#define BL_9 0x5079
+#define BL_10 0x507A
+#define BL_11 0x507B
+#define BL_12 0x507C
+#define BL_13 0x507D
+#define BL_14 0x507E
+#define BL_15 0x507F
+#define BL_DEC 0x5080
+#define BL_INC 0x5081
+#define BL_TOGG 0x5082
+#define BL_STEP 0x5083
 
 // GOTO layer - 16 layers max
 // when:
@@ -205,6 +256,14 @@ extern const uint16_t fn_actions[];
 // Toggle to layer - 256 layer max
 #define TG(layer) (layer | 0x5400)
 
+// One-shot layer - 256 layer max
+#define OSL(layer) (layer | 0x5500)
+
+// One-shot mod
+#define OSM(layer) (layer | 0x5600)
+
+// chording is currently at 0x57xx
+
 // M-od, T-ap - 256 keycode max
 #define MT(mod, kc) (kc | 0x7000 | ((mod & 0xF) << 8))
 #define CTL_T(kc) MT(0x1, kc)
@@ -220,14 +279,13 @@ extern const uint16_t fn_actions[];
 #define KC_HYPR HYPR(KC_NO)
 #define KC_MEH  MEH(KC_NO)
 
-// L-ayer, T-ap - 256 keycode max, 16 layer max
-#define LT(layer, kc) (kc | 0x8000 | ((layer & 0xF) << 8))
-
-// For sending unicode codes.
-// You may not send codes over 1FFF -- this supports most of UTF8.
-// To have a key that sends out Œ, go UC(0x0152)
-#define UNICODE(n) (n | 0x8000)
-#define UC(n) UNICODE(n)
+#ifdef UNICODE_ENABLE
+    // For sending unicode codes.
+    // You may not send codes over 7FFF -- this supports most of UTF8.
+    // To have a key that sends out Œ, go UC(0x0152)
+    #define UNICODE(n) (n | 0x8000)
+    #define UC(n) UNICODE(n)
+#endif
 
 // For tri-layer
 void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
diff --git a/quantum/keymap_extras/keymap_german_ch.h b/quantum/keymap_extras/keymap_german_ch.h
new file mode 100644
index 0000000000..0874abf7dd
--- /dev/null
+++ b/quantum/keymap_extras/keymap_german_ch.h
@@ -0,0 +1,102 @@
+#ifndef KEYMAP_SWISS_GERMAN
+#define KEYMAP_SWISS_GERMAN
+
+#include "keymap_common.h"
+
+// Alt gr
+#define ALGR(kc) kc | 0x1400
+#define CH_ALGR KC_RALT
+
+// normal characters
+#define CH_Z KC_Y
+#define CH_Y KC_Z
+
+#define CH_A KC_A
+#define CH_B KC_B
+#define CH_C KC_C
+#define CH_D KC_D
+#define CH_E KC_E
+#define CH_F KC_F
+#define CH_G KC_G
+#define CH_H KC_H
+#define CH_I KC_I
+#define CH_J KC_J
+#define CH_K KC_K
+#define CH_L KC_L
+#define CH_M KC_M
+#define CH_N KC_N
+#define CH_O KC_O
+#define CH_P KC_P
+#define CH_Q KC_Q
+#define CH_R KC_R
+#define CH_S KC_S
+#define CH_T KC_T
+#define CH_U KC_U
+#define CH_V KC_V
+#define CH_W KC_W
+#define CH_X KC_X
+
+#define CH_0 KC_0
+#define CH_1 KC_1
+#define CH_2 KC_2
+#define CH_3 KC_3
+#define CH_4 KC_4
+#define CH_5 KC_5
+#define CH_6 KC_6
+#define CH_7 KC_7
+#define CH_8 KC_8
+#define CH_9 KC_9
+
+#define CH_DOT KC_DOT
+#define CH_COMM KC_COMM
+
+#define CH_QUOT KC_MINS // ' ? ´
+#define CH_AE KC_QUOT
+#define CH_UE KC_LBRC
+#define CH_OE KC_SCLN
+
+#define CH_PARA KC_GRAVE // secction sign § and °
+#define CH_CARR KC_EQL // carret ^ ` ~
+#define CH_DIER KC_RBRC // dieresis ¨ ! ]
+#define CH_DLR KC_BSLS // $ £ }
+#define CH_LESS KC_NUBS // < and > and backslash
+#define CH_MINS KC_SLSH // - and _
+
+// shifted characters
+#define CH_RING LSFT(CH_PARA) // °
+#define CH_PLUS LSFT(KC_1) // +
+#define CH_DQOT LSFT(KC_2) // "
+#define CH_PAST LSFT(KC_3) // *
+#define CH_CELA  LSFT(KC_4) // ç
+#define CH_PERC LSFT(KC_5) // %
+#define CH_AMPR LSFT(KC_6) // &
+#define CH_SLSH LSFT(KC_7) // /
+#define CH_LPRN LSFT(KC_8) // (
+#define CH_RPRN LSFT(KC_9) // )
+#define CH_EQL  LSFT(KC_0) // =
+#define CH_QST  LSFT(CH_QUOT) // ?
+#define CH_GRV  LSFT(CH_CARR) // `
+#define CH_EXLM LSFT(CH_DIER) // !
+#define CH_POND LSFT(CH_DLR) // £
+#define CH_MORE LSFT(CH_LESS) // >
+#define CH_COLN LSFT(KC_DOT) // :
+#define CH_SCLN LSFT(KC_COMM) // ;
+#define CH_UNDS LSFT(CH_MINS) // _
+
+// Alt Gr-ed characters
+#define CH_BRBR ALGR(KC_1) // ¦ brocken bar
+#define CH_AT ALGR(KC_2) // @
+#define CH_HASH ALGR(KC_3) // #
+#define CH_NOTL ALGR(KC_6) // ¬ negative logic
+#define CH_PIPE ALGR(KC_7) // |
+#define CH_CENT ALGR(KC_8) // ¢ cent
+#define CH_ACUT ALGR(CH_QUOT) // ´
+#define CH_TILD ALGR(CH_CARR) // ~
+#define CH_EURO ALGR(KC_E) // €
+#define CH_LBRC ALGR(CH_UE) // [
+#define CH_RBRC ALGR(CH_DIER) // ]
+#define CH_LCBR ALGR(CH_AE) // {
+#define CH_RCBR ALGR(CH_DLR) // }
+#define CH_BSLS ALGR(CH_LESS) // backslash
+
+#endif
diff --git a/quantum/keymap_midi.h b/quantum/keymap_midi.h
index 795f26380e..3a2bf3afff 100644
--- a/quantum/keymap_midi.h
+++ b/quantum/keymap_midi.h
@@ -25,11 +25,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #define CHNL(note, channel) (note + (channel << 8))
 
-#define SCALE (int []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \
-						0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \
-						0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \
-						0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \
-						0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), }
+#define SCALE (int8_t []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \
+                           0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \
+                           0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \
+                           0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \
+                           0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), }
 
 #define N_CN1  (0x600C + (12 * -1) + 0 )
 #define N_CN1S (0x600C + (12 * -1) + 1 )
diff --git a/quantum/keymap_unicode.c b/quantum/keymap_unicode.c
deleted file mode 100644
index a44965e611..0000000000
--- a/quantum/keymap_unicode.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
-Copyright 2015 Jack Humbert <jack.humb@gmail.com>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "keymap_common.h"
-
-uint16_t hextokeycode(int hex) {
-    if (hex == 0x0) {
-        return KC_0;
-    } else if (hex < 0xA) {
-        return KC_1 + (hex - 0x1);
-    } else {
-        return KC_A + (hex - 0xA);
-    }
-}
-
-void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
-{
-
-    // For more info on how this works per OS, see here: https://en.wikipedia.org/wiki/Unicode_input#Hexadecimal_code_input
-
-    if (record->event.pressed) {
-        uint16_t unicode = (opt << 8) | id;
-        register_code(KC_LALT);
-
-        register_code(hextokeycode((unicode & 0xF000) >> 12));
-        unregister_code(hextokeycode((unicode & 0xF000) >> 12));
-        register_code(hextokeycode((unicode & 0x0F00) >> 8));
-        unregister_code(hextokeycode((unicode & 0x0F00) >> 8));
-        register_code(hextokeycode((unicode & 0x00F0) >> 4));
-        unregister_code(hextokeycode((unicode & 0x00F0) >> 4));
-        register_code(hextokeycode((unicode & 0x000F)));
-        unregister_code(hextokeycode((unicode & 0x000F)));
-        
-        /* Test 'a' */
-        // register_code(hextokeycode(0x0));
-        // unregister_code(hextokeycode(0x0));
-        // register_code(hextokeycode(0x0));
-        // unregister_code(hextokeycode(0x0));
-        // register_code(hextokeycode(0x6));
-        // unregister_code(hextokeycode(0x6));
-        // register_code(hextokeycode(0x1));
-        // unregister_code(hextokeycode(0x1));
-
-        unregister_code(KC_LALT);
-    }
-    return;
-}
\ No newline at end of file
diff --git a/quantum/matrix.c b/quantum/matrix.c
index 2dab6ae941..cab39e117a 100644
--- a/quantum/matrix.c
+++ b/quantum/matrix.c
@@ -42,18 +42,25 @@ static matrix_row_t matrix_debouncing[MATRIX_ROWS];
     static matrix_row_t matrix_reversed_debouncing[MATRIX_COLS];
 #endif
 
+
+#if MATRIX_COLS > 16
+    #define SHIFTER 1UL
+#else
+    #define SHIFTER 1
+#endif
+
 static matrix_row_t read_cols(void);
 static void init_cols(void);
 static void unselect_rows(void);
 static void select_row(uint8_t row);
 
 __attribute__ ((weak))
-void matrix_init_kb(void) {
+void matrix_init_quantum(void) {
 
 }
 
 __attribute__ ((weak))
-void matrix_scan_kb(void) {
+void matrix_scan_quantum(void) {
 
 }
 
@@ -86,7 +93,7 @@ void matrix_init(void)
         matrix_debouncing[i] = 0;
     }
 
-    matrix_init_kb();
+    matrix_init_quantum();
 }
 
 
@@ -150,7 +157,7 @@ uint8_t matrix_scan(void)
     }
 #endif
 
-    matrix_scan_kb();
+    matrix_scan_quantum();
 
     return 1;
 }
@@ -235,15 +242,15 @@ static matrix_row_t read_cols(void)
 #endif
 
         if ((col & 0xF0) == 0x20) { 
-            result |= (PINB&(1<<(col & 0x0F)) ? 0 : (1<<x)); 
+            result |= (PINB&(1<<(col & 0x0F)) ? 0 : (SHIFTER<<x)); 
         } else if ((col & 0xF0) == 0x30) { 
-            result |= (PINC&(1<<(col & 0x0F)) ? 0 : (1<<x)); 
+            result |= (PINC&(1<<(col & 0x0F)) ? 0 : (SHIFTER<<x)); 
         } else if ((col & 0xF0) == 0x40) { 
-            result |= (PIND&(1<<(col & 0x0F)) ? 0 : (1<<x)); 
+            result |= (PIND&(1<<(col & 0x0F)) ? 0 : (SHIFTER<<x)); 
         } else if ((col & 0xF0) == 0x50) { 
-            result |= (PINE&(1<<(col & 0x0F)) ? 0 : (1<<x)); 
+            result |= (PINE&(1<<(col & 0x0F)) ? 0 : (SHIFTER<<x)); 
         } else if ((col & 0xF0) == 0x60) { 
-            result |= (PINF&(1<<(col & 0x0F)) ? 0 : (1<<x)); 
+            result |= (PINF&(1<<(col & 0x0F)) ? 0 : (SHIFTER<<x)); 
         } 
     }
     return result;
diff --git a/quantum/quantum.c b/quantum/quantum.c
new file mode 100644
index 0000000000..34c575af42
--- /dev/null
+++ b/quantum/quantum.c
@@ -0,0 +1,463 @@
+#include "quantum.h"
+#include "timer.h"
+
+__attribute__ ((weak))
+void matrix_init_kb(void) {}
+
+__attribute__ ((weak))
+void matrix_scan_kb(void) {}
+
+__attribute__ ((weak))
+bool process_action_kb(keyrecord_t *record) {
+  return true;
+}
+
+__attribute__ ((weak))
+void leader_start(void) {}
+
+__attribute__ ((weak))
+void leader_end(void) {}
+
+uint8_t starting_note = 0x0C;
+int offset = 7;
+
+#ifdef AUDIO_ENABLE
+  bool music_activated = false;
+  float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
+
+  // music sequencer
+  static bool music_sequence_recording = false;
+  static bool music_sequence_playing = false;
+  static float music_sequence[16] = {0};
+  static uint8_t music_sequence_count = 0;
+  static uint8_t music_sequence_position = 0;
+
+  static uint16_t music_sequence_timer = 0;
+  static uint16_t music_sequence_interval = 100;
+
+#endif
+
+#ifdef MIDI_ENABLE
+  bool midi_activated = false;
+#endif
+
+// Leader key stuff
+bool leading = false;
+uint16_t leader_time = 0;
+
+uint16_t leader_sequence[3] = {0, 0, 0};
+uint8_t leader_sequence_size = 0;
+
+// Chording stuff
+#define CHORDING_MAX 4
+bool chording = false;
+
+uint8_t chord_keys[CHORDING_MAX] = {0};
+uint8_t chord_key_count = 0;
+uint8_t chord_key_down = 0;
+
+#ifdef UNICODE_ENABLE
+  static uint8_t input_mode;
+#endif
+
+bool keys_chord(uint8_t keys[]) {
+  uint8_t keys_size = sizeof(keys)/sizeof(keys[0]);
+  bool pass = true;
+  uint8_t in = 0;
+  for (uint8_t i = 0; i < chord_key_count; i++) {
+    bool found = false;
+    for (uint8_t j = 0; j < keys_size; j++) {
+      if (chord_keys[i] == (keys[j] & 0xFF)) {
+        in++; // detects key in chord
+        found = true;
+        break;
+      }
+    }
+    if (found)
+      continue;
+    if (chord_keys[i] != 0)  {
+      pass = false; // makes sure rest are blank
+    }
+  }
+  return (pass && (in == keys_size));
+}
+
+#ifdef UNICODE_ENABLE
+
+uint16_t hex_to_keycode(uint8_t hex)
+{
+  if (hex == 0x0) {
+    return KC_0;
+  } else if (hex < 0xA) {
+    return KC_1 + (hex - 0x1);
+  } else {
+    return KC_A + (hex - 0xA);
+  }
+}
+
+void set_unicode_mode(uint8_t os_target)
+{
+  input_mode = os_target;
+}
+
+#endif
+
+bool process_record_quantum(keyrecord_t *record) {
+
+  /* This gets the keycode from the key pressed */
+  keypos_t key = record->event.key;
+  uint16_t keycode;
+
+  #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
+    uint8_t layer;
+
+    if (record->event.pressed) {
+      layer = layer_switch_get_layer(key);
+      update_source_layers_cache(key, layer);
+    } else {
+      layer = read_source_layers_cache(key);
+    }
+    keycode = keymap_key_to_keycode(layer, key);
+  #else
+    keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key);
+  #endif
+
+    // This is how you use actions here
+    // if (keycode == KC_LEAD) {
+    //   action_t action;
+    //   action.code = ACTION_DEFAULT_LAYER_SET(0);
+    //   process_action(record, action);
+    //   return false;
+    // }
+
+  #ifdef MIDI_ENABLE
+    if (keycode == MI_ON && record->event.pressed) {
+      midi_activated = true;
+      play_music_scale();
+      return false;
+    }
+
+    if (keycode == MI_OFF && record->event.pressed) {
+      midi_activated = false;
+      midi_send_cc(&midi_device, 0, 0x7B, 0);
+      return false;
+    }
+
+    if (midi_activated) {
+      if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) {
+          if (record->event.pressed) {
+              starting_note++; // Change key
+              midi_send_cc(&midi_device, 0, 0x7B, 0);
+              // midi_send_cc(&midi_device, 1, 0x7B, 0);
+              // midi_send_cc(&midi_device, 2, 0x7B, 0);
+              // midi_send_cc(&midi_device, 3, 0x7B, 0);
+              // midi_send_cc(&midi_device, 4, 0x7B, 0);
+          }
+          return false;
+      }
+      if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) {
+          if (record->event.pressed) {
+              starting_note--; // Change key
+              midi_send_cc(&midi_device, 0, 0x7B, 0);
+              // midi_send_cc(&midi_device, 1, 0x7B, 0);
+              // midi_send_cc(&midi_device, 2, 0x7B, 0);
+              // midi_send_cc(&midi_device, 3, 0x7B, 0);
+              // midi_send_cc(&midi_device, 4, 0x7B, 0);
+          }
+          return false;
+      }
+      if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
+          offset++; // Change scale
+          midi_send_cc(&midi_device, 0, 0x7B, 0);
+          // midi_send_cc(&midi_device, 1, 0x7B, 0);
+          // midi_send_cc(&midi_device, 2, 0x7B, 0);
+          // midi_send_cc(&midi_device, 3, 0x7B, 0);
+          // midi_send_cc(&midi_device, 4, 0x7B, 0);
+          return false;
+      }
+      if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
+          offset--; // Change scale
+          midi_send_cc(&midi_device, 0, 0x7B, 0);
+          // midi_send_cc(&midi_device, 1, 0x7B, 0);
+          // midi_send_cc(&midi_device, 2, 0x7B, 0);
+          // midi_send_cc(&midi_device, 3, 0x7B, 0);
+          // midi_send_cc(&midi_device, 4, 0x7B, 0);
+          return false;
+      }
+      // basic
+      // uint8_t note = (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row);
+      // advanced
+      // uint8_t note = (starting_note + record->event.key.col + offset)+12*(MATRIX_ROWS - record->event.key.row);
+      // guitar
+      uint8_t note = (starting_note + record->event.key.col + offset)+5*(MATRIX_ROWS - record->event.key.row);
+      // violin
+      // uint8_t note = (starting_note + record->event.key.col + offset)+7*(MATRIX_ROWS - record->event.key.row);
+
+      if (record->event.pressed) {
+        // midi_send_noteon(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
+        midi_send_noteon(&midi_device, 0, note, 127);
+      } else {
+        // midi_send_noteoff(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
+        midi_send_noteoff(&midi_device, 0, note, 127);
+      }
+
+      if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
+        return false;
+    }
+  #endif
+
+  #ifdef AUDIO_ENABLE
+    if (keycode == AU_ON && record->event.pressed) {
+      audio_on();
+      return false;
+    }
+
+    if (keycode == AU_OFF && record->event.pressed) {
+      audio_off();
+      return false;
+    }
+
+    if (keycode == AU_TOG && record->event.pressed) {
+        if (is_audio_on())
+        {
+            audio_off();
+        }
+        else
+        {
+            audio_on();
+        }
+      return false;
+    }
+
+    if (keycode == MU_ON && record->event.pressed) {
+      music_on();
+      return false;
+    }
+
+    if (keycode == MU_OFF && record->event.pressed) {
+      music_off();
+      return false;
+    }
+
+    if (keycode == MU_TOG && record->event.pressed) {
+        if (music_activated)
+        {
+          music_off();
+        }
+        else
+        {
+          music_on();
+        }
+        return false;
+    }
+
+    if (keycode == MUV_IN && record->event.pressed) {
+      voice_iterate();
+      play_music_scale();
+      return false;
+    }
+
+    if (keycode == MUV_DE && record->event.pressed) {
+      voice_deiterate();
+      play_music_scale();
+      return false;
+    }
+
+    if (music_activated) {
+
+      if (keycode == KC_LCTL && record->event.pressed) { // Start recording
+        stop_all_notes();
+        music_sequence_recording = true;
+        music_sequence_playing = false;
+        music_sequence_count = 0;
+        return false;
+      }
+      if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing
+        stop_all_notes();
+        music_sequence_recording = false;
+        music_sequence_playing = false;
+        return false;
+      }
+      if (keycode == KC_LGUI && record->event.pressed) { // Start playing
+        stop_all_notes();
+        music_sequence_recording = false;
+        music_sequence_playing = true;
+        music_sequence_position = 0;
+        music_sequence_timer = 0;
+        return false;
+      }
+
+      if (keycode == KC_UP) {
+        if (record->event.pressed)
+          music_sequence_interval-=10;
+        return false;
+      }
+      if (keycode == KC_DOWN) {
+        if (record->event.pressed)
+          music_sequence_interval+=10;
+        return false;
+      }
+
+      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));
+      if (record->event.pressed) {
+        play_note(freq, 0xF);
+        if (music_sequence_recording) {
+          music_sequence[music_sequence_count] = freq;
+          music_sequence_count++;
+        }
+      } else {
+        stop_note(freq);
+      }
+
+      if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
+        return false;
+    }
+  #endif
+
+#ifndef DISABLE_LEADER
+  // Leader key set-up
+  if (record->event.pressed) {
+    if (!leading && keycode == KC_LEAD) {
+      leader_start();
+      leading = true;
+      leader_time = timer_read();
+      leader_sequence_size = 0;
+      leader_sequence[0] = 0;
+      leader_sequence[1] = 0;
+      leader_sequence[2] = 0;
+      return false;
+    }
+    if (leading && timer_elapsed(leader_time) < LEADER_TIMEOUT) {
+      leader_sequence[leader_sequence_size] = keycode;
+      leader_sequence_size++;
+      return false;
+    }
+  }
+#endif
+
+#define DISABLE_CHORDING
+#ifndef DISABLE_CHORDING
+
+  if (keycode >= 0x5700 && keycode <= 0x57FF) {
+    if (record->event.pressed) {
+      if (!chording) {
+        chording = true;
+        for (uint8_t i = 0; i < CHORDING_MAX; i++)
+          chord_keys[i] = 0;
+        chord_key_count = 0;
+        chord_key_down = 0;
+      }
+      chord_keys[chord_key_count] = (keycode & 0xFF);
+      chord_key_count++;
+      chord_key_down++;
+      return false;
+    } else {
+      if (chording) {
+        chord_key_down--;
+        if (chord_key_down == 0) {
+          chording = false;
+          // Chord Dictionary
+          if (keys_chord((uint8_t[]){KC_ENTER, KC_SPACE})) {
+            register_code(KC_A);
+            unregister_code(KC_A);
+            return false;
+          }
+          for (uint8_t i = 0; i < chord_key_count; i++) {
+            register_code(chord_keys[i]);
+            unregister_code(chord_keys[i]);
+            return false;
+          }
+        }
+      }
+    }
+  }
+
+#endif
+
+#ifdef UNICODE_ENABLE
+
+  if (keycode > UNICODE(0) && record->event.pressed) {
+    uint16_t unicode = keycode & 0x7FFF;
+    switch(input_mode) {
+      case UC_OSX:
+        register_code(KC_LALT);
+        break;
+      case UC_LNX:
+        register_code(KC_LCTL);
+        register_code(KC_LSFT);
+        register_code(KC_U);
+        unregister_code(KC_U);
+        break;
+      case UC_WIN:
+        register_code(KC_LALT);
+        register_code(KC_PPLS);
+        unregister_code(KC_PPLS);
+        break;
+    }
+    for(int i = 3; i >= 0; i--) {
+        uint8_t digit = ((unicode >> (i*4)) & 0xF);
+        register_code(hex_to_keycode(digit));
+        unregister_code(hex_to_keycode(digit));
+    }
+    switch(input_mode) {
+      case UC_OSX:
+      case UC_WIN:
+        unregister_code(KC_LALT);
+        break;
+      case UC_LNX:
+        unregister_code(KC_LCTL);
+        unregister_code(KC_LSFT);
+        break;
+    }
+  }
+
+#endif
+
+  return process_action_kb(record);
+}
+
+void matrix_init_quantum() {
+  matrix_init_kb();
+}
+
+void matrix_scan_quantum() {
+  #ifdef AUDIO_ENABLE
+  if (music_sequence_playing) {
+    if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
+      music_sequence_timer = timer_read();
+      stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]);
+      play_note(music_sequence[music_sequence_position], 0xF);
+      music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
+    }
+  }
+
+  #endif
+
+  matrix_scan_kb();
+}
+#ifdef AUDIO_ENABLE
+  bool is_music_on(void) {
+      return (music_activated != 0);
+  }
+
+  void music_toggle(void) {
+      if (!music_activated) {
+          music_on();
+      } else {
+          music_off();
+      }
+  }
+
+  void music_on(void) {
+      music_activated = 1;
+      music_on_user();
+  }
+
+  void music_off(void) {
+      music_activated = 0;
+      stop_all_notes();
+  }
+
+#endif
+__attribute__ ((weak))
+void music_on_user() {}
diff --git a/quantum/quantum.h b/quantum/quantum.h
new file mode 100644
index 0000000000..d4da772890
--- /dev/null
+++ b/quantum/quantum.h
@@ -0,0 +1,72 @@
+#ifndef QUANTUM_H
+#define QUANTUM_H
+
+#include "matrix.h"
+#include "keymap_common.h"
+#ifdef BACKLIGHT_ENABLE
+    #include "backlight.h"
+#endif
+#ifdef RGBLIGHT_ENABLE
+  #include "rgblight.h"
+#endif
+#ifdef AUDIO_ENABLE
+  #include "audio.h"
+#endif
+#ifdef MIDI_ENABLE
+	#include <lufa.h>
+#endif
+#ifdef UNICODE_ENABLE
+	#include "unicode.h"
+#endif
+
+#include "action_layer.h"
+#include "eeconfig.h"
+#include <stddef.h>
+#include <avr/io.h>
+
+extern uint32_t default_layer_state;
+
+#ifndef NO_ACTION_LAYER
+	extern uint32_t layer_state;
+#endif
+
+#ifdef AUDIO_ENABLE
+	bool music_activated;
+#endif
+
+#ifdef UNICODE_ENABLE
+	#define UC_OSX 0
+	#define UC_LNX 1
+	#define UC_WIN 2
+	#define UC_BSD 3
+
+	void set_unicode_input_mode(uint8_t os_target);
+#endif
+
+#ifndef DISABLE_LEADER
+	void leader_start(void);
+	void leader_end(void);
+
+	#ifndef LEADER_TIMEOUT
+		#define LEADER_TIMEOUT 200
+	#endif
+	#define SEQ_ONE_KEY(key) if (leader_sequence[0] == (key) && leader_sequence[1] == 0 && leader_sequence[2] == 0)
+	#define SEQ_TWO_KEYS(key1, key2) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == 0)
+	#define SEQ_THREE_KEYS(key1, key2, key3) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3))
+
+	#define LEADER_EXTERNS() extern bool leading; extern uint16_t leader_time; extern uint16_t leader_sequence[3]; extern uint8_t leader_sequence_size
+	#define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT)
+#endif
+
+void matrix_init_kb(void);
+void matrix_scan_kb(void);
+bool process_action_kb(keyrecord_t *record);
+
+bool is_music_on(void);
+void music_toggle(void);
+void music_on(void);
+void music_off(void);
+
+void music_on_user(void);
+
+#endif
\ No newline at end of file
diff --git a/quantum/quantum.mk b/quantum/quantum.mk
index 83c4f1d1db..c099d67939 100644
--- a/quantum/quantum.mk
+++ b/quantum/quantum.mk
@@ -1,7 +1,8 @@
 QUANTUM_DIR = quantum
 
 # # project specific files
-SRC += $(QUANTUM_DIR)/keymap_common.c \
+SRC += $(QUANTUM_DIR)/quantum.c \
+	$(QUANTUM_DIR)/keymap_common.c \
 	$(QUANTUM_DIR)/led.c
 
 # ifdef KEYMAP_FILE
@@ -23,16 +24,14 @@ ifndef CUSTOM_MATRIX
 	SRC += $(QUANTUM_DIR)/matrix.c
 endif
 
-ifeq ($(strip $(MIDI_ENABLE)), yes)
-	SRC += $(QUANTUM_DIR)/keymap_midi.c
-endif
+#ifeq ($(strip $(MIDI_ENABLE)), yes)
+#	SRC += $(QUANTUM_DIR)/keymap_midi.c
+#endif
 
 ifeq ($(strip $(AUDIO_ENABLE)), yes)
-	SRC += $(QUANTUM_DIR)/audio/audio.c $(QUANTUM_DIR)/audio/voices.c
-endif
-
-ifeq ($(strip $(UNICODE_ENABLE)), yes)
-	SRC += $(QUANTUM_DIR)/keymap_unicode.c
+    SRC += $(QUANTUM_DIR)/audio/audio.c
+    SRC += $(QUANTUM_DIR)/audio/voices.c
+    SRC += $(QUANTUM_DIR)/audio/luts.c
 endif
 
 ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
diff --git a/quantum/template/template.c b/quantum/template/template.c
index 6050a2d20c..649072eb2e 100644
--- a/quantum/template/template.c
+++ b/quantum/template/template.c
@@ -11,8 +11,9 @@ void matrix_scan_user(void) {
 }
 
 __attribute__ ((weak))
-void process_action_user(keyrecord_t *record) {
+bool process_action_user(keyrecord_t *record) {
 	// leave this function blank - it can be defined in a keymap file
+    return true;
 }
 
 __attribute__ ((weak))
@@ -34,11 +35,11 @@ void matrix_scan_kb(void) {
 	matrix_scan_user();
 }
 
-void process_action_kb(keyrecord_t *record) {
+bool process_action_kb(keyrecord_t *record) {
 	// put your per-action keyboard code here
 	// runs for every action, just before processing by the firmware
 
-	process_action_user(record);
+	return process_action_user(record);
 }
 
 void led_set_kb(uint8_t usb_led) {
diff --git a/quantum/template/template.h b/quantum/template/template.h
index 22742105a3..8537e3b4be 100644
--- a/quantum/template/template.h
+++ b/quantum/template/template.h
@@ -24,7 +24,7 @@
 
 void matrix_init_user(void);
 void matrix_scan_user(void);
-void process_action_user(keyrecord_t *record);
+bool process_action_user(keyrecord_t *record);
 void led_set_user(uint8_t usb_led);
 
 #endif
diff --git a/quantum/tools/README.md b/quantum/tools/README.md
index 0702144238..5f355256de 100644
--- a/quantum/tools/README.md
+++ b/quantum/tools/README.md
@@ -1,6 +1,6 @@
 `eeprom_reset.hex` is to reset the eeprom on the Atmega32u4, like this:
 
     dfu-programmer atmega32u4 erase
-    dfu-programmer atmega32u4 flash --eeprom eeprom-reset.bin
+    dfu-programmer atmega32u4 flash --eeprom eeprom_reset.hex
 
- You'll need to reflash afterwards, because DFU requires the flash to be erased before messing with the eeprom.
\ No newline at end of file
+ You'll need to reflash afterwards, because DFU requires the flash to be erased before messing with the eeprom.
diff --git a/quantum/unicode.h b/quantum/unicode.h
new file mode 100644
index 0000000000..756ec8bc3f
--- /dev/null
+++ b/quantum/unicode.h
@@ -0,0 +1,128 @@
+/*
+Copyright 2016 Jack Humbert <jack.humb@gmail.com>
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef UNICODE_H
+#define UNICODE_H
+
+#include "quantum.h"
+#include <math.h>
+
+#define UC_BSPC	UC(0x0008)
+
+#define UC_SPC	UC(0x0020)
+
+#define UC_EXLM	UC(0x0021)
+#define UC_DQUT	UC(0x0022)
+#define UC_HASH	UC(0x0023)
+#define UC_DLR	UC(0x0024)
+#define UC_PERC	UC(0x0025)
+#define UC_AMPR	UC(0x0026)
+#define UC_QUOT	UC(0x0027)
+#define UC_LPRN	UC(0x0028)
+#define UC_RPRN	UC(0x0029)
+#define UC_ASTR	UC(0x002A)
+#define UC_PLUS	UC(0x002B)
+#define UC_COMM	UC(0x002C)
+#define UC_DASH	UC(0x002D)
+#define UC_DOT	UC(0x002E)
+#define UC_SLSH	UC(0x002F)
+
+#define UC_0	UC(0x0030)
+#define UC_1	UC(0x0031)
+#define UC_2	UC(0x0032)
+#define UC_3	UC(0x0033)
+#define UC_4	UC(0x0034)
+#define UC_5	UC(0x0035)
+#define UC_6	UC(0x0036)
+#define UC_7	UC(0x0037)
+#define UC_8	UC(0x0038)
+#define UC_9	UC(0x0039)
+
+#define UC_COLN UC(0x003A)
+#define UC_SCLN UC(0x003B)
+#define UC_LT	UC(0x003C)
+#define UC_EQL	UC(0x003D)
+#define UC_GT	UC(0x003E)
+#define UC_QUES	UC(0x003F)
+#define UC_AT 	UC(0x0040)
+
+#define UC_A 	UC(0x0041)
+#define UC_B 	UC(0x0042)
+#define UC_C 	UC(0x0043)
+#define UC_D 	UC(0x0044)
+#define UC_E 	UC(0x0045)
+#define UC_F 	UC(0x0046)
+#define UC_G 	UC(0x0047)
+#define UC_H 	UC(0x0048)
+#define UC_I 	UC(0x0049)
+#define UC_J 	UC(0x004A)
+#define UC_K 	UC(0x004B)
+#define UC_L 	UC(0x004C)
+#define UC_M 	UC(0x004D)
+#define UC_N 	UC(0x004E)
+#define UC_O 	UC(0x004F)
+#define UC_P 	UC(0x0050)
+#define UC_Q 	UC(0x0051)
+#define UC_R 	UC(0x0052)
+#define UC_S 	UC(0x0053)
+#define UC_T 	UC(0x0054)
+#define UC_U 	UC(0x0055)
+#define UC_V 	UC(0x0056)
+#define UC_W 	UC(0x0057)
+#define UC_X 	UC(0x0058)
+#define UC_Y 	UC(0x0059)
+#define UC_Z 	UC(0x005A)
+
+#define UC_LBRC	UC(0x005B)
+#define UC_BSLS	UC(0x005C)
+#define UC_RBRC	UC(0x005D)
+#define UC_CIRM	UC(0x005E)
+#define UC_UNDR	UC(0x005F)
+
+#define UC_GRV 	UC(0x0060)
+
+#define UC_a 	UC(0x0061)
+#define UC_b 	UC(0x0062)
+#define UC_c 	UC(0x0063)
+#define UC_d 	UC(0x0064)
+#define UC_e 	UC(0x0065)
+#define UC_f 	UC(0x0066)
+#define UC_g 	UC(0x0067)
+#define UC_h 	UC(0x0068)
+#define UC_i 	UC(0x0069)
+#define UC_j 	UC(0x006A)
+#define UC_k 	UC(0x006B)
+#define UC_l 	UC(0x006C)
+#define UC_m 	UC(0x006D)
+#define UC_n 	UC(0x006E)
+#define UC_o 	UC(0x006F)
+#define UC_p 	UC(0x0070)
+#define UC_q 	UC(0x0071)
+#define UC_r 	UC(0x0072)
+#define UC_s 	UC(0x0073)
+#define UC_t 	UC(0x0074)
+#define UC_u 	UC(0x0075)
+#define UC_v 	UC(0x0076)
+#define UC_w 	UC(0x0077)
+#define UC_x 	UC(0x0078)
+#define UC_y 	UC(0x0079)
+#define UC_z 	UC(0x007A)
+
+#define UC_LCBR	UC(0x007B)
+#define UC_PIPE	UC(0x007C)
+#define UC_RCBR	UC(0x007D)
+#define UC_TILD	UC(0x007E)
+#define UC_DEL	UC(0x007F)
+
+#endif
\ No newline at end of file