-
Notifications
You must be signed in to change notification settings - Fork 12
/
ModMatrix.h
167 lines (141 loc) · 4.77 KB
/
ModMatrix.h
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* SurgeXT for VCV Rack - a Surge Synth Team product
*
* A set of modules expressing Surge XT into the VCV Rack Module Ecosystem
*
* Copyright 2019 - 2024, Various authors, as described in the github
* transaction log.
*
* Surge XT for VCV Rack is released under the GNU General Public License
* 3.0 or later (GPL-3.0-or-later). A copy of the license is in this
* repository in the file "LICENSE" or at:
*
* or at https://www.gnu.org/licenses/gpl-3.0.en.html
*
* All source for Surge XT for VCV Rack is available at
* https://github.com/surge-synthesizer/surge-rack/
*/
#ifndef SURGE_XT_RACK_SRC_MODMATRIX_H
#define SURGE_XT_RACK_SRC_MODMATRIX_H
#include "SurgeXT.h"
#include "XTModule.h"
#include "rack.hpp"
#include <cstring>
#include "DebugHelpers.h"
#include "globals.h"
namespace sst::surgext_rack::modmatrix
{
struct ModMatrix : modules::XTModule
{
static constexpr int n_matrix_params{8};
static constexpr int n_mod_inputs{4};
enum ParamIds
{
TARGET0,
MATRIX_MOD_PARAM_0 = TARGET0 + n_matrix_params,
NUM_PARAMS = MATRIX_MOD_PARAM_0 + n_matrix_params * n_mod_inputs,
};
enum InputIds
{
MATRIX_MOD_INPUT,
NUM_INPUTS = MATRIX_MOD_INPUT + n_mod_inputs,
};
enum OutputIds
{
OUTPUT_0,
NUM_OUTPUTS = OUTPUT_0 + n_matrix_params
};
enum LightIds
{
NUM_LIGHTS
};
ModMatrix() : XTModule()
{
std::lock_guard<std::mutex> ltg(xtSurgeCreateMutex);
setupSurgeCommon(NUM_PARAMS, false, false);
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
for (int i = TARGET0; i <= TARGET0 + n_matrix_params; ++i)
{
auto name = std::string("Target ") + std::to_string(i + 1);
configParamNoRand(i, -10, 10, 0, name, "V");
}
for (int i = 0; i < n_matrix_params * n_mod_inputs; ++i)
{
int tp = paramModulatedBy(i + MATRIX_MOD_PARAM_0);
std::string name = std::string("Mod ") + std::to_string(i % 4 + 1) + " to Target " +
std::to_string(tp - TARGET0 + 1);
configParamNoRand(MATRIX_MOD_PARAM_0 + i, -1, 1, 0, name, "%", 0, 100);
}
for (int i = 0; i < n_mod_inputs; ++i)
{
configInput(MATRIX_MOD_INPUT + i, std::string("Modulator ") + std::to_string(i + 1));
}
for (int i = 0; i < n_matrix_params; ++i)
{
std::string name = std::string("Modulated Target ") + std::to_string(i + 1);
configOutput(OUTPUT_0 + i, name);
}
modulationAssistant.initialize(this);
}
std::string getName() override { return "ModMatrix"; }
float modulationDisplayValue(int paramId) override
{
return modulationAssistant.animValues[paramId - TARGET0];
}
static int modulatorIndexFor(int baseParam, int modulator)
{
int offset = baseParam - TARGET0;
return MATRIX_MOD_PARAM_0 + offset * n_mod_inputs + modulator;
}
static int paramModulatedBy(int modIndex)
{
int offset = modIndex - MATRIX_MOD_PARAM_0;
if (offset >= n_mod_inputs * (n_matrix_params + 1) || offset < 0)
return -1;
return offset / n_mod_inputs + TARGET0;
}
bool isBipolar(int paramId) override
{
if (paramId >= TARGET0 && paramId < TARGET0 + n_matrix_params)
return true;
return false;
}
modules::ModulationAssistant<ModMatrix, n_matrix_params, TARGET0, n_mod_inputs,
MATRIX_MOD_INPUT>
modulationAssistant;
static constexpr int slowUpdate{8};
int blockPos{slowUpdate};
int polyDepth{1}, polyDepthBy4{1};
int polyChannelCount() { return polyDepth; }
void process(const ProcessArgs &args) override
{
if (blockPos == slowUpdate)
{
modulationAssistant.setupMatrix(this);
blockPos = 0;
auto npd = 1;
for (int i = MATRIX_MOD_INPUT; i < MATRIX_MOD_INPUT + n_mod_inputs; i++)
{
auto pd = inputs[i].getChannels();
npd = std::max(npd, pd);
}
polyDepth = npd;
polyDepthBy4 = (polyDepth - 1) / 4 + 1;
blockPos = 0;
for (int i = OUTPUT_0; i < OUTPUT_0 + n_matrix_params; ++i)
outputs[i].setChannels(polyDepth);
}
modulationAssistant.updateValues(this);
for (int p = 0; p < polyDepthBy4; ++p)
{
for (int oi = OUTPUT_0; oi < OUTPUT_0 + n_matrix_params; oi++)
{
_mm_storeu_ps(outputs[oi].getVoltages(p * 4),
modulationAssistant.valuesSSE[oi - OUTPUT_0][p]);
}
}
blockPos++;
}
};
} // namespace sst::surgext_rack::modmatrix
#endif