-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTransposer.cpp
56 lines (44 loc) · 1.08 KB
/
Transposer.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
52
53
54
55
56
#include "Arduino.h"
#include "Transposer.h"
#include "GlobalScales.h"
Transposer::Transposer(Snapshot *snapshot)
{
this->snapshot = snapshot;
}
void Transposer::clock()
{
this->clock_counter += 1;
if(this->clock_counter == this->clock_division)
{
this->clock_counter = 0;
this->step();
}
}
void Transposer::step()
{
this->pattern_step += 1;
if(this->pattern_step == 16) this->pattern_step = 0;
}
void Transposer::reset()
{
this->pattern_step = 0;
this->clock_counter = 0;
}
uint16_t Transposer::transpose(int16_t note_to_transpose, uint8_t song)
{
int table_index = TRANSPOSITION_TABLES[song][this->pattern_step];
int tranpose_amount = 0;
if(table_index < 0)
{
tranpose_amount = (int) NOTES[abs(table_index)] * -1;
}
else
{
tranpose_amount = (int) NOTES[table_index];
}
int transposed_value = (int) note_to_transpose + tranpose_amount;
if(transposed_value > 4095) transposed_value = 4095 - transposed_value;
if(transposed_value < 0) transposed_value = -1 * transposed_value;
transposed_value = constrain(transposed_value, 0, 4095);
return(transposed_value);
}