aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keyboard/atomic/keymaps/pvc/keymap.c216
-rw-r--r--keyboard/atomic/keymaps/pvc/makefile.mk2
-rw-r--r--quantum/audio.c56
-rw-r--r--quantum/audio.h6
-rw-r--r--quantum/musical_notes.h13
-rw-r--r--quantum/song_list.h6
6 files changed, 189 insertions, 110 deletions
diff --git a/keyboard/atomic/keymaps/pvc/keymap.c b/keyboard/atomic/keymaps/pvc/keymap.c
index 9a2c57cb1..aaef6b041 100644
--- a/keyboard/atomic/keymaps/pvc/keymap.c
+++ b/keyboard/atomic/keymaps/pvc/keymap.c
@@ -17,6 +17,13 @@
17#define M_LW 1 17#define M_LW 1
18#define M_RS 2 18#define M_RS 2
19#define M_FN 3 19#define M_FN 3
20#define M_T1 4
21#define M_T2 5
22#define M_T3 6
23#define M_T4 7
24#define M_TU 8
25#define M_TD 9
26#define M_DF 10
20 27
21 28
22#define _______ KC_TRNS 29#define _______ KC_TRNS
@@ -63,7 +70,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
63 { 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___ }, 70 { 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___ },
64 { 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 }, 71 { 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 },
65 { 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 }, 72 { 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 },
66 { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, ___T___, ___T___, KC_MS_U, KC_WH_D }, 73 { _______, 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 },
67 { _______, _______, _______, _______, _______, KC_BTN1, KC_BTN1, _______, _______, _______, _______, _______, KC_MS_L, KC_MS_D, KC_MS_R }, 74 { _______, _______, _______, _______, _______, KC_BTN1, KC_BTN1, _______, _______, _______, _______, _______, KC_MS_L, KC_MS_D, KC_MS_R },
68 }, 75 },
69 [_AD] = { /* ADJUST */ 76 [_AD] = { /* ADJUST */
@@ -75,76 +82,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
75 }, 82 },
76}; 83};
77 84
78void update_quad_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3, uint8_t layer4, bool order)
79{
80 if (order)
81 {
82 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2))
83 {
84 layer_on(layer3);
85 }
86 else
87 {
88 layer_off(layer3);
89 layer_off(layer4);
90 }
91 }
92 else
93 {
94 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2))
95 {
96 layer_on(layer4);
97 }
98 else
99 {
100 layer_off(layer3);
101 layer_off(layer4);
102 }
103 }
104}
105
106
107const uint16_t PROGMEM fn_actions[] = {
108};
109
110
111const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
112{
113
114 // MACRODOWN only works in this function
115 switch(id) {
116 case M_LW:
117 if (record->event.pressed) {
118 #ifdef AUDIO_ENABLE
119 println("PlayNotes LW");
120 PLAY_NOTE_ARRAY(tone_lw, false, STACCATO);
121 #endif
122 layer_on(_LW);
123 update_tri_layer(_LW, _RS, _FN);
124 } else {
125 layer_off(_LW);
126 update_tri_layer(_LW, _RS, _FN);
127 }
128 break;
129 case M_RS:
130 if (record->event.pressed) {
131 #ifdef AUDIO_ENABLE
132 println("PlayNotes RS");
133 PLAY_NOTE_ARRAY(tone_rs, false, LEGATO);
134 #endif
135 layer_on(_RS);
136 update_tri_layer(_LW, _RS, _FN);
137 } else {
138 layer_off(_RS);
139 update_tri_layer(_LW, _RS, _FN);
140 }
141 break;
142 default:
143 break;
144 }
145 return MACRO_NONE;
146};
147
148 85
149 86
150#ifdef AUDIO_ENABLE 87#ifdef AUDIO_ENABLE
@@ -152,20 +89,6 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
152float start_up[][2] = SONG(ODE_TO_JOY); 89float start_up[][2] = SONG(ODE_TO_JOY);
153 90
154float tone_lw[][2] = { 91float tone_lw[][2] = {
155 /*
156 Q__NOTE(_C1 ) ,
157 Q__NOTE(_CS1 ) ,
158 Q__NOTE(_D1 ) ,
159 Q__NOTE(_DS1 ) ,
160 Q__NOTE(_E1 ) ,
161 Q__NOTE(_F1 ) ,
162 Q__NOTE(_FS1 ) ,
163 Q__NOTE(_G1 ) ,
164 Q__NOTE(_GS1 ) ,
165 Q__NOTE(_A1 ) ,
166 Q__NOTE(_AS1 ) ,
167 Q__NOTE(_B1 ) ,
168 */
169 92
170 Q__NOTE(_C4 ) , 93 Q__NOTE(_C4 ) ,
171 Q__NOTE(_CS4 ) , 94 Q__NOTE(_CS4 ) ,
@@ -178,6 +101,7 @@ float tone_lw[][2] = {
178 Q__NOTE(_GS4 ) , 101 Q__NOTE(_GS4 ) ,
179 Q__NOTE(_A4 ) , 102 Q__NOTE(_A4 ) ,
180 Q__NOTE(_AS4 ) , 103 Q__NOTE(_AS4 ) ,
104
181 Q__NOTE(_B1 ) , 105 Q__NOTE(_B1 ) ,
182 106
183 Q__NOTE(_C2 ) , 107 Q__NOTE(_C2 ) ,
@@ -266,14 +190,7 @@ float tone_lw[][2] = {
266 Q__NOTE(_B8 ) , 190 Q__NOTE(_B8 ) ,
267}; 191};
268 192
269float tone_rs[][2] = { 193float tone_rs[][2] = SONG(ROCK_A_BYE_BABY);
270 Q__NOTE(_A4 ) ,
271 Q__NOTE(_A4 ) ,
272 Q__NOTE(_A4 ) ,
273 Q__NOTE(_A4 ) ,
274 Q__NOTE(_AS8 ) ,
275 Q__NOTE(_B8 ) ,
276};
277 194
278void matrix_init_user(void) { 195void matrix_init_user(void) {
279 init_notes(); 196 init_notes();
@@ -282,3 +199,116 @@ void matrix_init_user(void) {
282} 199}
283 200
284#endif 201#endif
202
203
204void update_quad_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3, uint8_t layer4, bool order)
205{
206 if (order)
207 {
208 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2))
209 {
210 layer_on(layer3);
211 }
212 else
213 {
214 layer_off(layer3);
215 layer_off(layer4);
216 }
217 }
218 else
219 {
220 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2))
221 {
222 layer_on(layer4);
223 }
224 else
225 {
226 layer_off(layer3);
227 layer_off(layer4);
228 }
229 }
230}
231
232
233const uint16_t PROGMEM fn_actions[] = {
234};
235
236
237const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
238{
239
240 // MACRODOWN only works in this function
241 switch(id)
242 {
243 case M_LW:
244 if (record->event.pressed) {
245 #ifdef AUDIO_ENABLE
246 PLAY_NOTE_ARRAY(tone_lw, false, STACCATO);
247 #endif
248 layer_on(_LW);
249 update_tri_layer(_LW, _RS, _AD);
250 } else {
251 layer_off(_LW);
252 update_tri_layer(_LW, _RS, _AD);
253 }
254 break;
255 case M_RS:
256 if (record->event.pressed) {
257 #ifdef AUDIO_ENABLE
258 PLAY_NOTE_ARRAY(tone_rs, false, LEGATO);
259 #endif
260 layer_on(_RS);
261 update_tri_layer(_LW, _RS, _AD);
262 } else {
263 layer_off(_RS);
264 update_tri_layer(_LW, _RS, _AD);
265 }
266 break;
267
268 case M_FN:
269 if (record->event.pressed) {
270 layer_on(_FN);
271 } else {
272 layer_off(_FN);
273 }
274 break;
275
276 case M_T1:
277 if (record->event.pressed) set_timbre(TIMBRE_12);
278 break;
279
280 case M_T2:
281 if (record->event.pressed) set_timbre(TIMBRE_25);
282 break;
283
284 case M_T3:
285 if (record->event.pressed) set_timbre(TIMBRE_50);
286 break;
287
288 case M_T4:
289 if (record->event.pressed) set_timbre(TIMBRE_75);
290 break;
291
292
293 case M_TU:
294 if (record->event.pressed) increase_tempo(10);
295 break;
296
297 case M_TD:
298 if (record->event.pressed) decrease_tempo(10);
299 break;
300
301 case M_DF:
302 if (record->event.pressed)
303 {
304 set_timbre(TIMBRE_DEFAULT);
305 set_tempo(TEMPO_DEFAULT);
306 }
307 break;
308
309 default:
310 break;
311
312 }
313 return MACRO_NONE;
314}; \ No newline at end of file
diff --git a/keyboard/atomic/keymaps/pvc/makefile.mk b/keyboard/atomic/keymaps/pvc/makefile.mk
index d46996650..eefa42855 100644
--- a/keyboard/atomic/keymaps/pvc/makefile.mk
+++ b/keyboard/atomic/keymaps/pvc/makefile.mk
@@ -1,7 +1,7 @@
1BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) 1BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
2MOUSEKEY_ENABLE = yes # Mouse keys(+4700) 2MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
3EXTRAKEY_ENABLE = yes # Audio control and System control(+450) 3EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
4CONSOLE_ENABLE = yes # Console for debug(+400) 4CONSOLE_ENABLE = no # Console for debug(+400)
5COMMAND_ENABLE = yes # Commands for debug and configuration 5COMMAND_ENABLE = yes # Commands for debug and configuration
6NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work 6NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
7BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality 7BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
diff --git a/quantum/audio.c b/quantum/audio.c
index 119bd9229..9b9589f13 100644
--- a/quantum/audio.c
+++ b/quantum/audio.c
@@ -4,7 +4,7 @@
4#include <avr/pgmspace.h> 4#include <avr/pgmspace.h>
5#include <avr/interrupt.h> 5#include <avr/interrupt.h>
6#include <avr/io.h> 6#include <avr/io.h>
7 7#include "print.h"
8#include "audio.h" 8#include "audio.h"
9#include "keymap_common.h" 9#include "keymap_common.h"
10 10
@@ -57,9 +57,11 @@ bool notes = false;
57bool note = false; 57bool note = false;
58float note_frequency = 0; 58float note_frequency = 0;
59float note_length = 0; 59float note_length = 0;
60float note_tempo = TEMPO_DEFAULT;
61float note_timbre = TIMBRE_DEFAULT;
60uint16_t note_position = 0; 62uint16_t note_position = 0;
61float (* notes_pointer)[][2]; 63float (* notes_pointer)[][2];
62uint8_t notes_length; 64uint8_t notes_count;
63bool notes_repeat; 65bool notes_repeat;
64float notes_rest; 66float notes_rest;
65bool note_resting = false; 67bool note_resting = false;
@@ -255,7 +257,8 @@ ISR(TIMER3_COMPA_vect) {
255 place = 0.0; 257 place = 0.0;
256 } 258 }
257 ICR3 = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)); // Set max to the period 259 ICR3 = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)); // Set max to the period
258 OCR3A = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) >> 1 * duty_place; // Set compare to half the period 260 OCR3A = (int)((((double)F_CPU) / (note_frequency * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
261 //OCR3A = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) >> 1 * duty_place; // Set compare to half the period
259 place++; 262 place++;
260 // if (duty_counter > (frequencies[voice_place] / 500)) { 263 // if (duty_counter > (frequencies[voice_place] / 500)) {
261 // duty_place = (duty_place % 3) + 1; 264 // duty_place = (duty_place % 3) + 1;
@@ -288,8 +291,7 @@ ISR(TIMER3_COMPA_vect) {
288 #else 291 #else
289 if (note_frequency > 0) { 292 if (note_frequency > 0) {
290 ICR3 = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)); // Set max to the period 293 ICR3 = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)); // Set max to the period
291 //OCR3A = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)) >> 1; // Set compare to half the period 294 OCR3A = (int)((((double)F_CPU) / (note_frequency * CPU_PRESCALER)) * note_timbre); // Set compare to half the period
292 OCR3A = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)) >> 2; // Set compare to half the period
293 } else { 295 } else {
294 ICR3 = 0; 296 ICR3 = 0;
295 OCR3A = 0; 297 OCR3A = 0;
@@ -305,7 +307,7 @@ ISR(TIMER3_COMPA_vect) {
305 end_of_note = (note_position >= (note_length * 0x7FF)); 307 end_of_note = (note_position >= (note_length * 0x7FF));
306 if (end_of_note) { 308 if (end_of_note) {
307 current_note++; 309 current_note++;
308 if (current_note >= notes_length) { 310 if (current_note >= notes_count) {
309 if (notes_repeat) { 311 if (notes_repeat) {
310 current_note = 0; 312 current_note = 0;
311 } else { 313 } else {
@@ -328,10 +330,10 @@ ISR(TIMER3_COMPA_vect) {
328 note_resting = false; 330 note_resting = false;
329 #ifdef PWM_AUDIO 331 #ifdef PWM_AUDIO
330 note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE; 332 note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
331 note_length = (*notes_pointer)[current_note][1]; 333 note_length = (*notes_pointer)[current_note][1] * (note_tempo / 100);
332 #else 334 #else
333 note_frequency = (*notes_pointer)[current_note][0]; 335 note_frequency = (*notes_pointer)[current_note][0];
334 note_length = (*notes_pointer)[current_note][1] / 4; 336 note_length = ((*notes_pointer)[current_note][1] / 4) * (note_tempo / 100);
335 #endif 337 #endif
336 } 338 }
337 note_position = 0; 339 note_position = 0;
@@ -345,7 +347,7 @@ ISR(TIMER3_COMPA_vect) {
345 } 347 }
346} 348}
347 349
348void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat, float n_rest) { 350void play_notes(float (*np)[][2], uint8_t n_count, bool n_repeat, float n_rest) {
349 351
350if (audio_config.enable) { 352if (audio_config.enable) {
351 353
@@ -354,7 +356,7 @@ if (audio_config.enable) {
354 notes = true; 356 notes = true;
355 357
356 notes_pointer = np; 358 notes_pointer = np;
357 notes_length = n_length; 359 notes_count = n_count;
358 notes_repeat = n_repeat; 360 notes_repeat = n_repeat;
359 notes_rest = n_rest; 361 notes_rest = n_rest;
360 362
@@ -362,10 +364,10 @@ if (audio_config.enable) {
362 current_note = 0; 364 current_note = 0;
363 #ifdef PWM_AUDIO 365 #ifdef PWM_AUDIO
364 note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE; 366 note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE;
365 note_length = (*notes_pointer)[current_note][1]; 367 note_length = (*notes_pointer)[current_note][1] * (note_tempo / 100);
366 #else 368 #else
367 note_frequency = (*notes_pointer)[current_note][0]; 369 note_frequency = (*notes_pointer)[current_note][0];
368 note_length = (*notes_pointer)[current_note][1] / 4; 370 note_length = ((*notes_pointer)[current_note][1] / 4) * (note_tempo / 100);
369 #endif 371 #endif
370 note_position = 0; 372 note_position = 0;
371 373
@@ -439,4 +441,32 @@ if (audio_config.enable && voices < 8) {
439 441
440} 442}
441 443
442} \ No newline at end of file 444}
445
446void set_timbre(float timbre)
447{
448 note_timbre = timbre;
449}
450
451void set_tempo(float tempo)
452{
453 note_tempo = tempo;
454}
455
456void decrease_tempo(uint8_t tempo_change)
457{
458 note_tempo += (float) tempo_change;
459}
460
461void increase_tempo(uint8_t tempo_change)
462{
463 if (note_tempo - (float) tempo_change < 10)
464 {
465 note_tempo = 10;
466 }
467 else
468 {
469 note_tempo -= (float) tempo_change;
470 }
471}
472
diff --git a/quantum/audio.h b/quantum/audio.h
index 762c98064..8012aa6bf 100644
--- a/quantum/audio.h
+++ b/quantum/audio.h
@@ -24,8 +24,12 @@ void play_note(double freq, int vol);
24void stop_note(double freq); 24void stop_note(double freq);
25void stop_all_notes(void); 25void stop_all_notes(void);
26void init_notes(void); 26void init_notes(void);
27void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat, float n_rest); 27void play_notes(float (*np)[][2], uint8_t n_count, bool n_repeat, float n_rest);
28 28
29void set_timbre(float timbre);
30void set_tempo(float tempo);
31void increase_tempo(uint8_t tempo_change);
32void decrease_tempo(uint8_t tempo_change);
29 33
30// These macros are used to allow play_notes to play an array of indeterminate 34// These macros are used to allow play_notes to play an array of indeterminate
31// length. This works around the limitation of C's sizeof operation on pointers. 35// length. This works around the limitation of C's sizeof operation on pointers.
diff --git a/quantum/musical_notes.h b/quantum/musical_notes.h
index d2256a773..2170f3f18 100644
--- a/quantum/musical_notes.h
+++ b/quantum/musical_notes.h
@@ -2,7 +2,8 @@
2#define MUSICAL_NOTES_H 2#define MUSICAL_NOTES_H
3 3
4// Tempo Placeholder 4// Tempo Placeholder
5#define TEMPO 120 5#define TEMPO_DEFAULT 100
6
6 7
7#define SONG(notes...) { notes } 8#define SONG(notes...) { notes }
8 9
@@ -21,7 +22,6 @@
21#define EIGHTH_DOT_NOTE(note) MUSICAL_NOTE(note, 8+4) 22#define EIGHTH_DOT_NOTE(note) MUSICAL_NOTE(note, 8+4)
22#define SIXTEENTH_DOT_NOTE(note) MUSICAL_NOTE(note, 4+2) 23#define SIXTEENTH_DOT_NOTE(note) MUSICAL_NOTE(note, 4+2)
23 24
24
25// Note Type Shortcuts 25// Note Type Shortcuts
26#define M__NOTE(note, duration) MUSICAL_NOTE(note, duration) 26#define M__NOTE(note, duration) MUSICAL_NOTE(note, duration)
27#define W__NOTE(n) WHOLE_NOTE(n) 27#define W__NOTE(n) WHOLE_NOTE(n)
@@ -41,6 +41,15 @@
41#define STACCATO 0.01 41#define STACCATO 0.01
42#define LEGATO 0 42#define LEGATO 0
43 43
44// Note Timbre
45// Changes how the notes sound
46#define TIMBRE_12 0.125
47#define TIMBRE_25 0.250
48#define TIMBRE_50 0.500
49#define TIMBRE_75 0.750
50#define TIMBRE_DEFAULT TIMBRE_50
51
52
44// Notes - # = Octave 53// Notes - # = Octave
45#define NOTE_REST 0.00 54#define NOTE_REST 0.00
46#define NOTE_C0 16.35 55#define NOTE_C0 16.35
diff --git a/quantum/song_list.h b/quantum/song_list.h
index ef25eac35..ef36a1cdd 100644
--- a/quantum/song_list.h
+++ b/quantum/song_list.h
@@ -9,4 +9,10 @@
9 Q__NOTE(_C4), Q__NOTE(_C4), Q__NOTE(_D4), Q__NOTE(_E4), \ 9 Q__NOTE(_C4), Q__NOTE(_C4), Q__NOTE(_D4), Q__NOTE(_E4), \
10 QD_NOTE(_E4), E__NOTE(_D4), H__NOTE(_D4), 10 QD_NOTE(_E4), E__NOTE(_D4), H__NOTE(_D4),
11 11
12#define ROCK_A_BYE_BABY \
13 QD_NOTE(_B4), E__NOTE(_D4), Q__NOTE(_B5), \
14 H__NOTE(_A5), Q__NOTE(_G5), \
15 QD_NOTE(_B4), E__NOTE(_D5), Q__NOTE(_G5), \
16 H__NOTE(_FS5),
17
12#endif \ No newline at end of file 18#endif \ No newline at end of file