Skip to content

Commit

Permalink
Changes from pull request Chysn#105
Browse files Browse the repository at this point in the history
  • Loading branch information
suit4 committed Jun 17, 2022
1 parent 6c5b738 commit 7daa2ca
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions software/o_c_REV/HEM_Carpeggio.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public:
replay = 0;
transpose = 0;
ImprintChord(2);
pitch_out_for_step();
}

void Controller() {
Expand All @@ -53,8 +54,8 @@ public:
step = (y * 4) + x;
pitch_out_for_step();
} else {
pitch_out_for_step();
if (++step > 15) step = 0;
pitch_out_for_step();
}
replay = 0;
} else if (replay) {
Expand Down Expand Up @@ -85,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 @@ -130,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 @@ -149,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 @@ -188,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 Expand Up @@ -237,4 +272,4 @@ uint32_t Carpeggio_OnDataRequest(bool hemisphere) {

void Carpeggio_OnDataReceive(bool hemisphere, uint32_t data) {
Carpeggio_instance[hemisphere].OnDataReceive(data);
}
}

0 comments on commit 7daa2ca

Please sign in to comment.