diff options
author | cflip <cflip@cflip.net> | 2022-01-01 16:25:08 -0700 |
---|---|---|
committer | cflip <cflip@cflip.net> | 2022-01-01 16:25:08 -0700 |
commit | 3828bb56022c636a7dd056a4781249222ea0d3ca (patch) | |
tree | 3552634861456591c78cce31ab1b534a10b45832 | |
parent | 36ed961e04f87038d2df721926c6ffd030dfa47c (diff) |
Clean up GUI appearance
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | gui.cpp | 27 | ||||
-rw-r--r-- | gui.h | 8 |
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. @@ -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); @@ -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 { |