mirror of
https://github.com/AquaMorph/Droplets.git
synced 2025-04-29 17:35:33 +00:00
Droplet switching
This commit is contained in:
parent
1f758b1772
commit
1ce6820633
@ -4,6 +4,7 @@ VCODroplet::VCODroplet(DaisyPatch* m_patch,
|
||||
float sample_rate,
|
||||
DropletState m_state) {
|
||||
UpdateState(m_state);
|
||||
patch = m_patch;
|
||||
int num_waves = Oscillator::WAVE_LAST - 1;
|
||||
osc.Init(sample_rate);
|
||||
freqctrl.Init(patch->controls[patch->CTRL_1], 10.0,
|
||||
|
34
src/main.cpp
34
src/main.cpp
@ -1,27 +1,16 @@
|
||||
#include "daisysp.h"
|
||||
#include "daisy_patch.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "main.h"
|
||||
#include "util.h"
|
||||
#include "menu.h"
|
||||
#include "droplets/droplet.h"
|
||||
#include "droplets/noise_droplet.h"
|
||||
#include "droplets/vco_droplet.h"
|
||||
|
||||
using namespace daisy;
|
||||
|
||||
DaisyPatch patch;
|
||||
Menu menu(&patch);
|
||||
Droplet* droplet;
|
||||
float samplerate;
|
||||
|
||||
int main(void) {
|
||||
patch.Init();
|
||||
float samplerate = patch.AudioSampleRate();
|
||||
droplet = new VCODroplet(&patch,
|
||||
samplerate,
|
||||
DropletState::kFull);
|
||||
samplerate = patch.AudioSampleRate();
|
||||
droplet = GetDroplet();
|
||||
patch.StartAdc();
|
||||
patch.StartAudio(AudioThrough);
|
||||
|
||||
@ -39,6 +28,8 @@ void ProcessControls() {
|
||||
menu.UpdateMenuPosition();
|
||||
if (patch.encoder.RisingEdge()) {
|
||||
menu.SetInMenu(false);
|
||||
delete droplet;
|
||||
droplet = GetDroplet();
|
||||
}
|
||||
} else {
|
||||
if (patch.encoder.Pressed()) {
|
||||
@ -57,7 +48,6 @@ void ProcessOled() {
|
||||
if (menu.InMenu()) {
|
||||
menu.ProcessMenuOled();
|
||||
} else {
|
||||
WriteString(patch, 0, 0, Font_6x8, menu.SelectedName());
|
||||
droplet->Draw();
|
||||
}
|
||||
patch.display.Update();
|
||||
@ -70,3 +60,17 @@ static void AudioThrough(float **in,
|
||||
droplet->Process(in, out, size);
|
||||
}
|
||||
|
||||
Droplet* GetDroplet() {
|
||||
switch(menu.GetState()) {
|
||||
case MenuState::kVCO:
|
||||
return new VCODroplet(&patch,
|
||||
samplerate,
|
||||
DropletState::kFull);
|
||||
break;
|
||||
case MenuState::kNoise:
|
||||
default:
|
||||
return new NoiseDroplet(&patch,
|
||||
samplerate,
|
||||
DropletState::kFull);
|
||||
}
|
||||
}
|
||||
|
12
src/main.h
12
src/main.h
@ -1,4 +1,16 @@
|
||||
#include "daisysp.h"
|
||||
#include "daisy_patch.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "util.h"
|
||||
#include "menu.h"
|
||||
#include "droplets/droplet.h"
|
||||
#include "droplets/noise_droplet.h"
|
||||
#include "droplets/vco_droplet.h"
|
||||
|
||||
void ProcessControls();
|
||||
void ProcessOled();
|
||||
void ProcessOutputs();
|
||||
static void AudioThrough(float **, float **, size_t);
|
||||
Droplet* GetDroplet();
|
||||
|
27
src/menu.cpp
27
src/menu.cpp
@ -4,15 +4,7 @@ Menu::Menu(DaisyPatch* m_patch) {
|
||||
patch = m_patch;
|
||||
}
|
||||
const std::string MENU_ITEMS[] = {"VCO",
|
||||
"VCA",
|
||||
"Envelope",
|
||||
"LFO",
|
||||
"Logic",
|
||||
"Noise",
|
||||
"Delay",
|
||||
"Reverb",
|
||||
"Turing",
|
||||
"Quantizer"};
|
||||
"Noise"};
|
||||
const int MENU_SIZE = sizeof(MENU_ITEMS)/sizeof(*MENU_ITEMS);
|
||||
const int MAX_CHAR_LENGTH = 15;
|
||||
const int MENU_X[] = {0, 5, 10, 5, 0};
|
||||
@ -44,13 +36,18 @@ std::string Menu::FilterMenuText(int position) {
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::CreateMenuItem(std::string text, int position, bool highlighted) {
|
||||
void Menu::CreateMenuItem(std::string text,
|
||||
int position,
|
||||
bool highlighted) {
|
||||
text.insert(text.end(), MAX_CHAR_LENGTH-text.size(), ' ');
|
||||
if (highlighted) {
|
||||
DrawSolidRect(*patch, 0, MENU_Y[2], SSD1309_WIDTH, MENU_Y[2]+17, true);
|
||||
WriteString(*patch, MENU_X[position-1], MENU_Y[position-1], Font_11x18, text, !highlighted);
|
||||
DrawSolidRect(*patch, 0, MENU_Y[2],
|
||||
SSD1309_WIDTH, MENU_Y[2]+17, true);
|
||||
WriteString(*patch, MENU_X[position-1], MENU_Y[position-1],
|
||||
Font_11x18, text, !highlighted);
|
||||
} else {
|
||||
WriteString(*patch, MENU_X[position-1], MENU_Y[position-1], Font_7x10, text, !highlighted);
|
||||
WriteString(*patch, MENU_X[position-1], MENU_Y[position-1],
|
||||
Font_7x10, text, !highlighted);
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,3 +67,7 @@ void Menu::UpdateMenuPosition() {
|
||||
std::string Menu::SelectedName() {
|
||||
return MENU_ITEMS[selectedMenuItem];
|
||||
}
|
||||
|
||||
MenuState Menu::GetState() {
|
||||
return static_cast<MenuState>(selectedMenuItem);
|
||||
}
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
using namespace daisy;
|
||||
|
||||
enum class MenuState {kVCO, kNoise};
|
||||
|
||||
class Menu {
|
||||
private:
|
||||
DaisyPatch* patch;
|
||||
@ -23,6 +25,7 @@ class Menu {
|
||||
void ProcessMenuOled();
|
||||
void UpdateMenuPosition();
|
||||
std::string SelectedName();
|
||||
MenuState GetState();
|
||||
};
|
||||
|
||||
#endif // CASCADE_MENU_H_
|
||||
|
Loading…
x
Reference in New Issue
Block a user