summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.cpp79
1 files changed, 78 insertions, 1 deletions
diff --git a/main.cpp b/main.cpp
index 1572494..6a3306e 100644
--- a/main.cpp
+++ b/main.cpp
@@ -2,10 +2,51 @@
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
+#include <vector>
const float AMPLITUDE = 0.2f;
+float sequence[8] = { 130.81f, 220.f, 130.81f, 440.f, 330.f, 440.f, 130.81f, 261.63f };
-const float sequence[8] = { 130.81f, 220.f, 130.81f, 440.f, 330.f, 440.f, 130.81f, 261.63f };
+class Knob {
+public:
+ Knob(int x, int y, float *valuePtr)
+ : m_x(x), m_y(y), value(valuePtr) {}
+
+ void Draw(SDL_Renderer*);
+ bool InBounds(int x, int y);
+
+ float *value;
+ float valueScaling = 0.3f;
+private:
+ int m_x, m_y;
+};
+
+std::vector<Knob> knobs;
+
+class Window {
+public:
+ Window();
+private:
+ bool m_isRunning{ false };
+};
+
+void Knob::Draw(SDL_Renderer *renderer)
+{
+ constexpr int Radius = 25;
+ SDL_Rect rect = { m_x, m_y, Radius, Radius };
+ SDL_RenderDrawRect(renderer, &rect);
+
+ SDL_RenderDrawLine(renderer, m_x, m_y + (*value * valueScaling), m_x + Radius, m_y + (*value * valueScaling));
+}
+
+bool Knob::InBounds(int x, int y)
+{
+ constexpr int Radius = 25;
+ SDL_Rect rect = { m_x, m_y, Radius, Radius };
+ SDL_Point point = { x, y };
+
+ return SDL_PointInRect(&point, &rect);
+}
struct CallbackInfo {
int samplesDone;
@@ -53,6 +94,10 @@ void DrawInterface(SDL_Renderer* renderer, int currentStep)
rect.x += rect.w + 8;
}
+
+ for (Knob& knob : knobs) {
+ knob.Draw(renderer);
+ }
}
int main(int argc, char** argv)
@@ -92,13 +137,45 @@ int main(int argc, char** argv)
SDL_PauseAudio(0);
+ knobs.emplace_back(10, 120, sequence);
+ knobs.emplace_back(40, 120, sequence + 1);
+ knobs.emplace_back(70, 120, sequence + 2);
+ knobs.emplace_back(110, 120, sequence + 3);
+ knobs.emplace_back(140, 120, sequence + 4);
+ knobs.emplace_back(170, 120, sequence + 5);
+ knobs.emplace_back(210, 120, sequence + 6);
+ knobs.emplace_back(240, 120, sequence + 7);
+
bool running = true;
+ Knob* mouseKnob = nullptr;
+ int yStart = 0;
while (running) {
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
running = false;
break;
+ case SDL_MOUSEBUTTONDOWN:
+ for (Knob& knob : knobs) {
+ if (knob.InBounds(event.button.x, event.button.y)) {
+ mouseKnob = &knob;
+ yStart = event.button.y;
+ break;
+ }
+ }
+ break;
+ case SDL_MOUSEMOTION:
+ if (mouseKnob) {
+ *mouseKnob->value -= (yStart - event.button.y);
+ yStart = event.button.y;
+ if (*mouseKnob->value < 0) *mouseKnob->value = 0;
+ }
+
+ break;
+ case SDL_MOUSEBUTTONUP:
+ mouseKnob = nullptr;
+ yStart = 0;
+ break;
}
}