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) { if (*state == DropletState::kFull) {
//DrawSolidRect(patch, 30,30,40,40, true);
attack = attack_param.Process(); attack = attack_param.Process();
decay = decay_param.Process(); decay = decay_param.Process();
curve = curve_param.Process(); curve = curve_param.Process();

View File

@ -6,7 +6,8 @@ int main(void) {
patch.Init(); patch.Init();
sample_rate = patch.AudioSampleRate(); sample_rate = patch.AudioSampleRate();
selected_menu = left_menu; selected_menu = left_menu;
droplet_left = GetDroplet(DropletState::kFull); droplet_left = GetDroplet(DropletState::kFull,
selected_menu->GetState());
patch.StartAdc(); patch.StartAdc();
patch.StartAudio(AudioThrough); patch.StartAudio(AudioThrough);
@ -27,6 +28,7 @@ void ProcessControls() {
// Handle menu selection // Handle menu selection
if (patch.encoder.RisingEdge()) { if (patch.encoder.RisingEdge()) {
selected_menu->SetInMenu(false); selected_menu->SetInMenu(false);
selected_menu->Select();
// Split selected // Split selected
if(selected_menu->GetState() == MenuState::kSplit) { if(selected_menu->GetState() == MenuState::kSplit) {
manager->ToggleSplit(); manager->ToggleSplit();
@ -35,7 +37,8 @@ void ProcessControls() {
// Enable split // Enable split
if (manager->GetSplitMode()) { if (manager->GetSplitMode()) {
droplet_left->UpdateState(DropletState::kLeft); droplet_left->UpdateState(DropletState::kLeft);
droplet_right = GetDroplet(DropletState::kRight); droplet_right = GetDroplet(DropletState::kRight,
left_menu->GetBufferState());
} }
// Disable split // Disable split
else { else {
@ -56,14 +59,17 @@ void ProcessControls() {
if(manager->GetSplitMode()) { if(manager->GetSplitMode()) {
if (selected_menu == left_menu) { if (selected_menu == left_menu) {
delete droplet_left; delete droplet_left;
droplet_left = GetDroplet(DropletState::kLeft); droplet_left = GetDroplet(DropletState::kLeft,
selected_menu->GetState());
} else { } else {
delete droplet_right; delete droplet_right;
droplet_right = GetDroplet(DropletState::kRight); droplet_right = GetDroplet(DropletState::kRight,
selected_menu->GetState());
} }
} else { } else {
delete droplet_left; 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) { Droplet* GetDroplet(DropletState state,
switch(selected_menu->GetState()) { MenuState menu) {
switch(menu) {
default: default:
case MenuState::kAD: case MenuState::kAD:
return new ADDroplet(&patch, 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. * Initializes a new audio processing droplet based on menu state.
* *
* @param state new droplet state * @param state new droplet state
* @param menu menu state
* @return droplet * @return droplet
*/ */
Droplet* GetDroplet(DropletState state); Droplet* GetDroplet(DropletState state, MenuState menu);
#endif // DROPLETS_MAIN_H_ #endif // DROPLETS_MAIN_H_

View File

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

View File

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