Skip to content

Commit

Permalink
Merge pull request #24 from mattlongest/attenoff
Browse files Browse the repository at this point in the history
AttenOff: Improvements
  • Loading branch information
benirose authored Oct 8, 2022
2 parents 56f8fb2 + ceab582 commit 734bd40
Showing 1 changed file with 48 additions and 19 deletions.
67 changes: 48 additions & 19 deletions software/o_c_REV/HEM_AttenuateOffset.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,19 @@ public:
}

void Controller() {
mix_final = mix || Gate(0);
int prevSignal = 0;

ForEachChannel(ch)
{
int signal = Proportion(level[ch], 63, In(ch)) + (offset[ch] * ATTENOFF_INCREMENTS);
if (ch == 1 && mix_final) {
signal = signal + prevSignal;
}

// use the unconstrained signal for mixing
prevSignal = signal;

signal = constrain(signal, -HEMISPHERE_3V_CV, HEMISPHERE_MAX_CV);
Out(ch, signal);
}
Expand All @@ -46,44 +56,50 @@ public:
}

void OnButtonPress() {
if (++cursor > 3) cursor = 0;
if (++cursor > 4) cursor = 0;
ResetCursor();
}

void OnEncoderMove(int direction) {
uint8_t ch = cursor / 2;
if (cursor == 0 || cursor == 2) {
// Change offset voltage
int min = -HEMISPHERE_MAX_CV / ATTENOFF_INCREMENTS;
int max = HEMISPHERE_MAX_CV / ATTENOFF_INCREMENTS;
offset[ch] = constrain(offset[ch] + direction, min, max);
} else {
// Change level percentage
level[ch] = constrain(level[ch] + direction, 0, 63);
if (cursor == 4) {
mix = (direction > 0);
} else
{
uint8_t ch = cursor / 2;
if (cursor == 0 || cursor == 2) {
// Change offset voltage
int min = -HEMISPHERE_MAX_CV / ATTENOFF_INCREMENTS;
int max = HEMISPHERE_MAX_CV / ATTENOFF_INCREMENTS;
offset[ch] = constrain(offset[ch] + direction, min, max);
} else {
// Change level percentage
level[ch] = constrain(level[ch] + direction, -63, 63);
}
}

}

uint64_t OnDataRequest() {
uint64_t data = 0;
Pack(data, PackLocation {0,9}, offset[0] + 256);
Pack(data, PackLocation {10,9}, offset[1] + 256);
Pack(data, PackLocation {19,6}, level[0]);
Pack(data, PackLocation {25,6}, level[1]);
Pack(data, PackLocation {19,7}, level[0] + 64);
Pack(data, PackLocation {26,7}, level[1] + 64);
Pack(data, PackLocation {34,1}, mix);
return data;
}

void OnDataReceive(uint64_t data) {
offset[0] = Unpack(data, PackLocation {0,9}) - 256;
offset[1] = Unpack(data, PackLocation {10,9}) - 256;
level[0] = Unpack(data, PackLocation {19,6});
level[1] = Unpack(data, PackLocation {25,6});
level[0] = Unpack(data, PackLocation {19,7}) - 64;
level[1] = Unpack(data, PackLocation {26,7}) - 64;
mix = Unpack(data, PackLocation {34,1});
}

protected:
void SetHelp() {
// "------------------" <-- Size Guide
help[HEMISPHERE_HELP_DIGITALS] = "";
help[HEMISPHERE_HELP_DIGITALS] = "1=Mix A&B";
help[HEMISPHERE_HELP_CVS] = "CV Inputs 1,2";
help[HEMISPHERE_HELP_OUTS] = "Outputs A,B";
help[HEMISPHERE_HELP_ENCODER] = "Offset V / Level %";
Expand All @@ -94,6 +110,8 @@ private:
int cursor;
int level[2];
int offset[2];
bool mix = false;
bool mix_final = false;

void DrawInterface() {
ForEachChannel(ch)
Expand All @@ -105,9 +123,20 @@ private:
gfxPrint("%");
}

int ch = cursor / 2;
if (cursor == 0 or cursor == 2) gfxCursor(13, 23 + (ch * 20), 36);
else gfxCursor(13, 33 + (ch * 20), 36);
if (mix_final) {
gfxLine(3, 24, 3, 31);
gfxIcon(0, 25, DOWN_BTN_ICON);
}

if (cursor == 4) {
if (CursorBlink()) {
gfxFrame(0, 24, 9, 10);
}
} else{
int ch = cursor / 2;
if (cursor == 0 or cursor == 2) gfxCursor(13, 23 + (ch * 20), 36);
else gfxCursor(13, 33 + (ch * 20), 36);
}
}

};
Expand Down

0 comments on commit 734bd40

Please sign in to comment.