From 6c335ccabb76ca1b197d702323f332e382ffc981 Mon Sep 17 00:00:00 2001 From: Christian Colglazier Date: Thu, 3 Feb 2022 19:25:19 -0500 Subject: [PATCH] Sequencer step and reset --- src/droplets/sequencer_droplet.cpp | 18 +++++++++++++++++- src/droplets/sequencer_droplet.h | 15 +++++++++++++-- src/util.cpp | 7 +++++++ src/util.h | 14 ++++++++++++++ 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/droplets/sequencer_droplet.cpp b/src/droplets/sequencer_droplet.cpp index 243d8a6..caaf747 100644 --- a/src/droplets/sequencer_droplet.cpp +++ b/src/droplets/sequencer_droplet.cpp @@ -9,7 +9,14 @@ SequencerDroplet::SequencerDroplet(DaisyPatch* m_patch, SequencerDroplet::~SequencerDroplet() {} -void SequencerDroplet::Control() {} +void SequencerDroplet::Control() { + if(Patch()->gate_input[0].Trig()) { + Step(); + } + if(Patch()->gate_input[1].Trig()) { + Reset(); + } +} void SequencerDroplet::Process(AudioHandle::InputBuffer in, AudioHandle::OutputBuffer out, @@ -17,9 +24,18 @@ void SequencerDroplet::Process(AudioHandle::InputBuffer in, } void SequencerDroplet::Draw() { + WriteString(Patch(), 0, 10, std::to_string(step)); DrawName("Sequencer"); } void SequencerDroplet::UpdateStateCallback() {} void SequencerDroplet::SetControls() {} + +void SequencerDroplet::Step() { + step = (step + 1) % MAX_SEQUENCE_LENGTH; +} + +void SequencerDroplet::Reset() { + step = 0; +} diff --git a/src/droplets/sequencer_droplet.h b/src/droplets/sequencer_droplet.h index d9c41d9..dccb159 100644 --- a/src/droplets/sequencer_droplet.h +++ b/src/droplets/sequencer_droplet.h @@ -9,11 +9,22 @@ #include "droplet.h" #include "../util.h" +#define MAX_SEQUENCE_LENGTH 32 + class SequencerDroplet: public Droplet { private: - int sequence_length = 32; int step = 0; - float swquence[32] = { 0.0f }; + float swquence[MAX_SEQUENCE_LENGTH] = { 0.0f }; + + /* + * Set the sequencer to the next step. + */ + void Step(); + + /* + * Reset the sequencers to the first step of the sequence. + */ + void Reset(); public: /* * Constructor for a droplet. diff --git a/src/util.cpp b/src/util.cpp index 866f00f..6dc5f27 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -29,6 +29,13 @@ void WriteString(DaisyPatch* patch, WriteString(patch, x, y, font, text, true); } +void WriteString(DaisyPatch* patch, + int x, + int y, + std::string text) { + WriteString(patch, x, y, Font_6x8, text, true); +} + void WriteCenteredString(DaisyPatch* patch, int x, int y, diff --git a/src/util.h b/src/util.h index c0994c4..65bbdce 100644 --- a/src/util.h +++ b/src/util.h @@ -63,6 +63,20 @@ void WriteString(DaisyPatch* patch, FontDef font, std::string text); +/* + * Draws text on screen flushed left. + * + * @param patch daisy patch board + * @param x start of text x coordinate + * @param y start of text y coordinate + * @param text text to be written + */ +void WriteString(DaisyPatch* patch, + int x, + int y, + std::string text); + + /* * Draws text on screen centered. *