-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOneKnobPlugin.hpp
164 lines (131 loc) · 4.27 KB
/
OneKnobPlugin.hpp
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* DISTRHO OneKnob Series
* Copyright (C) 2021-2023 Filipe Coelho <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For a full copy of the GNU General Public License see the LICENSE file.
*/
#pragma once
#include "DistrhoPlugin.hpp"
#include "SharedMemory.hpp"
START_NAMESPACE_DISTRHO
// -----------------------------------------------------------------------
class OneKnobPlugin : public Plugin
{
public:
OneKnobPlugin()
: Plugin(kParameterCount, kProgramCount, kStateCount),
lineGraphFrameToReset(getSampleRate() / 60)
{
std::memset(parameters, 0, sizeof(parameters));
}
protected:
// -------------------------------------------------------------------
// Information
const char* getLabel() const noexcept override
{
return DISTRHO_PLUGIN_NAME;
}
const char* getMaker() const noexcept override
{
return DISTRHO_PLUGIN_BRAND;
}
const char* getHomePage() const override
{
return DISTRHO_PLUGIN_URI;
}
uint32_t getVersion() const noexcept override
{
return d_version(1, 0, 0);
}
// -------------------------------------------------------------------
// Parameters
float getParameterValue(const uint32_t index) const override
{
return parameters[index];
}
void setParameterValue(const uint32_t index, const float value) override
{
parameters[index] = value;
}
// -------------------------------------------------------------------
// State
void setState(const char* const key, const char* const value) override
{
if (std::strcmp(key, "filemapping") == 0)
{
if (lineGraphsData.isCreatedOrConnected())
{
DISTRHO_SAFE_ASSERT(! lineGraphActive);
lineGraph1.setFloatFifo(nullptr);
lineGraph2.setFloatFifo(nullptr);
lineGraphsData.close();
}
if (OneKnobLineGraphFifos* const fifos = lineGraphsData.connect(value))
{
lineGraph1.setFloatFifo(&fifos->v1);
lineGraph2.setFloatFifo(&fifos->v2);
lineGraphActive = true;
}
}
}
// -------------------------------------------------------------------
// Process
void activate() override
{
lineGraphFrameCounter = 0;
lineGraphHighest1 = lineGraphHighest2 = 0.0f;
}
void sampleRateChanged(const double newSampleRate) override
{
lineGraphFrameToReset = newSampleRate / 60;
}
// -------------------------------------------------------------------
void init()
{
// load values of default/first program
loadDefaultParameterValues();
// reset state if needed
deactivate();
}
void loadDefaultParameterValues()
{
for (uint i=0; i<kParameterCount; ++i)
parameters[i] = kParameterRanges[i].def;
}
inline void setMeters(const float v1, const float v2)
{
if (! lineGraphActive)
return;
if (lineGraphsData.getDataPointer()->closed)
{
lineGraphActive = false;
return;
}
lineGraph1.write(v1);
lineGraph2.write(v2);
}
// -------------------------------------------------------------------
float parameters[kParameterCount];
bool lineGraphActive = false;
uint32_t lineGraphFrameCounter = 0;
uint32_t lineGraphFrameToReset;
float lineGraphHighest1 = 0.0f;
float lineGraphHighest2 = 0.0f;
private:
OneKnobFloatFifoControl lineGraph1;
OneKnobFloatFifoControl lineGraph2;
SharedMemory<OneKnobLineGraphFifos> lineGraphsData;
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(OneKnobPlugin)
};
// -----------------------------------------------------------------------
END_NAMESPACE_DISTRHO