Skip to content

Commit f0cb88d

Browse files
committed
Improve parameter class
1 parent 2a79350 commit f0cb88d

File tree

6 files changed

+213
-197
lines changed

6 files changed

+213
-197
lines changed

NeuralRack/clap/NeuralRack.cc

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323

2424
#include "engine.h"
2525
#include "ParallelThread.h"
26+
#include "Parameter.h"
2627
#define CLAPPLUG
2728
#include "NeuralRack.c"
2829

2930
class NeuralRack
3031
{
3132
public:
3233
Widget_t* TopWin;
33-
std::atomic<bool> paramChanged;
34-
std::atomic<bool> controllerChanged;
34+
Params param;
3535

36-
NeuralRack() : engine() {
36+
NeuralRack() : engine(), param() {
3737
workToDo.store(false, std::memory_order_release);
3838
s_time = 0.0;
3939
ui = (X11_UI*)malloc(sizeof(X11_UI));
@@ -47,8 +47,7 @@ class NeuralRack
4747
title = "NeuralRack";
4848
firstLoop = true;
4949
p = 0;
50-
paramChanged.store(false, std::memory_order_release);
51-
controllerChanged.store(false, std::memory_order_release);
50+
registerParameters();
5251
for(int i = 0;i<CONTROLS;i++)
5352
ui->widget[i] = NULL;
5453
}
@@ -59,6 +58,33 @@ class NeuralRack
5958
free(ui);
6059
}
6160

61+
void registerParameters() {
62+
param.registerParam("Buffered Mode", "Global", 0,2,0,1, (void*)&engine.buffered, true, Is_FLOAT);
63+
param.registerParam("Enable", "Global", 0,1,0,1, (void*)&engine.bypass, true, IS_UINT);
64+
65+
param.registerParam("Gate Enable", "NoiseGate",0,1,0,1, (void*)&engine.ngOnOff, true, IS_UINT);
66+
param.registerParam("Gate Thresh", "NoiseGate", 0.01, 0.31, 0.017, 0.001, (void*)&engine.ngate->threshold, false, Is_FLOAT);
67+
68+
param.registerParam("Norm Slot A", "Pedal", 0,1,0,1, (void*)&engine.normSlotA, true, IS_INT);
69+
param.registerParam("Input Gain A", "Pedal", -20,20,0,0.1, (void*)&engine.inputGain, false, Is_FLOAT);
70+
param.registerParam("Output Gain A", "Pedal", -20,20,0,0.1, (void*)&engine.outputGain, false, Is_FLOAT);
71+
72+
param.registerParam("Norm Slot B", "Amp", 0,1,0,1, (void*)&engine.normSlotB, true, IS_INT);
73+
param.registerParam("Input Gain B", "Amp", -20,20,0,0.1, (void*)&engine.inputGain1, false, Is_FLOAT);
74+
param.registerParam("Output Gain B", "Amp", -20,20,0,0.1, (void*)&engine.outputGain1, false, Is_FLOAT);
75+
76+
param.registerParam("EQ Enable", "EQ", 0,1,0,1, (void*)&engine.eqOnOff, true, IS_UINT);
77+
param.registerParam("EQ Band 1", "EQ", -20,20,0,0.1, (void*)&engine.peq->fVslider1, false, Is_FLOAT);
78+
param.registerParam("EQ Band 2", "EQ", -20,20,0,0.1, (void*)&engine.peq->fVslider0, false, Is_FLOAT);
79+
param.registerParam("EQ Band 3", "EQ", -20,20,0,0.1, (void*)&engine.peq->fVslider2, false, Is_FLOAT);
80+
param.registerParam("EQ Band 4", "EQ", -20,20,0,0.1, (void*)&engine.peq->fVslider3, false, Is_FLOAT);
81+
param.registerParam("EQ Band 5", "EQ", -20,20,0,0.1, (void*)&engine.peq->fVslider4, false, Is_FLOAT);
82+
param.registerParam("EQ Band 6", "EQ", -20,20,0,0.1, (void*)&engine.peq->fVslider5, false, Is_FLOAT);
83+
84+
param.registerParam("IR Out Gain L", "IR", -20,20,0,0.1, (void*)&engine.IRoutputGain, false, Is_FLOAT);
85+
param.registerParam("IR Out Gain R", "IR", -20,20,0,0.1, (void*)&engine.IRoutputGain1, false, Is_FLOAT);
86+
}
87+
6288
void startGui(Window window) {
6389
main_init(&ui->main);
6490
set_custom_theme(ui);
@@ -157,9 +183,9 @@ class NeuralRack
157183
checkParentWindowSize(TopWin->width, TopWin->height);
158184
firstLoop = false;
159185
}
160-
if (paramChanged.load(std::memory_order_acquire)) {
186+
if (param.paramChanged.load(std::memory_order_acquire)) {
161187
getEngineValues();
162-
paramChanged.store(false, std::memory_order_release);
188+
param.paramChanged.store(false, std::memory_order_release);
163189
}
164190
run_embedded(&ui->main);
165191
}
@@ -298,7 +324,7 @@ class NeuralRack
298324
engine.normSlotB = static_cast<int32_t>(value);
299325
break;
300326
case 14:
301-
engine.bypass = static_cast<int32_t>(value);
327+
engine.bypass = static_cast<uint32_t>(value);
302328
break;
303329
case 15:
304330
{
@@ -366,7 +392,7 @@ class NeuralRack
366392
break;
367393
}
368394
// inform the process thread that a controller value was changed by the GUI thread
369-
controllerChanged.store(true, std::memory_order_release);
395+
param.controllerChanged.store(true, std::memory_order_release);
370396
}
371397

372398
// send a file name from GUI to the engine

NeuralRack/clap/NeuralRackClap.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
typedef struct neuralrack_plugin_t neuralrack_plugin_t;
1717

18-
#include "NeuralRackParameter.h"
19-
2018
#define WINDOW_WIDTH 620
2119
#define WINDOW_HEIGHT 580
2220

@@ -38,7 +36,6 @@ struct neuralrack_plugin_t {
3836
clap_plugin_t plugin;
3937
const clap_host_t *host;
4038
NeuralRack *r;
41-
NeuralRackParams params;
4239
bool guiIsCreated;
4340
uint32_t latency;
4441
uint32_t width;
@@ -49,42 +46,46 @@ struct neuralrack_plugin_t {
4946
** Parameter handling
5047
*/
5148

52-
#include "NeuralRackParameter.cc"
53-
54-
static uint32_t params_count(const clap_plugin_t*) {
55-
return (uint32_t)neuralrack_parameters.size();
49+
static uint32_t params_count(const clap_plugin_t* plugin) {
50+
neuralrack_plugin_t *plug = (neuralrack_plugin_t *)plugin->plugin_data;
51+
return (uint32_t)plug->r->param.parameter.size();
5652
}
5753

58-
static bool params_get_info(const clap_plugin_t*, uint32_t param_index, clap_param_info_t* param_info) {
59-
if (param_index >= neuralrack_parameters.size()) return false;
60-
const auto& def = neuralrack_parameters[param_index];
54+
static bool params_get_info(const clap_plugin_t* plugin, uint32_t param_index, clap_param_info_t* param_info) {
55+
neuralrack_plugin_t *plug = (neuralrack_plugin_t *)plugin->plugin_data;
56+
if (param_index >= plug->r->param.parameter.size()) return false;
57+
const auto& def = plug->r->param.parameter[param_index];
6158
memset(param_info, 0, sizeof(*param_info));
6259
param_info->id = def.id;
6360
strncpy(param_info->name, def.name.c_str(), CLAP_NAME_SIZE-1);
64-
strncpy(param_info->module, def.module.c_str(), CLAP_PATH_SIZE-1);
61+
strncpy(param_info->module, def.group.c_str(), CLAP_PATH_SIZE-1);
6562
param_info->default_value = def.def;
6663
param_info->min_value = def.min;
6764
param_info->max_value = def.max;
68-
param_info->flags = def.flags;
65+
uint32_t flags = CLAP_PARAM_IS_AUTOMATABLE;
66+
if (def.isStepped) flags |= CLAP_PARAM_IS_STEPPED;
67+
param_info->flags = flags;
6968
param_info->cookie = nullptr;
7069
return true;
7170
}
7271

7372
static bool params_get_value(const clap_plugin_t* plugin, clap_id param_id, double* value) {
7473
neuralrack_plugin_t *plug = (neuralrack_plugin_t *)plugin->plugin_data;
75-
if (param_id < 0 || param_id >= PARAM_COUNT) return false;
76-
*value = plug->params.getParam(plug, param_id);
74+
if (param_id < 0 || param_id >= plug->r->param.parameter.size()) return false;
75+
*value = plug->r->param.getParam(param_id);
7776
return true;
7877
}
7978

80-
static bool params_value_to_text(const clap_plugin_t*, clap_id param_id, double value, char* out, uint32_t size) {
81-
if (param_id < 0 || param_id >= PARAM_COUNT) return false;
79+
static bool params_value_to_text(const clap_plugin_t* plugin, clap_id param_id, double value, char* out, uint32_t size) {
80+
neuralrack_plugin_t *plug = (neuralrack_plugin_t *)plugin->plugin_data;
81+
if (param_id < 0 || param_id >= plug->r->param.parameter.size()) return false;
8282
snprintf(out, size, "%.2f", value);
8383
return true;
8484
}
8585

86-
static bool params_text_to_value(const clap_plugin_t*, clap_id param_id, const char* text, double* out_value) {
87-
if (param_id < 0 || param_id >= PARAM_COUNT) return false;
86+
static bool params_text_to_value(const clap_plugin_t* plugin, clap_id param_id, const char* text, double* out_value) {
87+
neuralrack_plugin_t *plug = (neuralrack_plugin_t *)plugin->plugin_data;
88+
if (param_id < 0 || param_id >= plug->r->param.parameter.size()) return false;
8889
*out_value = atof(text);
8990
return true;
9091
}
@@ -95,7 +96,7 @@ static void sync_params_to_plug(const clap_plugin_t *plugin, const clap_event_he
9596
switch (hdr->type) {
9697
case CLAP_EVENT_PARAM_VALUE: {
9798
const clap_event_param_value_t *ev = (const clap_event_param_value_t *)hdr;
98-
plug->params.setParam(plug, ev->param_id, ev->value);
99+
plug->r->param.setParam(ev->param_id, ev->value);
99100
break;
100101
}
101102
}
@@ -104,7 +105,7 @@ static void sync_params_to_plug(const clap_plugin_t *plugin, const clap_event_he
104105

105106
static void sync_params_to_host(const clap_plugin_t *plugin, const clap_output_events_t *out) {
106107
neuralrack_plugin_t *plug = (neuralrack_plugin_t *)plugin->plugin_data;
107-
for (uint32_t i = 0; i < PARAM_COUNT; i++) {
108+
for (uint32_t i = 0; i < plug->r->param.parameter.size(); i++) {
108109
clap_event_param_value_t event = {};
109110
event.header.size = sizeof(event);
110111
event.header.time = 0;
@@ -117,7 +118,7 @@ static void sync_params_to_host(const clap_plugin_t *plugin, const clap_output_e
117118
event.port_index = -1;
118119
event.channel = -1;
119120
event.key = -1;
120-
event.value = plug->params.getParam(plug, i);;
121+
event.value = plug->r->param.getParam(i);
121122
out->try_push(out, &event.header);
122123
}
123124
}
@@ -130,8 +131,8 @@ static void params_flush(const clap_plugin_t *plugin,
130131
const clap_event_header_t *ev = in->get(in, i);
131132
if (ev->type == CLAP_EVENT_PARAM_VALUE) {
132133
auto *p = (const clap_event_param_value_t *)ev;
133-
if (p->param_id >= 0 && p->param_id < PARAM_COUNT) {
134-
plug->params.setParam(plug, p->param_id, p->value);
134+
if (p->param_id >= 0 && p->param_id < plug->r->param.parameter.size()) {
135+
plug->r->param.setParam(p->param_id, p->value);
135136
}
136137
}
137138
}
@@ -274,7 +275,6 @@ static bool neuralrack_gui_create(const clap_plugin *plugin, const char *api, bo
274275
if (!plug->guiIsCreated) {
275276
plug->r->startGui();
276277
plug->r->enableEngine(1);
277-
fprintf(stderr, "createGui\n");
278278
}
279279
plug->guiIsCreated = true;
280280
return true;
@@ -391,9 +391,9 @@ static clap_process_status neuralrack_process(const clap_plugin_t *plugin, const
391391
uint32_t ev_index = 0;
392392
uint32_t next_ev_frame = nev > 0 ? 0 : nframes;
393393

394-
if (plug->r->controllerChanged.load(std::memory_order_acquire)) {
394+
if (plug->r->param.controllerChanged.load(std::memory_order_acquire)) {
395395
sync_params_to_host(plugin, process->out_events);
396-
plug->r->controllerChanged.store(false, std::memory_order_release);
396+
plug->r->param.controllerChanged.store(false, std::memory_order_release);
397397
}
398398

399399
for (uint32_t i = 0; i < nframes;++i) {

NeuralRack/clap/NeuralRackParameter.cc

Lines changed: 0 additions & 101 deletions
This file was deleted.

NeuralRack/clap/NeuralRackParameter.h

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)