|
|
@ -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,9 +121,14 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
|
|
|
|
return false;
|
|
|
|
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
|
|
|
|
if (music_activated) {
|
|
|
|
|
|
|
|
if (record->event.pressed) {
|
|
|
|
|
|
|
|
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;
|
|
|
@ -109,7 +137,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
|
|
|
|
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;
|
|
|
@ -119,7 +147,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (keycode == KC_LGUI && record->event.pressed && music_sequence_recorded) { // Start playing
|
|
|
|
if (keycode == KC_LGUI && music_sequence_recorded) { // Start playing
|
|
|
|
music_all_notes_off();
|
|
|
|
music_all_notes_off();
|
|
|
|
music_sequence_recording = false;
|
|
|
|
music_sequence_recording = false;
|
|
|
|
music_sequence_playing = true;
|
|
|
|
music_sequence_playing = true;
|
|
|
@ -129,28 +157,27 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (keycode == KC_UP) {
|
|
|
|
if (keycode == KC_UP) {
|
|
|
|
if (record->event.pressed)
|
|
|
|
|
|
|
|
music_sequence_interval-=10;
|
|
|
|
music_sequence_interval-=10;
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (keycode == KC_DOWN) {
|
|
|
|
if (keycode == KC_DOWN) {
|
|
|
|
if (record->event.pressed)
|
|
|
|
|
|
|
|
music_sequence_interval+=10;
|
|
|
|
music_sequence_interval+=10;
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define MUSIC_MODE_GUITAR
|
|
|
|
uint8_t note;
|
|
|
|
|
|
|
|
if (music_mode == MUSIC_MODE_CHROMATIC)
|
|
|
|
#ifdef MUSIC_MODE_CHROMATIC
|
|
|
|
note = (music_starting_note + record->event.key.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.row);
|
|
|
|
uint8_t 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)
|
|
|
|
#elif defined(MUSIC_MODE_GUITAR)
|
|
|
|
note = (music_starting_note + record->event.key.col + music_offset + 32)+5*(MATRIX_ROWS - record->event.key.row);
|
|
|
|
uint8_t 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)
|
|
|
|
#elif defined(MUSIC_MODE_VIOLIN)
|
|
|
|
note = (music_starting_note + record->event.key.col + music_offset + 32)+7*(MATRIX_ROWS - record->event.key.row);
|
|
|
|
uint8_t 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)
|
|
|
|
#else
|
|
|
|
note = (music_starting_note + SCALE[record->event.key.col + music_offset] - 3)+12*(MATRIX_ROWS - record->event.key.row);
|
|
|
|
uint8_t note = (music_starting_note + SCALE[record->event.key.col + music_offset] - 3)+12*(MATRIX_ROWS - record->event.key.row);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
note = music_starting_note;
|
|
|
|
|
|
|
|
|
|
|
|
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)) {
|
|
|
|