Skip to content

Commit 65b0edf

Browse files
committed
Added 'Run' option
1 parent ea2f5a1 commit 65b0edf

File tree

4 files changed

+72
-61
lines changed

4 files changed

+72
-61
lines changed

src/matrix-sequencer.cpp

Lines changed: 13 additions & 10 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() : _current_step(0, 0, 0)
4+
Matrix_sequencer::Matrix_sequencer() : _current_step(0, 0, 0), _run(true), _reset(false)
55
{
66
{
77
config(PARAMS_LEN, INPUTS_LEN, OUTPUTS_LEN, LIGHTS_LEN);
@@ -34,19 +34,17 @@ Matrix_sequencer::Matrix_sequencer() : _current_step(0, 0, 0)
3434
configOutput(X4_OUT_OUTPUT, "Out X:4");
3535
configOutput(TOTAL_PITCH_OUT_OUTPUT, "Sequence output");
3636
}
37-
38-
_reset = false;
3937
}
4038

4139

42-
inline uint8_t Matrix_sequencer::translateCoords()
40+
void Matrix_sequencer::process(const ProcessArgs& args)
4341
{
44-
return _current_step.x + (_current_step.y << 2);
45-
}
42+
// Stop / Run control
43+
if (!_run)
44+
for (auto& out : outputs)
45+
out.setVoltage(0);
4646

4747

48-
void Matrix_sequencer::process(const ProcessArgs& args)
49-
{
5048
// Reset sequencer
5149
if (inputs[RESET_IN_INPUT].getVoltage())
5250
{
@@ -63,7 +61,7 @@ void Matrix_sequencer::process(const ProcessArgs& args)
6361
//------------ Current Step = chosen callback algorithm ------------//
6462
_current_step = static_cast<sequence_t>(SequnceAlgorithm_base(_current_step));
6563
float param_voltage = params[translateCoords()].getValue();
66-
64+
6765
outputs[_current_step.y].setVoltage(param_voltage);
6866
outputs[_current_step.x + 3].setVoltage(param_voltage);
6967
outputs[TOTAL_PITCH_OUT_OUTPUT].setVoltage(param_voltage);
@@ -74,6 +72,12 @@ void Matrix_sequencer::process(const ProcessArgs& args)
7472
}
7573

7674

75+
inline uint8_t Matrix_sequencer::translateCoords()
76+
{
77+
return _current_step.x + (_current_step.y << 2);
78+
}
79+
80+
7781
Matrix_sequencerWidget::Matrix_sequencerWidget(Matrix_sequencer* module) {
7882
setModule(module);
7983
setPanel(createPanel(asset::plugin(pluginInstance, "res/matrix-sequencer.svg")));
@@ -133,5 +137,4 @@ Matrix_sequencerWidget::Matrix_sequencerWidget(Matrix_sequencer* module) {
133137
}
134138

135139

136-
137140
Model* modelMatrix_sequencer = createModel<Matrix_sequencer, Matrix_sequencerWidget>("matrix-sequencer");

src/matrix-sequencer.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ struct Matrix_sequencer : Module {
6969

7070
void process(const ProcessArgs& args) override;
7171

72+
private:
7273
inline uint8_t translateCoords();
7374

7475
private:
76+
bool _run;
7577
bool _reset;
7678
sequence_t _current_step;
7779
dsp::SchmittTrigger clockTrigger;

src/sequence_algorithm.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "sequence_algorithm.hpp"
2+
3+
void SequnceAlgorithm_base::callback()
4+
{
5+
uint8_t* direction = reinterpret_cast<uint8_t*>((&this->x) + (round & 1));
6+
uint8_t* shift = reinterpret_cast<uint8_t*>((&this->y) - (round & 1));
7+
8+
(*direction)++;
9+
if ((*direction) > 3)
10+
{
11+
(*direction) = 0;
12+
(*shift)++ ;
13+
}
14+
15+
if ((*shift) > 3)
16+
{
17+
(*shift) = 0;
18+
this->round++ ;
19+
}
20+
};

src/sequence_algorithm.hpp

Lines changed: 37 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,37 @@
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
1+
#ifndef SEQUENCE_ALGORITHM
2+
#define SEQUENCE_ALGORITHM
3+
4+
#include <cstdint>
5+
#include <iostream>
6+
7+
struct sequence_t
8+
{
9+
uint8_t x;
10+
uint8_t y;
11+
uint8_t round;
12+
sequence_t(uint8_t _x, uint8_t _y, uint8_t _round) : x(_x), y(_y), round(_round) {}
13+
};
14+
15+
16+
struct SequnceAlgorithm_base : public sequence_t
17+
{
18+
SequnceAlgorithm_base(sequence_t current_step) : sequence_t(current_step)
19+
{
20+
callback();
21+
}
22+
23+
SequnceAlgorithm_base() = delete;
24+
25+
SequnceAlgorithm_base(const SequnceAlgorithm_base&) = delete;
26+
27+
SequnceAlgorithm_base(SequnceAlgorithm_base&&) = delete;
28+
29+
30+
private:
31+
/* Default algorithm
32+
Override this function to implement own algorithm
33+
*/
34+
virtual void callback();
35+
};
36+
37+
#endif

0 commit comments

Comments
 (0)