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
1820typedef 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+
3238struct 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+
9581static 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 ---
12199void 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
130106void 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+
136115static 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