From 26293db40f8ac62f3971e0e9dbbc0bf3439e61c0 Mon Sep 17 00:00:00 2001 From: Vasile Vilvoiu Date: Tue, 29 Dec 2020 19:33:03 +0200 Subject: Initial commit --- src/renderer.hpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/renderer.hpp (limited to 'src/renderer.hpp') diff --git a/src/renderer.hpp b/src/renderer.hpp new file mode 100644 index 0000000..4272203 --- /dev/null +++ b/src/renderer.hpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2020-2021 Vasile Vilvoiu + * + * specgram is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See LICENSE for details. + */ +#ifndef _RENDERER_HPP_ +#define _RENDERER_HPP_ + +#include "configuration.hpp" +#include +#include +#include + +/* Axis tick */ +typedef std::tuple AxisTick; + +/* Orientation */ +enum class Orientation { + k90CCW, + kNormal, + k90CW, + k180 +}; + +/* + * Spectrogram rendering class + */ +class Renderer { +private: + const Configuration configuration_; + const std::size_t fft_count_; + + sf::Font font_; + + sf::RenderTexture canvas_; + sf::Texture fft_area_texture_; + + std::size_t width_; + std::size_t height_; + + sf::Transform legend_transform_; + sf::Transform fft_live_transform_; + sf::Transform fft_area_transform_; + + std::list frequency_ticks_; + std::list live_ticks_; + + static std::list GetLinearTicks(double v_min, double v_max, const std::string& v_unit, + unsigned int num_ticks); + static std::list GetNiceTicks(double v_min, double v_max, const std::string& v_unit, + unsigned int length_px, unsigned int est_tick_length_px); + + void RenderAxis(sf::RenderTexture& texture, + const sf::Transform& t, bool lhs, Orientation orientation, double length, + const std::list& ticks); + +public: + Renderer() = delete; + Renderer(const Configuration& conf, const ColorMap& cmap, const ValueMap& vmap, std::size_t fft_count); + + /* render commands */ + void RenderFFTArea(const std::vector& memory); + void RenderFFTArea(const std::list>& history); + void RenderLiveFFT(const RealWindow& window, const std::vector& colors); + + /* canvas builder */ + sf::Texture GetCanvas(); + + /* size getters */ + auto GetWidth() const { return width_; } + auto GetHeight() const { return height_; } +}; + +#endif \ No newline at end of file -- cgit v1.2.3