rests between notes as an argument
This commit is contained in:
parent
8f4ce501eb
commit
41cc35425a
5 changed files with 37 additions and 23 deletions
|
@ -194,7 +194,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
|
||||||
case _QW:
|
case _QW:
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
play_notes(&tone_qw, 4, false);
|
play_notes(&tone_qw, 4, false, 0);
|
||||||
#endif
|
#endif
|
||||||
default_layer_set(1UL<<_QW);
|
default_layer_set(1UL<<_QW);
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
|
||||||
case _CM:
|
case _CM:
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
play_notes(&tone_cm, 6, false);
|
play_notes(&tone_cm, 6, false, 0);
|
||||||
#endif
|
#endif
|
||||||
default_layer_set(1UL<<_CM);
|
default_layer_set(1UL<<_CM);
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
|
||||||
case _DV:
|
case _DV:
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
play_notes(&tone_dv, 8, false);
|
play_notes(&tone_dv, 8, false, 0);
|
||||||
#endif
|
#endif
|
||||||
default_layer_set(1UL<<_DV);
|
default_layer_set(1UL<<_DV);
|
||||||
}
|
}
|
||||||
|
@ -254,7 +254,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
audio_on();
|
audio_on();
|
||||||
play_notes(&start_up, 5, false);
|
play_notes(&start_up, 5, false, 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -265,6 +265,6 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
|
||||||
void matrix_init_user(void) {
|
void matrix_init_user(void) {
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
init_notes();
|
init_notes();
|
||||||
play_notes(&start_up, 5, false);
|
play_notes(&start_up, 5, false, 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,7 +242,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
|
||||||
case _QWERTY:
|
case _QWERTY:
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
play_notes(&tone_qwerty, 4, false);
|
play_notes(&tone_qwerty, 4, false, 0);
|
||||||
#endif
|
#endif
|
||||||
persistant_default_layer_set(1UL<<_QWERTY);
|
persistant_default_layer_set(1UL<<_QWERTY);
|
||||||
}
|
}
|
||||||
|
@ -250,7 +250,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
|
||||||
case _COLEMAK:
|
case _COLEMAK:
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
play_notes(&tone_colemak, 6, false);
|
play_notes(&tone_colemak, 6, false, 1);
|
||||||
#endif
|
#endif
|
||||||
persistant_default_layer_set(1UL<<_COLEMAK);
|
persistant_default_layer_set(1UL<<_COLEMAK);
|
||||||
}
|
}
|
||||||
|
@ -258,7 +258,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
|
||||||
case _DVORAK:
|
case _DVORAK:
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
play_notes(&tone_dvorak, 8, false);
|
play_notes(&tone_dvorak, 8, false, 10);
|
||||||
#endif
|
#endif
|
||||||
persistant_default_layer_set(1UL<<_DVORAK);
|
persistant_default_layer_set(1UL<<_DVORAK);
|
||||||
}
|
}
|
||||||
|
@ -302,7 +302,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
audio_on();
|
audio_on();
|
||||||
play_notes(&start_up, 4, false);
|
play_notes(&start_up, 4, false, 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -317,7 +317,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
|
||||||
case 9:
|
case 9:
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
play_notes(&tone_music, 8, false);
|
play_notes(&tone_music, 8, false, 0);
|
||||||
layer_on(_MUSIC);
|
layer_on(_MUSIC);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -333,9 +333,9 @@ void process_action_user(keyrecord_t *record) {
|
||||||
|
|
||||||
if (IS_LAYER_ON(_MUSIC)) {
|
if (IS_LAYER_ON(_MUSIC)) {
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
play_note(((double)261.626)*pow(2.0, -3.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)), 0xF);
|
play_note(((double)220.0)*pow(2.0, -4.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)), 0xF);
|
||||||
} else {
|
} else {
|
||||||
stop_note(((double)261.626)*pow(2.0, -3.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)));
|
stop_note(((double)220.0)*pow(2.0, -4.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,6 +344,6 @@ void process_action_user(keyrecord_t *record) {
|
||||||
void matrix_init_user(void) {
|
void matrix_init_user(void) {
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
init_notes();
|
init_notes();
|
||||||
play_notes(&start_up, 4, false);
|
play_notes(&start_up, 4, false, 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,11 @@ uint16_t note_position = 0;
|
||||||
float (* notes_pointer)[][2];
|
float (* notes_pointer)[][2];
|
||||||
uint8_t notes_length;
|
uint8_t notes_length;
|
||||||
bool notes_repeat;
|
bool notes_repeat;
|
||||||
|
float notes_rest;
|
||||||
|
bool note_resting = false;
|
||||||
|
|
||||||
uint8_t current_note = 0;
|
uint8_t current_note = 0;
|
||||||
|
uint8_t rest_counter = 0;
|
||||||
|
|
||||||
audio_config_t audio_config;
|
audio_config_t audio_config;
|
||||||
|
|
||||||
|
@ -314,13 +318,21 @@ ISR(TIMER3_COMPA_vect) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef PWM_AUDIO
|
if (!note_resting && ((int)notes_rest != 0)) {
|
||||||
note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
|
note_resting = true;
|
||||||
note_length = (*notes_pointer)[current_note][1];
|
note_frequency = 0;
|
||||||
#else
|
note_length = notes_rest;
|
||||||
note_frequency = (*notes_pointer)[current_note][0];
|
current_note--;
|
||||||
note_length = (*notes_pointer)[current_note][1] / 4;
|
} else {
|
||||||
#endif
|
note_resting = false;
|
||||||
|
#ifdef PWM_AUDIO
|
||||||
|
note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
|
||||||
|
note_length = (*notes_pointer)[current_note][1];
|
||||||
|
#else
|
||||||
|
note_frequency = (*notes_pointer)[current_note][0];
|
||||||
|
note_length = (*notes_pointer)[current_note][1] / 4;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
note_position = 0;
|
note_position = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,7 +344,7 @@ ISR(TIMER3_COMPA_vect) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat) {
|
void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat, float n_rest) {
|
||||||
|
|
||||||
if (audio_config.enable) {
|
if (audio_config.enable) {
|
||||||
|
|
||||||
|
@ -343,6 +355,7 @@ if (audio_config.enable) {
|
||||||
notes_pointer = np;
|
notes_pointer = np;
|
||||||
notes_length = n_length;
|
notes_length = n_length;
|
||||||
notes_repeat = n_repeat;
|
notes_repeat = n_repeat;
|
||||||
|
notes_rest = n_rest;
|
||||||
|
|
||||||
place = 0;
|
place = 0;
|
||||||
current_note = 0;
|
current_note = 0;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
|
#include "musical_notes.h"
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
uint8_t raw;
|
uint8_t raw;
|
||||||
|
@ -20,4 +21,4 @@ void play_note(double freq, int vol);
|
||||||
void stop_note(double freq);
|
void stop_note(double freq);
|
||||||
void stop_all_notes();
|
void stop_all_notes();
|
||||||
void init_notes();
|
void init_notes();
|
||||||
void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat);
|
void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat, float n_rest);
|
||||||
|
|
|
@ -189,7 +189,7 @@ static action_t keycode_to_action(uint16_t keycode)
|
||||||
case RESET: ; // RESET is 0x5000, which is why this is here
|
case RESET: ; // RESET is 0x5000, which is why this is here
|
||||||
clear_keyboard();
|
clear_keyboard();
|
||||||
#ifdef AUDIO_ENABLE
|
#ifdef AUDIO_ENABLE
|
||||||
play_notes(&goodbye, 3, false);
|
play_notes(&goodbye, 3, false, 0);
|
||||||
#endif
|
#endif
|
||||||
_delay_ms(250);
|
_delay_ms(250);
|
||||||
#ifdef ATREUS_ASTAR
|
#ifdef ATREUS_ASTAR
|
||||||
|
|
Loading…
Reference in a new issue