Skip to content

Commit a15f60a

Browse files
committed
Fix issue #12 as well for vst2
1 parent d067477 commit a15f60a

File tree

3 files changed

+99
-56
lines changed

3 files changed

+99
-56
lines changed

NeuralRack/clap/NeuralRack.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class NeuralRack
4242
ui->uiSampleRate = 0;
4343
ui->f_index = 0;
4444
title = "NeuralRack";
45+
firstLoop = true;
46+
p = 0;
4547
for(int i = 0;i<CONTROLS;i++)
4648
ui->widget[i] = NULL;
4749
}
@@ -95,6 +97,7 @@ class NeuralRack
9597
engine._notify_ui.store(true, std::memory_order_release);
9698
getEngineValues();
9799
widget_show_all(TopWin);
100+
firstLoop = true;
98101
}
99102

100103
void setParent(Window window) {
@@ -103,10 +106,37 @@ class NeuralRack
103106
#else
104107
XReparentWindow(ui->main.dpy, TopWin->widget, (Window) window, 0, 0);
105108
#endif
109+
p = window;
110+
}
111+
112+
void checkParentWindowSize(int width, int height) {
113+
#if defined (IS_VST2)
114+
if (!p) return;
115+
int host_width = 1;
116+
int host_height = 1;
117+
#if defined(_WIN32)
118+
RECT rect;
119+
if (GetClientRect((HWND) p, &rect)) {
120+
host_width = rect.right - rect.left;
121+
host_height = rect.bottom - rect.top;
122+
}
123+
#else
124+
XWindowAttributes attrs;
125+
if (XGetWindowAttributes(ui->main.dpy, p, &attrs)) {
126+
host_width = attrs.width;
127+
host_height = attrs.height;
128+
}
129+
#endif
130+
if ((host_width != width && host_width != 1) ||
131+
(host_height != height && host_height != 1)) {
132+
os_resize_window(ui->main.dpy, TopWin, host_width, host_height);
133+
}
134+
#endif
106135
}
107136

108137
void hideGui() {
109138
widget_hide(TopWin);
139+
firstLoop = false;
110140
}
111141

112142
void quitGui() {
@@ -115,6 +145,10 @@ class NeuralRack
115145

116146
void runGui() {
117147
checkEngine();
148+
if (firstLoop) {
149+
checkParentWindowSize(TopWin->width, TopWin->height);
150+
firstLoop = false;
151+
}
118152
run_embedded(&ui->main);
119153
}
120154

@@ -504,9 +538,11 @@ class NeuralRack
504538
ParallelThread fetch;
505539
X11_UI* ui;
506540
neuralrack::Engine engine;
541+
Window p;
507542
std::atomic<bool> workToDo;
508543
double s_time;
509544
std::string title;
545+
bool firstLoop;
510546

511547
// rebuild file menu when needed
512548
void rebuild_file_menu(ModelPicker *m) {

NeuralRack/makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ ifeq (,$(filter mod,$(MAKECMDGOALS)))
229229
ifeq (,$(filter modapp,$(MAKECMDGOALS)))
230230
ifeq (,$(filter lv2,$(MAKECMDGOALS)))
231231
ifeq (,$(filter clap,$(MAKECMDGOALS)))
232+
ifeq (,$(filter vst2,$(MAKECMDGOALS)))
232233
INFOSTRING = with
233234
HAVEJACK = $(shell $(PKGCONFIG) $(PKGCONFIG_FLAGS) --cflags --libs jack 2>/dev/null)
234235
ifneq ($(HAVEJACK), )
@@ -256,6 +257,7 @@ endif
256257
endif
257258
endif
258259
endif
260+
endif
259261

260262
ifeq ($(PAWPAW_BUILD),1)
261263
CXXFLAGS += -DPAWPAW=1

NeuralRack/vst2/NeuralRackvst.cpp

Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
*/
88

99
#include "vestige.h"
10+
1011
#include <cstring>
1112
#include <cstdio>
1213
#include <cstdlib>
13-
1414
#include <stdint.h>
1515
#include <stddef.h>
16+
17+
#define IS_VST2
1618
#include "NeuralRack.cc"
1719

1820
typedef struct ERect {
@@ -29,6 +31,10 @@ typedef struct ERect {
2931

3032
#define FlagsChunks (1 << 5)
3133

34+
/****************************************************************
35+
** neuralrack_plugin_t -> the plugin struct
36+
*/
37+
3238
struct neuralrack_plugin_t {
3339
AEffect* effect;
3440
NeuralRack *r;
@@ -54,44 +60,24 @@ void sendFileName(X11_UI *ui, ModelPicker* m, int old){
5460
r->sendFileName(m, old);
5561
}
5662

57-
// Forward declarations
58-
static intptr_t dispatcher(AEffect*, int32_t, int32_t, intptr_t, void*, float);
59-
static void processReplacing(AEffect*, float**, float**, int32_t);
60-
static void setParameter(AEffect*, int32_t, float);
61-
static float getParameter(AEffect*, int32_t);
62-
63-
// --- Param helpers ---
64-
static void getParameterName(AEffect*, int32_t, char*);
63+
/****************************************************************
64+
** Parameter handling not used here
65+
*/
6566

66-
// --- Main Entry ---
67+
static void setParameter(AEffect* effect, int32_t index, float value) {
68+
}
6769

68-
extern "C" __attribute__ ((visibility ("default")))
69-
AEffect* VSTPluginMain(audioMasterCallback audioMaster) {
70-
neuralrack_plugin_t* plug = (neuralrack_plugin_t*)calloc(1, sizeof(neuralrack_plugin_t));
71-
AEffect* effect = (AEffect*)calloc(1, sizeof(AEffect));
72-
plug->r = new NeuralRack();
73-
effect->object = plug;
74-
plug->effect = effect;
75-
plug->width = WINDOW_WIDTH;
76-
plug->height = WINDOW_HEIGHT;
77-
plug->editorRect = {0, 0, (short) plug->height, (short) plug->width};
78-
plug->SampleRate = 48000.0;
70+
static float getParameter(AEffect* effect, int32_t index) {
71+
return 0.0;
72+
}
7973

80-
effect->magic = kEffectMagic;
81-
effect->dispatcher = dispatcher;
82-
effect->processReplacing = processReplacing;
83-
effect->setParameter = setParameter;
84-
effect->getParameter = getParameter;
85-
effect->numPrograms = 1;
86-
effect->numParams = 0;
87-
effect->numInputs = 1;
88-
effect->numOutputs = 2;
89-
effect->flags = effFlagsHasEditor | effFlagsCanReplacing | FlagsChunks;
90-
effect->uniqueID = PLUGIN_UID;
91-
return effect;
74+
static void getParameterName(AEffect*, int32_t index, char* label) {
9275
}
9376

94-
// --- Audio processing ---
77+
/****************************************************************
78+
** The audio process
79+
*/
80+
9581
static void processReplacing(AEffect* effect, float** inputs, float** outputs, int32_t sampleFrames) {
9682
neuralrack_plugin_t* plug = (neuralrack_plugin_t*)effect->object;
9783

@@ -106,39 +92,32 @@ static void processReplacing(AEffect* effect, float** inputs, float** outputs, i
10692
plug->r->process(sampleFrames, left_output, right_output);
10793
}
10894

109-
// --- Parameter handling ---
110-
static void setParameter(AEffect* effect, int32_t index, float value) {
111-
}
112-
113-
static float getParameter(AEffect* effect, int32_t index) {
114-
return 0.0;
115-
}
116-
117-
static void getParameterName(AEffect*, int32_t index, char* label) {
118-
}
95+
/****************************************************************
96+
** Save and load state
97+
*/
11998

120-
// --- state handling ---
12199
void saveState(neuralrack_plugin_t* plug, void** data, int* size, int isBank) {
122100
plug->r->saveState(&plug->state);
123101
*size = strlen(plug->state.c_str());
124-
//asprintf((char**)data, "%s", plug->state.c_str());
102+
// only save data here for later loading
125103
*data = (void*)plug->state.c_str();
126-
//fprintf(stderr, "state %s\n", plug->state.c_str());
127-
//fprintf(stderr, "data %s\n", (char*)*data);
128104
}
129105

130106
void loadState(neuralrack_plugin_t* plug, int size, int isBank) {
131107
if (plug->state.empty()) return;
132-
//fprintf(stderr, "Load state %s\n", plug->state.c_str());
133108
plug->r->readState(plug->state);
134109
}
135-
// --- Dispatcher ---
110+
111+
/****************************************************************
112+
** The Dispatcher
113+
*/
114+
136115
static intptr_t dispatcher(AEffect* effect, int32_t opCode, int32_t index, intptr_t value, void* ptr, float opt) {
137116
neuralrack_plugin_t* plug = (neuralrack_plugin_t*)effect->object;
138117
switch (opCode) {
139118
case effEditGetRect:
140119
if (ptr) *(ERect**)ptr = &plug->editorRect;
141-
break;
120+
return 1;
142121
case effGetEffectName:
143122
strncpy((char*)ptr, "NeuralRack", VestigeMaxNameLen - 1);
144123
((char*)ptr)[VestigeMaxNameLen - 1] = '\0';
@@ -183,7 +162,6 @@ static intptr_t dispatcher(AEffect* effect, int32_t opCode, int32_t index, intpt
183162
break;
184163
//case effGetProgram:
185164
case 23: { // effGetChunk
186-
//fprintf(stderr, "saveState\n");
187165
void* chunkData = nullptr;
188166
int chunkSize = 0;
189167
saveState(plug, &chunkData, &chunkSize, index); // index=0: program, 1: bank
@@ -192,14 +170,41 @@ static intptr_t dispatcher(AEffect* effect, int32_t opCode, int32_t index, intpt
192170
}
193171
//case effSetProgram:
194172
case 24: { // effSetChunk
195-
// index == 0: set plugin state; index == 1: set bank state
196-
//fprintf(stderr, "loadState\n");
197173
plug->state = (const char*) ptr;
198-
// int chunkSize = value; // value = data size in bytes
199-
// loadState(plug, chunkSize, index); // index=0: program, 1: bank
174+
// read state, but load it after we got the sample rate
200175
break;
201176
}
202177
default: break;
203178
}
204179
return 0;
205180
}
181+
182+
/****************************************************************
183+
** The Main Entry
184+
*/
185+
186+
extern "C" __attribute__ ((visibility ("default")))
187+
AEffect* VSTPluginMain(audioMasterCallback audioMaster) {
188+
neuralrack_plugin_t* plug = (neuralrack_plugin_t*)calloc(1, sizeof(neuralrack_plugin_t));
189+
AEffect* effect = (AEffect*)calloc(1, sizeof(AEffect));
190+
plug->r = new NeuralRack();
191+
effect->object = plug;
192+
plug->effect = effect;
193+
plug->width = WINDOW_WIDTH;
194+
plug->height = WINDOW_HEIGHT;
195+
plug->editorRect = {0, 0, (short) plug->height, (short) plug->width};
196+
plug->SampleRate = 48000.0;
197+
198+
effect->magic = kEffectMagic;
199+
effect->dispatcher = dispatcher;
200+
effect->processReplacing = processReplacing;
201+
effect->setParameter = setParameter;
202+
effect->getParameter = getParameter;
203+
effect->numPrograms = 1;
204+
effect->numParams = 0;
205+
effect->numInputs = 1;
206+
effect->numOutputs = 2;
207+
effect->flags = effFlagsHasEditor | effFlagsCanReplacing | FlagsChunks;
208+
effect->uniqueID = PLUGIN_UID;
209+
return effect;
210+
}

0 commit comments

Comments
 (0)