Adjustable sequence length

This commit is contained in:
Christian Colglazier 2022-02-06 21:42:51 -05:00
parent 017e4f4b61
commit f7b2552773
2 changed files with 38 additions and 19 deletions

View File

@ -5,8 +5,9 @@ SequencerDroplet::SequencerDroplet(DaisyPatch* m_patch,
float sample_rate) : float sample_rate) :
Droplet(m_patch, Droplet(m_patch,
m_state) { m_state) {
SetControls();
SetColumns(); SetColumns();
SetControls();
AdjustSelected(-1);
} }
SequencerDroplet::~SequencerDroplet() {} SequencerDroplet::~SequencerDroplet() {}
@ -26,7 +27,16 @@ void SequencerDroplet::Control() {
if (control_rate_count == CONTROL_RATE_LIMIT) { if (control_rate_count == CONTROL_RATE_LIMIT) {
for (size_t chn = GetChannelMin(); chn < GetChannelMax(); chn++) { for (size_t chn = GetChannelMin(); chn < GetChannelMax(); chn++) {
if (std::abs(control[chn].Process()-last_control_value[chn]) > CONTROL_DEADZONE) { if (std::abs(control[chn].Process()-last_control_value[chn]) > CONTROL_DEADZONE) {
if (!InMenu()) {
sequence[chn+selected*num_columns] = control[chn].Process(); sequence[chn+selected*num_columns] = control[chn].Process();
} else {
if (chn == GetChannelMin()) {
sequence_length = std::max(1.0f,control[chn].Process()/4.9f*MAX_SEQUENCE_LENGTH);
SetColumns();
selected = 0;
AdjustSelected(-1);
}
}
} }
last_control_value[chn] = control[chn].Process(); last_control_value[chn] = control[chn].Process();
} }
@ -48,11 +58,13 @@ void SequencerDroplet::Draw() {
int left_padding = 4+GetScreenMin(); int left_padding = 4+GetScreenMin();
// Active Input // Active Input
if (!InMenu()) {
DrawSolidRect(Patch(), DrawSolidRect(Patch(),
GetScreenMin(), GetScreenMin(),
8+selected*8, 8+selected*8,
GetScreenMin()+2, GetScreenMin()+2,
15+selected*8, true); 15+selected*8, true);
}
// Notes // Notes
for (int i = 0; i < num_columns*NUM_ROWS && i < sequence_length; i++) { for (int i = 0; i < num_columns*NUM_ROWS && i < sequence_length; i++) {
@ -64,8 +76,8 @@ void SequencerDroplet::Draw() {
} }
// Draw info bar // Draw info bar
DrawSolidRect(Patch(),GetScreenMin(),56,GetScreenMax(),63, true); DrawSolidRect(Patch(),GetScreenMin(),56,GetScreenMax(),63, InMenu());
WriteString(Patch(), 2+GetScreenMin(), 56, std::to_string(step+1), false); WriteString(Patch(), 2+GetScreenMin(), 56, std::to_string(step+1), !InMenu());
DrawName("Sequencer"); DrawName("Sequencer");
} }
@ -98,9 +110,13 @@ void SequencerDroplet::SetColumns() {
} else { } else {
num_columns = 4; num_columns = 4;
} }
num_rows = std::ceil((float)sequence_length/num_columns);
} }
void SequencerDroplet::AdjustSelected(int adj) { void SequencerDroplet::AdjustSelected(int adj) {
int rows = std::ceil(sequence_length/num_columns); selected = (num_rows+selected+adj+1) % (num_rows+1);
selected = (rows+selected+adj) % rows; }
bool SequencerDroplet::InMenu() {
return selected >= num_rows;
} }

View File

@ -20,6 +20,7 @@ private:
int selected = 0; int selected = 0;
int sequence_length = 16; int sequence_length = 16;
int num_columns = 4; int num_columns = 4;
int num_rows = NUM_ROWS;
int control_rate_count = 0; int control_rate_count = 0;
float sequence[MAX_SEQUENCE_LENGTH] = { 0.0f }; float sequence[MAX_SEQUENCE_LENGTH] = { 0.0f };
Parameter control[4]; Parameter control[4];
@ -38,6 +39,8 @@ private:
void SetColumns(); void SetColumns();
void AdjustSelected(int adj); void AdjustSelected(int adj);
bool InMenu();
public: public:
/* /*
* Constructor for a droplet. * Constructor for a droplet.