From bbe0dd00f0061383ebdf49ed3d6f47449d639114 Mon Sep 17 00:00:00 2001 From: Christian Colglazier Date: Mon, 14 Sep 2020 14:14:10 -0400 Subject: [PATCH] Centered text --- src/droplets/noise_droplet.cpp | 14 +++++++++++++- src/droplets/noise_droplet.h | 1 + src/main.cpp | 11 ++++++++--- src/util.cpp | 19 +++++++++++++++++++ src/util.h | 13 +++++++++++++ 5 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/droplets/noise_droplet.cpp b/src/droplets/noise_droplet.cpp index 9b85bce..67fc25d 100644 --- a/src/droplets/noise_droplet.cpp +++ b/src/droplets/noise_droplet.cpp @@ -28,5 +28,17 @@ void NoiseDroplet::Process(float** in, float** out, size_t size) { } void NoiseDroplet::Draw() { - WriteString(*patch, 0, 30, Font_6x8, "Test"); + DrawName(patch); +} + + +void NoiseDroplet::DrawName(DaisyPatch* patch) { + int min = 0; + int max = SSD1309_WIDTH; + if (state == DropletState::kLeft) { + max = SSD1309_WIDTH / 2; + } else if (state == DropletState::kRight) { + min = SSD1309_WIDTH / 2; + } + WriteCenteredString(*patch, (min + max) / 2, 0, Font_6x8, "Noise"); } diff --git a/src/droplets/noise_droplet.h b/src/droplets/noise_droplet.h index 4ef697c..c51d1bb 100644 --- a/src/droplets/noise_droplet.h +++ b/src/droplets/noise_droplet.h @@ -14,6 +14,7 @@ class NoiseDroplet: public Droplet { DaisyPatch* patch; daisysp::WhiteNoise noise; daisysp::NlFilt filter; + void DrawName(DaisyPatch*); public: NoiseDroplet(DaisyPatch*, float, DropletState); void Control(); diff --git a/src/main.cpp b/src/main.cpp index 299fa47..8ade0d0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,9 @@ Droplet* droplet; int main(void) { patch.Init(); float samplerate = patch.AudioSampleRate(); - droplet = new NoiseDroplet(&patch, samplerate, DropletState::kFull); + droplet = new NoiseDroplet(&patch, + samplerate, + DropletState::kFull); patch.StartAdc(); patch.StartAudio(AudioThrough); @@ -39,7 +41,8 @@ void ProcessControls() { } } else { if (patch.encoder.Pressed()) { - if (patch.encoder.TimeHeldMs() > 500 && patch.encoder.TimeHeldMs() < 505) { + if (patch.encoder.TimeHeldMs() > 500 && + patch.encoder.TimeHeldMs() < 505) { menu.SetInMenu(true); } } @@ -59,7 +62,9 @@ void ProcessOled() { patch.display.Update(); } -static void AudioThrough(float **in, float **out, size_t size) { +static void AudioThrough(float **in, + float **out, + size_t size) { patch.UpdateAnalogControls(); droplet->Process(in, out, size); } diff --git a/src/util.cpp b/src/util.cpp index db1cda2..8d47094 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -28,3 +28,22 @@ void WriteString(DaisyPatch patch, std::string text) { WriteString(patch, x, y, font, text, true); } + +void WriteCenteredString(DaisyPatch patch, + int x, + int y, + FontDef font, + std::string text, + bool on) { + + int text_width = font.FontWidth * text.size(); + WriteString(patch, x - (text_width / 2), y, font, text, on); +} + +void WriteCenteredString(DaisyPatch patch, + int x, + int y, + FontDef font, + std::string text) { + WriteCenteredString(patch, x, y, font, text, true); +} diff --git a/src/util.h b/src/util.h index f5c720b..b22ba9b 100644 --- a/src/util.h +++ b/src/util.h @@ -29,4 +29,17 @@ void WriteString(DaisyPatch, FontDef, std::string); +void WriteCenteredString(DaisyPatch, + int, + int, + FontDef, + std::string, + bool); + +void WriteCenteredString(DaisyPatch, + int, + int, + FontDef, + std::string); + #endif // CASCADE_UTIL_H_