summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rw-r--r--gui.cpp27
-rw-r--r--gui.h8
3 files changed, 17 insertions, 23 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..bf51149
--- /dev/null
+++ b/README.md
@@ -0,0 +1,5 @@
+# fmseq
+
+fmseq is a simple virtual groovebox that combines an 8-step sequencer with an FM
+synthesizer.
+Currently it is very simple, but in the future I would like to add support for multiple tracks, MIDI note and CC input, and variable sequence lengths and tempos.
diff --git a/gui.cpp b/gui.cpp
index 428959b..1070e9f 100644
--- a/gui.cpp
+++ b/gui.cpp
@@ -5,20 +5,14 @@
void Slider::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));
+ SDL_RenderDrawRect(renderer, &m_bounds);
+ SDL_RenderDrawLine(renderer, m_bounds.x, m_bounds.y + (*value * valueScaling), m_bounds.x + m_bounds.w, m_bounds.y + (*value * valueScaling));
}
bool Slider::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);
+ return SDL_PointInRect(&point, &m_bounds);
}
GUI::GUI(Sequence& seq)
@@ -26,10 +20,10 @@ GUI::GUI(Sequence& seq)
{
int i = 0;
for (auto& step : seq.steps) {
- ++i;
- m_sliders.emplace_back(i * 30 + 10, 120, &step.carrierFreq, 0.1f);
- m_sliders.emplace_back(i * 30 + 10, 180, &step.modFreq);
- m_sliders.emplace_back(i * 30 + 10, 220, &step.modDepth, 3.0f);
+ m_sliders.emplace_back(i * 40 + 14, 60, &step.carrierFreq, 0.1f);
+ m_sliders.emplace_back(i * 40 + 14, 145, &step.modFreq);
+ m_sliders.emplace_back(i * 40 + 14, 230, &step.modDepth, 3.0f);
+ i++;
}
}
@@ -63,12 +57,7 @@ void GUI::OnMouseMove(int x, int y)
void GUI::Repaint(SDL_Renderer* renderer, int currentStep)
{
- SDL_Rect rect = {
- 40,
- 40,
- 32,
- 32
- };
+ SDL_Rect rect = { 10, 10, 32, 32 };
for (int i = 0; i < 8; i++) {
SDL_SetRenderDrawColor(renderer, m_sequence.steps[i].modDepth * 8, m_sequence.steps[i].modFreq * 2, m_sequence.steps[i].carrierFreq / 3, 255);
diff --git a/gui.h b/gui.h
index b510c7e..ee6a51c 100644
--- a/gui.h
+++ b/gui.h
@@ -1,14 +1,14 @@
#pragma once
+#include <SDL2/SDL.h>
+
#include <vector>
#include "sequence.h"
-struct SDL_Renderer;
-
class Slider {
public:
Slider(int x, int y, float* valuePtr, float scaling = 1.f)
- : m_x(x), m_y(y), value(valuePtr), valueScaling(scaling) {}
+ : m_bounds({ x, y, 25, 75 }), value(valuePtr), valueScaling(scaling) {}
void Draw(SDL_Renderer*);
bool InBounds(int x, int y);
@@ -16,7 +16,7 @@ public:
float* value;
float valueScaling;
private:
- int m_x, m_y;
+ SDL_Rect m_bounds;
};
class GUI {