-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathSequencer.cpp
More file actions
126 lines (104 loc) · 2.82 KB
/
Sequencer.cpp
File metadata and controls
126 lines (104 loc) · 2.82 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "daisysp.h"
#include "daisy_patch.h"
#include <string>
using namespace daisy;
using namespace daisysp;
DaisyPatch patch;
int values[5];
bool trigs[5];
int stepNumber;
bool trigOut;
int menuPos;
bool inSubMenu;
void UpdateControls();
void UpdateOled();
void UpdateOutputs();
int main(void)
{
patch.Init(); // Initialize hardware (daisy seed, and patch)
//init global vars
stepNumber = 0;
trigOut = false;
menuPos = 0;
inSubMenu = false;
for(int i = 0; i < 5; i++)
{
values[i] = 0.f;
trigs[i] = false;
}
patch.StartAdc();
while(1)
{
UpdateControls();
UpdateOled();
UpdateOutputs();
}
}
void UpdateControls()
{
patch.ProcessAnalogControls();
patch.ProcessDigitalControls();
//encoder
//can we simplify the menu logic?
if(!inSubMenu)
{
menuPos += patch.encoder.Increment();
menuPos = (menuPos % 10 + 10) % 10;
if(menuPos < 5)
{
inSubMenu = patch.encoder.RisingEdge() ? true : false;
}
else
{
trigs[menuPos % 5] = patch.encoder.RisingEdge()
? !trigs[menuPos % 5]
: trigs[menuPos % 5];
}
}
else
{
values[menuPos] += patch.encoder.Increment();
values[menuPos] = values[menuPos] < 0.f ? 0.f : values[menuPos];
values[menuPos] = values[menuPos] > 60.f ? 60.f : values[menuPos];
inSubMenu = patch.encoder.RisingEdge() ? false : true;
}
//gate in
if(patch.gate_input[0].Trig() || patch.gate_input[1].Trig())
{
stepNumber++;
stepNumber %= 5;
trigOut = trigs[stepNumber];
}
}
void UpdateOled()
{
patch.display.Fill(false);
std::string str = "!";
char* cstr = &str[0];
patch.display.SetCursor(25 * stepNumber, 45);
patch.display.WriteString(cstr, Font_7x10, true);
//values and trigs
for(int i = 0; i < 5; i++)
{
sprintf(cstr, "%d", values[i]);
patch.display.SetCursor(i * 25, 10);
patch.display.WriteString(cstr, Font_7x10, true);
str = trigs[i % 5] ? "X" : "O";
patch.display.SetCursor(i * 25, 30);
patch.display.WriteString(cstr, Font_7x10, true);
}
//cursor
str = inSubMenu ? "@" : "o";
patch.display.SetCursor((menuPos % 5) * 25, (menuPos > 4) * 20);
patch.display.WriteString(cstr, Font_7x10, true);
patch.display.Update();
}
void UpdateOutputs()
{
patch.seed.dac.WriteValue(DacHandle::Channel::ONE,
round((values[stepNumber] / 12.f) * 819.2f));
patch.seed.dac.WriteValue(DacHandle::Channel::TWO,
round((values[stepNumber] / 12.f) * 819.2f));
patch.gate_output.Write(trigOut);
trigOut = false;
}