Skip to content

Commit

Permalink
add graphics for envelope mode
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Mar 18, 2021
1 parent 79b738a commit ddfb967
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions bleepbloopmachine/src/main.cc
Expand Up @@ -129,7 +129,10 @@ Point getCoord(int idx) {
};
}

class SoundBlock {
#define MAX_ATTACK 400.0
#define MAX_DECAY 400.0

class SoundBlock {
public:
int note = 0;
int octave = 3;
Expand All @@ -154,14 +157,14 @@ Point getCoord(int idx) {
void noteDown() { note = wrapping_sub(note, 11); }
void octaveUp() { octave = wrapping_add(octave, 8); }
void octaveDown() { octave = wrapping_sub(octave, 8); }
void decayUp() { decay = saturating_add(decay, 400.0, 20.0, 0); }
void decayDown() { decay = saturating_sub(decay, 400.0, 20.0, 0); }
void decayUp() { decay = saturating_add(decay, MAX_DECAY, 20.0, 0); }
void decayDown() { decay = saturating_sub(decay, MAX_DECAY, 20.0, 0); }
void ampUp() { amp = saturating_add(amp, 1.0, 0.1, 0); }
void ampDown() { amp = saturating_sub(amp, 1.0, 0.1, 0); }
void panLeft() { pan = saturating_sub(pan, 1.0); }
void panRight() { pan = saturating_add(pan, 1.0); }
void attackUp() { attack = saturating_add(attack, 400.0, 20.0, 0); }
void attackDown() { attack = saturating_sub(attack, 400.0, 20.0, 0); }
void attackUp() { attack = saturating_add(attack, MAX_ATTACK, 20.0, 0); }
void attackDown() { attack = saturating_sub(attack, MAX_ATTACK, 20.0, 0); }
void sustainUp() { sustain = saturating_add(sustain, 1.0, 0.137, 0); }
void sustainDown() { sustain = saturating_sub(sustain, 1.0, 0.137, 0); }
SoundBlock cut() {
Expand Down Expand Up @@ -287,6 +290,26 @@ class Wave {
auto panX = ((BLOCK_SIZE / 2) * sound->pan) + BLOCK_SIZE / 2;
display->fillRect(point.x + panX, point.y + BLOCK_SIZE - 2, 2, 2,
ST7735_CYAN);

// draw attack/decay/sustain
auto envColor = ST7735_GREEN;
float attackX = ((float)BLOCK_SIZE / 2 / MAX_ATTACK) * sound->attack;
float decayW = ((float)BLOCK_SIZE / 2 / MAX_DECAY) * sound->decay;
/// attack/sus
display->drawLine(
point.x, point.y + BLOCK_SIZE, point.x + attackX,
(point.y + BLOCK_SIZE) - BLOCK_SIZE * sound->sustain, envColor);
/// decay/sus
display->drawLine(
point.x + attackX,
(point.y + BLOCK_SIZE) - BLOCK_SIZE * sound->sustain,
point.x + attackX + decayW, (point.y + BLOCK_SIZE), envColor);

// draw amp
auto ampY = BLOCK_SIZE * sound->amp;
display->fillRect(point.x + BLOCK_SIZE - 4,
point.y + (BLOCK_SIZE - ampY), 4, ampY,
ST7735_CYAN);
}
} else if (mode == MenuMode::menu2) {
display->drawPixel(point.x + 5, point.y + 5, ST7735_BLACK);
Expand Down Expand Up @@ -489,10 +512,10 @@ class BleepBloopMachine {
}
if (a_mode) {
if (released & PAD_RIGHT) {
sound->decayDown();
sound->decayUp();
}
if (released & PAD_LEFT) {
sound->decayUp();
sound->decayDown();
}
}
if (ab_mode) {
Expand Down

0 comments on commit ddfb967

Please sign in to comment.