mirror of
https://github.com/AquaMorph/Droplets.git
synced 2025-04-30 09:45:35 +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,
|
float sample_rate,
|
||||||
DropletState m_state) {
|
DropletState m_state) {
|
||||||
UpdateState(m_state);
|
UpdateState(m_state);
|
||||||
|
patch = m_patch;
|
||||||
int num_waves = Oscillator::WAVE_LAST - 1;
|
int num_waves = Oscillator::WAVE_LAST - 1;
|
||||||
osc.Init(sample_rate);
|
osc.Init(sample_rate);
|
||||||
freqctrl.Init(patch->controls[patch->CTRL_1], 10.0,
|
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 "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;
|
using namespace daisy;
|
||||||
|
|
||||||
DaisyPatch patch;
|
DaisyPatch patch;
|
||||||
Menu menu(&patch);
|
Menu menu(&patch);
|
||||||
Droplet* droplet;
|
Droplet* droplet;
|
||||||
|
float samplerate;
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
patch.Init();
|
patch.Init();
|
||||||
float samplerate = patch.AudioSampleRate();
|
samplerate = patch.AudioSampleRate();
|
||||||
droplet = new VCODroplet(&patch,
|
droplet = GetDroplet();
|
||||||
samplerate,
|
|
||||||
DropletState::kFull);
|
|
||||||
patch.StartAdc();
|
patch.StartAdc();
|
||||||
patch.StartAudio(AudioThrough);
|
patch.StartAudio(AudioThrough);
|
||||||
|
|
||||||
@ -39,6 +28,8 @@ void ProcessControls() {
|
|||||||
menu.UpdateMenuPosition();
|
menu.UpdateMenuPosition();
|
||||||
if (patch.encoder.RisingEdge()) {
|
if (patch.encoder.RisingEdge()) {
|
||||||
menu.SetInMenu(false);
|
menu.SetInMenu(false);
|
||||||
|
delete droplet;
|
||||||
|
droplet = GetDroplet();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (patch.encoder.Pressed()) {
|
if (patch.encoder.Pressed()) {
|
||||||
@ -57,7 +48,6 @@ void ProcessOled() {
|
|||||||
if (menu.InMenu()) {
|
if (menu.InMenu()) {
|
||||||
menu.ProcessMenuOled();
|
menu.ProcessMenuOled();
|
||||||
} else {
|
} else {
|
||||||
WriteString(patch, 0, 0, Font_6x8, menu.SelectedName());
|
|
||||||
droplet->Draw();
|
droplet->Draw();
|
||||||
}
|
}
|
||||||
patch.display.Update();
|
patch.display.Update();
|
||||||
@ -70,3 +60,17 @@ static void AudioThrough(float **in,
|
|||||||
droplet->Process(in, out, size);
|
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 ProcessControls();
|
||||||
void ProcessOled();
|
void ProcessOled();
|
||||||
void ProcessOutputs();
|
void ProcessOutputs();
|
||||||
static void AudioThrough(float **, float **, size_t);
|
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;
|
patch = m_patch;
|
||||||
}
|
}
|
||||||
const std::string MENU_ITEMS[] = {"VCO",
|
const std::string MENU_ITEMS[] = {"VCO",
|
||||||
"VCA",
|
"Noise"};
|
||||||
"Envelope",
|
|
||||||
"LFO",
|
|
||||||
"Logic",
|
|
||||||
"Noise",
|
|
||||||
"Delay",
|
|
||||||
"Reverb",
|
|
||||||
"Turing",
|
|
||||||
"Quantizer"};
|
|
||||||
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;
|
||||||
const int MENU_X[] = {0, 5, 10, 5, 0};
|
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(), ' ');
|
text.insert(text.end(), MAX_CHAR_LENGTH-text.size(), ' ');
|
||||||
if (highlighted) {
|
if (highlighted) {
|
||||||
DrawSolidRect(*patch, 0, MENU_Y[2], SSD1309_WIDTH, MENU_Y[2]+17, true);
|
DrawSolidRect(*patch, 0, MENU_Y[2],
|
||||||
WriteString(*patch, MENU_X[position-1], MENU_Y[position-1], Font_11x18, text, !highlighted);
|
SSD1309_WIDTH, MENU_Y[2]+17, true);
|
||||||
|
WriteString(*patch, MENU_X[position-1], MENU_Y[position-1],
|
||||||
|
Font_11x18, text, !highlighted);
|
||||||
} else {
|
} 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() {
|
std::string Menu::SelectedName() {
|
||||||
return MENU_ITEMS[selectedMenuItem];
|
return MENU_ITEMS[selectedMenuItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MenuState Menu::GetState() {
|
||||||
|
return static_cast<MenuState>(selectedMenuItem);
|
||||||
|
}
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
using namespace daisy;
|
using namespace daisy;
|
||||||
|
|
||||||
|
enum class MenuState {kVCO, kNoise};
|
||||||
|
|
||||||
class Menu {
|
class Menu {
|
||||||
private:
|
private:
|
||||||
DaisyPatch* patch;
|
DaisyPatch* patch;
|
||||||
@ -23,6 +25,7 @@ class Menu {
|
|||||||
void ProcessMenuOled();
|
void ProcessMenuOled();
|
||||||
void UpdateMenuPosition();
|
void UpdateMenuPosition();
|
||||||
std::string SelectedName();
|
std::string SelectedName();
|
||||||
|
MenuState GetState();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CASCADE_MENU_H_
|
#endif // CASCADE_MENU_H_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user