-
Notifications
You must be signed in to change notification settings - Fork 16
/
ModuleArpeggio.cpp
41 lines (31 loc) · 920 Bytes
/
ModuleArpeggio.cpp
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
#include "Arduino.h"
#include "ModuleArpeggio.h"
#include "defines.h"
ModuleArpeggio::ModuleArpeggio()
{
this->clocked = false;
this->step = 0;
this->my_output = 0;
// Initialize all inputs
this->root_note_input = NULL;
this->pattern_input = NULL;
this->clock_input = NULL;
}
uint16_t ModuleArpeggio::compute()
{
uint32_t clock = this->readInput(clock_input);
if((clock < MID_CV) && clocked) clocked = false;
if((clock >= MID_CV) && !clocked)
{
clocked = true;
// Read scale input.
// Convert the standard 12 bit CV value to a 3-bit value, which ranges from 0 to 7
uint32_t pattern = this->readInput(pattern_input, CONVERT_TO_3_BIT);
// Read root note
uint32_t root_note = this->readInput(root_note_input);
my_output = (arpeggiations[pattern][step] * 4096/60) + root_note;
step++;
if(step == 8) step = 0;
}
return(my_output);
}