summaryrefslogtreecommitdiff
path: root/src/live.hpp
blob: 399d856fb3560b075fe4a2116132368762ad37ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * Copyright (c) 2020-2021 Vasile Vilvoiu <vasi@vilvoiu.ro>
 *
 * specgram is free software; you can redistribute it and/or modify
 * it under the terms of the MIT license. See LICENSE for details.
 */
#ifndef _LIVE_HPP_
#define _LIVE_HPP_

#include "configuration.hpp"
#include "renderer.hpp"
#include "color-map.hpp"
#include <SFML/Graphics.hpp>

/**
 * Live output God object, keeping track of rendering, window, history etc.
 */
class LiveOutput {
private:
    /* configuration */
    std::size_t width_;
    bool is_horizontal_;
    Renderer renderer_;

    /* live window */
    sf::RenderWindow window_;

    /* raw FFT history */
    std::vector<uint8_t> fft_area_;

public:
    LiveOutput() = delete;
    LiveOutput(const LiveOutput &c) = delete;
    LiveOutput(LiveOutput &&) = delete;
    LiveOutput & operator=(const LiveOutput&) = delete;

    /**
     * @param conf Configuration to use.
     * @param cmap Color map instance to use.
     * @param vmap Value map instance to use.
     */
    LiveOutput(const Configuration& conf);

    /**
     * Add a FFT window to the history and render it.
     * @param win_values Window values, real, scaled.
     * @return A copy of the colorized window that is rendered.
     */
    std::vector<uint8_t> AddWindow(const RealWindow& win_values);

    /**
     * Handle window events.
     * @return True if window was closed.
     */
    bool HandleEvents();

    /**
     * Render live window.
     */
    void Render();
};

#endif