]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Added trimble and tempo adjustments!
authorIBNobody <ibnobody@gmail.com>
Sun, 17 Apr 2016 07:52:38 +0000 (02:52 -0500)
committerIBNobody <ibnobody@gmail.com>
Sun, 17 Apr 2016 07:52:38 +0000 (02:52 -0500)
keyboard/atomic/keymaps/pvc/keymap.c
keyboard/atomic/keymaps/pvc/makefile.mk
quantum/audio.c
quantum/audio.h
quantum/musical_notes.h
quantum/song_list.h

index 9a2c57cb18c9151a682a0fed02667cda96dc5ec6..aaef6b041d1f6237363e751f1335888a2fb4c18c 100644 (file)
 #define M_LW 1
 #define M_RS 2
 #define M_FN 3
+#define M_T1 4
+#define M_T2 5
+#define M_T3 6
+#define M_T4 7
+#define M_TU 8
+#define M_TD 9
+#define M_DF 10
 
 
 #define _______ KC_TRNS
@@ -63,7 +70,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
   { KC_NLCK, KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,  ___T___, ___T___  },
   { KC_SLCK, KC_F13,  KC_F14,  KC_F15,  KC_F16,  KC_F17,  KC_F18,  KC_F19,  KC_F20,  KC_F21,  KC_F22,  KC_F23,  KC_F24,  KC_PAUS, KC_PSCR  },
   { KC_CAPS, KC_BTN5, KC_BTN4, KC_BTN3, KC_BTN2, KC_ACL0, KC_ACL2, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY, _______, ___T___, ___T___, KC_WH_U  },
-  { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, ___T___, ___T___, KC_MS_U, KC_WH_D  },
+  { _______, M(M_T1), M(M_T2), M(M_T3), M(M_T4), M(M_TU), M(M_TD), M(M_DF), _______, _______, _______, ___T___, ___T___, KC_MS_U, KC_WH_D  },
   { _______, _______, _______, _______, _______, KC_BTN1, KC_BTN1, _______, _______, _______, _______, _______, KC_MS_L, KC_MS_D, KC_MS_R  },
  },
  [_AD] = { /* ADJUST */
@@ -75,76 +82,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  },
 };
 
-void update_quad_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3, uint8_t layer4, bool order)
-{
-       if (order)
-       {
-               if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2))
-               {
-                       layer_on(layer3);
-               }
-               else
-               {
-                   layer_off(layer3);
-                   layer_off(layer4);
-               }
-       }
-       else
-       {
-               if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2))
-               {
-                       layer_on(layer4);
-               }
-               else
-               {
-                       layer_off(layer3);
-                   layer_off(layer4);
-               }
-       }
-}
-
-
-const uint16_t PROGMEM fn_actions[] = {
-};
-
-
-const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
-{
-
-  // MACRODOWN only works in this function
-      switch(id) {
-        case M_LW:
-          if (record->event.pressed) {
-            #ifdef AUDIO_ENABLE
-              println("PlayNotes LW");
-              PLAY_NOTE_ARRAY(tone_lw, false, STACCATO);
-            #endif
-            layer_on(_LW);
-            update_tri_layer(_LW, _RS, _FN);
-          } else {
-            layer_off(_LW);
-            update_tri_layer(_LW, _RS, _FN);
-          }
-          break;
-        case M_RS:
-          if (record->event.pressed) {
-            #ifdef AUDIO_ENABLE
-              println("PlayNotes RS");
-              PLAY_NOTE_ARRAY(tone_rs, false, LEGATO);
-            #endif
-            layer_on(_RS);
-            update_tri_layer(_LW, _RS, _FN);
-          } else {
-            layer_off(_RS);
-            update_tri_layer(_LW, _RS, _FN);
-          }
-          break;
-               default:
-               break;
-      }
-    return MACRO_NONE;
-};
-
 
 
 #ifdef AUDIO_ENABLE
@@ -152,20 +89,6 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
 float start_up[][2] = SONG(ODE_TO_JOY);
 
 float tone_lw[][2] = {
-       /*
-       Q__NOTE(_C1   ) ,
-       Q__NOTE(_CS1  ) ,
-       Q__NOTE(_D1   ) ,
-       Q__NOTE(_DS1  ) ,
-       Q__NOTE(_E1   ) ,
-       Q__NOTE(_F1   ) ,
-       Q__NOTE(_FS1  ) ,
-       Q__NOTE(_G1   ) ,
-       Q__NOTE(_GS1  ) ,
-       Q__NOTE(_A1   ) ,
-       Q__NOTE(_AS1  ) ,
-       Q__NOTE(_B1   ) ,
-       */
 
        Q__NOTE(_C4   ) ,
        Q__NOTE(_CS4  ) ,
@@ -178,6 +101,7 @@ float tone_lw[][2] = {
        Q__NOTE(_GS4  ) ,
        Q__NOTE(_A4   ) ,
        Q__NOTE(_AS4  ) ,
+
        Q__NOTE(_B1   ) ,
 
        Q__NOTE(_C2   ) ,
@@ -266,14 +190,7 @@ float tone_lw[][2] = {
        Q__NOTE(_B8   ) ,
 };
 
-float tone_rs[][2] = {
-       Q__NOTE(_A4   ) ,
-       Q__NOTE(_A4   ) ,
-       Q__NOTE(_A4   ) ,
-       Q__NOTE(_A4   ) ,
-       Q__NOTE(_AS8  ) ,
-       Q__NOTE(_B8   ) ,
-};
+float tone_rs[][2] = SONG(ROCK_A_BYE_BABY);
 
 void matrix_init_user(void) {
        init_notes();
@@ -282,3 +199,116 @@ void matrix_init_user(void) {
 }
 
 #endif
+
+
+void update_quad_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3, uint8_t layer4, bool order)
+{
+       if (order)
+       {
+               if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2))
+               {
+                       layer_on(layer3);
+               }
+               else
+               {
+                   layer_off(layer3);
+                   layer_off(layer4);
+               }
+       }
+       else
+       {
+               if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2))
+               {
+                       layer_on(layer4);
+               }
+               else
+               {
+                       layer_off(layer3);
+                   layer_off(layer4);
+               }
+       }
+}
+
+
+const uint16_t PROGMEM fn_actions[] = {
+};
+
+
+const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
+{
+
+       // MACRODOWN only works in this function
+       switch(id)
+       {
+               case M_LW:
+                       if (record->event.pressed) {
+                               #ifdef AUDIO_ENABLE
+                               PLAY_NOTE_ARRAY(tone_lw, false, STACCATO);
+                               #endif
+                               layer_on(_LW);
+                               update_tri_layer(_LW, _RS, _AD);
+                       } else {
+                               layer_off(_LW);
+                               update_tri_layer(_LW, _RS, _AD);
+                       }
+                       break;
+               case M_RS:
+                       if (record->event.pressed) {
+                               #ifdef AUDIO_ENABLE
+                               PLAY_NOTE_ARRAY(tone_rs, false, LEGATO);
+                               #endif
+                               layer_on(_RS);
+                               update_tri_layer(_LW, _RS, _AD);
+                       } else {
+                               layer_off(_RS);
+                               update_tri_layer(_LW, _RS, _AD);
+                       }
+                       break;
+
+               case M_FN:
+                       if (record->event.pressed) {
+                               layer_on(_FN);
+                       } else {
+                               layer_off(_FN);
+                       }
+                       break;
+
+               case M_T1:
+                       if (record->event.pressed) set_timbre(TIMBRE_12);
+                       break;
+
+               case M_T2:
+                       if (record->event.pressed) set_timbre(TIMBRE_25);
+                       break;
+
+               case M_T3:
+                       if (record->event.pressed) set_timbre(TIMBRE_50);
+                       break;
+
+               case M_T4:
+                       if (record->event.pressed) set_timbre(TIMBRE_75);
+                       break;
+
+
+               case M_TU:
+                       if (record->event.pressed) increase_tempo(10);
+                       break;
+
+               case M_TD:
+                       if (record->event.pressed) decrease_tempo(10);
+                       break;
+
+               case M_DF:
+                       if (record->event.pressed)
+                       {
+                               set_timbre(TIMBRE_DEFAULT);
+                               set_tempo(TEMPO_DEFAULT);
+                       }
+                       break;
+
+               default:
+                       break;
+
+       }
+       return MACRO_NONE;
+};
\ No newline at end of file
index d4699665010116326ce5bcb08f2c21751bfe6b8c..eefa42855fd7d504495b1b9dc1200b353c848b8b 100644 (file)
@@ -1,7 +1,7 @@
 BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
 MOUSEKEY_ENABLE  = yes # Mouse keys(+4700)
 EXTRAKEY_ENABLE  = yes # Audio control and System control(+450)
-CONSOLE_ENABLE   = yes # Console for debug(+400)
+CONSOLE_ENABLE   = no  # Console for debug(+400)
 COMMAND_ENABLE   = yes # Commands for debug and configuration
 NKRO_ENABLE      = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
 BACKLIGHT_ENABLE = no  # Enable keyboard backlight functionality
index 119bd922985b69a16a603603869d0fe186bee9d5..9b9589f1337e235689080f33a8c2c8080e618384 100644 (file)
@@ -4,7 +4,7 @@
 #include <avr/pgmspace.h>
 #include <avr/interrupt.h>
 #include <avr/io.h>
-
+#include "print.h"
 #include "audio.h"
 #include "keymap_common.h"
 
@@ -57,9 +57,11 @@ bool notes = false;
 bool note = false;
 float note_frequency = 0;
 float note_length = 0;
+float note_tempo = TEMPO_DEFAULT;
+float note_timbre = TIMBRE_DEFAULT;
 uint16_t note_position = 0;
 float (* notes_pointer)[][2];
-uint8_t notes_length;
+uint8_t notes_count;
 bool notes_repeat;
 float notes_rest;
 bool note_resting = false;
@@ -255,7 +257,8 @@ ISR(TIMER3_COMPA_vect) {
                     place = 0.0;
                 }
                 ICR3 = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)); // Set max to the period
-                OCR3A = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) >> 1 * duty_place; // Set compare to half the period
+                OCR3A = (int)((((double)F_CPU) / (note_frequency * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
+                //OCR3A = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) >> 1 * duty_place; // Set compare to half the period
                 place++;
                 // if (duty_counter > (frequencies[voice_place] / 500)) {
                 //     duty_place = (duty_place % 3) + 1;
@@ -288,8 +291,7 @@ ISR(TIMER3_COMPA_vect) {
         #else
             if (note_frequency > 0) {
                 ICR3 = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)); // Set max to the period
-                //OCR3A = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)) >> 1; // Set compare to half the period
-                OCR3A = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)) >> 2; // Set compare to half the period
+                OCR3A = (int)((((double)F_CPU) / (note_frequency * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
             } else {
                 ICR3 = 0;
                 OCR3A = 0;
@@ -305,7 +307,7 @@ ISR(TIMER3_COMPA_vect) {
             end_of_note = (note_position >= (note_length * 0x7FF));
         if (end_of_note) {
             current_note++;
-            if (current_note >= notes_length) {
+            if (current_note >= notes_count) {
                 if (notes_repeat) {
                     current_note = 0;
                 } else {
@@ -328,10 +330,10 @@ ISR(TIMER3_COMPA_vect) {
                 note_resting = false;
                 #ifdef PWM_AUDIO
                     note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
-                    note_length = (*notes_pointer)[current_note][1];
+                    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_length = ((*notes_pointer)[current_note][1] / 4) * (note_tempo / 100);
                 #endif
             }
             note_position = 0;
@@ -345,7 +347,7 @@ ISR(TIMER3_COMPA_vect) {
     }
 }
 
-void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat, float n_rest) {
+void play_notes(float (*np)[][2], uint8_t n_count, bool n_repeat, float n_rest) {
 
 if (audio_config.enable) {
 
@@ -354,7 +356,7 @@ if (audio_config.enable) {
     notes = true;
 
     notes_pointer = np;
-    notes_length = n_length;
+    notes_count = n_count;
     notes_repeat = n_repeat;
     notes_rest = n_rest;
 
@@ -362,10 +364,10 @@ if (audio_config.enable) {
     current_note = 0;
     #ifdef PWM_AUDIO
         note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
-        note_length = (*notes_pointer)[current_note][1];
+        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_length = ((*notes_pointer)[current_note][1] / 4) * (note_tempo / 100);
     #endif
     note_position = 0;
 
@@ -439,4 +441,32 @@ if (audio_config.enable && voices < 8) {
 
 }
 
-}
\ No newline at end of file
+}
+
+void set_timbre(float timbre)
+{
+       note_timbre = timbre;
+}
+
+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;
+               }
+}
+
index 762c980643c2b5d28c0d6c3a246298dd6e2ab42e..8012aa6bf19694f76bea225ade645257da0fe0e2 100644 (file)
@@ -24,8 +24,12 @@ void play_note(double freq, int vol);
 void stop_note(double freq);
 void stop_all_notes(void);
 void init_notes(void);
-void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat, float n_rest);
+void play_notes(float (*np)[][2], uint8_t n_count, bool n_repeat, float n_rest);
 
+void set_timbre(float timbre);
+void set_tempo(float tempo);
+void increase_tempo(uint8_t tempo_change);
+void decrease_tempo(uint8_t tempo_change);
 
 // 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.
index d2256a7736231b3487d7a1ac90ab0226771b0e61..2170f3f18bd97292eeb24c157079bd5ac8fcb96d 100644 (file)
@@ -2,7 +2,8 @@
 #define MUSICAL_NOTES_H
 
 // Tempo Placeholder
-#define TEMPO 120
+#define TEMPO_DEFAULT 100
+
 
 #define SONG(notes...) { notes }
 
@@ -21,7 +22,6 @@
 #define EIGHTH_DOT_NOTE(note)          MUSICAL_NOTE(note,  8+4)
 #define SIXTEENTH_DOT_NOTE(note)       MUSICAL_NOTE(note,  4+2)
 
-
 // Note Type Shortcuts
 #define M__NOTE(note, duration)        MUSICAL_NOTE(note, duration)
 #define W__NOTE(n)                     WHOLE_NOTE(n)
 #define STACCATO 0.01
 #define LEGATO   0
 
+// Note Timbre
+// Changes how the notes sound
+#define TIMBRE_12       0.125
+#define TIMBRE_25       0.250
+#define TIMBRE_50       0.500
+#define TIMBRE_75       0.750
+#define TIMBRE_DEFAULT  TIMBRE_50
+
+
 // Notes - # = Octave
 #define NOTE_REST         0.00
 #define NOTE_C0          16.35
index ef25eac35a4b08f1059eaddd96d40f7f8eac5fe6..ef36a1cddf38a05aed0dfe5fa2ba41402a5b9c12 100644 (file)
@@ -9,4 +9,10 @@
        Q__NOTE(_C4), Q__NOTE(_C4), Q__NOTE(_D4), Q__NOTE(_E4), \
        QD_NOTE(_E4), E__NOTE(_D4), H__NOTE(_D4),
 
+#define ROCK_A_BYE_BABY                            \
+       QD_NOTE(_B4), E__NOTE(_D4), Q__NOTE(_B5),      \
+       H__NOTE(_A5), Q__NOTE(_G5),                    \
+       QD_NOTE(_B4), E__NOTE(_D5), Q__NOTE(_G5),      \
+       H__NOTE(_FS5),
+
 #endif
\ No newline at end of file