-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuclid.cpp
More file actions
110 lines (97 loc) · 3.08 KB
/
Copy patheuclid.cpp
File metadata and controls
110 lines (97 loc) · 3.08 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "euclid.hpp"
void Euclidian::init()
{
stepsParam.Init(patch.controls[DaisyPatch::CTRL_1], 1, MAX_STEP+1, Parameter::LINEAR);
fillParam.Init(patch.controls[DaisyPatch::CTRL_2], 0, 1, Parameter::LINEAR);
rotParam.Init(patch.controls[DaisyPatch::CTRL_3], 0, 1, Parameter::LINEAR);
strPattern[MAX_STEP] = '\0';
}
void Euclidian::AudioCallback(const float* const*, float**, unsigned int)
{}
void Euclidian::refill_pattern()
{
uint16_t pulses = stepsCount * fill;
uint16_t rotation = stepsCount * rot;
uint16_t bucket = 0; //out variable to add pulses together for each step
//fill array with rhythm
for( int i=rotation ; i < stepsCount + rotation; i++){
bucket += pulses;
if(bucket >= stepsCount) {
bucket -= stepsCount;
pattern[i % stepsCount] = true;
} else {
pattern[i % stepsCount] = false;
}
}
int i = 0;
for( ; i < stepsCount; i++)
{
strPattern[i] = pattern[i] ? 'x' : '.';
}
for( ; i < MAX_STEP; i++)
{
strPattern[i] = ' ';
}
}
void Euclidian::processOled() {
patch.display.Fill(false);
patch.display.SetCursor(0,0);
patch.display.WriteString("EUCLIDIAN", Font_7x10, true);
printSimpleParam(1, "steps", stepsCount);
printSimpleParam(2, "fill", (int)(stepsCount * fill));
printSimpleParam(3, "rot", (int)(stepsCount * rot));
int drawstep = 0;
for (int line = 0; line < MAX_STEP/16; line++) {
for (int i =0; i < 16; i++) {
patch.display.SetCursor(7*i, 40 + line * 10);
if (drawstep == step) {
if (strPattern[drawstep] == 'x')
patch.display.WriteChar('X', Font_7x10, true);
if (strPattern[drawstep] == '.')
patch.display.WriteChar('_', Font_7x10, true);
} else {
patch.display.WriteChar(strPattern[drawstep], Font_7x10, true);
}
drawstep++;
}
}
patch.display.Update();
}
void Euclidian::processInput()
{
int new_steps_count = floorf(stepsParam.Process());
float new_fill = fillParam.Process();
float new_rot = rotParam.Process();
if (new_steps_count != stepsCount
|| -(int)(new_fill * 100) != (int)(fill * 100)
|| -(int)(new_rot * 100 != (int)(rot * 100)))
{
stepsCount = new_steps_count;
fill = new_fill;
rot = new_rot;
refill_pattern();
}
}
void Euclidian::processOutput()
{
if (patch.gate_input[1].Trig()) {
step = 0;
}
if (patch.gate_input[0].Trig()) {
if (pattern[step]) {
dsy_gpio_write(&patch.gate_output, 1);
patch.DelayMs(10);
dsy_gpio_write(&patch.gate_output, 0);
}
step++;
step %= stepsCount;
}
}
void Euclidian::process() {
processInput();
processOled();
processOutput();
}