int RemotePluginClient::getOutputCount() { writeOpcode(m_controlRequestFd, RemotePluginGetOutputCount); m_numOutputs = readInt(m_controlResponseFd); sizeShm(); return m_numOutputs; }
void RemotePluginClient::setBufferSize(int s) { if (s == m_bufferSize) return; m_bufferSize = s; sizeShm(); writeOpcode(&m_shmControl->ringBuffer, RemotePluginSetBufferSize); writeInt(&m_shmControl->ringBuffer, s); commitWrite(&m_shmControl->ringBuffer); waitForServer(); }
void RemotePluginServer::dispatchControlEvents() { RemotePluginOpcode opcode = RemotePluginNoOpcode; static float *parameterBuffer = 0; tryRead(m_controlRequestFd, &opcode, sizeof(RemotePluginOpcode)); switch (opcode) { case RemotePluginGetVersion: writeFloat(m_controlResponseFd, getVersion()); break; case RemotePluginGetName: writeString(m_controlResponseFd, getName()); break; case RemotePluginGetMaker: writeString(m_controlResponseFd, getMaker()); break; case RemotePluginTerminate: terminate(); break; case RemotePluginGetInputCount: m_numInputs = getInputCount(); writeInt(m_controlResponseFd, m_numInputs); break; case RemotePluginGetOutputCount: m_numOutputs = getOutputCount(); writeInt(m_controlResponseFd, m_numOutputs); break; case RemotePluginGetParameterCount: writeInt(m_controlResponseFd, getParameterCount()); break; case RemotePluginGetParameterName: writeString(m_controlResponseFd, getParameterName(readInt(m_controlRequestFd))); break; case RemotePluginGetParameter: writeFloat(m_controlResponseFd, getParameter(readInt(m_controlRequestFd))); break; case RemotePluginGetParameterDefault: writeFloat(m_controlResponseFd, getParameterDefault(readInt(m_controlRequestFd))); break; case RemotePluginGetParameters: { if (!parameterBuffer) { parameterBuffer = new float[getParameterCount()]; } int p0 = readInt(m_controlRequestFd); int pn = readInt(m_controlRequestFd); getParameters(p0, pn, parameterBuffer); tryWrite(m_controlResponseFd, parameterBuffer, (pn - p0 + 1) * sizeof(float)); break; } case RemotePluginHasMIDIInput: { bool m = hasMIDIInput(); tryWrite(m_controlResponseFd, &m, sizeof(bool)); break; } case RemotePluginGetProgramCount: writeInt(m_controlResponseFd, getProgramCount()); break; case RemotePluginGetProgramName: writeString(m_controlResponseFd, getProgramName(readInt(m_controlRequestFd))); break; case RemotePluginIsReady: { if (!m_shm) sizeShm(); bool b(isReady()); std::cerr << "isReady: returning " << b << std::endl; tryWrite(m_controlResponseFd, &b, sizeof(bool)); } case RemotePluginSetDebugLevel: { RemotePluginDebugLevel newLevel = m_debugLevel; tryRead(m_controlRequestFd, &newLevel, sizeof(RemotePluginDebugLevel)); setDebugLevel(newLevel); m_debugLevel = newLevel; break; } case RemotePluginWarn: { bool b = warn(readString(m_controlRequestFd)); tryWrite(m_controlResponseFd, &b, sizeof(bool)); break; } case RemotePluginShowGUI: { showGUI(readString(m_controlRequestFd)); break; } case RemotePluginHideGUI: { hideGUI(); break; } //Deryabin Andrew: vst chunks support case RemotePluginGetVSTChunk: { std::vector<char> chunk = getVSTChunk(); writeRaw(m_controlResponseFd, chunk); break; } case RemotePluginSetVSTChunk: { std::vector<char> chunk = readRaw(m_controlRequestFd); setVSTChunk(chunk); break; } //Deryabin Andrew: vst chunks support: end code case RemotePluginNoOpcode: break; case RemotePluginReset: reset(); break; default: std::cerr << "WARNING: RemotePluginServer::dispatchControlEvents: unexpected opcode " << opcode << std::endl; } }
void RemotePluginServer::dispatchProcessEvents() { RemotePluginOpcode opcode = RemotePluginNoOpcode; tryRead(&m_shmControl->ringBuffer, &opcode, sizeof(RemotePluginOpcode)); // std::cerr << "read opcode: " << opcode << std::endl; switch (opcode) { case RemotePluginProcess: { if (m_bufferSize < 0) { std::cerr << "ERROR: RemotePluginServer: buffer size must be set before process" << std::endl; return; } if (m_numInputs < 0) { std::cerr << "ERROR: RemotePluginServer: input count must be tested before process" << std::endl; return; } if (m_numOutputs < 0) { std::cerr << "ERROR: RemotePluginServer: output count must be tested before process" << std::endl; return; } if (!m_shm) { sizeShm(); if (!m_shm) { std::cerr << "ERROR: RemotePluginServer: no shared memory region available" << std::endl; return; } } // std::cerr << "server process: entering" << std::endl; size_t blocksz = m_bufferSize * sizeof(float); for (int i = 0; i < m_numInputs; ++i) { m_inputs[i] = (float *)(m_shm + i * blocksz); } for (int i = 0; i < m_numOutputs; ++i) { m_outputs[i] = (float *)(m_shm + (i + m_numInputs) * blocksz); } process(m_inputs, m_outputs); // std::cerr << "server process: written" << std::endl; break; } case RemotePluginSetParameter: { int pn(readInt(&m_shmControl->ringBuffer)); setParameter(pn, readFloat(&m_shmControl->ringBuffer)); break; } case RemotePluginSetCurrentProgram: setCurrentProgram(readInt(&m_shmControl->ringBuffer)); break; case RemotePluginSendMIDIData: { int events = 0; int *frameoffsets = 0; unsigned char *data = readMIDIData(&m_shmControl->ringBuffer, &frameoffsets, events); if (events && data && frameoffsets) { // std::cerr << "RemotePluginServer::sendMIDIData(" << events << ")" << std::endl; sendMIDIData(data, frameoffsets, events); } break; } case RemotePluginSetBufferSize: { int newSize = readInt(&m_shmControl->ringBuffer); setBufferSize(newSize); m_bufferSize = newSize; break; } case RemotePluginSetSampleRate: setSampleRate(readInt(&m_shmControl->ringBuffer)); break; default: std::cerr << "WARNING: RemotePluginServer::dispatchProcessEvents: unexpected opcode " << opcode << std::endl; } }