Skip to content

Commit

Permalink
Merge branch 'feature_47' of github.com:mebitek/performer into stocha…
Browse files Browse the repository at this point in the history
…stic
  • Loading branch information
mebitek committed Jan 8, 2024
2 parents 0cb64f2 + c66ae0b commit 49e47db
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- launchpad circuit mode improvements
- random generator: random seed just on init method
- patter follow
- pattern chain quick shortcut from pattern page

## v0.1.46 (4 January 2024)

Expand Down
65 changes: 46 additions & 19 deletions src/apps/sequencer/ui/pages/PatternPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "model/PlayState.h"

#include "core/utils/StringBuilder.h"
#include <iostream>

enum class Function {
Latch = 0,
Expand Down Expand Up @@ -268,32 +269,45 @@ void PatternPage::keyPress(KeyPressEvent &event) {
// select edit pattern
_project.setSelectedPatternIndex(pattern);
} else {
UserSettings userSettings = _model.settings().userSettings();

int _patternChangeDefault = userSettings.get<PatternChange>(SettingPatternChange)->getValue();

int otherKey = otherPressedStepKey(key.state(), key.step());
if (otherKey != -1) {
int sedondPattern = key.step();
int firstPattern = otherKey;
auto &song = _project.song();
song.chainPattern(firstPattern);
song.chainPattern(sedondPattern);

} else {

UserSettings userSettings = _model.settings().userSettings();

int _patternChangeDefault = userSettings.get<PatternChange>(SettingPatternChange)->getValue();

// select playing pattern
// select playing pattern

PlayState::ExecuteType executeType = PlayState::Immediate;
if (_latching) executeType = PlayState::Latched;
else if (_syncing && _patternChangeDefault==1) executeType = PlayState::Immediate;
else if (_syncing && _patternChangeDefault==0) executeType = PlayState::Synced;
else if (_patternChangeDefault==0) executeType = PlayState::Immediate;
else if (_patternChangeDefault==1) executeType = PlayState::Synced;
PlayState::ExecuteType executeType = PlayState::Immediate;
if (_latching) executeType = PlayState::Latched;
else if (_syncing && _patternChangeDefault==1) executeType = PlayState::Immediate;
else if (_syncing && _patternChangeDefault==0) executeType = PlayState::Synced;
else if (_patternChangeDefault==0) executeType = PlayState::Immediate;
else if (_patternChangeDefault==1) executeType = PlayState::Synced;

bool globalChange = true;
for (int trackIndex = 0; trackIndex < CONFIG_TRACK_COUNT; ++trackIndex) {
if (pageKeyState()[MatrixMap::fromTrack(trackIndex)]) {
playState.selectTrackPattern(trackIndex, pattern, executeType);
globalChange = false;
bool globalChange = true;
for (int trackIndex = 0; trackIndex < CONFIG_TRACK_COUNT; ++trackIndex) {
if (pageKeyState()[MatrixMap::fromTrack(trackIndex)]) {
playState.selectTrackPattern(trackIndex, pattern, executeType);
globalChange = false;
}
}
if (globalChange) {
playState.selectPattern(pattern, executeType);
_project.setSelectedPatternIndex(pattern);
}
}
if (globalChange) {
playState.selectPattern(pattern, executeType);
_project.setSelectedPatternIndex(pattern);
}
event.consume();
}
event.consume();
}

if (key.isLeft()) {
Expand All @@ -306,6 +320,19 @@ void PatternPage::keyPress(KeyPressEvent &event) {
}
}

int *PatternPage::getPressedKeySteps(Key key) {
int *keys = new int [16];
for (int i=9, j=0; i < 25; ++i) {
auto s = key.state(i);
if (s == 1) {
keys[j] = i;
j++;
}
}

return keys;
}

void PatternPage::encoder(EncoderEvent &event) {
_project.editSelectedPatternIndex(event.value(), event.pressed());
}
Expand Down
22 changes: 22 additions & 0 deletions src/apps/sequencer/ui/pages/PatternPage.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include "BasePage.h"
#include "ui/KeyPressEventTracker.h"


class PatternPage : public BasePage {
public:
Expand All @@ -21,6 +23,8 @@ class PatternPage : public BasePage {
virtual void keyPress(KeyPressEvent &event) override;
virtual void encoder(EncoderEvent &event) override;

int *getPressedKeySteps(Key key);

private:
void contextShow();
void contextAction(int index);
Expand All @@ -35,4 +39,22 @@ class PatternPage : public BasePage {
bool _latching = false;
bool _syncing = false;
int8_t _snapshotTargetPattern = -1;

KeyPressEventTracker _keyPressEventTracker;

int otherPressedStepKey(const KeyState &keyState, int step) const {
bool found = false;
int other = -1;
for (int i = 0; i < 16; ++i) {
if (i != step && keyState[MatrixMap::fromStep(i)]) {
if (found) {
return -1;
} else {
other = i;
found = true;
}
}
}
return other;
}
};

0 comments on commit 49e47db

Please sign in to comment.