Signed-off-by: falkTX <falktx@falktx.com>tags/v2.1-rc2
| @@ -1725,7 +1725,7 @@ private: | |||
| // ----------------------------------------------------------------------- | |||
| bool CarlaEngineNativeUI::msgReceived(const char*const msg) noexcept | |||
| bool CarlaEngineNativeUI::msgReceived(const char* const msg) noexcept | |||
| { | |||
| if (CarlaExternalUI::msgReceived(msg)) | |||
| return true; | |||
| @@ -1740,14 +1740,11 @@ bool CarlaEngineNativeUI::msgReceived(const char*const msg) noexcept | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(option), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(value), true); | |||
| readNextLineAsString(valueStr); // can be null | |||
| readNextLineAsString(valueStr, false); // can be null | |||
| try { | |||
| fEngine->setOption(static_cast<EngineOption>(option), value, valueStr); | |||
| } CARLA_SAFE_EXCEPTION("setOption"); | |||
| if (valueStr != nullptr) | |||
| delete[] valueStr; | |||
| } | |||
| else if (std::strcmp(msg, "clear_engine_xruns") == 0) | |||
| { | |||
| @@ -1761,37 +1758,31 @@ bool CarlaEngineNativeUI::msgReceived(const char*const msg) noexcept | |||
| { | |||
| const char* filename; | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename, false), true); | |||
| try { | |||
| ok = fEngine->loadFile(filename); | |||
| } CARLA_SAFE_EXCEPTION("loadFile"); | |||
| delete[] filename; | |||
| } | |||
| else if (std::strcmp(msg, "load_project") == 0) | |||
| { | |||
| const char* filename; | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename, false), true); | |||
| try { | |||
| ok = fEngine->loadProject(filename, true); | |||
| } CARLA_SAFE_EXCEPTION("loadProject"); | |||
| delete[] filename; | |||
| } | |||
| else if (std::strcmp(msg, "save_project") == 0) | |||
| { | |||
| const char* filename; | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename, false), true); | |||
| try { | |||
| ok = fEngine->saveProject(filename, true); | |||
| } CARLA_SAFE_EXCEPTION("saveProject"); | |||
| delete[] filename; | |||
| } | |||
| else if (std::strcmp(msg, "clear_project_filename") == 0) | |||
| { | |||
| @@ -1868,9 +1859,9 @@ bool CarlaEngineNativeUI::msgReceived(const char*const msg) noexcept | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(btype), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(ptype), true); | |||
| readNextLineAsString(filename); // can be null | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(name), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(label), true); | |||
| readNextLineAsString(filename, true); // can be null | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(name, true), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(label, true), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsLong(uniqueId), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(options), true); | |||
| @@ -1917,11 +1908,9 @@ bool CarlaEngineNativeUI::msgReceived(const char*const msg) noexcept | |||
| const char* newName; | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(newName), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(newName, false), true); | |||
| ok = fEngine->renamePlugin(pluginId, newName); | |||
| delete[] newName; | |||
| } | |||
| else if (std::strcmp(msg, "clone_plugin") == 0) | |||
| { | |||
| @@ -1955,15 +1944,13 @@ bool CarlaEngineNativeUI::msgReceived(const char*const msg) noexcept | |||
| const char* filename; | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename, false), true); | |||
| if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId)) | |||
| { | |||
| plugin->loadStateFromFile(filename); | |||
| _updateParamValues(plugin, pluginId, false, true); | |||
| } | |||
| delete[] filename; | |||
| } | |||
| else if (std::strcmp(msg, "save_plugin_state") == 0) | |||
| { | |||
| @@ -1971,12 +1958,10 @@ bool CarlaEngineNativeUI::msgReceived(const char*const msg) noexcept | |||
| const char* filename; | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename, false), true); | |||
| if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId)) | |||
| plugin->saveStateToFile(filename); | |||
| delete[] filename; | |||
| } | |||
| else if (std::strcmp(msg, "set_option") == 0) | |||
| { | |||
| @@ -2169,16 +2154,15 @@ bool CarlaEngineNativeUI::msgReceived(const char*const msg) noexcept | |||
| const char* value; | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(type), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(key), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(value), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(type, true), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(key, true), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(value, false), true); | |||
| if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId)) | |||
| plugin->setCustomData(type, key, value, true); | |||
| delete[] type; | |||
| delete[] key; | |||
| delete[] value; | |||
| } | |||
| else if (std::strcmp(msg, "set_chunk_data") == 0) | |||
| { | |||
| @@ -2186,7 +2170,7 @@ bool CarlaEngineNativeUI::msgReceived(const char*const msg) noexcept | |||
| const char* cdata; | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(cdata), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(cdata, false), true); | |||
| if (CarlaPlugin* const plugin = fEngine->getPlugin(pluginId)) | |||
| { | |||
| @@ -2198,8 +2182,6 @@ bool CarlaEngineNativeUI::msgReceived(const char*const msg) noexcept | |||
| #endif | |||
| _updateParamValues(plugin, pluginId, false, true); | |||
| } | |||
| delete[] cdata; | |||
| } | |||
| else if (std::strcmp(msg, "prepare_for_save") == 0) | |||
| { | |||
| @@ -7257,10 +7257,9 @@ bool CarlaPipeServerLV2::msgReceived(const char* const msg) noexcept | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(index), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(size), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(base64atom), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(base64atom, false), true); | |||
| std::vector<uint8_t> chunk(carla_getChunkFromBase64String(base64atom)); | |||
| delete[] base64atom; | |||
| CARLA_SAFE_ASSERT_RETURN(chunk.size() >= sizeof(LV2_Atom), true); | |||
| #ifdef CARLA_PROPER_CPP11_SUPPORT | |||
| @@ -7296,7 +7295,7 @@ bool CarlaPipeServerLV2::msgReceived(const char* const msg) noexcept | |||
| const char* uri; | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(urid), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(uri), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(uri, false), true); | |||
| if (urid != 0) | |||
| { | |||
| @@ -7305,7 +7304,6 @@ bool CarlaPipeServerLV2::msgReceived(const char* const msg) noexcept | |||
| } CARLA_SAFE_EXCEPTION("msgReceived urid"); | |||
| } | |||
| delete[] uri; | |||
| return true; | |||
| } | |||
| @@ -88,7 +88,7 @@ public: | |||
| #endif | |||
| delete[] fLastReadLine; | |||
| fLastReadLine = CarlaPipeClient::_readlineblock(timeout); | |||
| fLastReadLine = CarlaPipeClient::_readlineblock(true, timeout); | |||
| return fLastReadLine; | |||
| } | |||
| @@ -158,13 +158,12 @@ bool CarlaBridgeFormat::msgReceived(const char* const msg) noexcept | |||
| const char* key; | |||
| const char* value; | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(key), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(value), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(key, true), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(value, false), true); | |||
| dspStateChanged(key, value); | |||
| delete[] key; | |||
| delete[] value; | |||
| return true; | |||
| } | |||
| @@ -189,10 +188,9 @@ bool CarlaBridgeFormat::msgReceived(const char* const msg) noexcept | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(index), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(atomTotalSize), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(base64atom), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(base64atom, false), true); | |||
| std::vector<uint8_t> chunk(carla_getChunkFromBase64String(base64atom)); | |||
| delete[] base64atom; | |||
| CARLA_SAFE_ASSERT_RETURN(chunk.size() >= sizeof(LV2_Atom), true); | |||
| #ifdef CARLA_PROPER_CPP11_SUPPORT | |||
| @@ -215,12 +213,11 @@ bool CarlaBridgeFormat::msgReceived(const char* const msg) noexcept | |||
| const char* uri; | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(urid), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(uri), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(uri, false), true); | |||
| if (urid != 0) | |||
| dspURIDReceived(urid, uri); | |||
| delete[] uri; | |||
| return true; | |||
| } | |||
| @@ -235,7 +232,7 @@ bool CarlaBridgeFormat::msgReceived(const char* const msg) noexcept | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(opts.uiScale), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(opts.useTheme), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsBool(opts.useThemeColors), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(opts.windowTitle), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(opts.windowTitle, true), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsULong(transientWindowId), true); | |||
| opts.transientWindowId = transientWindowId; | |||
| @@ -279,11 +276,9 @@ bool CarlaBridgeFormat::msgReceived(const char* const msg) noexcept | |||
| { | |||
| const char* title; | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(title), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(title, false), true); | |||
| fToolkit->setTitle(title); | |||
| delete[] title; | |||
| return true; | |||
| } | |||
| @@ -199,7 +199,7 @@ class CarlaMiniW(ExternalUI, HostWindow): | |||
| value2 = int(self.readlineblock()) | |||
| value3 = int(self.readlineblock()) | |||
| valuef = float(self.readlineblock()) | |||
| valueStr = self.readlineblock().replace("\r", "\n") | |||
| valueStr = self.readlineblock() | |||
| self.host._setViaCallback(action, pluginId, value1, value2, value3, valuef, valueStr) | |||
| engineCallback(self.host, action, pluginId, value1, value2, value3, valuef, valueStr) | |||
| @@ -238,13 +238,13 @@ class CarlaMiniW(ExternalUI, HostWindow): | |||
| self.host._add(pluginId) | |||
| type_, category, hints, uniqueId, optsAvail, optsEnabled = [int(i) for i in self.readlineblock().split(":")] | |||
| filename = self.readlineblock().replace("\r", "\n") | |||
| name = self.readlineblock().replace("\r", "\n") | |||
| iconName = self.readlineblock().replace("\r", "\n") | |||
| realName = self.readlineblock().replace("\r", "\n") | |||
| label = self.readlineblock().replace("\r", "\n") | |||
| maker = self.readlineblock().replace("\r", "\n") | |||
| copyright = self.readlineblock().replace("\r", "\n") | |||
| filename = self.readlineblock() | |||
| name = self.readlineblock() | |||
| iconName = self.readlineblock() | |||
| realName = self.readlineblock() | |||
| label = self.readlineblock() | |||
| maker = self.readlineblock() | |||
| copyright = self.readlineblock() | |||
| pinfo = { | |||
| 'type': type_, | |||
| @@ -280,10 +280,10 @@ class CarlaMiniW(ExternalUI, HostWindow): | |||
| pluginId, paramId = [int(i) for i in msg.replace("PARAMETER_DATA_", "").split(":")] | |||
| paramType, paramHints, mappedControlIndex, midiChannel = [int(i) for i in self.readlineblock().split(":")] | |||
| mappedMinimum, mappedMaximum = [float(i) for i in self.readlineblock().split(":")] | |||
| paramName = self.readlineblock().replace("\r", "\n") | |||
| paramUnit = self.readlineblock().replace("\r", "\n") | |||
| paramComment = self.readlineblock().replace("\r", "\n") | |||
| paramGroupName = self.readlineblock().replace("\r", "\n") | |||
| paramName = self.readlineblock() | |||
| paramUnit = self.readlineblock() | |||
| paramComment = self.readlineblock() | |||
| paramGroupName = self.readlineblock() | |||
| paramInfo = { | |||
| 'name': paramName, | |||
| @@ -328,7 +328,7 @@ class CarlaMiniW(ExternalUI, HostWindow): | |||
| elif msg.startswith("PROGRAM_NAME_"): | |||
| pluginId, progId = [int(i) for i in msg.replace("PROGRAM_NAME_", "").split(":")] | |||
| progName = self.readlineblock().replace("\r", "\n") | |||
| progName = self.readlineblock() | |||
| self.host._set_programName(pluginId, progId, progName) | |||
| elif msg.startswith("MIDI_PROGRAM_COUNT_"): | |||
| @@ -339,7 +339,7 @@ class CarlaMiniW(ExternalUI, HostWindow): | |||
| elif msg.startswith("MIDI_PROGRAM_DATA_"): | |||
| pluginId, midiProgId = [int(i) for i in msg.replace("MIDI_PROGRAM_DATA_", "").split(":")] | |||
| bank, program = [int(i) for i in self.readlineblock().split(":")] | |||
| name = self.readlineblock().replace("\r", "\n") | |||
| name = self.readlineblock() | |||
| self.host._set_midiProgramData(pluginId, midiProgId, {'bank': bank, 'program': program, 'name': name}) | |||
| elif msg.startswith("CUSTOM_DATA_COUNT_"): | |||
| @@ -349,14 +349,14 @@ class CarlaMiniW(ExternalUI, HostWindow): | |||
| elif msg.startswith("CUSTOM_DATA_"): | |||
| pluginId, customDataId = [int(i) for i in msg.replace("CUSTOM_DATA_", "").split(":")] | |||
| type_ = self.readlineblock().replace("\r", "\n") | |||
| key = self.readlineblock().replace("\r", "\n") | |||
| value = self.readlineblock().replace("\r", "\n") | |||
| type_ = self.readlineblock() | |||
| key = self.readlineblock() | |||
| value = self.readlineblock() | |||
| self.host._set_customData(pluginId, customDataId, {'type': type_, 'key': key, 'value': value}) | |||
| elif msg == "osc-urls": | |||
| tcp = self.readlineblock().replace("\r", "\n") | |||
| udp = self.readlineblock().replace("\r", "\n") | |||
| tcp = self.readlineblock() | |||
| udp = self.readlineblock() | |||
| self.host.fOscTCP = tcp | |||
| self.host.fOscUDP = udp | |||
| @@ -373,7 +373,7 @@ class CarlaMiniW(ExternalUI, HostWindow): | |||
| self.host.fSampleRate = srate | |||
| elif msg == "error": | |||
| error = self.readlineblock().replace("\r", "\n") | |||
| error = self.readlineblock() | |||
| engineCallback(self.host, ENGINE_CALLBACK_ERROR, 0, 0, 0, 0, 0.0, error) | |||
| elif msg == "show": | |||
| @@ -391,7 +391,7 @@ class CarlaMiniW(ExternalUI, HostWindow): | |||
| self.uiQuit() | |||
| elif msg == "uiTitle": | |||
| uiTitle = self.readlineblock().replace("\r", "\n") | |||
| uiTitle = self.readlineblock() | |||
| self.uiTitleChanged(uiTitle) | |||
| else: | |||
| @@ -139,8 +139,8 @@ class ExternalUI(object): | |||
| self.dspProgramChanged(channel, bank, program) | |||
| elif msg == "configure": | |||
| key = self.readlineblock() #.replace("\r", "\n") | |||
| value = self.readlineblock() #.replace("\r", "\n") | |||
| key = self.readlineblock() | |||
| value = self.readlineblock() | |||
| self.dspStateChanged(key, value) | |||
| elif msg == "note": | |||
| @@ -164,7 +164,7 @@ class ExternalUI(object): | |||
| self.uiQuit() | |||
| elif msg == "uiTitle": | |||
| uiTitle = self.readlineblock() #.replace("\r", "\n") | |||
| uiTitle = self.readlineblock() | |||
| self.uiTitleChanged(uiTitle) | |||
| else: | |||
| @@ -180,15 +180,14 @@ protected: | |||
| const char* key; | |||
| const char* value; | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(key), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(value), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(key, true), true); | |||
| CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(value, false), true); | |||
| try { | |||
| uiCustomDataChanged(key, value); | |||
| } CARLA_SAFE_EXCEPTION("uiCustomDataChanged"); | |||
| delete[] key; | |||
| delete[] value; | |||
| return true; | |||
| } | |||
| @@ -596,7 +596,7 @@ struct CarlaPipeCommon::PrivateData { | |||
| CarlaMutex writeLock; | |||
| // temporary buffers for _readline() | |||
| mutable char tmpBuf[0xff+1]; | |||
| mutable char tmpBuf[0xffff]; | |||
| mutable CarlaString tmpStr; | |||
| PrivateData() noexcept | |||
| @@ -625,7 +625,7 @@ struct CarlaPipeCommon::PrivateData { | |||
| ovSend = ::CreateEvent(nullptr, FALSE, FALSE, nullptr); | |||
| #endif | |||
| carla_zeroChars(tmpBuf, 0xff+1); | |||
| carla_zeroChars(tmpBuf, 0xffff); | |||
| } | |||
| CARLA_DECLARE_NON_COPY_STRUCT(PrivateData) | |||
| @@ -655,11 +655,13 @@ bool CarlaPipeCommon::isPipeRunning() const noexcept | |||
| void CarlaPipeCommon::idlePipe(const bool onlyOnce) noexcept | |||
| { | |||
| bool readSucess; | |||
| for (;;) | |||
| { | |||
| const char* const msg(_readline()); | |||
| const char* const msg = _readline(true, readSucess); | |||
| if (msg == nullptr) | |||
| if (msg == nullptr || ! readSucess) | |||
| break; | |||
| pData->isReading = true; | |||
| @@ -712,10 +714,9 @@ bool CarlaPipeCommon::readNextLineAsBool(bool& value) const noexcept | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(pData->isReading, false); | |||
| if (const char* const msg = _readlineblock()) | |||
| if (const char* const msg = _readlineblock(false)) | |||
| { | |||
| value = (std::strcmp(msg, "true") == 0); | |||
| delete[] msg; | |||
| return true; | |||
| } | |||
| @@ -726,14 +727,13 @@ bool CarlaPipeCommon::readNextLineAsByte(uint8_t& value) const noexcept | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(pData->isReading, false); | |||
| if (const char* const msg = _readlineblock()) | |||
| if (const char* const msg = _readlineblock(false)) | |||
| { | |||
| int tmp = std::atoi(msg); | |||
| delete[] msg; | |||
| const int asint = std::atoi(msg); | |||
| if (tmp >= 0 && tmp <= 0xFF) | |||
| if (asint >= 0 && asint <= 0xFF) | |||
| { | |||
| value = static_cast<uint8_t>(tmp); | |||
| value = static_cast<uint8_t>(asint); | |||
| return true; | |||
| } | |||
| } | |||
| @@ -745,10 +745,9 @@ bool CarlaPipeCommon::readNextLineAsInt(int32_t& value) const noexcept | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(pData->isReading, false); | |||
| if (const char* const msg = _readlineblock()) | |||
| if (const char* const msg = _readlineblock(false)) | |||
| { | |||
| value = std::atoi(msg); | |||
| delete[] msg; | |||
| return true; | |||
| } | |||
| @@ -759,14 +758,13 @@ bool CarlaPipeCommon::readNextLineAsUInt(uint32_t& value) const noexcept | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(pData->isReading, false); | |||
| if (const char* const msg = _readlineblock()) | |||
| if (const char* const msg = _readlineblock(false)) | |||
| { | |||
| const long tmp = std::atol(msg); | |||
| delete[] msg; | |||
| const long aslong = std::atol(msg); | |||
| if (tmp >= 0) | |||
| if (aslong >= 0) | |||
| { | |||
| value = static_cast<uint32_t>(tmp); | |||
| value = static_cast<uint32_t>(aslong); | |||
| return true; | |||
| } | |||
| } | |||
| @@ -778,10 +776,9 @@ bool CarlaPipeCommon::readNextLineAsLong(int64_t& value) const noexcept | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(pData->isReading, false); | |||
| if (const char* const msg = _readlineblock()) | |||
| if (const char* const msg = _readlineblock(false)) | |||
| { | |||
| value = std::atol(msg); | |||
| delete[] msg; | |||
| return true; | |||
| } | |||
| @@ -792,14 +789,13 @@ bool CarlaPipeCommon::readNextLineAsULong(uint64_t& value) const noexcept | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(pData->isReading, false); | |||
| if (const char* const msg = _readlineblock()) | |||
| if (const char* const msg = _readlineblock(false)) | |||
| { | |||
| const int64_t tmp = std::atol(msg); | |||
| delete[] msg; | |||
| const int64_t asint64 = std::atol(msg); | |||
| if (tmp >= 0) | |||
| if (asint64 >= 0) | |||
| { | |||
| value = static_cast<uint64_t>(tmp); | |||
| value = static_cast<uint64_t>(asint64); | |||
| return true; | |||
| } | |||
| } | |||
| @@ -811,13 +807,12 @@ bool CarlaPipeCommon::readNextLineAsFloat(float& value) const noexcept | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(pData->isReading, false); | |||
| if (const char* const msg = _readlineblock()) | |||
| if (const char* const msg = _readlineblock(false)) | |||
| { | |||
| { | |||
| const CarlaScopedLocale csl; | |||
| value = static_cast<float>(std::atof(msg)); | |||
| } | |||
| delete[] msg; | |||
| return true; | |||
| } | |||
| @@ -828,24 +823,23 @@ bool CarlaPipeCommon::readNextLineAsDouble(double& value) const noexcept | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(pData->isReading, false); | |||
| if (const char* const msg = _readlineblock()) | |||
| if (const char* const msg = _readlineblock(false)) | |||
| { | |||
| { | |||
| const CarlaScopedLocale csl; | |||
| value = std::atof(msg); | |||
| } | |||
| delete[] msg; | |||
| return true; | |||
| } | |||
| return false; | |||
| } | |||
| bool CarlaPipeCommon::readNextLineAsString(const char*& value) const noexcept | |||
| bool CarlaPipeCommon::readNextLineAsString(const char*& value, const bool allocateString) const noexcept | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(pData->isReading, false); | |||
| if (const char* const msg = _readlineblock()) | |||
| if (const char* const msg = _readlineblock(allocateString)) | |||
| { | |||
| value = msg; | |||
| return true; | |||
| @@ -920,6 +914,8 @@ bool CarlaPipeCommon::writeAndFixMessage(const char* const msg) const noexcept | |||
| { | |||
| fixedMsg[0] = '\n'; | |||
| fixedMsg[1] = '\0'; | |||
| carla_stderr2("wrote empty message:'%s'", fixedMsg); | |||
| } | |||
| return _writeMsgBuffer(fixedMsg, size+1); | |||
| @@ -970,21 +966,21 @@ void CarlaPipeCommon::writeErrorMessage(const char* const error) const noexcept | |||
| void CarlaPipeCommon::writeControlMessage(const uint32_t index, const float value) const noexcept | |||
| { | |||
| char tmpBuf[0xff+1]; | |||
| tmpBuf[0xff] = '\0'; | |||
| char tmpBuf[0xff]; | |||
| tmpBuf[0xfe] = '\0'; | |||
| const CarlaMutexLocker cml(pData->writeLock); | |||
| if (! _writeMsgBuffer("control\n", 8)) | |||
| return; | |||
| std::snprintf(tmpBuf, 0xff, "%i\n", index); | |||
| std::snprintf(tmpBuf, 0xfe, "%i\n", index); | |||
| if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) | |||
| return; | |||
| { | |||
| const CarlaScopedLocale csl; | |||
| std::snprintf(tmpBuf, 0xff, "%.12g\n", static_cast<double>(value)); | |||
| std::snprintf(tmpBuf, 0xfe, "%.12g\n", static_cast<double>(value)); | |||
| } | |||
| if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) | |||
| @@ -1012,15 +1008,15 @@ void CarlaPipeCommon::writeConfigureMessage(const char* const key, const char* c | |||
| void CarlaPipeCommon::writeProgramMessage(const uint32_t index) const noexcept | |||
| { | |||
| char tmpBuf[0xff+1]; | |||
| tmpBuf[0xff] = '\0'; | |||
| char tmpBuf[0xff]; | |||
| tmpBuf[0xfe] = '\0'; | |||
| const CarlaMutexLocker cml(pData->writeLock); | |||
| if (! _writeMsgBuffer("program\n", 8)) | |||
| return; | |||
| std::snprintf(tmpBuf, 0xff, "%i\n", index); | |||
| std::snprintf(tmpBuf, 0xfe, "%i\n", index); | |||
| if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) | |||
| return; | |||
| @@ -1029,23 +1025,23 @@ void CarlaPipeCommon::writeProgramMessage(const uint32_t index) const noexcept | |||
| void CarlaPipeCommon::writeProgramMessage(const uint8_t channel, const uint32_t bank, const uint32_t program) const noexcept | |||
| { | |||
| char tmpBuf[0xff+1]; | |||
| tmpBuf[0xff] = '\0'; | |||
| char tmpBuf[0xff]; | |||
| tmpBuf[0xfe] = '\0'; | |||
| const CarlaMutexLocker cml(pData->writeLock); | |||
| if (! _writeMsgBuffer("program\n", 8)) | |||
| return; | |||
| std::snprintf(tmpBuf, 0xff, "%i\n", channel); | |||
| std::snprintf(tmpBuf, 0xfe, "%i\n", channel); | |||
| if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) | |||
| return; | |||
| std::snprintf(tmpBuf, 0xff, "%i\n", bank); | |||
| std::snprintf(tmpBuf, 0xfe, "%i\n", bank); | |||
| if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) | |||
| return; | |||
| std::snprintf(tmpBuf, 0xff, "%i\n", program); | |||
| std::snprintf(tmpBuf, 0xfe, "%i\n", program); | |||
| if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) | |||
| return; | |||
| @@ -1054,19 +1050,19 @@ void CarlaPipeCommon::writeProgramMessage(const uint8_t channel, const uint32_t | |||
| void CarlaPipeCommon::writeMidiProgramMessage(const uint32_t bank, const uint32_t program) const noexcept | |||
| { | |||
| char tmpBuf[0xff+1]; | |||
| tmpBuf[0xff] = '\0'; | |||
| char tmpBuf[0xff]; | |||
| tmpBuf[0xfe] = '\0'; | |||
| const CarlaMutexLocker cml(pData->writeLock); | |||
| if (! _writeMsgBuffer("midiprogram\n", 12)) | |||
| return; | |||
| std::snprintf(tmpBuf, 0xff, "%i\n", bank); | |||
| std::snprintf(tmpBuf, 0xfe, "%i\n", bank); | |||
| if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) | |||
| return; | |||
| std::snprintf(tmpBuf, 0xff, "%i\n", program); | |||
| std::snprintf(tmpBuf, 0xfe, "%i\n", program); | |||
| if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) | |||
| return; | |||
| @@ -1075,15 +1071,15 @@ void CarlaPipeCommon::writeMidiProgramMessage(const uint32_t bank, const uint32_ | |||
| void CarlaPipeCommon::writeReloadProgramsMessage(const int32_t index) const noexcept | |||
| { | |||
| char tmpBuf[0xff+1]; | |||
| tmpBuf[0xff] = '\0'; | |||
| char tmpBuf[0xff]; | |||
| tmpBuf[0xfe] = '\0'; | |||
| const CarlaMutexLocker cml(pData->writeLock); | |||
| if (! _writeMsgBuffer("reloadprograms\n", 15)) | |||
| return; | |||
| std::snprintf(tmpBuf, 0xff, "%i\n", index); | |||
| std::snprintf(tmpBuf, 0xfe, "%i\n", index); | |||
| if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) | |||
| return; | |||
| @@ -1096,27 +1092,27 @@ void CarlaPipeCommon::writeMidiNoteMessage(const bool onOff, const uint8_t chann | |||
| CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,); | |||
| CARLA_SAFE_ASSERT_RETURN(velocity < MAX_MIDI_VALUE,); | |||
| char tmpBuf[0xff+1]; | |||
| tmpBuf[0xff] = '\0'; | |||
| char tmpBuf[0xff]; | |||
| tmpBuf[0xfe] = '\0'; | |||
| const CarlaMutexLocker cml(pData->writeLock); | |||
| if (! _writeMsgBuffer("note\n", 5)) | |||
| return; | |||
| std::snprintf(tmpBuf, 0xff, "%s\n", bool2str(onOff)); | |||
| std::snprintf(tmpBuf, 0xfe, "%s\n", bool2str(onOff)); | |||
| if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) | |||
| return; | |||
| std::snprintf(tmpBuf, 0xff, "%i\n", channel); | |||
| std::snprintf(tmpBuf, 0xfe, "%i\n", channel); | |||
| if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) | |||
| return; | |||
| std::snprintf(tmpBuf, 0xff, "%i\n", note); | |||
| std::snprintf(tmpBuf, 0xfe, "%i\n", note); | |||
| if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) | |||
| return; | |||
| std::snprintf(tmpBuf, 0xff, "%i\n", velocity); | |||
| std::snprintf(tmpBuf, 0xfe, "%i\n", velocity); | |||
| if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) | |||
| return; | |||
| @@ -1127,8 +1123,8 @@ void CarlaPipeCommon::writeLv2AtomMessage(const uint32_t index, const LV2_Atom* | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(atom != nullptr,); | |||
| char tmpBuf[0xff+1]; | |||
| tmpBuf[0xff] = '\0'; | |||
| char tmpBuf[0xff]; | |||
| tmpBuf[0xfe] = '\0'; | |||
| const uint32_t atomTotalSize(lv2_atom_total_size(atom)); | |||
| CarlaString base64atom(CarlaString::asBase64(atom, atomTotalSize)); | |||
| @@ -1138,11 +1134,11 @@ void CarlaPipeCommon::writeLv2AtomMessage(const uint32_t index, const LV2_Atom* | |||
| if (! _writeMsgBuffer("atom\n", 5)) | |||
| return; | |||
| std::snprintf(tmpBuf, 0xff, "%i\n", index); | |||
| std::snprintf(tmpBuf, 0xfe, "%i\n", index); | |||
| if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) | |||
| return; | |||
| std::snprintf(tmpBuf, 0xff, "%i\n", atomTotalSize); | |||
| std::snprintf(tmpBuf, 0xfe, "%i\n", atomTotalSize); | |||
| if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) | |||
| return; | |||
| @@ -1157,15 +1153,15 @@ void CarlaPipeCommon::writeLv2UridMessage(const uint32_t urid, const char* const | |||
| CARLA_SAFE_ASSERT_RETURN(urid != 0,); | |||
| CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0',); | |||
| char tmpBuf[0xff+1]; | |||
| tmpBuf[0xff] = '\0'; | |||
| char tmpBuf[0xff]; | |||
| tmpBuf[0xfe] = '\0'; | |||
| const CarlaMutexLocker cml(pData->writeLock); | |||
| if (! _writeMsgBuffer("urid\n", 5)) | |||
| return; | |||
| std::snprintf(tmpBuf, 0xff, "%i\n", urid); | |||
| std::snprintf(tmpBuf, 0xfe, "%i\n", urid); | |||
| if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) | |||
| return; | |||
| @@ -1178,17 +1174,18 @@ void CarlaPipeCommon::writeLv2UridMessage(const uint32_t urid, const char* const | |||
| // ------------------------------------------------------------------- | |||
| // internal | |||
| const char* CarlaPipeCommon::_readline() const noexcept | |||
| const char* CarlaPipeCommon::_readline(const bool allocReturn, bool& readSucess) const noexcept | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(pData->pipeRecv != INVALID_PIPE_VALUE, nullptr); | |||
| char c; | |||
| char* ptr = pData->tmpBuf; | |||
| ssize_t ret = -1; | |||
| bool tooBig = false; | |||
| pData->tmpStr.clear(); | |||
| for (int i=0; i<0xff; ++i) | |||
| for (int i=0; i<0xfffe; ++i) | |||
| { | |||
| try { | |||
| #ifdef CARLA_OS_WIN | |||
| @@ -1206,10 +1203,11 @@ const char* CarlaPipeCommon::_readline() const noexcept | |||
| *ptr++ = c; | |||
| if (i+1 == 0xff) | |||
| if (i+1 == 0xfffe) | |||
| { | |||
| i = 0; | |||
| *ptr = '\0'; | |||
| tooBig = true; | |||
| pData->tmpStr += pData->tmpBuf; | |||
| ptr = pData->tmpBuf; | |||
| } | |||
| @@ -1218,26 +1216,39 @@ const char* CarlaPipeCommon::_readline() const noexcept | |||
| if (ptr != pData->tmpBuf) | |||
| { | |||
| *ptr = '\0'; | |||
| if (! allocReturn && ! tooBig) | |||
| { | |||
| readSucess = true; | |||
| return pData->tmpBuf; | |||
| } | |||
| pData->tmpStr += pData->tmpBuf; | |||
| } | |||
| else if (pData->tmpStr.isEmpty() && ret != 1) | |||
| { | |||
| // some error | |||
| readSucess = false; | |||
| return nullptr; | |||
| } | |||
| try { | |||
| return pData->tmpStr.dup(); | |||
| } CARLA_SAFE_EXCEPTION_RETURN("CarlaPipeCommon::readline() - dup", nullptr); | |||
| if (! allocReturn && ! tooBig) | |||
| return pData->tmpBuf; | |||
| readSucess = true; | |||
| return allocReturn ? pData->tmpStr.releaseBufferPointer() : pData->tmpStr.buffer(); | |||
| } | |||
| const char* CarlaPipeCommon::_readlineblock(const uint32_t timeOutMilliseconds) const noexcept | |||
| const char* CarlaPipeCommon::_readlineblock(const bool allocReturn, const uint32_t timeOutMilliseconds) const noexcept | |||
| { | |||
| const uint32_t timeoutEnd(water::Time::getMillisecondCounter() + timeOutMilliseconds); | |||
| const uint32_t timeoutEnd = water::Time::getMillisecondCounter() + timeOutMilliseconds; | |||
| bool readSucess; | |||
| for (;;) | |||
| { | |||
| if (const char* const msg = _readline()) | |||
| const char* const msg = _readline(allocReturn, readSucess); | |||
| if (readSucess) | |||
| return msg; | |||
| if (water::Time::getMillisecondCounter() >= timeoutEnd) | |||
| @@ -1246,13 +1257,17 @@ const char* CarlaPipeCommon::_readlineblock(const uint32_t timeOutMilliseconds) | |||
| carla_msleep(5); | |||
| } | |||
| if (std::getenv("CARLA_VALGRIND_TEST") != nullptr) | |||
| static const bool testingForValgrind = std::getenv("CARLA_VALGRIND_TEST") != nullptr; | |||
| if (testingForValgrind) | |||
| { | |||
| const uint32_t timeoutEnd2(water::Time::getMillisecondCounter() + 1000); | |||
| const uint32_t timeoutEnd2 = water::Time::getMillisecondCounter() + 1000; | |||
| for (;;) | |||
| { | |||
| if (const char* const msg = _readline()) | |||
| const char* const msg = _readline(allocReturn, readSucess); | |||
| if (readSucess) | |||
| return msg; | |||
| if (water::Time::getMillisecondCounter() >= timeoutEnd2) | |||
| @@ -48,14 +48,14 @@ protected: | |||
| * If extra data is required, use any of the readNextLineAs* functions. | |||
| * Returning true means the message has been handled and should not propagate to subclasses. | |||
| */ | |||
| virtual bool msgReceived(const char* const msg) noexcept = 0; | |||
| virtual bool msgReceived(const char* msg) noexcept = 0; | |||
| /*! | |||
| * An error has occurred during the current requested operation. | |||
| * Reimplementing this method allows to catch these errors as strings. | |||
| * By default the error is simply printed to stderr. | |||
| */ | |||
| virtual void fail(const char* const error) noexcept | |||
| virtual void fail(const char* error) noexcept | |||
| { | |||
| carla_stderr2(error); | |||
| } | |||
| @@ -69,7 +69,7 @@ public: | |||
| /*! | |||
| * Check the pipe for new messages and send them to msgReceived(). | |||
| */ | |||
| void idlePipe(const bool onlyOnce = false) noexcept; | |||
| void idlePipe(bool onlyOnce = false) noexcept; | |||
| // ------------------------------------------------------------------- | |||
| // write lock | |||
| @@ -142,7 +142,7 @@ public: | |||
| * Read the next line as a string. | |||
| * @note: @a value must be deleted if valid. | |||
| */ | |||
| bool readNextLineAsString(const char*& value) const noexcept; | |||
| bool readNextLineAsString(const char*& value, bool allocateString) const noexcept; | |||
| // ------------------------------------------------------------------- | |||
| // write messages, must be locked before calling | |||
| @@ -151,18 +151,18 @@ public: | |||
| * Write a valid message with unknown size. | |||
| * A valid message has only one '\n' character and it's at the end. | |||
| */ | |||
| bool writeMessage(const char* const msg) const noexcept; | |||
| bool writeMessage(const char* msg) const noexcept; | |||
| /*! | |||
| * Write a valid message with known size. | |||
| * A valid message has only one '\n' character and it's at the end. | |||
| */ | |||
| bool writeMessage(const char* const msg, std::size_t size) const noexcept; | |||
| bool writeMessage(const char* msg, std::size_t size) const noexcept; | |||
| /*! | |||
| * Write and fix a message. | |||
| */ | |||
| bool writeAndFixMessage(const char* const msg) const noexcept; | |||
| bool writeAndFixMessage(const char* msg) const noexcept; | |||
| /*! | |||
| * Write an empty message, which means a single '\n'. | |||
| @@ -180,52 +180,52 @@ public: | |||
| /*! | |||
| * Write an "error" message. | |||
| */ | |||
| void writeErrorMessage(const char* const error) const noexcept; | |||
| void writeErrorMessage(const char* error) const noexcept; | |||
| /*! | |||
| * Write a "control" message used for parameter changes. | |||
| */ | |||
| void writeControlMessage(const uint32_t index, const float value) const noexcept; | |||
| void writeControlMessage(uint32_t index, float value) const noexcept; | |||
| /*! | |||
| * Write a "configure" message used for state changes. | |||
| */ | |||
| void writeConfigureMessage(const char* const key, const char* const value) const noexcept; | |||
| void writeConfigureMessage(const char* key, const char* value) const noexcept; | |||
| /*! | |||
| * Write a "program" message (using index). | |||
| */ | |||
| void writeProgramMessage(const uint32_t index) const noexcept; | |||
| void writeProgramMessage(uint32_t index) const noexcept; | |||
| /*! | |||
| * Write a "program" message (using channel, bank and program). | |||
| */ | |||
| void writeProgramMessage(const uint8_t channel, const uint32_t bank, const uint32_t program) const noexcept; | |||
| void writeProgramMessage(uint8_t channel, uint32_t bank, uint32_t program) const noexcept; | |||
| /*! | |||
| * Write a "midiprogram" message (using bank and program). | |||
| */ | |||
| void writeMidiProgramMessage(const uint32_t bank, const uint32_t program) const noexcept; | |||
| void writeMidiProgramMessage(uint32_t bank, uint32_t program) const noexcept; | |||
| /*! | |||
| * Write a "reloadprograms" message. | |||
| */ | |||
| void writeReloadProgramsMessage(const int32_t index) const noexcept; | |||
| void writeReloadProgramsMessage(int32_t index) const noexcept; | |||
| /*! | |||
| * Write a MIDI "note" message. | |||
| */ | |||
| void writeMidiNoteMessage(const bool onOff, const uint8_t channel, const uint8_t note, const uint8_t velocity) const noexcept; | |||
| void writeMidiNoteMessage(bool onOff, uint8_t channel, uint8_t note, uint8_t velocity) const noexcept; | |||
| /*! | |||
| * Write an lv2 "atom" message. | |||
| */ | |||
| void writeLv2AtomMessage(const uint32_t index, const LV2_Atom* const atom) const noexcept; | |||
| void writeLv2AtomMessage(uint32_t index, const LV2_Atom* atom) const noexcept; | |||
| /*! | |||
| * Write an lv2 "urid" message. | |||
| */ | |||
| void writeLv2UridMessage(const uint32_t urid, const char* const uri) const noexcept; | |||
| void writeLv2UridMessage(uint32_t urid, const char* uri) const noexcept; | |||
| // ------------------------------------------------------------------- | |||
| @@ -236,13 +236,13 @@ protected: | |||
| // ------------------------------------------------------------------- | |||
| /*! @internal */ | |||
| const char* _readline() const noexcept; | |||
| const char* _readline(bool allocReturn, bool& readSucess) const noexcept; | |||
| /*! @internal */ | |||
| const char* _readlineblock(const uint32_t timeOutMilliseconds = 50) const noexcept; | |||
| const char* _readlineblock(bool allocReturn, uint32_t timeOutMilliseconds = 50) const noexcept; | |||
| /*! @internal */ | |||
| bool _writeMsgBuffer(const char* const msg, const std::size_t size) const noexcept; | |||
| bool _writeMsgBuffer(const char* msg, std::size_t size) const noexcept; | |||
| CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPipeCommon) | |||
| }; | |||