-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement Lv2 Urid feature #5517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
590ac4f
Implement Lv2 Urid feature
JohannesLorenz edff1b4
Fix urid.h include path
JohannesLorenz 2f7d0b5
Lv2UridMap.cpp: Use std::lock_guard
JohannesLorenz 1cfa713
Refactor supported Lv2 features
JohannesLorenz 3314b72
Fix include order
JohannesLorenz da2eef3
Use map mutex in UridMap::unmap, too
JohannesLorenz 95d54fa
UridMap::map fixes
JohannesLorenz 483c3ed
Lv2Features.cpp: Use Q_ASSERT instead of assert
JohannesLorenz 015cd6e
Lv2Manager::isFeatureSupported: Replace loop by set::find
JohannesLorenz c5a8c89
Lv2Features::featurePointers: Return as C-array
JohannesLorenz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * Lv2Features.h - Lv2Features class | ||
| * | ||
| * Copyright (c) 2020-2020 Johannes Lorenz <jlsf2013$users.sourceforge.net, $=@> | ||
| * | ||
| * 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 LV2FEATURES_H | ||
| #define LV2FEATURES_H | ||
|
|
||
| #include "lmmsconfig.h" | ||
|
|
||
| #ifdef LMMS_HAVE_LV2 | ||
|
|
||
| #include <lv2.h> | ||
| #include <map> | ||
| #include <vector> | ||
| #include "Lv2Manager.h" | ||
|
|
||
| /** | ||
| Feature container | ||
| References all available features for a plugin and maps them to their URIs. | ||
| The public member functions should be called in descending order: | ||
| 1. initCommon: map plugin-common features | ||
| 2. operator[]: map plugin-specific features | ||
| 3. createFeatureVectors: create the feature vectors required for | ||
| lilv_plugin_instantiate | ||
| 4. access the latter | ||
| */ | ||
| class Lv2Features | ||
| { | ||
| public: | ||
| //! Return if a feature is supported by LMMS | ||
| static bool isFeatureSupported(const char *featName); | ||
|
|
||
| Lv2Features(); | ||
|
|
||
| //! Register only plugin-common features | ||
| void initCommon(); | ||
| //! Return reference to feature data with given URI featName | ||
| void*& operator[](const char* featName); | ||
| //! Fill m_features and m_featurePointers with all features | ||
| void createFeatureVectors(); | ||
| //! Return LV2_Feature pointer vector, suited for lilv_plugin_instantiate | ||
| const std::vector<const LV2_Feature*>& featurePointers() const | ||
| { | ||
| return m_featurePointers; | ||
| } | ||
|
|
||
| private: | ||
| //! feature storage | ||
| std::vector<LV2_Feature> m_features; | ||
| //! pointers to m_features, required for lilv_plugin_instantiate | ||
| std::vector<const LV2_Feature*> m_featurePointers; | ||
| //! features + data, ordered by URI | ||
| std::map<const char*, void*, Lv2Manager::CmpStr> m_featureByUri; | ||
| }; | ||
|
|
||
| #endif // LMMS_HAVE_LV2 | ||
|
|
||
| #endif // LV2FEATURES_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * Lv2UridMap.cpp - Lv2UridMap class | ||
| * | ||
| * Copyright (c) 2019 Johannes Lorenz <j.git$$$lorenz-ho.me, $$$=@> | ||
| * | ||
| * 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 LV2URIDMAP_H | ||
| #define LV2URIDMAP_H | ||
|
|
||
| #include "lmmsconfig.h" | ||
|
|
||
| #ifdef LMMS_HAVE_LV2 | ||
|
|
||
| #include <lv2/lv2plug.in/ns/ext/urid/urid.h> | ||
| #include <mutex> // TODO: use semaphore, even though this is not realtime critical | ||
| #include <unordered_map> | ||
| #include <vector> | ||
|
|
||
| /** | ||
| * Complete implementation of the Lv2 Urid Map extension | ||
| */ | ||
| class UridMap | ||
| { | ||
| std::unordered_map<std::string, LV2_URID> m_map; | ||
| std::vector<const char*> m_unMap; | ||
|
|
||
| //! mutex for both m_map and m_unMap | ||
| //! the URID map is global, which is why a mutex is required here | ||
| std::mutex m_MapMutex; | ||
|
|
||
| LV2_URID_Map m_mapFeature; | ||
| LV2_URID_Unmap m_unmapFeature; | ||
|
|
||
| LV2_URID m_lastUrid = 0; | ||
|
|
||
| public: | ||
| //! constructor; will set up the features | ||
| UridMap(); | ||
|
|
||
| //! map feature function | ||
| LV2_URID map(const char* uri); | ||
| //! unmap feature function | ||
| const char* unmap(LV2_URID urid); | ||
|
|
||
| // access the features | ||
| LV2_URID_Map* mapFeature() { return &m_mapFeature; } | ||
| LV2_URID_Unmap* unmapFeature() { return &m_unmapFeature; } | ||
| }; | ||
|
|
||
| #endif // LMMS_HAVE_LV2 | ||
| #endif // LV2URIDMAP_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* | ||
| * Lv2Features.cpp - Lv2Features implementation | ||
| * | ||
| * Copyright (c) 2020-2020 Johannes Lorenz <jlsf2013$users.sourceforge.net, $=@> | ||
| * | ||
| * 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 "Lv2Features.h" | ||
|
|
||
| #ifdef LMMS_HAVE_LV2 | ||
|
|
||
| #include <QtGlobal> | ||
|
|
||
| #include "Engine.h" | ||
| #include "Lv2Manager.h" | ||
|
|
||
|
|
||
| bool Lv2Features::isFeatureSupported(const char* featName) | ||
| { | ||
| return Engine::getLv2Manager()->isFeatureSupported(featName); | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| Lv2Features::Lv2Features() | ||
| { | ||
| const Lv2Manager* man = Engine::getLv2Manager(); | ||
| // create (yet empty) map feature URI -> feature | ||
| for(const char* uri : man->supportedFeatureURIs()) | ||
| { | ||
| m_featureByUri.emplace(uri, nullptr); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| void Lv2Features::initCommon() | ||
| { | ||
| Lv2Manager* man = Engine::getLv2Manager(); | ||
| // init m_featureByUri with the plugin-common features | ||
| operator[](LV2_URID__map) = man->uridMap().mapFeature(); | ||
| operator[](LV2_URID__unmap) = man->uridMap().unmapFeature(); | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| void Lv2Features::createFeatureVectors() | ||
| { | ||
| // create vector of features | ||
| for(std::pair<const char* const, void*>& pr : m_featureByUri) | ||
| { | ||
| Q_ASSERT(pr.second != nullptr); | ||
| m_features.push_back(LV2_Feature { pr.first, pr.second }); | ||
| } | ||
|
|
||
| // create pointer vector (for lilv_plugin_instantiate) | ||
| m_featurePointers.reserve(m_features.size() + 1); | ||
| for(std::size_t i = 0; i < m_features.size(); ++i) | ||
| { | ||
| m_featurePointers.push_back(&m_features[i]); | ||
| } | ||
| m_featurePointers.push_back(nullptr); | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| void *&Lv2Features::operator[](const char *featName) | ||
| { | ||
| auto itr = m_featureByUri.find(featName); | ||
| Q_ASSERT(itr != m_featureByUri.end()); | ||
| return itr->second; | ||
| } | ||
|
|
||
|
|
||
| #endif // LMMS_HAVE_LV2 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.