Split creates two of the same droplet

This commit is contained in:
Christian Colglazier 2022-01-21 21:32:56 -05:00
parent 796092e4ee
commit 6bbaa0c862
5 changed files with 38 additions and 9 deletions

View File

@ -20,7 +20,6 @@ void AD::Process(DacHandle::Channel chn,
}
if (*state == DropletState::kFull) {
//DrawSolidRect(patch, 30,30,40,40, true);
attack = attack_param.Process();
decay = decay_param.Process();
curve = curve_param.Process();

View File

@ -6,7 +6,8 @@ int main(void) {
patch.Init();
sample_rate = patch.AudioSampleRate();
selected_menu = left_menu;
droplet_left = GetDroplet(DropletState::kFull);
droplet_left = GetDroplet(DropletState::kFull,
selected_menu->GetState());
patch.StartAdc();
patch.StartAudio(AudioThrough);
@ -27,6 +28,7 @@ void ProcessControls() {
// Handle menu selection
if (patch.encoder.RisingEdge()) {
selected_menu->SetInMenu(false);
selected_menu->Select();
// Split selected
if(selected_menu->GetState() == MenuState::kSplit) {
manager->ToggleSplit();
@ -35,7 +37,8 @@ void ProcessControls() {
// Enable split
if (manager->GetSplitMode()) {
droplet_left->UpdateState(DropletState::kLeft);
droplet_right = GetDroplet(DropletState::kRight);
droplet_right = GetDroplet(DropletState::kRight,
left_menu->GetBufferState());
}
// Disable split
else {
@ -56,14 +59,17 @@ void ProcessControls() {
if(manager->GetSplitMode()) {
if (selected_menu == left_menu) {
delete droplet_left;
droplet_left = GetDroplet(DropletState::kLeft);
droplet_left = GetDroplet(DropletState::kLeft,
selected_menu->GetState());
} else {
delete droplet_right;
droplet_right = GetDroplet(DropletState::kRight);
droplet_right = GetDroplet(DropletState::kRight,
selected_menu->GetState());
}
} else {
delete droplet_left;
droplet_left = GetDroplet(DropletState::kFull);
droplet_left = GetDroplet(DropletState::kFull,
selected_menu->GetState());
}
}
}
@ -112,8 +118,9 @@ static void AudioThrough(AudioHandle::InputBuffer in,
}
}
Droplet* GetDroplet(DropletState state) {
switch(selected_menu->GetState()) {
Droplet* GetDroplet(DropletState state,
MenuState menu) {
switch(menu) {
default:
case MenuState::kAD:
return new ADDroplet(&patch,

View File

@ -59,8 +59,9 @@ static void AudioThrough(AudioHandle::InputBuffer in,
* Initializes a new audio processing droplet based on menu state.
*
* @param state new droplet state
* @param menu menu state
* @return droplet
*/
Droplet* GetDroplet(DropletState state);
Droplet* GetDroplet(DropletState state, MenuState menu);
#endif // DROPLETS_MAIN_H_

View File

@ -109,6 +109,10 @@ MenuState Menu::GetState() {
return highlighted->GetState();
}
MenuState Menu::GetBufferState() {
return buffer->GetState();
}
void Menu::UpdateMenuState() {
if (manager->GetSplitMode()) {
head->SetStateVisibility(MenuState::kChange, true);
@ -118,3 +122,8 @@ void Menu::UpdateMenuState() {
head->SetStateTitle(MenuState::kSplit, "Split");
}
}
void Menu::Select() {
buffer = selected;
selected = highlighted;
}

View File

@ -85,10 +85,23 @@ class Menu {
*/
MenuState GetState();
/*
* Returns the previously selected menu item.
*
* @return menu state
*/
MenuState GetBufferState();
/*
* Updates the menu upon a split or a merge.
*/
void UpdateMenuState();
/*
* Select the currently highlighted menu item.
*/
void Select();
};
#endif // DROPLETS_MENU_H_