diff --git a/src/apps/sequencer/engine/StochasticEngine.cpp b/src/apps/sequencer/engine/StochasticEngine.cpp index 86fb6025..7cbae688 100644 --- a/src/apps/sequencer/engine/StochasticEngine.cpp +++ b/src/apps/sequencer/engine/StochasticEngine.cpp @@ -330,15 +330,17 @@ void StochasticEngine::triggerStep(uint32_t tick, uint32_t divisor, bool forNext if (stepIndex < 0) return; - int probability[12]; + auto &scale = sequence.selectedScale(_model.project().scale()); + + int probability[scale.notesPerOctave()]; int sum =0; - for (int i = 0; i < 12; ++i) { + for (int i = 0; i < scale.notesPerOctave(); ++i) { probability[i] = clamp(sequence.step(i).noteVariationProbability() + _stochasticTrack.noteProbabilityBias(), -1, StochasticSequence::NoteVariationProbability::Max); sum = sum + probability[i]; } if (sum==0) { return;} - stepIndex= getNextWeightedPitch(probability, sequence.reseed()); + stepIndex= getNextWeightedPitch(probability, sequence.reseed(), scale.notesPerOctave()); auto &step = sequence.step(stepIndex); @@ -428,11 +430,11 @@ void StochasticEngine::triggerStep(uint32_t tick, uint32_t divisor, bool forNext } -int StochasticEngine::getNextWeightedPitch(int *distr, bool reseed) { +int StochasticEngine::getNextWeightedPitch(int *distr, bool reseed, int notesPerOctave) { int total_weights = 0; - for(int i = 0; i < 12; i++) { - total_weights += distr[i % 12]; + for(int i = 0; i < notesPerOctave; i++) { + total_weights += distr[i % notesPerOctave]; } if (reseed) { @@ -441,8 +443,8 @@ int StochasticEngine::getNextWeightedPitch(int *distr, bool reseed) { } int rnd = 1 + ( std::rand() % ( (total_weights) - 1 + 1 ) ); - for(int i = 0; i < 12; i++) { - int weight = distr[i % 12]; + for(int i = 0; i < notesPerOctave; i++) { + int weight = distr[i % notesPerOctave]; if (rnd <= weight && weight > 0) { return i; } diff --git a/src/apps/sequencer/engine/StochasticEngine.h b/src/apps/sequencer/engine/StochasticEngine.h index 6c4a047a..1df37222 100644 --- a/src/apps/sequencer/engine/StochasticEngine.h +++ b/src/apps/sequencer/engine/StochasticEngine.h @@ -46,7 +46,7 @@ class StochasticEngine : public TrackEngine { void setMonitorStep(int index); - int getNextWeightedPitch(int *distr, bool reseed = false); + int getNextWeightedPitch(int *distr, bool reseed = false, int notesPerOctave = 12); private: void triggerStep(uint32_t tick, uint32_t divisor, bool nextStep); @@ -62,6 +62,7 @@ class StochasticEngine : public TrackEngine { TrackLinkData _linkData; + Project _project; StochasticSequence *_sequence; const StochasticSequence *_fillSequence; diff --git a/src/apps/sequencer/model/StochasticSequence.cpp b/src/apps/sequencer/model/StochasticSequence.cpp index 44f0ad7b..c5acb919 100644 --- a/src/apps/sequencer/model/StochasticSequence.cpp +++ b/src/apps/sequencer/model/StochasticSequence.cpp @@ -256,7 +256,9 @@ void StochasticSequence::clearSteps() { step.clear(); } - for (int i = 0; i < 12; ++i) { + + + for (int i = 0; i < 64; ++i) { _steps[i].setGate(false); _steps[i].setNoteVariationProbability(0); _steps[i].setNote(i); diff --git a/src/apps/sequencer/ui/pages/StochasticSequenceEditPage.cpp b/src/apps/sequencer/ui/pages/StochasticSequenceEditPage.cpp index 4e1bbcc0..f90b6030 100644 --- a/src/apps/sequencer/ui/pages/StochasticSequenceEditPage.cpp +++ b/src/apps/sequencer/ui/pages/StochasticSequenceEditPage.cpp @@ -64,6 +64,7 @@ void StochasticSequenceEditPage::enter() { updateMonitorStep(); _showDetail = false; + _section = 0; } void StochasticSequenceEditPage::exit() { @@ -94,7 +95,11 @@ void StochasticSequenceEditPage::draw(Canvas &canvas) { const int stepWidth = Width / StepCount; const int stepOffset = this->stepOffset(); - const int loopY = 16; + int stepsToDraw = scale.notesPerOctave(); + if (scale.notesPerOctave() % 16 != scale.notesPerOctave() && _section > 0) { + stepsToDraw = scale.notesPerOctave() % 16; + } + const int loopY = stepsToDraw; // Track Pattern Section on the UI @@ -109,14 +114,17 @@ void StochasticSequenceEditPage::draw(Canvas &canvas) { // draw loop points canvas.setBlendMode(BlendMode::Set); canvas.setColor(Color::Bright); - SequencePainter::drawLoopStart(canvas, (sequence.firstStep() - stepOffset) * stepWidth + 1, loopY, stepWidth - 2); - SequencePainter::drawLoopEnd(canvas, (sequence.lastStep() - stepOffset) * stepWidth + 1, loopY, stepWidth - 2); + SequencePainter::drawLoopStart(canvas, ((sequence.firstStep() - stepOffset) * stepWidth + 1)+((16 - stepsToDraw)*stepWidth)/2, loopY, stepWidth - 2); + SequencePainter::drawLoopEnd(canvas, ((sequence.lastStep() - stepOffset) * stepWidth + 1)+((16 - stepsToDraw)*stepWidth)/2, loopY, stepWidth - 2); + + + - for (int i = 0; i < 12; ++i) { + for (int i = 0; i < stepsToDraw; ++i) { int stepIndex = stepOffset + i; - const auto &step = sequence.step(stepIndex); + auto &step = sequence.step(stepIndex); - int x = i * stepWidth; + int x = (i * stepWidth) + ((16 - stepsToDraw)*stepWidth)/2 ; int y = 20; // loop @@ -404,13 +412,13 @@ void StochasticSequenceEditPage::keyPress(KeyPressEvent &event) { } } - + const auto &scale = sequence.selectedScale(_project.scale()); if (key.isLeft()) { if (key.shiftModifier()) { sequence.shiftSteps(_stepSelection.selected(), -1); } else { setSectionTracking(false); - _section = std::max(0, _section - 1); + _section = std::max(0, (_section - 1) ); } event.consume(); } @@ -418,8 +426,15 @@ void StochasticSequenceEditPage::keyPress(KeyPressEvent &event) { if (key.shiftModifier()) { sequence.shiftSteps(_stepSelection.selected(), 1); } else { - setSectionTracking(false); - _section = std::min(3, _section + 1); + int stepsToDraw = scale.notesPerOctave(); + if (scale.notesPerOctave() % 16 != scale.notesPerOctave() && _section > 0) { + stepsToDraw = scale.notesPerOctave() % 16; + } + + if (stepsToDraw > 16) { + setSectionTracking(false); + _section = std::min(3, _section + 1); + } } event.consume(); }