Start of droplet splitting

This commit is contained in:
Christian Colglazier 2020-09-28 20:17:14 -04:00
parent 50a0281a5a
commit 7f2d278fcb
5 changed files with 84 additions and 27 deletions

View File

@ -40,6 +40,8 @@ void Droplet::DrawName(std::string name) {
void Droplet::UpdateState(DropletState m_state) { void Droplet::UpdateState(DropletState m_state) {
state = m_state; state = m_state;
chn_min = 0;
chn_max = 4;
screen_min = 0; screen_min = 0;
screen_max = SSD1309_WIDTH; screen_max = SSD1309_WIDTH;
if (state == DropletState::kLeft) { if (state == DropletState::kLeft) {

View File

@ -5,7 +5,7 @@ using namespace daisy;
int main(void) { int main(void) {
patch.Init(); patch.Init();
sample_rate = patch.AudioSampleRate(); sample_rate = patch.AudioSampleRate();
droplet = GetDroplet(); droplet_left = GetDroplet(DropletState::kFull);
patch.StartAdc(); patch.StartAdc();
patch.StartAudio(AudioThrough); patch.StartAudio(AudioThrough);
@ -19,35 +19,56 @@ int main(void) {
void ProcessControls() { void ProcessControls() {
patch.UpdateAnalogControls(); patch.UpdateAnalogControls();
patch.DebounceControls(); patch.DebounceControls();
if (menu.InMenu()) { if (left_menu.InMenu()) {
menu.UpdateMenuPosition(); left_menu.UpdateMenuPosition();
if (patch.encoder.RisingEdge()) { if (patch.encoder.RisingEdge()) {
menu.SetInMenu(false); left_menu.SetInMenu(false);
delete droplet; if(left_menu.GetState() == MenuState::kSplit) {
droplet = GetDroplet(); split = !split;
if (split) {
droplet_left->UpdateState(DropletState::kLeft);
droplet_right = GetDroplet(DropletState::kRight);
} else {
droplet_left->UpdateState(DropletState::kFull);
delete droplet_right;
}
} else {
delete droplet_left;
if(split) {
droplet_left = GetDroplet(DropletState::kLeft);
} else {
droplet_left = GetDroplet(DropletState::kFull);
}
}
} }
} else { } else {
if (patch.encoder.Pressed()) { if (patch.encoder.Pressed()) {
if (patch.encoder.TimeHeldMs() > 500 && if (patch.encoder.TimeHeldMs() > 500 &&
patch.encoder.TimeHeldMs() < 505) { patch.encoder.TimeHeldMs() < 505) {
menu.SetInMenu(true); left_menu.SetInMenu(true);
} }
} }
} }
} }
void ProcessOutputs() { void ProcessOutputs() {
if(!menu.InMenu()) { if(!left_menu.InMenu()) {
droplet->Control(); droplet_left->Control();
if (split) {
droplet_right->Control();
}
} }
} }
void ProcessOled() { void ProcessOled() {
patch.display.Fill(false); patch.display.Fill(false);
if (menu.InMenu()) { if (left_menu.InMenu()) {
menu.ProcessMenuOled(); left_menu.ProcessMenuOled();
} else { } else {
droplet->Draw(); droplet_left->Draw();
if (split) {
droplet_right->Draw();
}
} }
patch.display.Update(); patch.display.Update();
} }
@ -55,18 +76,21 @@ void ProcessOled() {
static void AudioThrough(float **in, static void AudioThrough(float **in,
float **out, float **out,
size_t size) { size_t size) {
droplet->Process(in, out, size); droplet_left->Process(in, out, size);
if (split) {
droplet_right->Process(in, out, size);
}
} }
Droplet* GetDroplet() { Droplet* GetDroplet(DropletState state) {
switch(menu.GetState()) { switch(left_menu.GetState()) {
case MenuState::kVCO: case MenuState::kVCO:
return new VCODroplet(&patch, return new VCODroplet(&patch,
DropletState::kFull, state,
sample_rate); sample_rate);
case MenuState::kNoise: case MenuState::kNoise:
default: default:
return new NoiseDroplet(&patch, return new NoiseDroplet(&patch,
DropletState::kFull); state);
} }
} }

View File

@ -15,8 +15,11 @@
#include "droplets/vco_droplet.h" #include "droplets/vco_droplet.h"
DaisyPatch patch; DaisyPatch patch;
Menu menu(&patch); bool split = false;
Droplet* droplet; Menu left_menu(&patch, "Right", &split);
Menu right_menu(&patch, "Left", &split);
Droplet* droplet_left;
Droplet* droplet_right;
float sample_rate; float sample_rate;
/* /*
@ -49,8 +52,9 @@ static void AudioThrough(float** in,
/* /*
* Initializes a new audio processing droplet based on menu state. * Initializes a new audio processing droplet based on menu state.
* *
* @return a droplet * @param state new droplet state
* @return droplet
*/ */
Droplet* GetDroplet(); Droplet* GetDroplet(DropletState state);
#endif // CASCADE_MAIN_H_ #endif // CASCADE_MAIN_H_

View File

@ -1,9 +1,15 @@
#include "menu.h" #include "menu.h"
Menu::Menu(DaisyPatch* m_patch) { Menu::Menu(DaisyPatch* m_patch,
std::string m_name,
bool* m_split) {
patch = m_patch; patch = m_patch;
name = m_name;
split = m_split;
} }
const std::string MENU_ITEMS[] = {"VCO", const std::string MENU_ITEMS[] = {"Split",
"Change",
"VCO",
"Noise"}; "Noise"};
const int MENU_SIZE = sizeof(MENU_ITEMS)/sizeof(*MENU_ITEMS); const int MENU_SIZE = sizeof(MENU_ITEMS)/sizeof(*MENU_ITEMS);
const int MAX_CHAR_LENGTH = 15; const int MAX_CHAR_LENGTH = 15;
@ -32,6 +38,11 @@ std::string Menu::FilterMenuText(int position) {
if (position >= MENU_SIZE || position < 0) { if (position >= MENU_SIZE || position < 0) {
return ""; return "";
} else { } else {
if (ConvertState(position) == MenuState::kSplit && *split) {
return "Merge";
} else if (ConvertState(position) == MenuState::kChange) {
return name;
}
return MENU_ITEMS[position]; return MENU_ITEMS[position];
} }
} }
@ -69,5 +80,9 @@ std::string Menu::SelectedName() {
} }
MenuState Menu::GetState() { MenuState Menu::GetState() {
return static_cast<MenuState>(selectedMenuItem); return ConvertState(selectedMenuItem);
}
MenuState Menu::ConvertState(int menu_state) {
return static_cast<MenuState>(menu_state);
} }

View File

@ -10,18 +10,30 @@
using namespace daisy; using namespace daisy;
enum class MenuState {kVCO, kNoise}; enum class MenuState {kSplit, kChange, kVCO, kNoise};
class Menu { class Menu {
private: private:
DaisyPatch* patch; DaisyPatch* patch;
bool* split;
std::string name;
/*
* Converts a number to the related menu state.
*
* @param menu_state state number
* @return menu state
*/
MenuState ConvertState(int menu_state);
public: public:
/* /*
* Constructor for a menu system to control the state of the patch. * Constructor for a menu system to control the state of the patch.
* *
* @param m_patch pointer to patch * @param m_patch pointer to patch
* @param m_name name of the menu
* @param m_split one or two droplets
*/ */
Menu(DaisyPatch* m_patch); Menu(DaisyPatch* m_patch, std::string m_name, bool* m_split);
/* /*
* Gives if the user is currently in the menu. * Gives if the user is currently in the menu.