-
-
Notifications
You must be signed in to change notification settings - Fork 456
Expand file tree
/
Copy pathCustomWaveform.hpp
More file actions
111 lines (89 loc) · 3.94 KB
/
CustomWaveform.hpp
File metadata and controls
111 lines (89 loc) · 3.94 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#pragma once
#include "WaveformPerFrameContext.hpp"
#include "WaveformPerPointContext.hpp"
#include <Renderer/Backend/OpenGL/OpenGLRenderItem.hpp>
#include <vector>
namespace libprojectM {
namespace MilkdropPreset {
class PresetFileParser;
namespace MilkdropPreset {
class CustomWaveform : public libprojectM::Renderer::Backend::OpenGL::OpenGLRenderItem
{
public:
/**
* @brief Creates a new waveform with the given number of samples.
* @param presetState The preset state container.
*/
explicit CustomWaveform(PresetState& presetState);
void InitVertexAttrib() override;
/**
* @brief Loads the initial values and code from the preset file.
* @param parsedFile The file parser with the preset data.
* @param index The waveform index.
*/
void Initialize(::libprojectM::PresetFileParser& parsedFile, int index);
/**
* @brief Compiles all code blocks and runs the init expression.
* @throws MilkdropCompileException Thrown if one of the code blocks couldn't be compiled.
* @param presetPerFrameContext The per-frame context to retrieve the init Q vars from.
*/
void CompileCodeAndRunInitExpressions(const PerFrameContext& presetPerFrameContext);
/**
* @brief Renders the waveform.
* @param presetPerFrameContext The per-frame context to retrieve the init Q vars from.
*/
void Draw(const PerFrameContext& presetPerFrameContext);
private:
/**
* @brief Initializes the per-frame context with the preset per-frame state.
* @param presetPerFrameContext The preset per-frame context to pull q vars from.
*/
void LoadPerFrameEvaluationVariables(const PerFrameContext& presetPerFrameContext);
/**
* @brief Loads the Q and T variables from the per-frame code into the per-point context.
*/
void InitPerPointEvaluationVariables();
/**
* @brief Loads the variables for each point into the per-point evaluation context.
* @param sample The sample index being rendered.
* @param value1 The left channel value.
* @param value2 The right channel value.
*/
void LoadPerPointEvaluationVariables(float sample, float value1, float value2);
/**
* @brief Does a better-than-linear smooth on a wave.
*
* Roughly doubles the number of points.
*
* @param inputVertices Array of input vertices to be smoothed.
* @param vertexCount Number of vertices in the input array.
* @param outputVertices Array to store the smoothed vertices.
* @return The number of vertices in the output array.
*/
static int SmoothWave(const ColoredPoint* inputVertices, int vertexCount, ColoredPoint* outputVertices);
int m_index{0}; //!< Custom waveform index in the preset.
bool m_enabled{false}; //!< Render waveform if non-zero.
int m_samples{WaveformMaxPoints}; //!< Number of samples/vertices in the waveform.
int m_sep{0}; //!< Separation distance of dual waveforms.
float m_scaling{1.0f}; //!< Scale factor of waveform.
float m_smoothing{0.5f}; //!< Smooth factor of waveform.
float m_x{0.5f};
float m_y{0.5f};
float m_r{1.0f};
float m_g{1.0f};
float m_b{1.0f};
float m_a{1.0f};
bool m_spectrum{false}; //!< Spectrum data or PCM data.
bool m_useDots{false}; //!< If non-zero, draw wave as dots instead of lines.
bool m_drawThick{false}; //!< Draw thicker lines.
bool m_additive{false}; //!< Add color values together.
PRJM_EVAL_F m_tValuesAfterInitCode[TVarCount]{};
PresetState& m_presetState; //!< The global preset state.
WaveformPerFrameContext m_perFrameContext; //!< Holds the code execution context for per-frame expressions
WaveformPerPointContext m_perPointContext; //!< Holds the code execution context for per-point expressions
Renderer::Mesh m_mesh; //!< Points in this waveform.
friend class WaveformPerFrameContext;
friend class WaveformPerPointContext;
};
} // namespace MilkdropPreset
} // namespace libprojectM