-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAXECurveTest.cpp
More file actions
276 lines (200 loc) · 7.61 KB
/
AXECurveTest.cpp
File metadata and controls
276 lines (200 loc) · 7.61 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#include "AXETypes.hpp"
#include "Debug/Logger.hpp"
#include "imgui/imgui_utils.hpp"
#include "json_impl.hpp"
#include <string>
#include <vector>
#define IMGUI_DEFINE_MATH_OPERATORS
// #include "ImCurveEdit.h"
#include "imgui.h"
namespace Shadow::AXE {
/*
struct RampEdit : public ImCurveEdit::Delegate {
RampEdit() {
mPts[0][0] = ImVec2(-10.f, 0);
mPts[0][1] = ImVec2(20.f, 0.6f);
mPts[0][2] = ImVec2(25.f, 0.2f);
mPts[0][3] = ImVec2(70.f, 0.4f);
mPts[0][4] = ImVec2(120.f, 1.f);
mPointCount[0] = 5;
mPts[1][0] = ImVec2(-50.f, 0.2f);
mPts[1][1] = ImVec2(33.f, 0.7f);
mPts[1][2] = ImVec2(80.f, 0.2f);
mPts[1][3] = ImVec2(82.f, 0.8f);
mPointCount[1] = 4;
mPts[2][0] = ImVec2(40.f, 0);
mPts[2][1] = ImVec2(60.f, 0.1f);
mPts[2][2] = ImVec2(90.f, 0.82f);
mPts[2][3] = ImVec2(150.f, 0.24f);
mPts[2][4] = ImVec2(200.f, 0.34f);
mPts[2][5] = ImVec2(250.f, 0.12f);
mPointCount[2] = 6;
mbVisible[0] = mbVisible[1] = mbVisible[2] = true;
mMax = ImVec2(1.f, 1.f);
mMin = ImVec2(0.f, 0.f);
}
size_t GetCurveCount() { return 3; }
bool IsVisible(size_t curveIndex) { return mbVisible[curveIndex]; }
size_t GetPointCount(size_t curveIndex) { return mPointCount[curveIndex]; }
uint32_t GetCurveColor(size_t curveIndex) {
uint32_t cols[] = { 0xFF0000FF, 0xFF00FF00, 0xFFFF0000 };
return cols[curveIndex];
}
ImVec2* GetPoints(size_t curveIndex) { return mPts[curveIndex]; }
virtual ImCurveEdit::CurveType GetCurveType(size_t curveIndex) const {
return ImCurveEdit::CurveSmooth;
}
virtual int EditPoint(size_t curveIndex, int pointIndex, ImVec2 value) {
mPts[curveIndex][pointIndex] = ImVec2(value.x, value.y);
SortValues(curveIndex);
for (size_t i = 0; i < GetPointCount(curveIndex); i++) {
if (mPts[curveIndex][i].x == value.x)
return (int)i;
}
return pointIndex;
}
virtual void AddPoint(size_t curveIndex, ImVec2 value) {
if (mPointCount[curveIndex] >= 8)
return;
mPts[curveIndex][mPointCount[curveIndex]++] = value;
SortValues(curveIndex);
}
virtual ImVec2& GetMax() { return mMax; }
virtual ImVec2& GetMin() { return mMin; }
virtual unsigned int GetBackgroundColor() { return 0; }
ImVec2 mPts[3][8];
size_t mPointCount[3];
bool mbVisible[3];
ImVec2 mMin;
ImVec2 mMax;
private:
void SortValues(size_t curveIndex) {
auto b = std::begin(mPts[curveIndex]);
auto e = std::begin(mPts[curveIndex]) + GetPointCount(curveIndex);
std::sort(b, e, [](ImVec2 a, ImVec2 b) { return a.x < b.x; });
}
}; */
// static RampEdit rampEdit;
static std::vector<ImVec2> points;
#if 0
void drawAutomation(ImRect bounds) {
using namespace ImGui;
if (GetCurrentWindow()->SkipItems) return;
ImU32 defCol = IM_COL32(255, 0, 0, 255);
ImDrawList* fg = GetForegroundDrawList();
ImDrawList* drawList = GetWindowDrawList();
fg->AddRect(bounds.Min, bounds.Max, IM_COL32(255, 0, 0, 255), 2.0f, 0, 2.0f);
PushClipRect(bounds.Min, bounds.Max, true);
int pointIt = 1;
// !! TRIANGLE LEAK !! //
// for (auto& point : points) {
// ImVec2 screenPoint = bounds.Min + point;
// bool hovered;
// bool held;
// bool press = ButtonBehavior(ImRect(screenPoint.x - 10, screenPoint.y - 10, screenPoint.x + 10, screenPoint.y + 10), GetID(pointIt), &hovered, &held);
// if (hovered) defCol = IM_COL32(0, 255, 0, 255);
// if (held) {
// point = GetMousePos() - bounds.Min;
// }
// drawList->AddCircleFilled(bounds.Min + point, 10.0f, defCol, 4);
// drawList->AddCircleFilled(bounds.Min + point, 3.0f, IM_COL32(0, 0, 0, 255), 4);
// pointIt++;
// }
PopClipRect();
}
#endif
static ma_result result;
static ma_engine engine;
static ma_sound sound;
static void chkRes(ma_result res) {
if (res != MA_SUCCESS) {
ERROUT("ERR IN AUDIO ENGINE %i", res);
}
}
void initCurveTest() {
result = ma_engine_init(NULL, &engine);
chkRes(result);
ma_node_graph_config nodeGraphConfig = ma_node_graph_config_init(2);
ma_node_graph nodeGraph;
result = ma_node_graph_init(&nodeGraphConfig, NULL, &nodeGraph); // Second parameter is a pointer to allocation callbacks.
chkRes(result);
// Load audio
result = ma_sound_init_from_file(&engine, "./Resources/sound.wav", MA_SOUND_FLAG_DECODE, nullptr, nullptr, &sound);
chkRes(result);
ma_data_source_node_config config = ma_data_source_node_config_init(&sound);
ma_data_source_node dataSourceNode;
result = ma_data_source_node_init(&nodeGraph, &config, NULL, &dataSourceNode);
chkRes(result);
ma_lpf_node_config lpfConfig = ma_lpf_node_config_init(2, ma_engine_get_sample_rate(&engine), 200, 1);
ma_lpf_node lpfNode;
result = ma_lpf_node_init(&nodeGraph, &lpfConfig, nullptr, &lpfNode);
chkRes(result);
result = ma_node_attach_output_bus(&dataSourceNode, 0, &lpfNode, 0);
chkRes(result);
result = ma_node_attach_output_bus(&lpfNode, 0, ma_node_graph_get_endpoint(&nodeGraph), 0);
// result = ma_node_attach_output_bus(&dataSourceNode, 0, ma_node_graph_get_endpoint(&nodeGraph), 0);
// chkRes(result);
// ma_data_source_node_config config = ma_data_source_node_config_init(pMyDataSource);
// ma_data_source_node dataSourceNode;
// result = ma_data_source_node_init(&nodeGraph, &config, NULL, &dataSourceNode);
if (result != MA_SUCCESS) {
// Failed to create data source node.
}
// ma_lpf_node_config lpfConfig = ma_lpf_node_config_init(2, 44800, double cutoffFrequency, ma_uint32 order)
}
static std::string axewftoload = "";
static bool dataLoaded = false;
json x;
void updateCurveTest() {
using namespace ImGui;
Begin("Curve Edit");
// Terrible code btw
if (Button("sound")) {
// ma_engine_play_sound(&engine, "./Resources/sound.wav", nullptr);
ma_sound_seek_to_pcm_frame(&sound, 0);
ma_sound_start(&sound);
}
InputText("AXEwf to load", &axewftoload);
SameLine();
if (Button("Load")) {
x = JSON::readBsonFile(axewftoload);
dataLoaded = true;
}
if (dataLoaded) {
Text("Hash %s", std::string(x["audioHash"]).c_str());
Text("Channels %s", std::to_string((int)x["channels"]).c_str());
Text("Bits %s", std::to_string((int)x["bits"]).c_str());
Text("Sample Rate %s", std::to_string((int)x["sample_rate"]).c_str());
Text("Samples per pixel %s", std::to_string((int)x["samples_per_pixel"]).c_str());
for (auto& point : x["data"]) {
TextUnformatted(std::to_string((int)point).c_str());
}
}
// DragScalar("const char *label", ImGuiDataType_U32, "void *p_data");
/* ImRect legendClippingRect = ImRect(GetWindowPos() + ImVec2(20,50), GetWindowPos() + GetWindowSize() - ImVec2(20,50));
ImRect legendRect = legendClippingRect;
ImRect rc = legendClippingRect;
ImDrawList* draw_list = GetWindowDrawList();
static const char* labels[] = { "Translation", "Rotation" , "Scale" };
rampEdit.mMax = ImVec2(float(500.0f), 1.f);
rampEdit.mMin = ImVec2(float(1.0f), 0.f);
draw_list->PushClipRect(legendClippingRect.Min, legendClippingRect.Max, true);
for (int i = 0; i < 3; i++) {
ImVec2 pta(legendRect.Min.x + 30, legendRect.Min.y + i * 14.f);
ImVec2 ptb(legendRect.Max.x, legendRect.Min.y + (i + 1) * 14.f);
draw_list->AddText(pta, rampEdit.mbVisible[i] ? 0xFFFFFFFF : 0x80FFFFFF, labels[i]);
if (ImRect(pta, ptb).Contains(ImGui::GetMousePos()) && ImGui::IsMouseClicked(0))
rampEdit.mbVisible[i] = !rampEdit.mbVisible[i];
}
draw_list->PopClipRect();
ImGui::SetCursorScreenPos(rc.Min);
ImCurveEdit::Edit(rampEdit, rc.Max - rc.Min, 137, &legendClippingRect);
// ImCurveEdit::Edit(rampEdit, ImVec2(0,0), GetID(111)); */
// points.push_back(ImVec2(100, 100));
// points.push_back(ImVec2(200, 200));
// points.push_back(ImVec2(300, 300));
// points.push_back(ImVec2(400, 400));
// drawAutomation(ImRect(GetWindowPos() + ImVec2(20,50), GetWindowPos() + GetWindowSize() - ImVec2(20,50)));
End();
}
}