mirror of
https://github.com/AquaMorph/Droplets.git
synced 2025-04-30 01:35:34 +00:00
Refactored code
This commit is contained in:
parent
08559603b6
commit
94c5b276bb
@ -5,7 +5,35 @@ Droplet::Droplet(DaisyPatch* m_patch, DropletState m_state) {
|
||||
UpdateState(m_state);
|
||||
}
|
||||
|
||||
void Droplet::DrawName(DaisyPatch* patch, std::string name) {
|
||||
DaisyPatch* Droplet::Patch() {
|
||||
return patch;
|
||||
}
|
||||
|
||||
DropletState Droplet::GetState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
int Droplet::GetTitleHeight() {
|
||||
return kTitleHeight;
|
||||
}
|
||||
|
||||
int Droplet::GetScreenMin() {
|
||||
return screen_min;
|
||||
}
|
||||
|
||||
int Droplet::GetScreenMax() {
|
||||
return screen_max;
|
||||
}
|
||||
|
||||
size_t Droplet::GetChannelMin() {
|
||||
return chn_min;
|
||||
}
|
||||
|
||||
size_t Droplet::GetChannelMax() {
|
||||
return chn_max;
|
||||
}
|
||||
|
||||
void Droplet::DrawName(std::string name) {
|
||||
WriteCenteredString(*patch, (screen_min + screen_max) / 2, 0,
|
||||
Font_6x8, name);
|
||||
}
|
||||
@ -37,3 +65,7 @@ void Droplet::AnimationInc() {
|
||||
void Droplet::SetAnimationRate(int rate) {
|
||||
animation_rate = rate;
|
||||
}
|
||||
|
||||
int Droplet::GetAnimationCount() {
|
||||
return animation_count;
|
||||
}
|
||||
|
@ -15,27 +15,34 @@ enum class DropletState {kFull, kLeft, kRight};
|
||||
|
||||
class Droplet {
|
||||
private:
|
||||
unsigned int count = 0;
|
||||
unsigned int animation_rate = 1;
|
||||
public:
|
||||
DaisyPatch* patch;
|
||||
DropletState state;
|
||||
const int kTitleHeight = 7;
|
||||
unsigned int count = 0;
|
||||
unsigned int animation_rate = 1;
|
||||
unsigned int animation_count = 0;
|
||||
int screen_min;
|
||||
int screen_max;
|
||||
size_t chn_min = 0;
|
||||
size_t chn_max = 4;
|
||||
public:
|
||||
Droplet(DaisyPatch*, DropletState);
|
||||
virtual ~Droplet() {};
|
||||
virtual void Control()=0;
|
||||
virtual void Process(float**, float**, size_t)=0;
|
||||
virtual void Draw()=0;
|
||||
const int kTitleHeight = 7;
|
||||
int screen_min;
|
||||
int screen_max;
|
||||
size_t chn_min = 0;
|
||||
size_t chn_max = 4;
|
||||
void DrawName(daisy::DaisyPatch*,
|
||||
std::string);
|
||||
DaisyPatch* Patch();
|
||||
DropletState GetState();
|
||||
int GetTitleHeight();
|
||||
int GetScreenMin();
|
||||
int GetScreenMax();
|
||||
size_t GetChannelMin();
|
||||
size_t GetChannelMax();
|
||||
void DrawName(std::string);
|
||||
void UpdateState(DropletState);
|
||||
unsigned int animation_count = 0;
|
||||
void AnimationInc();
|
||||
void SetAnimationRate(int);
|
||||
int GetAnimationCount();
|
||||
};
|
||||
|
||||
#endif // CASCADE_DROPLETS_DROPLET_H_
|
||||
|
@ -12,17 +12,17 @@ void NoiseDroplet::Control() {}
|
||||
void NoiseDroplet::Process(float** in, float** out, size_t size) {
|
||||
for (size_t i = 0; i < size; i += 2) {
|
||||
float sig = noise.Process();
|
||||
for (size_t chn = chn_min; chn < chn_max; chn++) {
|
||||
for (size_t chn = GetChannelMin(); chn < GetChannelMax(); chn++) {
|
||||
out[chn][i] = sig;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NoiseDroplet::Draw() {
|
||||
for (int h = 0; h < kTitleHeight; h++) {
|
||||
for (int w = screen_min; w < screen_max; w++) {
|
||||
patch->display.DrawPixel(w, h, rand() % 15 == 0);
|
||||
for (int h = 0; h < GetTitleHeight(); h++) {
|
||||
for (int w = GetScreenMin(); w < GetScreenMax(); w++) {
|
||||
Patch()->display.DrawPixel(w, h, rand() % 15 == 0);
|
||||
}
|
||||
}
|
||||
DrawName(patch, "Noise");
|
||||
DrawName("Noise");
|
||||
}
|
||||
|
@ -8,13 +8,13 @@ VCODroplet::VCODroplet(DaisyPatch* m_patch,
|
||||
int num_waves = Oscillator::WAVE_LAST;
|
||||
SetAnimationRate(10);
|
||||
osc.Init(sample_rate);
|
||||
freqctrl.Init(patch->controls[patch->CTRL_1], 10.0,
|
||||
freqctrl.Init(Patch()->controls[Patch()->CTRL_1], 10.0,
|
||||
110.0f, Parameter::LINEAR);
|
||||
finectrl.Init(patch->controls[patch->CTRL_2], 0.f,
|
||||
finectrl.Init(Patch()->controls[Patch()->CTRL_2], 0.f,
|
||||
7.f, Parameter::LINEAR);
|
||||
wavectrl.Init(patch->controls[patch->CTRL_3], 0.0,
|
||||
wavectrl.Init(Patch()->controls[Patch()->CTRL_3], 0.0,
|
||||
num_waves, Parameter::LINEAR);
|
||||
ampctrl.Init(patch->controls[patch->CTRL_4], 0.0,
|
||||
ampctrl.Init(Patch()->controls[Patch()->CTRL_4], 0.0,
|
||||
0.5f, Parameter::LINEAR);
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ void VCODroplet::Process(float** in, float** out, size_t size) {
|
||||
float sig, freq, amp;
|
||||
size_t wave;
|
||||
|
||||
patch->UpdateAnalogControls();
|
||||
Patch()->UpdateAnalogControls();
|
||||
|
||||
for (size_t i = 0; i < size; i += 2) {
|
||||
// Read Knobs
|
||||
@ -51,14 +51,14 @@ void VCODroplet::Process(float** in, float** out, size_t size) {
|
||||
void VCODroplet::Draw() {
|
||||
wave->SetBlank();
|
||||
for (int i = 0; i < sine_width; i++) {
|
||||
int pixel = (int) round(std::sin(2*pi*((double)(i + animation_count%sine_width)/sine_width)) * (kTitleHeight/2) + kTitleHeight/2);
|
||||
int pixel = (int) round(std::sin(2*pi*((double)(i + GetAnimationCount()%sine_width)/sine_width)) * (GetTitleHeight()/2) + GetTitleHeight()/2);
|
||||
wave->SetPixel(i, pixel, true);
|
||||
}
|
||||
|
||||
WriteString(*patch, 0, 54, Font_6x8,
|
||||
WriteString(*Patch(), 0, 54, Font_6x8,
|
||||
WaveToString(wavectrl.Process()));
|
||||
wave->DrawTile(*patch, screen_min, 0, screen_max, kTitleHeight);
|
||||
DrawName(patch, "VCO");
|
||||
wave->DrawTile(*Patch(), GetScreenMin(), 0, GetScreenMax(), GetTitleHeight());
|
||||
DrawName("VCO");
|
||||
AnimationInc();
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ private:
|
||||
std::string WaveToString(uint8_t);
|
||||
const double pi = std::acos(-1);
|
||||
int sine_width = 20;
|
||||
Sprite* wave = new Sprite(sine_width, kTitleHeight);
|
||||
Sprite* wave = new Sprite(sine_width, GetTitleHeight());
|
||||
public:
|
||||
VCODroplet(DaisyPatch*, DropletState, float);
|
||||
~VCODroplet();
|
||||
|
Loading…
x
Reference in New Issue
Block a user