]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
fix up midi stuff w/music mode
authorJack Humbert <jack.humb@gmail.com>
Sun, 10 Dec 2017 15:57:52 +0000 (10:57 -0500)
committerJack Humbert <jack.humb@gmail.com>
Sun, 10 Dec 2017 15:59:47 +0000 (10:59 -0500)
quantum/process_keycode/process_music.c
quantum/process_keycode/process_music.h
quantum/quantum.c
quantum/quantum_keycodes.h

index 63841d1e8754dd746ae31eb51e7bb886d1139840..f69d13ff583098e8f8f8d496f6f11a1755666ba0 100644 (file)
@@ -25,6 +25,7 @@
 #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
 
 bool music_activated = false;
+bool midi_activated = false;
 uint8_t music_starting_note = 0x0C;
 int music_offset = 7;
 uint8_t music_mode = MUSIC_MODE_CHROMATIC;
@@ -47,6 +48,12 @@ static uint16_t music_sequence_interval = 100;
   #ifndef MUSIC_OFF_SONG
     #define MUSIC_OFF_SONG SONG(MUSIC_OFF_SOUND)
   #endif
+  #ifndef MIDI_ON_SONG
+    #define MIDI_ON_SONG SONG(MUSIC_ON_SOUND)
+  #endif
+  #ifndef MIDI_OFF_SONG
+    #define MIDI_OFF_SONG SONG(MUSIC_OFF_SOUND)
+  #endif
   #ifndef CHROMATIC_SONG
     #define CHROMATIC_SONG SONG(CHROMATIC_SOUND)
   #endif
@@ -67,6 +74,8 @@ static uint16_t music_sequence_interval = 100;
   };
   float music_on_song[][2] = MUSIC_ON_SONG;
   float music_off_song[][2] = MUSIC_OFF_SONG;
+  float midi_on_song[][2] = MIDI_ON_SONG;
+  float midi_off_song[][2] = MIDI_OFF_SONG;
 #endif
 
 #ifndef MUSIC_MASK
@@ -75,28 +84,34 @@ static uint16_t music_sequence_interval = 100;
 
 static void music_noteon(uint8_t note) {
     #ifdef AUDIO_ENABLE
-    process_audio_noteon(note);
+    if (music_activated)
+      process_audio_noteon(note);
     #endif
     #if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
-    process_midi_basic_noteon(note);
+    if (midi_activated)
+      process_midi_basic_noteon(note);
     #endif
 }
 
 static void music_noteoff(uint8_t note) {
     #ifdef AUDIO_ENABLE
-    process_audio_noteoff(note);
+    if (music_activated)
+      process_audio_noteoff(note);
     #endif
     #if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
-    process_midi_basic_noteoff(note);
+    if (midi_activated)
+      process_midi_basic_noteoff(note);
     #endif
 }
 
 void music_all_notes_off(void) {
     #ifdef AUDIO_ENABLE
-    process_audio_all_notes_off();
+    if (music_activated)
+      process_audio_all_notes_off();
     #endif
     #if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
-    process_midi_all_notes_off();
+    if (midi_activated)
+      process_midi_all_notes_off();
     #endif
 }
 
@@ -105,7 +120,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
     if (keycode == MU_ON && record->event.pressed) {
         music_on();
         return false;
-    }
+    }    
 
     if (keycode == MU_OFF && record->event.pressed) {
         music_off();
@@ -121,12 +136,31 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
         return false;
     }
 
+    if (keycode == MI_ON && record->event.pressed) {
+        midi_on();
+        return false;
+    }    
+
+    if (keycode == MI_OFF && record->event.pressed) {
+        midi_off();
+        return false;
+    }
+
+    if (keycode == MI_TOG && record->event.pressed) {
+        if (midi_activated) {
+            midi_off();
+        } else {
+            midi_on();
+        }
+        return false;
+    }
+
     if (keycode == MU_MOD && record->event.pressed) {
       music_mode_cycle();
       return false;
     }
 
-    if (music_activated) {
+    if (music_activated || midi_activated) {
       if (record->event.pressed) {
         if (keycode == KC_LCTL) { // Start recording
           music_all_notes_off();
@@ -224,6 +258,34 @@ void music_off(void) {
     #endif
 }
 
+bool is_midi_on(void) {
+    return (midi_activated != 0);
+}
+
+void midi_toggle(void) {
+    if (!midi_activated) {
+        midi_on();
+    } else {
+        midi_off();
+    }
+}
+
+void midi_on(void) {
+    midi_activated = 1;
+    #ifdef AUDIO_ENABLE
+      PLAY_SONG(midi_on_song);
+    #endif
+    midi_on_user();
+}
+
+void midi_off(void) {
+    process_midi_all_notes_off();
+    midi_activated = 0;
+    #ifdef AUDIO_ENABLE
+      PLAY_SONG(midi_off_song);
+    #endif
+}
+
 void music_mode_cycle(void) {
   music_all_notes_off();
   music_mode = (music_mode + 1) % NUMBER_OF_MODES;
@@ -248,6 +310,9 @@ void matrix_scan_music(void) {
 __attribute__ ((weak))
 void music_on_user() {}
 
+__attribute__ ((weak))
+void midi_on_user() {}
+
 __attribute__ ((weak))
 void music_scale_user() {}
 
index ee027197c2e7fee56822b8dc6f63a167ae780829..773bbfa6baa68f45e03a162d7798ec0976966af7 100644 (file)
@@ -36,7 +36,13 @@ void music_toggle(void);
 void music_on(void);
 void music_off(void);
 
+bool is_midi_on(void);
+void midi_toggle(void);
+void midi_on(void);
+void midi_off(void);
+
 void music_on_user(void);
+void midi_on_user(void);
 void music_scale_user(void);
 void music_all_notes_off(void);
 void music_mode_cycle(void);
index dee2fc4b634f9db832eabac91f8789448fc982e4..e2280b707ea95ab05fb7da0ed3f2f1ebe989e04b 100644 (file)
@@ -132,7 +132,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
 
 void reset_keyboard(void) {
   clear_keyboard();
-#if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_ENABLE_BASIC))
+#if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
   music_all_notes_off();
   uint16_t timer_start = timer_read();
   PLAY_SONG(goodbye_song);
index 048da326735690da48e995034601993ddfff1de6..f2cb25718824cef39c3148dd7cd49dedb64c8309 100644 (file)
@@ -152,8 +152,9 @@ enum quantum_keycodes {
 
     // Midi
 #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
-    MI_ON,  // send midi notes when music mode is enabled
-    MI_OFF, // don't send midi notes when music mode is enabled
+    MI_ON,
+    MI_OFF,
+    MI_TOG,
 #endif
 
 #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_ADVANCED))