]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
adds music mode, music mode songs, music mask
authorJack Humbert <jack.humb@gmail.com>
Sat, 22 Jul 2017 04:14:26 +0000 (00:14 -0400)
committerJack Humbert <jack.humb@gmail.com>
Sun, 23 Jul 2017 18:59:29 +0000 (14:59 -0400)
keyboards/planck/keymaps/default/config.h
keyboards/planck/keymaps/default/keymap.c
keyboards/preonic/keymaps/default/config.h
keyboards/preonic/keymaps/default/keymap.c
quantum/audio/audio.h
quantum/audio/song_list.h
quantum/process_keycode/process_audio.c
quantum/process_keycode/process_music.c
quantum/process_keycode/process_music.h
quantum/quantum_keycodes.h

index 1ce547b9493964e5f65efb69d7166f8c6e1f63b5..b406e2fed97b366af03d53def9ffd549aa64d318 100644 (file)
@@ -3,6 +3,18 @@
 
 #include "../../config.h"
 
+#ifdef AUDIO_ENABLE
+    #define STARTUP_SONG SONG(PLANCK_SOUND)
+    // #define STARTUP_SONG SONG(NO_SOUND)
+
+    #define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
+                                  SONG(COLEMAK_SOUND), \
+                                  SONG(DVORAK_SOUND) \
+                                }
+#endif
+
+#define MUSIC_MASK (keycode != KC_NO)
+
 /*
  * MIDI options
  */
 /* enable basic MIDI features:
    - MIDI notes can be sent when in Music mode is on
 */
+                                
 #define MIDI_BASIC
 
-#ifdef AUDIO_ENABLE
-    #define STARTUP_SONG SONG(PLANCK_SOUND)
-    // #define STARTUP_SONG SONG(NO_SOUND)
-
-    #define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
-                                  SONG(COLEMAK_SOUND), \
-                                  SONG(DVORAK_SOUND) \
-                                }
-#endif
-
 /* enable advanced MIDI features:
    - MIDI notes can be added to the keymap
    - Octave shift and transpose
index 34a011b0c983d58e3688dfa7ec856b022106425a..f71a2b59b9cf49eccdb0bad99c4c2a11eac43193 100644 (file)
@@ -164,7 +164,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  */
 [_ADJUST] = {
   {_______, RESET,   _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL },
-  {_______, _______, _______, AU_ON,   AU_OFF,  AG_NORM, AG_SWAP, QWERTY,  COLEMAK, DVORAK,  PLOVER,  _______},
+  {_______, _______, MU_MOD,  AU_ON,   AU_OFF,  AG_NORM, AG_SWAP, QWERTY,  COLEMAK, DVORAK,  PLOVER,  _______},
   {_______, MUV_DE,  MUV_IN,  MU_ON,   MU_OFF,  MI_ON,   MI_OFF,  _______, _______, _______, _______, _______},
   {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
 }
index 1ce547b9493964e5f65efb69d7166f8c6e1f63b5..003fd259c5907acc0dcebc10782852d7efa632d3 100644 (file)
@@ -3,6 +3,18 @@
 
 #include "../../config.h"
 
+#ifdef AUDIO_ENABLE
+    #define STARTUP_SONG SONG(PLANCK_SOUND)
+    // #define STARTUP_SONG SONG(NO_SOUND)
+
+    #define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
+                                  SONG(COLEMAK_SOUND), \
+                                  SONG(DVORAK_SOUND) \
+                                }
+#endif
+
+#define MUSIC_MASK (keycode != KC_NO)
+
 /*
  * MIDI options
  */
 /* enable basic MIDI features:
    - MIDI notes can be sent when in Music mode is on
 */
-#define MIDI_BASIC
-
-#ifdef AUDIO_ENABLE
-    #define STARTUP_SONG SONG(PLANCK_SOUND)
-    // #define STARTUP_SONG SONG(NO_SOUND)
 
-    #define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
-                                  SONG(COLEMAK_SOUND), \
-                                  SONG(DVORAK_SOUND) \
-                                }
-#endif
+#define MIDI_BASIC
 
 /* enable advanced MIDI features:
    - MIDI notes can be added to the keymap
index 491f4ae850a4c7b4bbd718d9bfb67037c70e7714..01f40542ca9a9a10c8c327bc680e356d5dd2ec4c 100644 (file)
@@ -158,7 +158,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
 [_ADJUST] = {
   {KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12},
   {_______, RESET,   _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL},
-  {_______, _______, _______, AU_ON,   AU_OFF,  AG_NORM, AG_SWAP, QWERTY,  COLEMAK, DVORAK,  _______, _______},
+  {_______, _______, MU_MOD,  AU_ON,   AU_OFF,  AG_NORM, AG_SWAP, QWERTY,  COLEMAK, DVORAK,  _______, _______},
   {_______, MUV_DE,  MUV_IN,  MU_ON,   MU_OFF,  MI_ON,   MI_OFF,  _______, _______, _______, _______, _______},
   {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
 }
index e29770e3b8467597602b6754331731472a46a592..79e0da2295fa12ddd9348e0a11e6e18599f1c6cc 100644 (file)
@@ -100,8 +100,8 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat);
 #define NOTE_ARRAY_SIZE(x) ((int16_t)(sizeof(x) / (sizeof(x[0]))))
 #define PLAY_NOTE_ARRAY(note_array, note_repeat, deprecated_arg) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), (note_repeat)); \
        _Pragma ("message \"'PLAY_NOTE_ARRAY' macro is deprecated\"")
-#define PLAY_SONG(note_array) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), false);
-#define PLAY_LOOP(note_array) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), true);
+#define PLAY_SONG(note_array) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), false)
+#define PLAY_LOOP(note_array) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), true)
 
 bool is_playing_notes(void);
 
index 6960bee6da9d773050696537dce3bcc87ecd54ed..f355d371bd35e367de09499e49814e48b04944c0 100644 (file)
     E__NOTE(_B5),        \
     E__NOTE(_A5 ),
 
+#define VOICE_CHANGE_SOUND \
+    Q__NOTE(_A5 ),        \
+    Q__NOTE(_CS6),        \
+    Q__NOTE(_E6 ),        \
+    Q__NOTE(_A6 ),
+
+#define CHROMATIC_SOUND \
+    Q__NOTE(_A5 ),        \
+    Q__NOTE(_AS5 ),        \
+    Q__NOTE(_B5),        \
+    Q__NOTE(_C6 ),        \
+    Q__NOTE(_CS6 ),        
+
+#define MAJOR_SOUND \
+    Q__NOTE(_A5 ),        \
+    Q__NOTE(_B5 ),        \
+    Q__NOTE(_CS6),        \
+    Q__NOTE(_D6 ),        \
+    Q__NOTE(_E6 ),        
+
+#define GUITAR_SOUND \
+    Q__NOTE(_E5 ),        \
+    Q__NOTE(_A5),        \
+    Q__NOTE(_D6 ),        \
+    Q__NOTE(_G6 ),
+
+#define VIOLIN_SOUND \
+    Q__NOTE(_G5 ),        \
+    Q__NOTE(_D6),        \
+    Q__NOTE(_A6 ),        \
+    Q__NOTE(_E7 ),
+
 #define CAPS_LOCK_ON_SOUND \
     E__NOTE(_A3),          \
     E__NOTE(_B3),
index 0b6380ed39ab04cb1a2d4bc8cc985981e633e905..eb74796fa7a9dd6f7daf61ab642e0b803c9d7ad4 100644 (file)
@@ -1,6 +1,11 @@
 #include "audio.h"
 #include "process_audio.h"
 
+#ifndef VOICE_CHANGE_SONG
+    #define VOICE_CHANGE_SONG SONG(VOICE_CHANGE_SOUND)
+#endif
+float voice_change_song[][2] = VOICE_CHANGE_SONG;
+
 static float compute_freq_for_midi_note(uint8_t note)
 {
     // https://en.wikipedia.org/wiki/MIDI_tuning_standard
@@ -20,12 +25,9 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) {
     }
 
     if (keycode == AU_TOG && record->event.pressed) {
-        if (is_audio_on())
-        {
+        if (is_audio_on()) {
             audio_off();
-        }
-        else
-        {
+        } else {
             audio_on();
         }
         return false;
@@ -33,13 +35,13 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) {
 
     if (keycode == MUV_IN && record->event.pressed) {
         voice_iterate();
-        music_scale_user();
+        PLAY_SONG(voice_change_song);
         return false;
     }
 
     if (keycode == MUV_DE && record->event.pressed) {
         voice_deiterate();
-        music_scale_user();
+        PLAY_SONG(voice_change_song);
         return false;
     }
 
index ec2287df1b1d4ecdc5a3844ebbca28d23d19e6ff..63841d1e8754dd746ae31eb51e7bb886d1139840 100644 (file)
@@ -27,6 +27,7 @@
 bool music_activated = false;
 uint8_t music_starting_note = 0x0C;
 int music_offset = 7;
+uint8_t music_mode = MUSIC_MODE_CHROMATIC;
 
 // music sequencer
 static bool music_sequence_recording = false;
@@ -46,10 +47,32 @@ static uint16_t music_sequence_interval = 100;
   #ifndef MUSIC_OFF_SONG
     #define MUSIC_OFF_SONG SONG(MUSIC_OFF_SOUND)
   #endif
+  #ifndef CHROMATIC_SONG
+    #define CHROMATIC_SONG SONG(CHROMATIC_SOUND)
+  #endif
+  #ifndef GUITAR_SONG
+    #define GUITAR_SONG SONG(GUITAR_SOUND)
+  #endif
+  #ifndef VIOLIN_SONG
+    #define VIOLIN_SONG SONG(VIOLIN_SOUND)
+  #endif
+  #ifndef MAJOR_SONG
+    #define MAJOR_SONG SONG(MAJOR_SOUND)
+  #endif
+  float music_mode_songs[NUMBER_OF_MODES][5][2] = {
+    CHROMATIC_SONG,
+    GUITAR_SONG,
+    VIOLIN_SONG,
+    MAJOR_SONG
+  };
   float music_on_song[][2] = MUSIC_ON_SONG;
   float music_off_song[][2] = MUSIC_OFF_SONG;
 #endif
 
+#ifndef MUSIC_MASK
+  #define MUSIC_MASK keycode < 0xFF
+#endif
+
 static void music_noteon(uint8_t note) {
     #ifdef AUDIO_ENABLE
     process_audio_noteon(note);
@@ -98,59 +121,63 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
         return false;
     }
 
-    if (music_activated) {
+    if (keycode == MU_MOD && record->event.pressed) {
+      music_mode_cycle();
+      return false;
+    }
 
-      if (keycode == KC_LCTL && record->event.pressed) { // Start recording
-        music_all_notes_off();
-        music_sequence_recording = true;
-        music_sequence_recorded = false;
-        music_sequence_playing = false;
-        music_sequence_count = 0;
-        return false;
-      }
+    if (music_activated) {
+      if (record->event.pressed) {
+        if (keycode == KC_LCTL) { // Start recording
+          music_all_notes_off();
+          music_sequence_recording = true;
+          music_sequence_recorded = false;
+          music_sequence_playing = false;
+          music_sequence_count = 0;
+          return false;
+        }
 
-      if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing
-        music_all_notes_off();
-        if (music_sequence_recording) { // was recording
-          music_sequence_recorded = true;
+        if (keycode == KC_LALT) { // Stop recording/playing
+          music_all_notes_off();
+          if (music_sequence_recording) { // was recording
+            music_sequence_recorded = true;
+          }
+          music_sequence_recording = false;
+          music_sequence_playing = false;
+          return false;
         }
-        music_sequence_recording = false;
-        music_sequence_playing = false;
-        return false;
-      }
 
-      if (keycode == KC_LGUI && record->event.pressed && music_sequence_recorded) { // Start playing
-        music_all_notes_off();
-        music_sequence_recording = false;
-        music_sequence_playing = true;
-        music_sequence_position = 0;
-        music_sequence_timer = 0;
-        return false;
-      }
+        if (keycode == KC_LGUI && music_sequence_recorded) { // Start playing
+          music_all_notes_off();
+          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_UP) {
+          music_sequence_interval-=10;
+          return false;
+        }
 
-      if (keycode == KC_DOWN) {
-        if (record->event.pressed)
-            music_sequence_interval+=10;
-        return false;
+        if (keycode == KC_DOWN) {
+          music_sequence_interval+=10;
+          return false;
+        }
       }
 
-      #define MUSIC_MODE_GUITAR
-
-      #ifdef MUSIC_MODE_CHROMATIC
-      uint8_t note = (music_starting_note + record->event.key.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.row);
-      #elif defined(MUSIC_MODE_GUITAR)
-      uint8_t note = (music_starting_note + record->event.key.col + music_offset + 32)+5*(MATRIX_ROWS - record->event.key.row);
-      #elif defined(MUSIC_MODE_VIOLIN)
-      uint8_t note = (music_starting_note + record->event.key.col + music_offset + 32)+7*(MATRIX_ROWS - record->event.key.row);
-      #else
-      uint8_t note = (music_starting_note + SCALE[record->event.key.col + music_offset] - 3)+12*(MATRIX_ROWS - record->event.key.row);
-      #endif
+      uint8_t note;
+      if (music_mode == MUSIC_MODE_CHROMATIC) 
+        note = (music_starting_note + record->event.key.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.row);
+      else if (music_mode == MUSIC_MODE_GUITAR)
+        note = (music_starting_note + record->event.key.col + music_offset + 32)+5*(MATRIX_ROWS - record->event.key.row);
+      else if (music_mode == MUSIC_MODE_VIOLIN)
+        note = (music_starting_note + record->event.key.col + music_offset + 32)+7*(MATRIX_ROWS - record->event.key.row);
+      else if (music_mode == MUSIC_MODE_MAJOR)
+        note = (music_starting_note + SCALE[record->event.key.col + music_offset] - 3)+12*(MATRIX_ROWS - record->event.key.row);
+      else
+        note = music_starting_note;
 
       if (record->event.pressed) {
         music_noteon(note);
@@ -162,7 +189,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
         music_noteoff(note);
       }
 
-      if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
+      if (MUSIC_MASK)
         return false;
     }
 
@@ -197,6 +224,14 @@ void music_off(void) {
     #endif
 }
 
+void music_mode_cycle(void) {
+  music_all_notes_off();
+  music_mode = (music_mode + 1) % NUMBER_OF_MODES;
+  #ifdef AUDIO_ENABLE
+    PLAY_SONG(music_mode_songs[music_mode]);
+  #endif
+}
+
 void matrix_scan_music(void) {
   if (music_sequence_playing) {
     if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
index 8dfbf041f4a2b3a5c183ccb44aaeb433b28018b8..ee027197c2e7fee56822b8dc6f63a167ae780829 100644 (file)
 
 #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
 
+enum music_modes {
+  MUSIC_MODE_CHROMATIC,
+  MUSIC_MODE_GUITAR,
+  MUSIC_MODE_VIOLIN,
+  MUSIC_MODE_MAJOR,
+  NUMBER_OF_MODES
+};
+
 bool process_music(uint16_t keycode, keyrecord_t *record);
 
 bool is_music_on(void);
@@ -31,6 +39,7 @@ void music_off(void);
 void music_on_user(void);
 void music_scale_user(void);
 void music_all_notes_off(void);
+void music_mode_cycle(void);
 
 void matrix_scan_music(void);
 
index c863b887afcd00365d3c3353dc2b6cbe90b41823..06ab6d18db655c562807ab49f0e7c831f50080b9 100644 (file)
@@ -132,6 +132,9 @@ enum quantum_keycodes {
     MU_OFF,
     MU_TOG,
 
+    // Music mode cycle
+    MU_MOD,
+
     // Music voice iterate
     MUV_IN,
     MUV_DE,