-
Notifications
You must be signed in to change notification settings - Fork 0
/
doNote.ino
47 lines (39 loc) · 1.67 KB
/
doNote.ino
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
void doNoteFunction(uint16_t noteToDac) {
// write new note if...
if (!glideEnabled || // glide is off...
(glideEnabled && !mode && glideLegato && activeNotePlates < 2) ||// or glideLegato is active, and only one key is pressed...
(glideEnabled && mode && glideLegato && !arpGlide)) { // or arpeggiator and glideLegato is active but arpGlide is false
writeDAC(noteToDac);
glideNote = noteToDac;
}
// glide function
if ((glideEnabled && !glideLegato) ||
(glideEnabled && !mode && glideLegato && activeNotePlates >= 2) ||
(glideEnabled && mode && glideLegato && arpGlide)) {
// get the note to which we are gliding to
glideStop = noteToDac;
// if it's the same, return
if (glideNote == glideStop){
return;
}
// Setup glide params for INT2, so it can increment/decrememnt glideNote
// in each tick with glide_step_per_tick
// glide_step_per_tick = (noteToDac - glideNote) / glide_time_ticks
// direction of sweep
if (glideNote < glideStop){ // up
glideDirection = GLIDE_DIRECTION_UP;
glide_step_per_tick = ((uint32_t)(noteToDac - glideNote) << 10) / totalGlideTicks;
glide_accumlator = (((uint32_t)glideNote) << 10) + glide_step_per_tick;
}
else { // down
glideDirection = GLIDE_DIRECTION_DOWN;
glide_step_per_tick = ((uint32_t)(glideNote - noteToDac) << 10) / totalGlideTicks;
glide_accumlator = (((uint32_t)glideNote) << 10) - glide_step_per_tick;
}
gliding = GLIDE_ON;
// calculate new gliding note
glideNote = glide_accumlator >> 10;
// refresh DAC
writeDAC(glideNote);
}
}