From 0d89d64f499cab7cdbef47bf2325306a6cb47098 Mon Sep 17 00:00:00 2001 From: Johannes Lorenz Date: Sun, 18 Oct 2020 14:24:16 +0200 Subject: [PATCH] Implement unused Lv2UridCache --- include/Lv2Manager.h | 6 +++- include/Lv2UridCache.h | 52 ++++++++++++++++++++++++++++++++ src/core/CMakeLists.txt | 1 + src/core/lv2/Lv2Manager.cpp | 3 +- src/core/lv2/Lv2UridCache.cpp | 57 +++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 include/Lv2UridCache.h create mode 100644 src/core/lv2/Lv2UridCache.cpp diff --git a/include/Lv2Manager.h b/include/Lv2Manager.h index 0b5fc6923..6261d70f6 100644 --- a/include/Lv2Manager.h +++ b/include/Lv2Manager.h @@ -34,6 +34,7 @@ #include #include "Lv2Basics.h" +#include "Lv2UridCache.h" #include "Lv2UridMap.h" #include "Plugin.h" @@ -123,7 +124,7 @@ public: }; UridMap& uridMap() { return m_uridMap; } - //! Return all + const Lv2UridCache& uridCache() const { return m_uridCache; } const std::set& supportedFeatureURIs() const { return m_supportedFeatureURIs; @@ -140,6 +141,9 @@ private: // feature data that are common for all Lv2Proc UridMap m_uridMap; + // URID cache for fast URID access + Lv2UridCache m_uridCache; + // functions bool isSubclassOf(const LilvPluginClass *clvss, const char *uriStr); }; diff --git a/include/Lv2UridCache.h b/include/Lv2UridCache.h new file mode 100644 index 000000000..b4cfa59f3 --- /dev/null +++ b/include/Lv2UridCache.h @@ -0,0 +1,52 @@ +/* + * Lv2UridCache.h - Lv2UridCache definition + * + * Copyright (c) 2020-2020 Johannes Lorenz + * + * This file is part of LMMS - https://lmms.io + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + +#ifndef LV2URIDCACHE_H +#define LV2URIDCACHE_H + +#include "lmmsconfig.h" + +#ifdef LMMS_HAVE_LV2 + +#include + +//! Cached URIDs for fast access (for use in real-time code) +class Lv2UridCache +{ +public: + enum class Id //!< ID for m_uridCache array + { + midi_MidiEvent, //!< just an example, unused yet + size + }; + //! Return URID for a cache ID + uint32_t operator[](Id id) const; + + Lv2UridCache(class UridMap& mapper); +private: + uint32_t m_cache[static_cast(Id::size)]; +}; + +#endif // LMMS_HAVE_LV2 +#endif // LV2URIDCACHE_H diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 82fc4c63e..8dbee31d3 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -98,6 +98,7 @@ set(LMMS_SRCS core/lv2/Lv2Proc.cpp core/lv2/Lv2Manager.cpp core/lv2/Lv2SubPluginFeatures.cpp + core/lv2/Lv2UridCache.cpp core/lv2/Lv2UridMap.cpp core/midi/MidiAlsaRaw.cpp diff --git a/src/core/lv2/Lv2Manager.cpp b/src/core/lv2/Lv2Manager.cpp index 69fbd0137..b1f03079b 100644 --- a/src/core/lv2/Lv2Manager.cpp +++ b/src/core/lv2/Lv2Manager.cpp @@ -44,7 +44,8 @@ -Lv2Manager::Lv2Manager() +Lv2Manager::Lv2Manager() : + m_uridCache(m_uridMap) { const char* dbgStr = getenv("LMMS_LV2_DEBUG"); m_debug = (dbgStr && *dbgStr); diff --git a/src/core/lv2/Lv2UridCache.cpp b/src/core/lv2/Lv2UridCache.cpp new file mode 100644 index 000000000..5887a8e39 --- /dev/null +++ b/src/core/lv2/Lv2UridCache.cpp @@ -0,0 +1,57 @@ +/* + * Lv2UridCache.cpp - Lv2UridCache implementation + * + * Copyright (c) 2020-2020 Johannes Lorenz + * + * This file is part of LMMS - https://lmms.io + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + +#include "Lv2UridCache.h" + +#ifdef LMMS_HAVE_LV2 + +#include +#include + +#include "Lv2UridMap.h" + +uint32_t Lv2UridCache::operator[](Lv2UridCache::Id id) const +{ + Q_ASSERT(id != Id::size); + return m_cache[static_cast(id)]; +} + +Lv2UridCache::Lv2UridCache(UridMap &mapper) +{ + const uint32_t noIdYet = 0; + std::fill_n(m_cache, static_cast(Id::size), noIdYet); + + auto init = [this, &mapper](Id id, const char* uridStr) + { + m_cache[static_cast(id)] = mapper.map(uridStr); + }; + + init(Id::midi_MidiEvent, LV2_MIDI__MidiEvent); + + for(uint32_t urid : m_cache) { Q_ASSERT(urid != noIdYet); } +} + +#endif // LMMS_HAVE_LV2 + +