Skip to content

Commit

Permalink
implemented setting the trigger conditions as a fourth parameter set
Browse files Browse the repository at this point in the history
  • Loading branch information
zueblin committed Apr 13, 2020
1 parent d1bbc35 commit 13a251a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 23 deletions.
35 changes: 31 additions & 4 deletions Software/Polaron/Sequencer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ void Sequencer::doStep() {
step.params.parameter6 = input2.getValue();
}
break;

case PLockParamSet::SET4:
step.triggerMask = triggerPattern;
break;
}
}
if (!tracks[i].isMuted() && step.isTriggerOn() && step.isTriggerConditionOn()) {
Expand Down Expand Up @@ -168,6 +172,12 @@ void Sequencer::updateState() {


hasActivePLockReceivers = false;
for (int i = 0; i < NUMBER_OF_INSTRUMENTTRACKS; i++) {
if (tracks[i].getCurrentPattern().isInPLockMode()) {
hasActivePLockReceivers = true;
break;
}
}

if (functionButtons[BUTTON_SET_PARAMSET_1].rose()) {
pLockParamSet = PLockParamSet::SET1;
Expand All @@ -176,7 +186,12 @@ void Sequencer::updateState() {
pLockParamSet = PLockParamSet::SET2;
deactivateSensors();
} else if (functionButtons[BUTTON_SET_PARAMSET_3].rose()) {
pLockParamSet = PLockParamSet::SET3;
if (pLockParamSet == PLockParamSet::SET3){
pLockParamSet = PLockParamSet::SET4;
triggerPattern = 0b00111111;
} else {
pLockParamSet = PLockParamSet::SET3;
}
deactivateSensors();
}

Expand Down Expand Up @@ -226,8 +241,9 @@ void Sequencer::updateState() {
default:
break;
}

if (functionMode != FunctionMode::TOGGLE_MUTES && functionMode != FunctionMode::PATTERN_OPS && functionMode != FunctionMode::SET_TEMPO) {
if (hasActivePLockReceivers && pLockParamSet == PLockParamSet::SET4){
doSetTriggerConditions();
} else if (functionMode != FunctionMode::TOGGLE_MUTES && functionMode != FunctionMode::PATTERN_OPS && functionMode != FunctionMode::SET_TEMPO) {
// for all modes that do not use the track buttons in a special (non track selection) way
// do default track selection
doSetTrackSelection();
Expand Down Expand Up @@ -542,6 +558,17 @@ void Sequencer::doLeavePatternOps() {
nextPatternIndex = -1;
}

void Sequencer::doSetTriggerConditions(){
for (int i = 0; i < NUMBER_OF_INSTRUMENTTRACKS; i++) {
int idx = NUMBER_OF_INSTRUMENTTRACKS - i - 1;
if (trackButtons[i].rose()){
triggerPattern ^= _BV(idx);
}
trackLED(i) = triggerPattern & _BV(idx)? CRGB::Green : CRGB::CornflowerBlue;
}

}

void Sequencer::doSetTrackSelection() {
for (int i = 0; i < NUMBER_OF_INSTRUMENTTRACKS; i++) {
if (trackButtons[i].rose()) {
Expand Down Expand Up @@ -657,7 +684,7 @@ void Sequencer::setFunctionButtonLights() {
}
functionLED(BUTTON_SET_PARAMSET_1) = pLockParamSet == PLockParamSet::SET1 ? CRGB::Green : CRGB::CornflowerBlue;
functionLED(BUTTON_SET_PARAMSET_2) = pLockParamSet == PLockParamSet::SET2 ? CRGB::Green : CRGB::CornflowerBlue;
functionLED(BUTTON_SET_PARAMSET_3) = pLockParamSet == PLockParamSet::SET3 ? CRGB::Green : CRGB::CornflowerBlue;
functionLED(BUTTON_SET_PARAMSET_3) = pLockParamSet == PLockParamSet::SET3 ? CRGB::Green : (pLockParamSet == PLockParamSet::SET4) ? CRGB::SeaGreen : CRGB::CornflowerBlue;
}


Expand Down
4 changes: 3 additions & 1 deletion Software/Polaron/Sequencer.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ enum class FunctionMode {
LOAD_PROJECT,
SAVE_PROJECT
};
enum class PLockParamSet { SET1, SET2, SET3 };
enum class PLockParamSet { SET1, SET2, SET3, SET4 };

class Sequencer {
public:
Expand Down Expand Up @@ -140,6 +140,7 @@ class Sequencer {
uint8_t ledFader = 0;

uint8_t patternOpsArmState = 0;
uint8_t triggerPattern = 0;

// tracks state of step copy operation
int8_t sourceStepIndex = -1;
Expand Down Expand Up @@ -172,6 +173,7 @@ class Sequencer {
void doUpdateMutes();
void doTurnOffPlockMode();
void doSetTrackSelection();
void doSetTriggerConditions();
void doPatternOps();
void doLeavePatternOps();
void doSetTempo();
Expand Down
11 changes: 6 additions & 5 deletions Software/Polaron/SequencerPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SequencerPattern::SequencerPattern() : trackLength(NUMBER_OF_STEPS_PER_PATTERN)

void SequencerPattern::init(ParameterSet &defaultValues) {
for (int i = 0; i < NUMBER_OF_STEPS_PER_PATTERN; i++) {
steps[i].init(defaultValues,i, &triggerState, &pLockArmState, &loopCount);
steps[i].init(defaultValues,i, &triggerState, &pLockArmState, &currentIteration);
}
}

Expand All @@ -36,9 +36,7 @@ SequencerStep & SequencerPattern::doStep() {
if (autoMutate){
triggerState ^= triggerState << 2;
}
if (++loopCount >= 4){
loopCount = 0;
}
currentIteration++;
}
return getCurrentStep();
}
Expand Down Expand Up @@ -68,4 +66,7 @@ void SequencerPattern::togglePLockMode() {
}
}

void SequencerPattern::onStop() { currentStep = 16; }
void SequencerPattern::onStop() {
currentStep = 16;
currentIteration = 0b11111111;
}
8 changes: 2 additions & 6 deletions Software/Polaron/SequencerPattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ class SequencerPattern {
void setCurrentStepIndex(uint8_t index){
currentStep = index % NUMBER_OF_STEPS_PER_PATTERN;
}
void setLoopCount(uint8_t index){
loopCount = index;
}

void init(ParameterSet &defaultValues);
void copyValuesFrom(SequencerPattern sourcePattern);
Expand Down Expand Up @@ -73,9 +70,8 @@ class SequencerPattern {
SequencerStep steps[NUMBER_OF_STEPS_PER_PATTERN];

private:
int8_t currentStep = 16;
uint8_t loopCount = 4;

uint8_t currentStep = 16;
uint8_t currentIteration = 0b11111111;


};
Expand Down
11 changes: 7 additions & 4 deletions Software/Polaron/SequencerStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@

SequencerStep::SequencerStep() {}

void SequencerStep::init(ParameterSet &defaultValues, uint8_t stepIdx, uint16_t *trState, uint16_t *pLState, uint8_t *loopCnt) {
void SequencerStep::init(ParameterSet &defaultValues, uint8_t stepIdx, uint16_t *trState, uint16_t *pLState, uint8_t *patternIter) {

params = defaultValues;
stepIndex = stepIdx;
triggerState = trState;
pLockArmState = pLState;
loopCount = loopCnt;
triggerMask = 0b00001101;
patternIteration = patternIter;
triggerMask = 0b00111111;

}

Expand All @@ -50,7 +50,7 @@ bool SequencerStep::isTriggerOn() {
}

bool SequencerStep::isTriggerConditionOn() {
return triggerMask & _BV(*loopCount%4);
return triggerMask & _BV(*patternIteration % iterationMod);
}

void SequencerStep::toggleParameterLockRecord() {
Expand Down Expand Up @@ -94,6 +94,9 @@ void SequencerStep::copyValuesFrom(SequencerStep sourceStep) {
}
//state = sourceStep.state;
params = sourceStep.params;
triggerMask = sourceStep.triggerMask;
iterationMod = sourceStep.iterationMod;

}

/*
Expand Down
10 changes: 7 additions & 3 deletions Software/Polaron/SequencerStep.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,23 @@ class SequencerStep {
void setParameterLockRecordOff();
bool isParameterLockOn();
void copyValuesFrom(SequencerStep sourceStep);
void init(ParameterSet &defaultValues, uint8_t stepIdx, uint16_t *trState, uint16_t *pLState, uint8_t *loopCnt);
void init(ParameterSet &defaultValues, uint8_t stepIdx, uint16_t *trState, uint16_t *pLState, uint8_t *patternIter);

//uint8_t getState();
CRGB getColor();

ParameterSet params;

uint8_t triggerMask;
uint8_t iterationMod = 4;

private:
uint8_t stepIndex;
uint16_t *triggerState;
uint16_t *pLockArmState;
uint8_t *loopCount;
uint8_t triggerMask;
uint8_t *patternIteration;





Expand Down

0 comments on commit 13a251a

Please sign in to comment.