Skip to content

Commit ea2f5a1

Browse files
committed
Added abstract class for callback algorithms;
(Will be changed to function pointers)
1 parent 5ac5fd7 commit ea2f5a1

File tree

3 files changed

+73
-16
lines changed

3 files changed

+73
-16
lines changed

src/matrix-sequencer.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "matrix-sequencer.hpp"
22

33

4-
Matrix_sequencer::Matrix_sequencer()
4+
Matrix_sequencer::Matrix_sequencer() : _current_step(0, 0, 0)
55
{
66
{
77
config(PARAMS_LEN, INPUTS_LEN, OUTPUTS_LEN, LIGHTS_LEN);
@@ -35,35 +35,41 @@ Matrix_sequencer::Matrix_sequencer()
3535
configOutput(TOTAL_PITCH_OUT_OUTPUT, "Sequence output");
3636
}
3737

38-
_run = false;
3938
_reset = false;
40-
_current_step = X4_Y4_LIGHT_LIGHT;
4139
}
4240

43-
void Matrix_sequencer::process(const ProcessArgs& args)
41+
42+
inline uint8_t Matrix_sequencer::translateCoords()
4443
{
45-
if (inputs[RUN_IN_INPUT].getVoltage())
46-
_run = !_run;
44+
return _current_step.x + (_current_step.y << 2);
45+
}
46+
4747

48+
void Matrix_sequencer::process(const ProcessArgs& args)
49+
{
4850
// Reset sequencer
4951
if (inputs[RESET_IN_INPUT].getVoltage())
5052
{
51-
lights[_current_step].setBrightness(0);
52-
_current_step = X4_Y4_LIGHT_LIGHT;
53+
lights[translateCoords()].setBrightness(0);
54+
_current_step = {0, 0, 0};
5355
}
5456

5557
// Process trigger clock
5658
if (clockTrigger.process(inputs[CLOCK_IN_INPUT].getVoltage()))
5759
{
5860
// Turn off current light
59-
lights[_current_step].setBrightness(0);
61+
lights[translateCoords()].setBrightness(0);
62+
63+
//------------ Current Step = chosen callback algorithm ------------//
64+
_current_step = static_cast<sequence_t>(SequnceAlgorithm_base(_current_step));
65+
float param_voltage = params[translateCoords()].getValue();
6066

61-
// Switch light
62-
_current_step++ ;
63-
_current_step %= LIGHTS_LEN;
67+
outputs[_current_step.y].setVoltage(param_voltage);
68+
outputs[_current_step.x + 3].setVoltage(param_voltage);
69+
outputs[TOTAL_PITCH_OUT_OUTPUT].setVoltage(param_voltage);
6470

6571
// Turn on new light
66-
lights[_current_step].setBrightness(1);
72+
lights[translateCoords()].setBrightness(1);
6773
}
6874
}
6975

src/matrix-sequencer.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define MATRIX_SEQUNCER
33

44
#include "plugin.hpp"
5+
#include "sequence_algorithm.hpp"
56

67
struct Matrix_sequencer : Module {
78
enum ParamId {
@@ -68,12 +69,11 @@ struct Matrix_sequencer : Module {
6869

6970
void process(const ProcessArgs& args) override;
7071

71-
void updateSequence();
72+
inline uint8_t translateCoords();
7273

7374
private:
74-
bool _run;
7575
bool _reset;
76-
uint8_t _current_step;
76+
sequence_t _current_step;
7777
dsp::SchmittTrigger clockTrigger;
7878
};
7979

src/sequence_algorithm.hpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef SEQUENCE_ALGORITHM
2+
#define SEQUENCE_ALGORITHM
3+
4+
#include <iostream>
5+
6+
struct sequence_t
7+
{
8+
uint8_t x;
9+
uint8_t y;
10+
uint8_t round;
11+
sequence_t(uint8_t _x, uint8_t _y, uint8_t _round) : x(_x), y(_y), round(_round) {}
12+
};
13+
14+
15+
struct SequnceAlgorithm_base : public sequence_t
16+
{
17+
SequnceAlgorithm_base(sequence_t current_step) : sequence_t(current_step)
18+
{
19+
callback();
20+
}
21+
22+
SequnceAlgorithm_base() = delete;
23+
24+
SequnceAlgorithm_base(const SequnceAlgorithm_base&) = delete;
25+
26+
SequnceAlgorithm_base(SequnceAlgorithm_base&&) = delete;
27+
28+
29+
private:
30+
virtual void callback()
31+
{
32+
uint8_t* direction = reinterpret_cast<uint8_t*>((&this->x) + (round & 1));
33+
uint8_t* shift = reinterpret_cast<uint8_t*>((&this->y) - (round & 1));
34+
35+
(*direction)++;
36+
37+
if ((*direction) > 3)
38+
{
39+
(*direction) = 0;
40+
(*shift)++ ;
41+
}
42+
43+
if ((*shift) > 3)
44+
{
45+
(*shift) = 0;
46+
this->round++ ;
47+
}
48+
};
49+
};
50+
51+
#endif

0 commit comments

Comments
 (0)