Centered text

This commit is contained in:
Christian Colglazier 2020-09-14 14:14:10 -04:00
parent cb7fdcf50b
commit bbe0dd00f0
5 changed files with 54 additions and 4 deletions

View File

@ -28,5 +28,17 @@ void NoiseDroplet::Process(float** in, float** out, size_t size) {
} }
void NoiseDroplet::Draw() { 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");
} }

View File

@ -14,6 +14,7 @@ class NoiseDroplet: public Droplet {
DaisyPatch* patch; DaisyPatch* patch;
daisysp::WhiteNoise noise; daisysp::WhiteNoise noise;
daisysp::NlFilt filter; daisysp::NlFilt filter;
void DrawName(DaisyPatch*);
public: public:
NoiseDroplet(DaisyPatch*, float, DropletState); NoiseDroplet(DaisyPatch*, float, DropletState);
void Control(); void Control();

View File

@ -18,7 +18,9 @@ Droplet* droplet;
int main(void) { int main(void) {
patch.Init(); patch.Init();
float samplerate = patch.AudioSampleRate(); float samplerate = patch.AudioSampleRate();
droplet = new NoiseDroplet(&patch, samplerate, DropletState::kFull); droplet = new NoiseDroplet(&patch,
samplerate,
DropletState::kFull);
patch.StartAdc(); patch.StartAdc();
patch.StartAudio(AudioThrough); patch.StartAudio(AudioThrough);
@ -39,7 +41,8 @@ void ProcessControls() {
} }
} else { } else {
if (patch.encoder.Pressed()) { 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); menu.SetInMenu(true);
} }
} }
@ -59,7 +62,9 @@ void ProcessOled() {
patch.display.Update(); 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(); patch.UpdateAnalogControls();
droplet->Process(in, out, size); droplet->Process(in, out, size);
} }

View File

@ -28,3 +28,22 @@ void WriteString(DaisyPatch patch,
std::string text) { std::string text) {
WriteString(patch, x, y, font, text, true); 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);
}

View File

@ -29,4 +29,17 @@ void WriteString(DaisyPatch,
FontDef, FontDef,
std::string); std::string);
void WriteCenteredString(DaisyPatch,
int,
int,
FontDef,
std::string,
bool);
void WriteCenteredString(DaisyPatch,
int,
int,
FontDef,
std::string);
#endif // CASCADE_UTIL_H_ #endif // CASCADE_UTIL_H_