-
-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathProjectMCWrapper.cpp
398 lines (333 loc) · 11.7 KB
/
ProjectMCWrapper.cpp
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
#include "ProjectMCWrapper.hpp"
#include <projectM-4/projectM.h>
#include <Audio/AudioConstants.hpp>
#include <cstring>
#include <sstream>
#include <projectM-4/render_opengl.h>
#include <projectM-4/parameters.h>
namespace libprojectM {
void projectMWrapper::PresetSwitchRequestedEvent(bool isHardCut) const
{
if (m_presetSwitchRequestedEventCallback)
{
m_presetSwitchRequestedEventCallback(isHardCut, m_presetSwitchRequestedEventUserData);
}
}
void projectMWrapper::PresetSwitchFailedEvent(const std::string& presetFilename,
const std::string& failureMessage) const
{
if (m_presetSwitchFailedEventCallback)
{
m_presetSwitchFailedEventCallback(presetFilename.c_str(),
failureMessage.c_str(), m_presetSwitchFailedEventUserData);
}
}
} // namespace libprojectM
libprojectM::projectMWrapper* handle_to_instance(projectm_handle instance)
{
return reinterpret_cast<libprojectM::projectMWrapper*>(instance);
}
char* projectm_alloc_string(unsigned int length)
{
try
{
return new char[length]{};
}
catch (...)
{
return nullptr;
}
}
char* projectm_alloc_string_from_std_string(const std::string& str)
{
auto pointer = projectm_alloc_string(static_cast<uint32_t>(str.length() + 1));
if (pointer)
{
memcpy(pointer, str.c_str(), str.length());
}
return pointer;
}
void projectm_free_string(const char* str)
{
delete[] str;
}
projectm_handle projectm_create()
{
try
{
auto projectMInstance = new libprojectM::projectMWrapper();
return reinterpret_cast<projectm_handle>(projectMInstance);
}
catch (...)
{
return nullptr;
}
}
void projectm_destroy(projectm_handle instance)
{
auto projectMInstance = handle_to_instance(instance);
delete projectMInstance;
}
void projectm_load_preset_file(projectm_handle instance, const char* filename,
bool smooth_transition)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->LoadPresetFile(filename, smooth_transition);
}
void projectm_load_preset_data(projectm_handle instance, const char* data,
bool smooth_transition)
{
std::stringstream presetDataStream(data);
auto projectMInstance = handle_to_instance(instance);
projectMInstance->LoadPresetData(presetDataStream, smooth_transition);
}
void projectm_set_preset_switch_requested_event_callback(projectm_handle instance,
projectm_preset_switch_requested_event callback, void* user_data)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->m_presetSwitchRequestedEventCallback = callback;
projectMInstance->m_presetSwitchRequestedEventUserData = user_data;
}
void projectm_set_preset_switch_failed_event_callback(projectm_handle instance,
projectm_preset_switch_failed_event callback, void* user_data)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->m_presetSwitchFailedEventCallback = callback;
projectMInstance->m_presetSwitchFailedEventUserData = user_data;
}
void projectm_set_texture_search_paths(projectm_handle instance,
const char** texture_search_paths,
size_t count)
{
auto projectMInstance = handle_to_instance(instance);
std::vector<std::string> texturePaths;
for (size_t index = 0; index < count; index++)
{
texturePaths.emplace_back(texture_search_paths[index]);
}
projectMInstance->SetTexturePaths(texturePaths);
}
void projectm_reset_textures(projectm_handle instance)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->ResetTextures();
}
void projectm_get_version_components(int* major, int* minor, int* patch)
{
if (major != nullptr)
{
*major = PROJECTM_VERSION_MAJOR;
}
if (minor != nullptr)
{
*minor = PROJECTM_VERSION_MINOR;
}
if (patch != nullptr)
{
*patch = PROJECTM_VERSION_PATCH;
}
}
char* projectm_get_version_string()
{
auto versionLength = strlen(PROJECTM_VERSION_STRING);
auto buffer = projectm_alloc_string(static_cast<uint32_t>(versionLength + 1));
strncpy(buffer, PROJECTM_VERSION_STRING, versionLength + 1);
return buffer;
}
char* projectm_get_vcs_version_string()
{
auto versionLength = strlen(PROJECTM_VERSION_VCS);
auto buffer = projectm_alloc_string(static_cast<uint32_t>(versionLength + 1));
strncpy(buffer, PROJECTM_VERSION_VCS, versionLength + 1);
return buffer;
}
void projectm_opengl_render_frame(projectm_handle instance)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->RenderFrame();
}
void projectm_opengl_render_frame_fbo(projectm_handle instance, uint32_t framebuffer_object_id)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->RenderFrame(framebuffer_object_id);
}
void projectm_set_frame_time(projectm_handle instance, double seconds_since_first_frame)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->SetFrameTime(seconds_since_first_frame);
}
double projectm_get_last_frame_time(projectm_handle instance)
{
auto projectMInstance = handle_to_instance(instance);
return projectMInstance->GetFrameTime();
}
void projectm_set_beat_sensitivity(projectm_handle instance, float sensitivity)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->SetBeatSensitivity(sensitivity);
}
float projectm_get_beat_sensitivity(projectm_handle instance)
{
auto projectMInstance = handle_to_instance(instance);
return projectMInstance->GetBeatSensitivity();
}
double projectm_get_hard_cut_duration(projectm_handle instance)
{
auto projectMInstance = handle_to_instance(instance);
return projectMInstance->HardCutDuration();
}
void projectm_set_hard_cut_duration(projectm_handle instance, double seconds)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->SetHardCutDuration(seconds);
}
bool projectm_get_hard_cut_enabled(projectm_handle instance)
{
auto projectMInstance = handle_to_instance(instance);
return projectMInstance->HardCutEnabled();
}
void projectm_set_hard_cut_enabled(projectm_handle instance, bool enabled)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->SetHardCutEnabled(enabled);
}
float projectm_get_hard_cut_sensitivity(projectm_handle instance)
{
auto projectMInstance = handle_to_instance(instance);
return projectMInstance->HardCutSensitivity();
}
void projectm_set_hard_cut_sensitivity(projectm_handle instance, float sensitivity)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->SetHardCutSensitivity(sensitivity);
}
double projectm_get_soft_cut_duration(projectm_handle instance)
{
auto projectMInstance = handle_to_instance(instance);
return projectMInstance->SoftCutDuration();
}
void projectm_set_soft_cut_duration(projectm_handle instance, double seconds)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->SetSoftCutDuration(seconds);
}
double projectm_get_preset_duration(projectm_handle instance)
{
auto projectMInstance = handle_to_instance(instance);
return projectMInstance->PresetDuration();
}
void projectm_set_preset_duration(projectm_handle instance, double seconds)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->SetPresetDuration(seconds);
}
void projectm_get_mesh_size(projectm_handle instance, size_t* width, size_t* height)
{
uint32_t w, h;
auto projectMInstance = handle_to_instance(instance);
projectMInstance->MeshSize(w, h);
*width = static_cast<size_t>(w);
*height = static_cast<size_t>(h);
}
void projectm_set_mesh_size(projectm_handle instance, size_t width, size_t height)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->SetMeshSize(static_cast<uint32_t>(width), static_cast<uint32_t>(height));
}
int32_t projectm_get_fps(projectm_handle instance)
{
auto projectMInstance = handle_to_instance(instance);
return projectMInstance->TargetFramesPerSecond();
}
void projectm_set_fps(projectm_handle instance, int32_t fps)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->SetTargetFramesPerSecond(fps);
}
void projectm_set_aspect_correction(projectm_handle instance, bool enabled)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->SetAspectCorrection(enabled);
}
bool projectm_get_aspect_correction(projectm_handle instance)
{
auto projectMInstance = handle_to_instance(instance);
return projectMInstance->AspectCorrection();
}
void projectm_set_easter_egg(projectm_handle instance, float value)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->SetEasterEgg(value);
}
float projectm_get_easter_egg(projectm_handle instance)
{
auto projectMInstance = handle_to_instance(instance);
return projectMInstance->EasterEgg();
}
void projectm_touch(projectm_handle instance, float x, float y, int pressure, projectm_touch_type touch_type)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->Touch(x, y, pressure, touch_type);
}
void projectm_touch_drag(projectm_handle instance, float x, float y, int pressure)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->TouchDrag(x, y, pressure);
}
void projectm_touch_destroy(projectm_handle instance, float x, float y)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->TouchDestroy(x, y);
}
void projectm_touch_destroy_all(projectm_handle instance)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->TouchDestroyAll();
}
bool projectm_get_preset_locked(projectm_handle instance)
{
auto projectMInstance = handle_to_instance(instance);
return projectMInstance->PresetLocked();
}
void projectm_set_preset_locked(projectm_handle instance, bool lock)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->SetPresetLocked(lock);
}
void projectm_get_window_size(projectm_handle instance, size_t* width, size_t* height)
{
auto projectMInstance = handle_to_instance(instance);
*width = static_cast<size_t>(projectMInstance->WindowWidth());
*height = static_cast<size_t>(projectMInstance->WindowHeight());
}
void projectm_set_window_size(projectm_handle instance, size_t width, size_t height)
{
auto projectMInstance = handle_to_instance(instance);
projectMInstance->SetWindowSize(static_cast<uint32_t>(width), static_cast<uint32_t>(height));
}
unsigned int projectm_pcm_get_max_samples()
{
return libprojectM::Audio::WaveformSamples;
}
template<class BufferType>
static auto PcmAdd(projectm_handle instance, const BufferType* samples, unsigned int count, projectm_channels channels) -> void
{
auto* projectMInstance = handle_to_instance(instance);
projectMInstance->PCM().Add(samples, channels, count);
}
auto projectm_pcm_add_float(projectm_handle instance, const float* samples, unsigned int count, projectm_channels channels) -> void
{
PcmAdd(instance, samples, count, channels);
}
auto projectm_pcm_add_int16(projectm_handle instance, const int16_t* samples, unsigned int count, projectm_channels channels) -> void
{
PcmAdd(instance, samples, count, channels);
}
auto projectm_pcm_add_uint8(projectm_handle instance, const uint8_t* samples, unsigned int count, projectm_channels channels) -> void
{
PcmAdd(instance, samples, count, channels);
}
auto projectm_write_debug_image_on_next_frame(projectm_handle, const char*) -> void
{
// UNIMPLEMENTED
}