Skip to content

Commit

Permalink
finalize channel and shape contructors
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcBoule committed Oct 15, 2023
1 parent 37e62de commit bfe528b
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 48 deletions.
60 changes: 30 additions & 30 deletions src/ShapeMaster/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,37 @@



Channel::Channel(int _chanNum, bool* _running, uint32_t* _sosEosEoc, ClockDetector* _clockDetector, Input* _inputs, Output* _outputs, Param* _params, ParamQuantity* pqReps, PresetAndShapeManager* _presetAndShapeManager) {
chanNum = _chanNum;
running = _running;
if (_inputs) {
inInput = &_inputs[IN_INPUTS + chanNum];
scInput = &_inputs[SIDECHAIN_INPUT];
}
if (_outputs) {
outOutput = &_outputs[OUT_OUTPUTS + chanNum];
cvOutput = &_outputs[CV_OUTPUTS + chanNum];
}
hpFilter.setParameters(true, 0.1f);
lpFilter.setParameters(false, 0.4f);

paPhase = &_params[PHASE_PARAM + chanNum * NUM_CHAN_PARAMS];
paResponse = &_params[RESPONSE_PARAM + chanNum * NUM_CHAN_PARAMS];
paWarp = &_params[WARP_PARAM + chanNum * NUM_CHAN_PARAMS];
paAmount = &_params[AMOUNT_PARAM + chanNum * NUM_CHAN_PARAMS];
paSlew = &_params[SLEW_PARAM + chanNum * NUM_CHAN_PARAMS];
paSmooth = &_params[SMOOTH_PARAM + chanNum * NUM_CHAN_PARAMS];
paCrossover = &_params[CROSSOVER_PARAM + chanNum * NUM_CHAN_PARAMS];
paHigh = &_params[HIGH_PARAM + chanNum * NUM_CHAN_PARAMS];
paLow = &_params[LOW_PARAM + chanNum * NUM_CHAN_PARAMS];
paPrevNextPreSha = &_params[PREV_NEXT_PRE_SHA + chanNum * NUM_CHAN_PARAMS];
smoothFilter.setParameters(false, 0.4f);
presetAndShapeManager = _presetAndShapeManager;// can be null
clockDetector = _clockDetector;
playHead.construct(_chanNum, _sosEosEoc, _clockDetector, _running, pqReps, &_params[chanNum * NUM_CHAN_PARAMS], &_inputs[TRIG_INPUTS + chanNum], &scEnvelope, _presetAndShapeManager, &nodeTrigPulseGen, &nodeTrigDuration);
// Channel::Channel(int _chanNum, bool* _running, uint32_t* _sosEosEoc, ClockDetector* _clockDetector, Input* _inputs, Output* _outputs, Param* _params, ParamQuantity* pqReps, PresetAndShapeManager* _presetAndShapeManager, std::atomic_flag* lock_shape) {
// chanNum = _chanNum;
// running = _running;
// if (_inputs) {
// inInput = &_inputs[IN_INPUTS + chanNum];
// scInput = &_inputs[SIDECHAIN_INPUT];
// }
// if (_outputs) {
// outOutput = &_outputs[OUT_OUTPUTS + chanNum];
// cvOutput = &_outputs[CV_OUTPUTS + chanNum];
// }
// hpFilter.setParameters(true, 0.1f);
// lpFilter.setParameters(false, 0.4f);

// paPhase = &_params[PHASE_PARAM + chanNum * NUM_CHAN_PARAMS];
// paResponse = &_params[RESPONSE_PARAM + chanNum * NUM_CHAN_PARAMS];
// paWarp = &_params[WARP_PARAM + chanNum * NUM_CHAN_PARAMS];
// paAmount = &_params[AMOUNT_PARAM + chanNum * NUM_CHAN_PARAMS];
// paSlew = &_params[SLEW_PARAM + chanNum * NUM_CHAN_PARAMS];
// paSmooth = &_params[SMOOTH_PARAM + chanNum * NUM_CHAN_PARAMS];
// paCrossover = &_params[CROSSOVER_PARAM + chanNum * NUM_CHAN_PARAMS];
// paHigh = &_params[HIGH_PARAM + chanNum * NUM_CHAN_PARAMS];
// paLow = &_params[LOW_PARAM + chanNum * NUM_CHAN_PARAMS];
// paPrevNextPreSha = &_params[PREV_NEXT_PRE_SHA + chanNum * NUM_CHAN_PARAMS];
// smoothFilter.setParameters(false, 0.4f);
// presetAndShapeManager = _presetAndShapeManager;// can be null
// clockDetector = _clockDetector;
// playHead.construct(_chanNum, _sosEosEoc, _clockDetector, _running, pqReps, &_params[chanNum * NUM_CHAN_PARAMS], &_inputs[TRIG_INPUTS + chanNum], &scEnvelope, _presetAndShapeManager, &nodeTrigPulseGen, &nodeTrigDuration);

onReset(false); // redundant since ShapeMaster::onReset() will propagate to Channel::onReset(), but keep to reset anyways for static code analysis warnings (but we can avoid withParams at least)
}
// onReset(false); // redundant since ShapeMaster::onReset() will propagate to Channel::onReset(), but keep to reset anyways for static code analysis warnings (but we can avoid withParams at least)
// }

void Channel::onReset(bool withParams) {
if (withParams) {
Expand Down
38 changes: 34 additions & 4 deletions src/ShapeMaster/Channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,41 @@ class Channel {
PresetAndShapeManager* presetAndShapeManager = nullptr;
ClockDetector* clockDetector = nullptr;
bool prevNextButtonsClicked[4] = {};// matches the PREV_NEXT_PRE_SHA param
dsp::SchmittTrigger arrowButtonTriggers[4] = {};
dsp::SchmittTrigger arrowButtonTriggers[4] = {};

public:

Channel(int _chanNum, bool* _running, uint32_t* _sosEosEoc, ClockDetector* _clockDetector, Input* _inputs, Output* _outputs, Param* _params, ParamQuantity* pqReps, PresetAndShapeManager* _presetAndShapeManager);
Channel(int _chanNum, bool* _running, uint32_t* _sosEosEoc, ClockDetector* _clockDetector, Input* _inputs, Output* _outputs, Param* _params, ParamQuantity* pqReps, PresetAndShapeManager* _presetAndShapeManager, std::atomic_flag* lock_shape) : shape(lock_shape) {
chanNum = _chanNum;
running = _running;
if (_inputs) {
inInput = &_inputs[IN_INPUTS + chanNum];
scInput = &_inputs[SIDECHAIN_INPUT];
}
if (_outputs) {
outOutput = &_outputs[OUT_OUTPUTS + chanNum];
cvOutput = &_outputs[CV_OUTPUTS + chanNum];
}
hpFilter.setParameters(true, 0.1f);
lpFilter.setParameters(false, 0.4f);

paPhase = &_params[PHASE_PARAM + chanNum * NUM_CHAN_PARAMS];
paResponse = &_params[RESPONSE_PARAM + chanNum * NUM_CHAN_PARAMS];
paWarp = &_params[WARP_PARAM + chanNum * NUM_CHAN_PARAMS];
paAmount = &_params[AMOUNT_PARAM + chanNum * NUM_CHAN_PARAMS];
paSlew = &_params[SLEW_PARAM + chanNum * NUM_CHAN_PARAMS];
paSmooth = &_params[SMOOTH_PARAM + chanNum * NUM_CHAN_PARAMS];
paCrossover = &_params[CROSSOVER_PARAM + chanNum * NUM_CHAN_PARAMS];
paHigh = &_params[HIGH_PARAM + chanNum * NUM_CHAN_PARAMS];
paLow = &_params[LOW_PARAM + chanNum * NUM_CHAN_PARAMS];
paPrevNextPreSha = &_params[PREV_NEXT_PRE_SHA + chanNum * NUM_CHAN_PARAMS];
smoothFilter.setParameters(false, 0.4f);
presetAndShapeManager = _presetAndShapeManager;// can be null
clockDetector = _clockDetector;
playHead.construct(_chanNum, _sosEosEoc, _clockDetector, _running, pqReps, &_params[chanNum * NUM_CHAN_PARAMS], &_inputs[TRIG_INPUTS + chanNum], &scEnvelope, _presetAndShapeManager, &nodeTrigPulseGen, &nodeTrigDuration);

onReset(false); // redundant since ShapeMaster::onReset() will propagate to Channel::onReset(), but keep to reset anyways for static code analysis warnings (but we can avoid withParams at least)
}

void onReset(bool withParams);

Expand Down Expand Up @@ -202,14 +232,14 @@ class Channel {
if (withHistory) {
h = new ShapeCompleteChange;
h->shapeSrc = &shape;
h->oldShape = new Shape();
h->oldShape = new Shape(NULL);
shape.copyShapeTo(h->oldShape);
}

shape.randomizeShape(&randomSettings, getGridX(), getRangeIndex(), isDecoupledFirstAndLast());

if (withHistory) {
h->newShape = new Shape();
h->newShape = new Shape(NULL);
shape.copyShapeTo(h->newShape);
h->name = "randomise shape";
APP->history->push(h);
Expand Down
4 changes: 2 additions & 2 deletions src/ShapeMaster/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void ShapeMasterDisplay::onDragStart(const event::DragStart& e) {
// Push ShapeCompleteChange history action (rest is done in onDragEnd())
dragHistoryStep = new ShapeCompleteChange;
dragHistoryStep->shapeSrc = shape;
dragHistoryStep->oldShape = new Shape();
dragHistoryStep->oldShape = new Shape(NULL);
shape->copyShapeTo(dragHistoryStep->oldShape);
}
}
Expand Down Expand Up @@ -286,7 +286,7 @@ void ShapeMasterDisplay::onDragEnd(const event::DragEnd& e) {

// history
if (dragHistoryStep != NULL) {
dragHistoryStep->newShape = new Shape();
dragHistoryStep->newShape = new Shape(NULL);
shape->copyShapeTo(dragHistoryStep->newShape);
dragHistoryStep->name = "add/move step";
APP->history->push(dragHistoryStep);
Expand Down
8 changes: 6 additions & 2 deletions src/ShapeMaster/Shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ float Shape::applyScalingToCtrl(float ctrl, float exponent) {


void Shape::onReset() {
lockShapeBlocking();
if (lock_shape) {// needed here since we can construct with a NULL lock_shape (from channelDirtyCache) which will call the reset automatically, but all good after that
lockShapeBlocking();
}
points[0].x = 0.0f;// must be 0.0f
points[0].y = 0.0f;
points[1].x = 0.5f;
Expand All @@ -41,7 +43,9 @@ void Shape::onReset() {
numPts = 3;
pc = 0;// not saved
pcDelta = 0;// not saved
unlockShape();
if (lock_shape) {// see comment above
unlockShape();
}
}


Expand Down
7 changes: 2 additions & 5 deletions src/ShapeMaster/Shape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,10 @@ class Shape {
}


Shape() {
lock_shape = new std::atomic_flag(ATOMIC_FLAG_INIT);
Shape(std::atomic_flag* _lock_shape) {
lock_shape = _lock_shape;
onReset();
}
~Shape() {
delete lock_shape;
}

void onReset();

Expand Down
5 changes: 3 additions & 2 deletions src/ShapeMaster/ShapeMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ ShapeMaster::ShapeMaster() {// : worker(&ShapeMaster::worker_nextPresetOrShape,
configLight(SC_LPF_LIGHT, "Current channel sidechain LPF active");


channelDirtyCache = new Channel(0, &running, NULL, NULL, &inputs[0], &outputs[0], channelDirtyCacheParams, NULL, NULL);
channelDirtyCache = new Channel(0, &running, NULL, NULL, &inputs[0], &outputs[0], channelDirtyCacheParams, NULL, NULL, NULL);
channels.reserve(8);
presetAndShapeManager.construct(&(channels[0]), channelDirtyCache, &miscSettings3);
for (int c = 0; c < 8; c++) {
ParamQuantity* pqReps = paramQuantities[REPETITIONS_PARAM + c * NUM_CHAN_PARAMS];
channels.push_back(Channel(c, &running, &sosEosEoc, &clockDetector, &inputs[0], &outputs[0], &params[0], pqReps, &presetAndShapeManager));
std::atomic_flag* _lock_shape = &(lock_shape[c]);
channels.push_back(Channel(c, &running, &sosEosEoc, &clockDetector, &inputs[0], &outputs[0], &params[0], pqReps, &presetAndShapeManager, _lock_shape));
}

onReset();
Expand Down
1 change: 1 addition & 0 deletions src/ShapeMaster/ShapeMaster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct ShapeMaster : Module {
PresetAndShapeManager presetAndShapeManager;
Channel* channelDirtyCache;
Param channelDirtyCacheParams[NUM_CHAN_PARAMS] = {};
std::atomic_flag lock_shape[8] = {ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT};


ShapeMaster();
Expand Down
6 changes: 3 additions & 3 deletions src/ShapeMaster/Widgets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ struct ShapeCommandsButtons : OpaqueWidget {// must use Opaque since LightWidget
// Push ShapeCompleteChange history action (rest is done further below)
ShapeCompleteChange* h = new ShapeCompleteChange;
h->shapeSrc = channels[*currChan].getShape();
h->oldShape = new Shape();
h->oldShape = new Shape(NULL);
h->shapeSrc->copyShapeTo(h->oldShape);

// Internal memory version:
Expand Down Expand Up @@ -278,13 +278,13 @@ struct ShapeCommandsButtons : OpaqueWidget {// must use Opaque since LightWidget
buttonPressed = 1;

if (successPaste) {
h->newShape = new Shape();
h->newShape = new Shape(NULL);
h->shapeSrc->copyShapeTo(h->newShape);
h->name = "paste shape";
APP->history->push(h);
}
else {
delete h;// h->oldShape will be automatically deleted by desctructor
delete h;// h->oldShape will be automatically deleted by destructor
}
}
leftX += textWidthsPx[1];
Expand Down

0 comments on commit bfe528b

Please sign in to comment.