Compare commits

..

No commits in common. "622b2ba1692c7fe8ee4d783d2ddad6a1ae94570f" and "7d9f2a0c3ad0f0796dd7aed52df49394dc8601ec" have entirely different histories.

2 changed files with 41 additions and 73 deletions

View File

@ -318,13 +318,11 @@ typedef struct pluginInstance {
#ifdef DATA_MESSAGING
Steinberg_Vst_IConnectionPointVtbl *vtblIConnectionPoint;
Steinberg_Vst_IConnectionPoint *connectedPoint;
uint8_t message_data_in[DATA_MESSAGING_MAX];
size_t message_data_in_size;
uint8_t message_data_out[DATA_MESSAGING_MAX];
size_t message_data_out_size;
char message_data_out_tosend; // This is to tell message_thread to send data
uint8_t message_data[DATA_MESSAGING_MAX];
size_t message_data_size;
char message_data_tosend; // This is to tell message_thread to send data
thrd_t message_thread;
int message_cmd;
int message_flag;
mtx_t message_mutex;
cnd_t message_cond;
@ -438,10 +436,7 @@ static Steinberg_tresult pluginIConnectionPointConnect(void* thisInterface, stru
if (!other) return Steinberg_kInvalidArgument;
if (p->connectedPoint) return Steinberg_kResultFalse;
mtx_lock(&p->message_mutex);
p->connectedPoint = other;
mtx_unlock(&p->message_mutex);
return Steinberg_kResultOk;
}
@ -449,9 +444,7 @@ static Steinberg_tresult pluginIConnectionPointConnect(void* thisInterface, stru
static Steinberg_tresult pluginIConnectionPointDisconnect(void* thisInterface, struct Steinberg_Vst_IConnectionPoint* other) {
pluginInstance *p = (pluginInstance *)((char *)thisInterface - offsetof(pluginInstance, vtblIConnectionPoint));
if (p->connectedPoint && other == p->connectedPoint) {
mtx_lock(&p->message_mutex);
p->connectedPoint = NULL;
mtx_unlock(&p->message_mutex);
return Steinberg_kResultOk;
}
return Steinberg_kResultFalse;
@ -470,16 +463,12 @@ static Steinberg_tresult pluginIConnectionPointNotify(void* thisInterface, struc
const void *data = NULL;
unsigned int size = 0;
alist->lpVtbl->getBinary(alist, "message_data", &data, &size);
alist->lpVtbl->getBinary(alist, "yoyoyo", &data, &size);
if (!data || size == 0)
if (!data || size <= 0)
return Steinberg_kResultFalse;
mtx_lock(&p->message_mutex);
memcpy(&p->message_data_in, data, size);
p->message_data_in_size = size;
mtx_unlock(&p->message_mutex);
plugin_receive_from_ui(&(p->p), data, size);
return Steinberg_kResultOk;
}
@ -498,12 +487,12 @@ static Steinberg_Vst_IConnectionPointVtbl pluginVtblIConnectionPoint = {
// Assuming this gets called by audio thread only
static char send_to_ui (void *handle, const void *data, size_t bytes) {
pluginInstance *p = (pluginInstance *)handle;
if (!data || bytes == 0 || bytes > DATA_MESSAGING_MAX) {
if (!data || bytes <= 0 || bytes > DATA_MESSAGING_MAX) {
return 1;
}
memcpy(p->message_data_out, data, bytes);
p->message_data_out_size = bytes;
p->message_data_out_tosend = 1;
memcpy(p->message_data, data, bytes);
p->message_data_size = bytes;
p->message_data_tosend = 1;
return 0;
}
# endif
@ -530,14 +519,13 @@ int message_thread_f(void *arg) {
while (1) {
mtx_lock(&p->message_mutex);
if (p->message_cmd == 0) { // Wait
while (p->message_flag == 0) { // Wait
cnd_wait(&p->message_cond, &p->message_mutex);
}
if (p->message_cmd == 1) { // do work
if (p->message_flag == 1) { // do work
if (!p->connectedPoint || ! p->context) {
mtx_unlock(&p->message_mutex);
thrd_sleep(&(struct timespec){.tv_nsec=1e+8}, NULL); // sleep 100 msec
// TODO: What to do there?
continue;
}
@ -547,33 +535,25 @@ int message_thread_f(void *arg) {
app->lpVtbl->createInstance(app, (char*) Steinberg_Vst_IMessage_iid, (char*) Steinberg_Vst_IMessage_iid, (void**)&msg);
if (!msg) {
mtx_unlock(&p->message_mutex);
thrd_sleep(&(struct timespec){.tv_nsec=1e+8}, NULL); // sleep 100 msec
// TODO: what to do here?
continue;
}
msg->lpVtbl->setMessageID(msg, "HelloMessage");
Steinberg_Vst_IAttributeList *alist = msg->lpVtbl->getAttributes(msg);
if (!alist) {
msg->lpVtbl->release(msg);
mtx_unlock(&p->message_mutex);
thrd_sleep(&(struct timespec){.tv_nsec=1e+8}, NULL); // sleep 100 msec
// TODO: what to do here?
continue;
}
alist->lpVtbl->setBinary(alist, "message_data", p->message_data_out, p->message_data_out_size);
Steinberg_tresult r = ov->notify(p->connectedPoint, msg);
if (r == Steinberg_kResultFalse) {
msg->lpVtbl->release(msg);
mtx_unlock(&p->message_mutex);
thrd_sleep(&(struct timespec){.tv_nsec=1e+8}, NULL); // sleep 100 msec
continue;
}
alist->lpVtbl->setBinary(alist, "yoyoyo", p->message_data, p->message_data_size);
ov->notify(p->connectedPoint, msg);
msg->lpVtbl->release(msg);
p->message_cmd = 0;
p->message_flag = 0;
} else if (p->message_cmd == 2) { // exit
} else if (p->message_flag == 2) { // exit
mtx_unlock(&p->message_mutex);
break;
}
@ -646,6 +626,7 @@ static Steinberg_tresult pluginInitialize(void *thisInterface, struct Steinberg_
mtx_init(&p->message_mutex, mtx_plain);
cnd_init(&p->message_cond);
if (thrd_create(&p->message_thread, message_thread_f, p) != thrd_success) {
fprintf(stderr, "Failed to create message_thread\n");
return Steinberg_kResultFalse;
}
#endif
@ -663,7 +644,7 @@ static Steinberg_tresult pluginTerminate(void *thisInterface) {
#ifdef DATA_MESSAGING
mtx_lock(&p->message_mutex);
p->message_cmd = 2;
p->message_flag = 2;
cnd_signal(&p->message_cond);
mtx_unlock(&p->message_mutex);
thrd_join(p->message_thread, NULL);
@ -1288,19 +1269,12 @@ static Steinberg_tresult pluginProcess(void* thisInterface, struct Steinberg_Vst
#endif
#ifdef DATA_MESSAGING
if (p->message_data_in_size > 0 || p->message_data_out_tosend) {
if (p->message_data_tosend) { // message_data_tosend is manipulated by audio thread only
if (mtx_trylock(&p->message_mutex) == thrd_success) {
if (p->message_data_in_size > 0) {
plugin_receive_from_ui(&(p->p), p->message_data_in, p->message_data_in_size);
p->message_data_in_size = 0;
}
if (p->message_data_out_tosend) { // message_data_out_tosend is manipulated by audio thread only
p->message_cmd = 1;
cnd_signal(&p->message_cond);
p->message_data_out_tosend = 0;
}
p->message_flag = 1;
cnd_signal(&p->message_cond);
mtx_unlock(&p->message_mutex);
p->message_data_tosend = 0;
}
}
#endif
@ -1682,13 +1656,12 @@ static void plugViewSetParameterEndCb(void *handle, size_t index, float value) {
static char send_to_dsp (void *handle, const void *data, size_t bytes) {
plugView *v = (plugView *)handle;
if (!data || bytes == 0 || bytes > DATA_MESSAGING_MAX) {
if (!data || bytes <= 0 || bytes > DATA_MESSAGING_MAX) {
return 1;
}
if (!v->ctrl->connectedPoint || !v->ctrl->context) {
return 1;
}
if (!v->ctrl->connectedPoint || !v->ctrl->context)
return 2;
Steinberg_Vst_IConnectionPointVtbl *ov = (Steinberg_Vst_IConnectionPointVtbl*) v->ctrl->connectedPoint->lpVtbl;
Steinberg_Vst_IHostApplication *app = (Steinberg_Vst_IHostApplication*) v->ctrl->context;
@ -1696,23 +1669,19 @@ static char send_to_dsp (void *handle, const void *data, size_t bytes) {
app->lpVtbl->createInstance(app, (char*) Steinberg_Vst_IMessage_iid, (char*) Steinberg_Vst_IMessage_iid, (void**)&(msg));
if (!msg)
return 1;
return 3;
msg->lpVtbl->setMessageID(msg, "HelloMessage");
Steinberg_Vst_IAttributeList *alist = msg->lpVtbl->getAttributes(msg);
if (!alist) {
msg->lpVtbl->release(msg);
return 1;
}
if (!alist)
return 4;
alist->lpVtbl->setBinary(alist, "message_data", data, bytes);
Steinberg_tresult r = ov->notify(v->ctrl->connectedPoint, msg);
if (r == Steinberg_kResultFalse) {
msg->lpVtbl->release(msg);
return 1;
}
alist->lpVtbl->setBinary(alist, "yoyoyo", data, bytes);
ov->notify(v->ctrl->connectedPoint, msg);
msg->lpVtbl->release(msg);
return 0;
}
# endif
@ -2603,9 +2572,9 @@ static Steinberg_tresult controllerIConnectionPointNotify(void* thisInterface, s
const void *data = NULL;
unsigned int size = 0;
alist->lpVtbl->getBinary(alist, "message_data", &data, &size);
alist->lpVtbl->getBinary(alist, "yoyoyo", &data, &size);
if (!data || size == 0)
if (!data || size <= 0)
return Steinberg_kResultFalse;
for (size_t i = 0; i < c->viewsCount; i++) {
@ -2726,8 +2695,7 @@ static Steinberg_tresult factoryCreateInstance(void *thisInterface, Steinberg_FI
#ifdef DATA_MESSAGING
p->vtblIConnectionPoint = &pluginVtblIConnectionPoint;
p->connectedPoint = NULL;
p->message_data_out_tosend = 0;
p->message_data_in_size = 0;
p->message_data_tosend = 0;
#endif
*obj = p;
TRACE(" instance: %p\n", (void *)p);

View File

@ -38,7 +38,7 @@ typedef struct {
plugin_ui_callbacks cbs;
} plugin_ui;
#ifdef TEMPLATE_SUPPORTS_MESSAGING
#if TEMPLATE_SUPPORTS_MESSAGING
static void plugin_ui_receive_from_dsp (plugin_ui *instance, const void *data, size_t bytes) {
(void) instance;
printf("plugin_ui_receive_from_dsp %ld bytes at %p: \n", bytes, data);