forked from mirrors/qmk_userspace
		
	adds music mode, music mode songs, music mask
This commit is contained in:
		
					parent
					
						
							
								9abbbe7089
							
						
					
				
			
			
				commit
				
					
						415d38ba9e
					
				
			
		
					 10 changed files with 168 additions and 81 deletions
				
			
		| 
						 | 
					@ -3,6 +3,18 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "../../config.h"
 | 
					#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
 | 
					 * MIDI options
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
| 
						 | 
					@ -13,18 +25,9 @@
 | 
				
			||||||
/* enable basic MIDI features:
 | 
					/* enable basic MIDI features:
 | 
				
			||||||
   - MIDI notes can be sent when in Music mode is on
 | 
					   - MIDI notes can be sent when in Music mode is on
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					                                
 | 
				
			||||||
#define MIDI_BASIC
 | 
					#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:
 | 
					/* enable advanced MIDI features:
 | 
				
			||||||
   - MIDI notes can be added to the keymap
 | 
					   - MIDI notes can be added to the keymap
 | 
				
			||||||
   - Octave shift and transpose
 | 
					   - Octave shift and transpose
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -164,7 +164,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
[_ADJUST] = {
 | 
					[_ADJUST] = {
 | 
				
			||||||
  {_______, RESET,   _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL },
 | 
					  {_______, 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,  _______, _______, _______, _______, _______},
 | 
					  {_______, MUV_DE,  MUV_IN,  MU_ON,   MU_OFF,  MI_ON,   MI_OFF,  _______, _______, _______, _______, _______},
 | 
				
			||||||
  {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
 | 
					  {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,18 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "../../config.h"
 | 
					#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
 | 
					 * MIDI options
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
| 
						 | 
					@ -13,18 +25,9 @@
 | 
				
			||||||
/* enable basic MIDI features:
 | 
					/* enable basic MIDI features:
 | 
				
			||||||
   - MIDI notes can be sent when in Music mode is on
 | 
					   - MIDI notes can be sent when in Music mode is on
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MIDI_BASIC
 | 
					#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:
 | 
					/* enable advanced MIDI features:
 | 
				
			||||||
   - MIDI notes can be added to the keymap
 | 
					   - MIDI notes can be added to the keymap
 | 
				
			||||||
   - Octave shift and transpose
 | 
					   - Octave shift and transpose
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -158,7 +158,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
 | 
				
			||||||
[_ADJUST] = {
 | 
					[_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},
 | 
					  {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},
 | 
					  {_______, 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,  _______, _______, _______, _______, _______},
 | 
					  {_______, MUV_DE,  MUV_IN,  MU_ON,   MU_OFF,  MI_ON,   MI_OFF,  _______, _______, _______, _______, _______},
 | 
				
			||||||
  {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
 | 
					  {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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 NOTE_ARRAY_SIZE(x) ((int16_t)(sizeof(x) / (sizeof(x[0]))))
 | 
				
			||||||
#define PLAY_NOTE_ARRAY(note_array, note_repeat, deprecated_arg) play_notes(¬e_array, NOTE_ARRAY_SIZE((note_array)), (note_repeat)); \
 | 
					#define PLAY_NOTE_ARRAY(note_array, note_repeat, deprecated_arg) play_notes(¬e_array, NOTE_ARRAY_SIZE((note_array)), (note_repeat)); \
 | 
				
			||||||
	_Pragma ("message \"'PLAY_NOTE_ARRAY' macro is deprecated\"")
 | 
						_Pragma ("message \"'PLAY_NOTE_ARRAY' macro is deprecated\"")
 | 
				
			||||||
#define PLAY_SONG(note_array) play_notes(¬e_array, NOTE_ARRAY_SIZE((note_array)), false);
 | 
					#define PLAY_SONG(note_array) play_notes(¬e_array, NOTE_ARRAY_SIZE((note_array)), false)
 | 
				
			||||||
#define PLAY_LOOP(note_array) play_notes(¬e_array, NOTE_ARRAY_SIZE((note_array)), true);
 | 
					#define PLAY_LOOP(note_array) play_notes(¬e_array, NOTE_ARRAY_SIZE((note_array)), true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool is_playing_notes(void);
 | 
					bool is_playing_notes(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -139,6 +139,38 @@
 | 
				
			||||||
    E__NOTE(_B5),        \
 | 
					    E__NOTE(_B5),        \
 | 
				
			||||||
    E__NOTE(_A5 ),
 | 
					    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 \
 | 
					#define CAPS_LOCK_ON_SOUND \
 | 
				
			||||||
    E__NOTE(_A3),          \
 | 
					    E__NOTE(_A3),          \
 | 
				
			||||||
    E__NOTE(_B3),
 | 
					    E__NOTE(_B3),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,11 @@
 | 
				
			||||||
#include "audio.h"
 | 
					#include "audio.h"
 | 
				
			||||||
#include "process_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)
 | 
					static float compute_freq_for_midi_note(uint8_t note)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    // https://en.wikipedia.org/wiki/MIDI_tuning_standard
 | 
					    // 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 (keycode == AU_TOG && record->event.pressed) {
 | 
				
			||||||
        if (is_audio_on())
 | 
					        if (is_audio_on()) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            audio_off();
 | 
					            audio_off();
 | 
				
			||||||
        }
 | 
					        } else {
 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            audio_on();
 | 
					            audio_on();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
| 
						 | 
					@ -33,13 +35,13 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (keycode == MUV_IN && record->event.pressed) {
 | 
					    if (keycode == MUV_IN && record->event.pressed) {
 | 
				
			||||||
        voice_iterate();
 | 
					        voice_iterate();
 | 
				
			||||||
        music_scale_user();
 | 
					        PLAY_SONG(voice_change_song);
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (keycode == MUV_DE && record->event.pressed) {
 | 
					    if (keycode == MUV_DE && record->event.pressed) {
 | 
				
			||||||
        voice_deiterate();
 | 
					        voice_deiterate();
 | 
				
			||||||
        music_scale_user();
 | 
					        PLAY_SONG(voice_change_song);
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,6 +27,7 @@
 | 
				
			||||||
bool music_activated = false;
 | 
					bool music_activated = false;
 | 
				
			||||||
uint8_t music_starting_note = 0x0C;
 | 
					uint8_t music_starting_note = 0x0C;
 | 
				
			||||||
int music_offset = 7;
 | 
					int music_offset = 7;
 | 
				
			||||||
 | 
					uint8_t music_mode = MUSIC_MODE_CHROMATIC;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// music sequencer
 | 
					// music sequencer
 | 
				
			||||||
static bool music_sequence_recording = false;
 | 
					static bool music_sequence_recording = false;
 | 
				
			||||||
| 
						 | 
					@ -46,10 +47,32 @@ static uint16_t music_sequence_interval = 100;
 | 
				
			||||||
  #ifndef MUSIC_OFF_SONG
 | 
					  #ifndef MUSIC_OFF_SONG
 | 
				
			||||||
    #define MUSIC_OFF_SONG SONG(MUSIC_OFF_SOUND)
 | 
					    #define MUSIC_OFF_SONG SONG(MUSIC_OFF_SOUND)
 | 
				
			||||||
  #endif
 | 
					  #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_on_song[][2] = MUSIC_ON_SONG;
 | 
				
			||||||
  float music_off_song[][2] = MUSIC_OFF_SONG;
 | 
					  float music_off_song[][2] = MUSIC_OFF_SONG;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef MUSIC_MASK
 | 
				
			||||||
 | 
					  #define MUSIC_MASK keycode < 0xFF
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void music_noteon(uint8_t note) {
 | 
					static void music_noteon(uint8_t note) {
 | 
				
			||||||
    #ifdef AUDIO_ENABLE
 | 
					    #ifdef AUDIO_ENABLE
 | 
				
			||||||
    process_audio_noteon(note);
 | 
					    process_audio_noteon(note);
 | 
				
			||||||
| 
						 | 
					@ -98,59 +121,63 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (keycode == MU_MOD && record->event.pressed) {
 | 
				
			||||||
 | 
					      music_mode_cycle();
 | 
				
			||||||
 | 
					      return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (music_activated) {
 | 
					    if (music_activated) {
 | 
				
			||||||
 | 
					      if (record->event.pressed) {
 | 
				
			||||||
      if (keycode == KC_LCTL && record->event.pressed) { // Start recording
 | 
					        if (keycode == KC_LCTL) { // Start recording
 | 
				
			||||||
        music_all_notes_off();
 | 
					          music_all_notes_off();
 | 
				
			||||||
        music_sequence_recording = true;
 | 
					          music_sequence_recording = true;
 | 
				
			||||||
        music_sequence_recorded = false;
 | 
					          music_sequence_recorded = false;
 | 
				
			||||||
        music_sequence_playing = false;
 | 
					          music_sequence_playing = false;
 | 
				
			||||||
        music_sequence_count = 0;
 | 
					          music_sequence_count = 0;
 | 
				
			||||||
        return false;
 | 
					          return false;
 | 
				
			||||||
      }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing
 | 
					        if (keycode == KC_LALT) { // Stop recording/playing
 | 
				
			||||||
        music_all_notes_off();
 | 
					          music_all_notes_off();
 | 
				
			||||||
        if (music_sequence_recording) { // was recording
 | 
					          if (music_sequence_recording) { // was recording
 | 
				
			||||||
          music_sequence_recorded = true;
 | 
					            music_sequence_recorded = true;
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          music_sequence_recording = false;
 | 
				
			||||||
 | 
					          music_sequence_playing = false;
 | 
				
			||||||
 | 
					          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) {
 | 
				
			||||||
 | 
					          music_sequence_interval-=10;
 | 
				
			||||||
 | 
					          return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (keycode == KC_DOWN) {
 | 
				
			||||||
 | 
					          music_sequence_interval+=10;
 | 
				
			||||||
 | 
					          return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        music_sequence_recording = false;
 | 
					 | 
				
			||||||
        music_sequence_playing = false;
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (keycode == KC_LGUI && record->event.pressed && music_sequence_recorded) { // Start playing
 | 
					      uint8_t note;
 | 
				
			||||||
        music_all_notes_off();
 | 
					      if (music_mode == MUSIC_MODE_CHROMATIC) 
 | 
				
			||||||
        music_sequence_recording = false;
 | 
					        note = (music_starting_note + record->event.key.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.row);
 | 
				
			||||||
        music_sequence_playing = true;
 | 
					      else if (music_mode == MUSIC_MODE_GUITAR)
 | 
				
			||||||
        music_sequence_position = 0;
 | 
					        note = (music_starting_note + record->event.key.col + music_offset + 32)+5*(MATRIX_ROWS - record->event.key.row);
 | 
				
			||||||
        music_sequence_timer = 0;
 | 
					      else if (music_mode == MUSIC_MODE_VIOLIN)
 | 
				
			||||||
        return false;
 | 
					        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);
 | 
				
			||||||
      if (keycode == KC_UP) {
 | 
					      else
 | 
				
			||||||
        if (record->event.pressed)
 | 
					        note = music_starting_note;
 | 
				
			||||||
            music_sequence_interval-=10;
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (keycode == KC_DOWN) {
 | 
					 | 
				
			||||||
        if (record->event.pressed)
 | 
					 | 
				
			||||||
            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
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (record->event.pressed) {
 | 
					      if (record->event.pressed) {
 | 
				
			||||||
        music_noteon(note);
 | 
					        music_noteon(note);
 | 
				
			||||||
| 
						 | 
					@ -162,7 +189,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
 | 
				
			||||||
        music_noteoff(note);
 | 
					        music_noteoff(note);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
 | 
					      if (MUSIC_MASK)
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -197,6 +224,14 @@ void music_off(void) {
 | 
				
			||||||
    #endif
 | 
					    #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) {
 | 
					void matrix_scan_music(void) {
 | 
				
			||||||
  if (music_sequence_playing) {
 | 
					  if (music_sequence_playing) {
 | 
				
			||||||
    if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
 | 
					    if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,6 +21,14 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
 | 
					#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 process_music(uint16_t keycode, keyrecord_t *record);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool is_music_on(void);
 | 
					bool is_music_on(void);
 | 
				
			||||||
| 
						 | 
					@ -31,6 +39,7 @@ void music_off(void);
 | 
				
			||||||
void music_on_user(void);
 | 
					void music_on_user(void);
 | 
				
			||||||
void music_scale_user(void);
 | 
					void music_scale_user(void);
 | 
				
			||||||
void music_all_notes_off(void);
 | 
					void music_all_notes_off(void);
 | 
				
			||||||
 | 
					void music_mode_cycle(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void matrix_scan_music(void);
 | 
					void matrix_scan_music(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -132,6 +132,9 @@ enum quantum_keycodes {
 | 
				
			||||||
    MU_OFF,
 | 
					    MU_OFF,
 | 
				
			||||||
    MU_TOG,
 | 
					    MU_TOG,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Music mode cycle
 | 
				
			||||||
 | 
					    MU_MOD,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Music voice iterate
 | 
					    // Music voice iterate
 | 
				
			||||||
    MUV_IN,
 | 
					    MUV_IN,
 | 
				
			||||||
    MUV_DE,
 | 
					    MUV_DE,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue