Skip to content

Commit b5ee6b7

Browse files
committed
modified: .gitignore
modified: src/matrix-sequencer.cpp modified: src/matrix-sequencer.hpp modified: src/sequence_algorithms.cpp modified: src/sequence_algorithms.hpp
1 parent 03310c2 commit b5ee6b7

File tree

5 files changed

+83
-16
lines changed

5 files changed

+83
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/*.dylib
66
/*.dll
77
.DS_Store
8+
/.vscode

src/matrix-sequencer.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Matrix_sequencer::Matrix_sequencer() : _current_step(0, 0, 0), _run(true), _reset(false)
55
{
66
_sequence_algorithms = {
7+
new StraightSequence(),
78
new LeftRight_UpDown(),
89
new SpiralSequence()
910
};
@@ -43,6 +44,7 @@ Matrix_sequencer::Matrix_sequencer() : _current_step(0, 0, 0), _run(true), _rese
4344
}
4445

4546
paramQuantities[ALGORITHM_KNOB_PARAM]->snapEnabled = true;
47+
_algorithm_type = params[ALGORITHM_KNOB_PARAM].getValue();
4648
}
4749

4850

@@ -68,15 +70,26 @@ void Matrix_sequencer::process(const ProcessArgs& args)
6870
_current_step = {0, 0, 0};
6971
}
7072

73+
_algorithm_type = params[ALGORITHM_KNOB_PARAM].getValue();
74+
if (inputs[ALGORITHM_FM_INPUT].isConnected())
75+
{
76+
_algorithm_type = std::ceil(inputs[ALGORITHM_FM_INPUT].getVoltage());
77+
78+
if (_algorithm_type >= _sequence_algorithms.size())
79+
_algorithm_type = _sequence_algorithms.size() - 1;
80+
81+
if (_algorithm_type < 0)
82+
_algorithm_type = 0;
83+
}
84+
7185
// Process trigger clock
7286
if (clockTrigger.process(inputs[CLOCK_IN_INPUT].getVoltage()))
7387
{
7488
// Turn off current light
7589
lights[translateCoords()].setBrightness(0);
7690

7791
//------------ Current Step = chosen callback algorithm ------------//
78-
// _current_step = static_cast<sequence_t>(SequnceAlgorithm_base(_current_step));
79-
_sequence_algorithms.at(params[ALGORITHM_KNOB_PARAM].getValue())->callback(_current_step);
92+
_sequence_algorithms.at(_algorithm_type)->callback(_current_step);
8093
float param_voltage = params[translateCoords()].getValue();
8194

8295
outputs[_current_step.y].setVoltage(param_voltage);

src/matrix-sequencer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct Matrix_sequencer : Module {
7979
private:
8080
bool _run;
8181
bool _reset;
82+
uint16_t _algorithm_type;
8283
sequence_t _current_step;
8384
dsp::SchmittTrigger clockTrigger;
8485
std::vector<SequenceAlgorithm_base*> _sequence_algorithms;

src/sequence_algorithms.cpp

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ void SequenceAlgorithm_base::callback(sequence_t &current_step)
55
throw std::runtime_error("Call of pure virtual function\n");
66
}
77

8+
9+
void StraightSequence::callback(sequence_t &current_step)
10+
{
11+
current_step.x++;
12+
if (current_step.x > 3)
13+
{
14+
current_step.x = 0;
15+
current_step.y++ ;
16+
}
17+
18+
if (current_step.y > 3)
19+
{
20+
current_step.y = 0;
21+
current_step.round++ ;
22+
}
23+
}
24+
25+
826
void LeftRight_UpDown::callback(sequence_t &current_step)
927
{
1028
uint8_t* direction = reinterpret_cast<uint8_t*>((&current_step.x) + (current_step.round & 1));
@@ -27,16 +45,46 @@ void LeftRight_UpDown::callback(sequence_t &current_step)
2745

2846
void SpiralSequence::callback(sequence_t &current_step)
2947
{
30-
current_step.x++;
31-
if (current_step.x > 3)
48+
// Change to inner spiral
49+
if ((current_step.y == (nearest + 1)) && (current_step.x == nearest))
3250
{
33-
current_step.x = 0;
34-
current_step.y++ ;
51+
furthest--;
52+
nearest++;
3553
}
36-
37-
if (current_step.y > 3)
54+
55+
// Down
56+
if ((current_step.x == furthest) && (current_step.y < furthest))
3857
{
39-
current_step.y = 0;
40-
current_step.round++ ;
58+
current_step.y++;
59+
return;
60+
}
61+
62+
// Right
63+
if ((current_step.x < furthest) && (current_step.y == nearest))
64+
{
65+
current_step.x++;
66+
return;
67+
}
68+
69+
// Left
70+
if ((current_step.y == furthest) && (current_step.x > nearest))
71+
{
72+
current_step.x--;
73+
return;
74+
}
75+
76+
// Up
77+
if ((current_step.x == nearest) && (current_step.y > nearest))
78+
{
79+
current_step.y--;
80+
return;
81+
}
82+
83+
// Reset
84+
else
85+
{
86+
current_step = {0, 0, 0};
87+
furthest = 3;
88+
nearest = 0;
4189
}
4290
}

src/sequence_algorithms.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ struct sequence_t
1818

1919
struct SequenceAlgorithm_base
2020
{
21-
// SequenceAlgorithm_base() = default;
22-
23-
// SequenceAlgorithm_base(const SequenceAlgorithm_base&) = default;
24-
25-
// SequenceAlgorithm_base(SequenceAlgorithm_base&&) = default;
26-
2721
// Override this function to implement own algorithm
2822
virtual void callback(sequence_t &current_step);
2923
};
3024

25+
struct StraightSequence : public SequenceAlgorithm_base
26+
{
27+
StraightSequence() = default;
28+
29+
void callback(sequence_t &current_step) override;
30+
};
31+
3132
struct LeftRight_UpDown : public SequenceAlgorithm_base
3233
{
3334
LeftRight_UpDown() = default;
@@ -40,6 +41,9 @@ struct SpiralSequence : public SequenceAlgorithm_base
4041
SpiralSequence() = default;
4142

4243
void callback(sequence_t &current_step) override;
44+
45+
private:
46+
uint8_t furthest = 3, nearest = 0;
4347
};
4448

4549
#endif

0 commit comments

Comments
 (0)