-
Notifications
You must be signed in to change notification settings - Fork 16
/
ModuleDrumSequencer.cpp
51 lines (41 loc) · 1.34 KB
/
ModuleDrumSequencer.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
42
43
44
45
46
47
48
49
50
51
#include "Arduino.h"
#include "ModuleDrumSequencer.h"
#include "defines.h"
ModuleDrumSequencer::ModuleDrumSequencer()
{
this->clocked = false;
this->step = 0;
// Initialize all inputs
this->clock_input = NULL;
this->kick_pattern_input = NULL;
this->snare_pattern_input = NULL;
this->hihat_pattern_input = NULL;
// Instantiate all outputs
kick_output = new ModuleOutput(this);
snare_output = new ModuleOutput(this);
hihat_output = new ModuleOutput(this);
}
uint16_t ModuleDrumSequencer::compute()
{
uint32_t clock = this->readInput(clock_input);
if((clock < MID_CV) && clocked)
{
clocked = false;
kick_output->value = 0;
snare_output->value = 0;
hihat_output->value = 0;
}
if((clock >= MID_CV) && !clocked)
{
clocked = true;
uint8_t kick_pattern = this->readInput(kick_pattern_input, CONVERT_TO_3_BIT);
uint8_t snare_pattern = this->readInput(snare_pattern_input, CONVERT_TO_3_BIT);
uint8_t hihat_pattern = this->readInput(hihat_pattern_input, CONVERT_TO_3_BIT);
kick_output->value = bitRead(patterns[0][kick_pattern], step) * MAX_CV;
snare_output->value = bitRead(patterns[1][snare_pattern], step) * MAX_CV;
hihat_output->value = bitRead(patterns[2][hihat_pattern], step) * MAX_CV;
step++;
if(step == 16) step = 0;
}
return(kick_output->value);
}