-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathV1_1_animate.h
85 lines (81 loc) · 2.84 KB
/
V1_1_animate.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
/*
This section of the code handles
LED animation responsive to key
presses
*/
// Effective Nov 15, 2024, the structure is cleaned up
// to lean on the hex_t definition in utils.h
// and the lookup of buttons at each hex
//
// this library works, so far, on ortho coordinates
uint64_t animFrame(button_t& h) {
if (h.timePressed) { // 2^20 microseconds is close enough to 1 second
return 1 + (((runTime - h.timePressed) * animationFPS) >> 20);
} else {
return 0;
}
}
void flagToAnimate(hex_t x) {
if (hexBoard.in_bounds(x)) {
hexBoard.button_at_coord(x).animate = 1;
}
}
void animateMirror(music_key_t& h) {
if (h.MIDIch) { // that is a held note
for (auto j : hexBoard.keys) {
if ((j.pixel >= 0) && (!(j.MIDIch))) {
int16_t delta = h.stepsFromC - j.stepsFromC; // look at difference between notes
if (animationType == ANIMATE_OCTAVE) { // set octave diff to zero if need be
delta = positiveMod(delta, current.tuning().cycleLength);
}
j.animate = (!(delta)); // highlight if diff is zero
}
}
}
}
void animateOrbit(music_key_t& h) {
if (h.MIDIch && (h.inScale || (!scaleLock))) { // that is a held note
uint8_t dir = (animFrame(h) % 6);
flagToAnimate(h.coord + unitHex[dir]); // different neighbor each frame
}
}
void animateRadial(music_key_t& h) {
if (h.inScale || (!scaleLock)) { // that is a note
uint64_t radius = animFrame(h);
if ((radius > 0) && (radius < 16)) { // played in the last 16 frames
uint8_t steps = ((animationType == ANIMATE_SPLASH) ? radius : 1); // star = 1 step to next corner; ring = 1 step per hex
hex_t turtle = h.coord + (unitHex[dir_sw] * radius);
for (uint8_t dir = dir_e; dir < 6; dir++) { // walk along the ring in each of the 6 hex directions
for (uint8_t i = 0; i < steps; i++) { // # of steps to the next corner
flagToAnimate(turtle); // flag for animation
turtle = turtle + (unitHex[dir] * (radius / steps));
}
}
}
}
}
void animate_calculate_pixels() {
if (animationType) {
for (auto& h : hexBoard.keys) {
// clear animation flags
h.animate = 0;
if (h.pixel >= 0) {
// recalculate for every hex
switch (animationType) {
case ANIMATE_STAR: case ANIMATE_SPLASH:
animateRadial(h);
break;
case ANIMATE_ORBIT:
animateOrbit(h);
break;
case ANIMATE_OCTAVE: case ANIMATE_BY_NOTE:
animateMirror(h);
break;
default:
break;
}
}
}
}
}