Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shuffle functionality to Carpeggio to mix up notes on the grid #105

Open
wants to merge 1 commit into
base: production
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion software/o_c_REV/HEM_Carpeggio.ino
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,25 @@ public:
cursor = 0; // Don't advance cursor when chord is changed
ImprintChord(chord);
}
if (++cursor > 2) cursor = 0;
if (++cursor > 3) cursor = 0;
ResetCursor();
}

void OnEncoderMove(int direction) {
if (cursor == 0) sequence[step] = constrain(sequence[step] += direction, -24, 60);
if (cursor == 1) chord = constrain(chord += direction, 0, Nr_of_arp_chords - 1);
if (cursor == 2) transpose = constrain(transpose += direction, -24, 24);
if (cursor == 3) {
// only imprint cord when turning left from shuffle
if (shuffle && direction < 0) {
ImprintChord(sel_chord);
}
// shuffle chord every time we turn right
if (direction > 0) {
ShuffleChord();
}

}
if (cursor != 1) replay = 1;
}

Expand Down Expand Up @@ -131,6 +142,7 @@ private:
int chord; // Selected chord
int sel_chord; // Most recently-imprinted chord
int transpose; // Transposition setting (-24 ~ +24)
bool shuffle = false;

// Variables to handle imprint confirmation animation
int confirm_animation_countdown;
Expand All @@ -150,6 +162,12 @@ private:
gfxPrint(transpose);
if (cursor == 2) gfxCursor(32, 33, 30);

// Shuffle selector
gfxBitmap(37, 36, 8, PLAY_ICON);
gfxBitmap(49, 36, 8, LOOP_ICON);
gfxInvert(36 + (shuffle ? 12 : 0), 35, 10, 10);
if (cursor == 3) gfxCursor(37, 46, 20);

// Note name editor
uint8_t midi_note = constrain(sequence[step] + 36 + transpose, 0, 127);
gfxPrint(38, 50, midi_note_numbers[midi_note]);
Expand Down Expand Up @@ -189,6 +207,22 @@ private:
chord = new_chord;
confirm_animation_position = 16;
confirm_animation_countdown = HEM_CARPEGGIO_ANIMATION_SPEED;
shuffle = false;
}

void ShuffleChord() {
int16_t old; // temp var for note being swapped
int16_t rnd; // temp var for index of note swapping in
for (int i = 0; i < 16; i++) {
// set old to current step value
old = sequence[i];
rnd = random(0, 16);
sequence[i] = sequence[rnd];
sequence[rnd] = old;
}
confirm_animation_position = 16;
confirm_animation_countdown = HEM_CARPEGGIO_ANIMATION_SPEED;
shuffle = true;
}

void pitch_out_for_step() {
Expand Down