void WebSocketOpcode_handleReceive(struct libwebsocket *websocket, WebSocketOpcode *self, CSOUND *csound, size_t inputDataSize, void *inputData) { const struct libwebsocket_protocols *protocol = libwebsockets_get_protocol(websocket); OpcodeArgument *argument = &self->outputArguments[protocol->protocol_index]; if (protocol->protocol_index >= self->outputArgumentCount || argument->iRateVarSent == true) { return; } if (argument->bytesCount != inputDataSize && argument->argumentType != STRING_VAR) { csound->Message(csound, Str("websocket: received message from %s is not correct " "size for variable %s, message dumped"), protocol->name, argument->name); return; } if (argument->argumentType == STRING_VAR && argument->bytesCount > stringVarMaximumBytesCount) { csound->Message(csound, Str("websocket: received string message from %s is " "too large, message dumped"), protocol->name, argument->name); return; } int writtenItems = csoundWriteCircularBuffer(csound, argument->circularBuffer, inputData, argument->itemsCount); if (writtenItems == 0) { csound->Message(csound, Str("websocket: received message from %s dumped, " "buffer overrrun"), argument->name); } else { if (argument->argumentType == IRATE_VAR || argument->argumentType == IRATE_ARRAY) { argument->iRateVarSent = true; } } }
void WebSocketOpcode_sendInputArgumentData(CSOUND *csound, WebSocketOpcode *self) { int i; for (i = 0; i < self->inputArgumentCount; ++i) { OpcodeArgument *currentArgument = &self->inputArguments[i]; if (currentArgument->iRateVarSent == true) { continue; } int itemsWritten = csoundWriteCircularBuffer(csound, currentArgument->circularBuffer, currentArgument->dataPointer, currentArgument->itemsCount); if (itemsWritten != currentArgument->itemsCount) { csound->Message(csound, Str("websocket: variable %s data not sent," "buffer overrrun\n"), currentArgument->name); } } }
int CsoundPerformanceThread::Perform() { int retval = 0; do { while (firstMessage) { csoundLockMutex(queueLock); do { CsoundPerformanceThreadMessage *msg; // get oldest message msg = (CsoundPerformanceThreadMessage*) firstMessage; if (!msg) break; // unlink from FIFO firstMessage = msg->nxt; if (!msg->nxt) lastMessage = (CsoundPerformanceThreadMessage*) 0; // process and destroy message retval = msg->run(); delete msg; // TODO: This should be moved out of the Perform function } while (!retval); if (paused) csoundWaitThreadLock(pauseLock, (size_t) 0); // mark queue as empty csoundNotifyThreadLock(flushLock); csoundUnlockMutex(queueLock); // if error or end of score, return now if (retval) goto endOfPerf; // if paused, wait until a new message is received, then loop back if (!paused) break; // VL: if this is paused, then it will double lock. csoundWaitThreadLockNoTimeout(pauseLock); csoundNotifyThreadLock(pauseLock); } if(processcallback != NULL) processcallback(cdata); retval = csoundPerformKsmps(csound); if (recordData.running) { MYFLT *spout = csoundGetSpout(csound); int len = csoundGetKsmps(csound) * csoundGetNchnls(csound); if (csoundGet0dBFS(csound) != 1.0) { MYFLT zdbfs = csoundGet0dBFS(csound); MYFLT *modspout = spout; for (int i = 0; i < len; i++) { *modspout /= zdbfs; modspout++; } } int written = csoundWriteCircularBuffer(NULL, recordData.cbuf, spout, len); if (written != len) { csoundMessage(csound, "perfThread record buffer overrun."); } } pthread_cond_signal(&recordData.condvar); // Needs to be outside the if for the case where stop record was requested } while (!retval); endOfPerf: status = retval; csoundCleanup(csound); // delete any pending messages csoundLockMutex(queueLock); { CsoundPerformanceThreadMessage *msg; msg = (CsoundPerformanceThreadMessage*) firstMessage; firstMessage = (CsoundPerformanceThreadMessage*) 0; lastMessage = (CsoundPerformanceThreadMessage*) 0; while (msg) { CsoundPerformanceThreadMessage *nxt = msg->nxt; delete msg; msg = nxt; } } csoundNotifyThreadLock(flushLock); csoundUnlockMutex(queueLock); running = 1; return retval; }