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

Display labels and values to ADSREG #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions software/o_c_REV/HEM_ADSREG.ino
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,15 @@ public:
}

void View() {
int adsr[4] = {attack, decay, sustain, release};
char *labels[] = {"Attack","Decay","Sustain","Release"};

gfxHeader(applet_name());
gfxPos(1, 15);
gfxPrint(labels[edit_stage]);
gfxPrint(45 + 18 - digitCount(adsr[edit_stage]) * 6, 15, adsr[edit_stage]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be beneficial to the next person to pull the equation of the first arg out into its own variable with a comment. This way there's less logic inline and less to consider while you're reading it.

gfxCursor(46, 23, 17);

DrawIndicator();
DrawADSR();
}
Expand Down
9 changes: 9 additions & 0 deletions software/o_c_REV/HemisphereApplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ class HemisphereApplet {
return padding;
}

int digitCount(int n) {
int count = 0;
while (n != 0) {
n /= 10; // n = n/10
++count;
}
return count;
}
Comment on lines +282 to +289

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, by no means a blocker, but I'm of the school of thought where we should avoid imperative-style code as well as potentially infinite loops. My brain is a little fried right now because I've been jumping between PRs all morning, but my instincts are telling me there might be a cleaner and safer way to write this method.

I could 100% be wrong and you could have tried a million things, in which case, ignore my dumb butt :p

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty much the canonical way to count digits in C. No int exists that will cause an infinite loop, and log10() is much slower.


//////////////// Hemisphere-specific graphics methods
////////////////////////////////////////////////////////////////////////////////

Expand Down