#define M_LW 1
#define M_RS 2
#define M_FN 3
+#define M_T1 4
+#define M_T2 5
+#define M_T3 6
+#define M_T4 7
+#define M_TU 8
+#define M_TD 9
+#define M_DF 10
#define _______ KC_TRNS
{ KC_NLCK, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, ___T___, ___T___ },
{ KC_SLCK, KC_F13, KC_F14, KC_F15, KC_F16, KC_F17, KC_F18, KC_F19, KC_F20, KC_F21, KC_F22, KC_F23, KC_F24, KC_PAUS, KC_PSCR },
{ KC_CAPS, KC_BTN5, KC_BTN4, KC_BTN3, KC_BTN2, KC_ACL0, KC_ACL2, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY, _______, ___T___, ___T___, KC_WH_U },
- { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, ___T___, ___T___, KC_MS_U, KC_WH_D },
+ { _______, M(M_T1), M(M_T2), M(M_T3), M(M_T4), M(M_TU), M(M_TD), M(M_DF), _______, _______, _______, ___T___, ___T___, KC_MS_U, KC_WH_D },
{ _______, _______, _______, _______, _______, KC_BTN1, KC_BTN1, _______, _______, _______, _______, _______, KC_MS_L, KC_MS_D, KC_MS_R },
},
[_AD] = { /* ADJUST */
},
};
-void update_quad_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3, uint8_t layer4, bool order)
-{
- if (order)
- {
- if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2))
- {
- layer_on(layer3);
- }
- else
- {
- layer_off(layer3);
- layer_off(layer4);
- }
- }
- else
- {
- if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2))
- {
- layer_on(layer4);
- }
- else
- {
- layer_off(layer3);
- layer_off(layer4);
- }
- }
-}
-
-
-const uint16_t PROGMEM fn_actions[] = {
-};
-
-
-const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
-{
-
- // MACRODOWN only works in this function
- switch(id) {
- case M_LW:
- if (record->event.pressed) {
- #ifdef AUDIO_ENABLE
- println("PlayNotes LW");
- PLAY_NOTE_ARRAY(tone_lw, false, STACCATO);
- #endif
- layer_on(_LW);
- update_tri_layer(_LW, _RS, _FN);
- } else {
- layer_off(_LW);
- update_tri_layer(_LW, _RS, _FN);
- }
- break;
- case M_RS:
- if (record->event.pressed) {
- #ifdef AUDIO_ENABLE
- println("PlayNotes RS");
- PLAY_NOTE_ARRAY(tone_rs, false, LEGATO);
- #endif
- layer_on(_RS);
- update_tri_layer(_LW, _RS, _FN);
- } else {
- layer_off(_RS);
- update_tri_layer(_LW, _RS, _FN);
- }
- break;
- default:
- break;
- }
- return MACRO_NONE;
-};
-
#ifdef AUDIO_ENABLE
float start_up[][2] = SONG(ODE_TO_JOY);
float tone_lw[][2] = {
- /*
- Q__NOTE(_C1 ) ,
- Q__NOTE(_CS1 ) ,
- Q__NOTE(_D1 ) ,
- Q__NOTE(_DS1 ) ,
- Q__NOTE(_E1 ) ,
- Q__NOTE(_F1 ) ,
- Q__NOTE(_FS1 ) ,
- Q__NOTE(_G1 ) ,
- Q__NOTE(_GS1 ) ,
- Q__NOTE(_A1 ) ,
- Q__NOTE(_AS1 ) ,
- Q__NOTE(_B1 ) ,
- */
Q__NOTE(_C4 ) ,
Q__NOTE(_CS4 ) ,
Q__NOTE(_GS4 ) ,
Q__NOTE(_A4 ) ,
Q__NOTE(_AS4 ) ,
+
Q__NOTE(_B1 ) ,
Q__NOTE(_C2 ) ,
Q__NOTE(_B8 ) ,
};
-float tone_rs[][2] = {
- Q__NOTE(_A4 ) ,
- Q__NOTE(_A4 ) ,
- Q__NOTE(_A4 ) ,
- Q__NOTE(_A4 ) ,
- Q__NOTE(_AS8 ) ,
- Q__NOTE(_B8 ) ,
-};
+float tone_rs[][2] = SONG(ROCK_A_BYE_BABY);
void matrix_init_user(void) {
init_notes();
}
#endif
+
+
+void update_quad_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3, uint8_t layer4, bool order)
+{
+ if (order)
+ {
+ if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2))
+ {
+ layer_on(layer3);
+ }
+ else
+ {
+ layer_off(layer3);
+ layer_off(layer4);
+ }
+ }
+ else
+ {
+ if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2))
+ {
+ layer_on(layer4);
+ }
+ else
+ {
+ layer_off(layer3);
+ layer_off(layer4);
+ }
+ }
+}
+
+
+const uint16_t PROGMEM fn_actions[] = {
+};
+
+
+const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
+{
+
+ // MACRODOWN only works in this function
+ switch(id)
+ {
+ case M_LW:
+ if (record->event.pressed) {
+ #ifdef AUDIO_ENABLE
+ PLAY_NOTE_ARRAY(tone_lw, false, STACCATO);
+ #endif
+ layer_on(_LW);
+ update_tri_layer(_LW, _RS, _AD);
+ } else {
+ layer_off(_LW);
+ update_tri_layer(_LW, _RS, _AD);
+ }
+ break;
+ case M_RS:
+ if (record->event.pressed) {
+ #ifdef AUDIO_ENABLE
+ PLAY_NOTE_ARRAY(tone_rs, false, LEGATO);
+ #endif
+ layer_on(_RS);
+ update_tri_layer(_LW, _RS, _AD);
+ } else {
+ layer_off(_RS);
+ update_tri_layer(_LW, _RS, _AD);
+ }
+ break;
+
+ case M_FN:
+ if (record->event.pressed) {
+ layer_on(_FN);
+ } else {
+ layer_off(_FN);
+ }
+ break;
+
+ case M_T1:
+ if (record->event.pressed) set_timbre(TIMBRE_12);
+ break;
+
+ case M_T2:
+ if (record->event.pressed) set_timbre(TIMBRE_25);
+ break;
+
+ case M_T3:
+ if (record->event.pressed) set_timbre(TIMBRE_50);
+ break;
+
+ case M_T4:
+ if (record->event.pressed) set_timbre(TIMBRE_75);
+ break;
+
+
+ case M_TU:
+ if (record->event.pressed) increase_tempo(10);
+ break;
+
+ case M_TD:
+ if (record->event.pressed) decrease_tempo(10);
+ break;
+
+ case M_DF:
+ if (record->event.pressed)
+ {
+ set_timbre(TIMBRE_DEFAULT);
+ set_tempo(TEMPO_DEFAULT);
+ }
+ break;
+
+ default:
+ break;
+
+ }
+ return MACRO_NONE;
+};
\ No newline at end of file
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/io.h>
-
+#include "print.h"
#include "audio.h"
#include "keymap_common.h"
bool note = false;
float note_frequency = 0;
float note_length = 0;
+float note_tempo = TEMPO_DEFAULT;
+float note_timbre = TIMBRE_DEFAULT;
uint16_t note_position = 0;
float (* notes_pointer)[][2];
-uint8_t notes_length;
+uint8_t notes_count;
bool notes_repeat;
float notes_rest;
bool note_resting = false;
place = 0.0;
}
ICR3 = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)); // Set max to the period
- OCR3A = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) >> 1 * duty_place; // Set compare to half the period
+ OCR3A = (int)((((double)F_CPU) / (note_frequency * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
+ //OCR3A = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) >> 1 * duty_place; // Set compare to half the period
place++;
// if (duty_counter > (frequencies[voice_place] / 500)) {
// duty_place = (duty_place % 3) + 1;
#else
if (note_frequency > 0) {
ICR3 = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)); // Set max to the period
- //OCR3A = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)) >> 1; // Set compare to half the period
- OCR3A = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)) >> 2; // Set compare to half the period
+ OCR3A = (int)((((double)F_CPU) / (note_frequency * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
} else {
ICR3 = 0;
OCR3A = 0;
end_of_note = (note_position >= (note_length * 0x7FF));
if (end_of_note) {
current_note++;
- if (current_note >= notes_length) {
+ if (current_note >= notes_count) {
if (notes_repeat) {
current_note = 0;
} else {
note_resting = false;
#ifdef PWM_AUDIO
note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
- note_length = (*notes_pointer)[current_note][1];
+ note_length = (*notes_pointer)[current_note][1] * (note_tempo / 100);
#else
note_frequency = (*notes_pointer)[current_note][0];
- note_length = (*notes_pointer)[current_note][1] / 4;
+ note_length = ((*notes_pointer)[current_note][1] / 4) * (note_tempo / 100);
#endif
}
note_position = 0;
}
}
-void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat, float n_rest) {
+void play_notes(float (*np)[][2], uint8_t n_count, bool n_repeat, float n_rest) {
if (audio_config.enable) {
notes = true;
notes_pointer = np;
- notes_length = n_length;
+ notes_count = n_count;
notes_repeat = n_repeat;
notes_rest = n_rest;
current_note = 0;
#ifdef PWM_AUDIO
note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
- note_length = (*notes_pointer)[current_note][1];
+ note_length = (*notes_pointer)[current_note][1] * (note_tempo / 100);
#else
note_frequency = (*notes_pointer)[current_note][0];
- note_length = (*notes_pointer)[current_note][1] / 4;
+ note_length = ((*notes_pointer)[current_note][1] / 4) * (note_tempo / 100);
#endif
note_position = 0;
}
-}
\ No newline at end of file
+}
+
+void set_timbre(float timbre)
+{
+ note_timbre = timbre;
+}
+
+void set_tempo(float tempo)
+{
+ note_tempo = tempo;
+}
+
+void decrease_tempo(uint8_t tempo_change)
+{
+ note_tempo += (float) tempo_change;
+}
+
+void increase_tempo(uint8_t tempo_change)
+{
+ if (note_tempo - (float) tempo_change < 10)
+ {
+ note_tempo = 10;
+ }
+ else
+ {
+ note_tempo -= (float) tempo_change;
+ }
+}
+