Skip to content
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

Lv2 core implementation #4899

Closed
wants to merge 155 commits into from
Closed
Show file tree
Hide file tree
Changes from 148 commits
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
0e516aa
Add PluginIssue class
JohannesLorenz Mar 16, 2019
e43d68e
Add Control classes
JohannesLorenz Mar 16, 2019
d20981c
Merge branch 'instr-sub-plugins' into lv2-review
JohannesLorenz Mar 16, 2019
f4d7f94
Merge branch 'model-visitor' into lv2-review
JohannesLorenz Mar 16, 2019
f586bac
Add linked model groups
JohannesLorenz Mar 16, 2019
8fc9921
Merge branch 'linked-model-groups' into lv2-review
JohannesLorenz Mar 16, 2019
577368f
Merge branch 'plugin-issue' into lv2-review
JohannesLorenz Mar 16, 2019
3434bee
Merge branch 'piano-optional' into lv2-review
JohannesLorenz Mar 16, 2019
f7b9d33
Merge branch 'variable-tab-widget' into lv2-review
JohannesLorenz Mar 16, 2019
d899cf7
Merge branch 'misc-lv2-preparation' into lv2-review
JohannesLorenz Mar 16, 2019
c623d2c
Merge branch 'variable-tab-widget' into lv2
JohannesLorenz Mar 17, 2019
288e83b
Lv2 core implementation
JohannesLorenz Mar 17, 2019
5dc7bf6
Fix CI: assert -> Q_ASSERT
JohannesLorenz Mar 17, 2019
ba70b60
Fixed warning about uninitialized values
JohannesLorenz Mar 17, 2019
ae8473c
Remove a lot of dead code
JohannesLorenz Mar 17, 2019
2a28ded
VST Bugfix, stolen from master
JohannesLorenz Mar 22, 2019
9b13377
Merge branch 'variable-tab-widget' into lv2-review
JohannesLorenz Mar 29, 2019
7961b25
Apply suggestions from code review
Spekular Apr 4, 2019
71e0951
Whitespace fixes
JohannesLorenz Apr 5, 2019
ce197d6
Apply suggestions from code review
Spekular Apr 5, 2019
f73d2ce
Fix more whitespace isssues
JohannesLorenz Apr 5, 2019
2610fae
PluginBrowser: Tree layout and search bar.
Apr 5, 2019
7c148e5
Do not delete help window on close
JohannesLorenz Apr 7, 2019
c168b6f
Add PluginIssue class
JohannesLorenz Mar 16, 2019
f3bb002
Editorial fixes after review
JohannesLorenz Apr 17, 2019
e9bf431
Fix memory cleanup
JohannesLorenz Apr 22, 2019
a396ae4
Fix review issues
JohannesLorenz Apr 22, 2019
01e507f
Merge branch 'linked-model-groups' into lv2-review
JohannesLorenz Apr 22, 2019
a9726f4
Lv2Effect: Implement checkGate
JohannesLorenz Apr 22, 2019
33df80b
Merge branch 'model-visitor' into linked-model-groups
JohannesLorenz Apr 27, 2019
b0758c1
Simplify LinkedModelGroups usage
JohannesLorenz Mar 23, 2019
dae999d
Code conventions + Merge fixes
JohannesLorenz Apr 27, 2019
27f62e6
Do not store nProc in LinkedModelGroup
JohannesLorenz Apr 27, 2019
52f2880
Merge branch 'linked-model-groups' into lv2-review
JohannesLorenz Apr 27, 2019
5745834
Merge branch 'variable-tab-widget' into lv2-review
JohannesLorenz Apr 27, 2019
b23fd06
Improve LinkedModelGroups member funcs
JohannesLorenz Apr 30, 2019
bfd2cdc
Merge branch 'linked-model-groups' into lv2-review
JohannesLorenz Apr 30, 2019
c4e3411
Remove redundant Lv2Proc::m_controlCount
JohannesLorenz Apr 30, 2019
fa677c2
Only show Lv2 button box if there are buttons
JohannesLorenz Apr 27, 2019
7d91d9b
LinkedModelGroups: Fix possible OOB read
JohannesLorenz May 15, 2019
82cba06
LinkedModelGroups: Hide if no controls
JohannesLorenz May 15, 2019
6c474fe
LinkedModelGroupViews: Fix comment
JohannesLorenz May 15, 2019
08c49a3
LinkedModelGroups: Move model into struct
JohannesLorenz May 15, 2019
78dee7d
LinkedModelGroups: Implement load/save
JohannesLorenz May 16, 2019
993fa46
Coding conventions
JohannesLorenz May 16, 2019
bc104f4
Merge branch 'linked-model-groups' into lv2-review
JohannesLorenz May 19, 2019
3e0525d
LinkedModelGroups: Fix nullptr indirection
JohannesLorenz May 25, 2019
e2d1320
Lv2: Fix compile after previous merge
JohannesLorenz May 26, 2019
6c90e50
Lv2ControlBase: Enable load/save
JohannesLorenz May 26, 2019
029c2e4
Remove unused variable
JohannesLorenz May 26, 2019
6f6b35f
Merge branch 'linked-model-groups' into lv2-review
JohannesLorenz May 26, 2019
2edb35e
LinkedModelGroups: Don't save linked models twice
JohannesLorenz May 27, 2019
079102c
Merge branch 'linked-model-groups' into lv2-review
JohannesLorenz May 27, 2019
24ca9f1
Code review
JohannesLorenz May 30, 2019
f47149a
Merge branch 'linked-model-groups' into lv2-review
JohannesLorenz May 30, 2019
0c1758e
Review rework, thanks to @DomClark
JohannesLorenz Jun 13, 2019
24f65bb
Merge branch 'linked-model-groups' into lv2-review
JohannesLorenz Jun 18, 2019
2ad9db6
Update connect instructions
JohannesLorenz Jun 18, 2019
c6ba10b
Lv2Effect/Instrument: Fix translate section
JohannesLorenz Jun 29, 2019
1229162
Replace redirecting slots by lambdas
JohannesLorenz Jun 29, 2019
88bb00c
Cleanup includes
JohannesLorenz Jun 29, 2019
2c423bb
Merge branch 'linked-model-groups' into lv2-review
JohannesLorenz Jun 29, 2019
eeade00
Merge branch 'variable-tab-widget' into lv2-review
JohannesLorenz Jul 21, 2019
538b5a5
Fix assertion for #LinkedModelGroups == 1
JohannesLorenz Jul 26, 2019
dcd7482
LinkedModelGroups: Priv members -> nested struct
JohannesLorenz Jul 22, 2019
2ce0b7f
Implement clearing models
JohannesLorenz Jul 22, 2019
b3d1fb1
Hide model vector in derived classes
JohannesLorenz Jul 23, 2019
0960b06
Fix unique_ptr compiler issues
JohannesLorenz Jul 24, 2019
65a7109
Merge branch 'linked-model-groups' into lv2-review
JohannesLorenz Jul 28, 2019
d9f61d0
Fix types (code review)
JohannesLorenz Aug 17, 2019
96a73be
Code review: Minor corrections
JohannesLorenz Aug 17, 2019
9ab8910
Code review: Improve loop readability
JohannesLorenz Aug 17, 2019
2ba3fec
Controls: allow to return model view
JohannesLorenz Dec 4, 2019
99cb22a
Implement LinkedModelGroupLayout
JohannesLorenz Dec 4, 2019
326e076
Merge branch linked-model-groups into lv2-review
JohannesLorenz Dec 4, 2019
5955e37
LinkedModelGroups: Always keep groups linked
JohannesLorenz Dec 5, 2019
173427f
Merge branch linked-model-groups into lv2-review
JohannesLorenz Dec 5, 2019
d0b7dc1
Remove linking LEDs
JohannesLorenz Dec 8, 2019
2565bf5
Merge branch 'linked-model-groups' into lv2-review
JohannesLorenz Dec 8, 2019
94ea93e
Show only one processor view
JohannesLorenz Dec 8, 2019
d9d5e99
Merge branch 'linked-model-groups' into lv2-review
JohannesLorenz Dec 8, 2019
74ad422
Minor cleanups, doc cleanups
JohannesLorenz Dec 10, 2019
57804c3
Merge branch 'linked-model-groups' into lv2-review
JohannesLorenz Dec 10, 2019
68777ef
Whitespace or non-functional fixes
JohannesLorenz Dec 10, 2019
4c41a5e
Merge branch 'linked-model-groups' into lv2-review
JohannesLorenz Dec 10, 2019
e631937
Fix broken doc/wiki submodule
JohannesLorenz Dec 10, 2019
36f1e6a
Do no set minimumSize for the view
JohannesLorenz Dec 11, 2019
0ae2ac0
Disable VST in this release, it's buggy
JohannesLorenz Dec 21, 2019
7841416
Merge branch 'linked-model-groups' into lv2-review
JohannesLorenz Dec 21, 2019
23b6b1d
Rename LinkedModelGroupLayout to ControlLayout
JohannesLorenz Dec 21, 2019
c45c38e
Merge branch 'linked-model-groups' into lv2-review
JohannesLorenz Dec 30, 2019
14c72b0
Implement LinkedModelGroup::containsModel
JohannesLorenz Dec 30, 2019
6641380
Style fixes, thanks to @Veratil
JohannesLorenz Jan 2, 2020
cf23825
LinkedModelGroup::ModelInfo: Delete default CTOR
JohannesLorenz Jan 2, 2020
0ff1877
Try to fix CI error
JohannesLorenz Jan 2, 2020
0a97c6b
Fix broken wiki submodule
JohannesLorenz Jan 2, 2020
87c4a03
Delete ModelInfo default CTOR
JohannesLorenz Jan 27, 2020
c6a28ed
LinkedModelGroup: Implement eraseModel() and getModel()
JohannesLorenz Jan 27, 2020
eeb1ef2
Add helpful comments
JohannesLorenz Feb 9, 2020
c9f03ba
Move removeControl from subclasses into this class
JohannesLorenz Feb 9, 2020
210d704
Detect search bar by name, not by position
JohannesLorenz Feb 12, 2020
5e7d708
Merge branch 'linked-model-groups' into lv2-review
JohannesLorenz Feb 12, 2020
5c2b947
Merge branch 'plugin-issue' into lv2-review
JohannesLorenz Feb 27, 2020
b907a6d
Merge branch 'master' into lv2-review
JohannesLorenz Feb 28, 2020
55a5d73
Add plugin load summary
JohannesLorenz Mar 30, 2020
c0a3e13
Lv2ControlBase: Don't expose vector storage
JohannesLorenz Apr 17, 2020
2c540bd
Move Lv2Manager::m_world to other privates
JohannesLorenz Apr 17, 2020
f10afcc
Remove Lv2Manager::Lv2Info copy CTOR deletion
JohannesLorenz Apr 19, 2020
38174ca
Introduce type Lv2Manager::Lv2InfoMap
JohannesLorenz Apr 18, 2020
a160000
Lv2Manager: Remove unused Iterator casts
JohannesLorenz Apr 18, 2020
f0fc456
Replace IS_PORT_TYPE with CRTP
JohannesLorenz Apr 18, 2020
289051c
~Lv2Proc: use override instead of virtual
JohannesLorenz Apr 18, 2020
e8e89cf
Lv2Proc: Improve port access
JohannesLorenz Apr 18, 2020
a544810
Lv2Effect::processAudioBuffer: Remove useless alias
JohannesLorenz Apr 19, 2020
e9c46ad
Lv2FxControls must not be a friend of Lv2Effect
JohannesLorenz Apr 19, 2020
960bf7c
Update all Lv2 Copyright headers
JohannesLorenz Apr 19, 2020
428e841
Remove unused Lv2FxControls::m_effect
JohannesLorenz Apr 19, 2020
1d34ba2
Lv2 reload buttons: clicked instead of toggled
JohannesLorenz Apr 19, 2020
e1f53a9
Lv2ControlBase CTOR: Use make_unique
JohannesLorenz Apr 19, 2020
c139582
Lv2ControlBase.cpp: Use auto for iterating
JohannesLorenz Apr 19, 2020
b91f99d
Lv2Manager::getPlugin: Pass QString by const ref
JohannesLorenz Apr 19, 2020
770174b
Lv2Manager::getPlugin: Convert QString->string directly
JohannesLorenz Apr 19, 2020
9feb491
Lv2Manager::initPlugins: Avoid using bool as int
JohannesLorenz Apr 19, 2020
063788f
Implement/Use new func stdStringFromPortName
JohannesLorenz Apr 19, 2020
bc447b3
Lv2Proc::copyModelsFromCore: Fix cast
JohannesLorenz Apr 19, 2020
6e2560d
Lv2ViewProc CTOR: Use plain LilvNode ptr
JohannesLorenz Apr 19, 2020
d4e5514
Lv2: Remove useless destructors where possible
JohannesLorenz Apr 21, 2020
193d755
Lv2Effect: Fix `checkGate()` call
JohannesLorenz Apr 21, 2020
4eeee2d
Lv2Proc CTOR: Remove unreachable else branch
JohannesLorenz Apr 21, 2020
ecfdf3b
Lv2SubPluginFeatures::listSubPluginKeys: Use auto in for loop
JohannesLorenz Apr 21, 2020
5098883
Lv2ViewBase: Fix memory leak
JohannesLorenz Apr 21, 2020
f14918f
Remove useless virtual keywords
JohannesLorenz Apr 21, 2020
6919ec1
Use AutoLilvNode where possible
JohannesLorenz Apr 22, 2020
15faa99
Add one doxygen comment
JohannesLorenz Apr 25, 2020
4a7f1ce
Implement D/W for Lv2 effects
JohannesLorenz Apr 25, 2020
43d758b
Distinguish between sidechain and optional ports
JohannesLorenz Apr 26, 2020
20f9b2c
Lv2ViewBase.cpp: Fix style issues
JohannesLorenz May 5, 2020
cea7f7d
Lv2Effect::tmpOutputSmps: Use 'm_' prefix
JohannesLorenz May 5, 2020
d8e36e5
Add LMMS_HAVE_SUIL to lmmsconfig.h.in
JohannesLorenz May 5, 2020
216b689
CMakeLists style fixes
JohannesLorenz May 5, 2020
a02b106
Lv2Effect.cpp: Use static_cast
JohannesLorenz May 5, 2020
12b2253
Remove unnecessary Lv2Ports::Control::accept
JohannesLorenz May 5, 2020
c7234aa
Lv2Effect.cpp: Style fixes
JohannesLorenz May 5, 2020
4c2a52a
Lv2Effect: Fix calling checkGate with only wet
JohannesLorenz May 7, 2020
13d39d2
Lv2ViewBase: Remove useless UI hint
JohannesLorenz May 7, 2020
5c6ec8a
Lv2Ports::Audio: Rename a function
JohannesLorenz May 7, 2020
74c92c3
Lv2Proc: Improve docs for 1st channel offsets
JohannesLorenz May 7, 2020
bca38f0
Enable turning on/off Lv2 debug output
JohannesLorenz May 10, 2020
e443ce1
Apply suggestions from code review
JohannesLorenz May 17, 2020
867973c
Merge branch 'master' into lv2-review
JohannesLorenz May 17, 2020
39bfecd
CMakeLists.txt: Improve `WANT_SUIL` description
JohannesLorenz May 19, 2020
3862929
Remove Lv2ViewProc::leaveEvent
JohannesLorenz May 21, 2020
d282952
Merge branch 'master' into lv2-review
JohannesLorenz May 23, 2020
756b84e
Revert "Remove Lv2ViewProc::leaveEvent"
JohannesLorenz May 23, 2020
5602bb9
Revert "Revert "Remove Lv2ViewProc::leaveEvent""
JohannesLorenz May 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis/linux..install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ SWH_PACKAGES="perl libxml2-utils libxml-perl liblist-moreutils-perl"
# VST dependencies
VST_PACKAGES="wine-dev qt59x11extras qtbase5-private-dev libxcb-util0-dev libxcb-keysyms1-dev"

# LV2 dependencies; libsuil-dev is not required
LV2_PACKAGES="lv2-dev liblilv-dev"

# Help with unmet dependencies
PACKAGES="$PACKAGES $SWH_PACKAGES $VST_PACKAGES libjack-jackd2-0"
PACKAGES="$PACKAGES $SWH_PACKAGES $VST_PACKAGES $LV2_PACKAGES libjack-jackd2-0"

# shellcheck disable=SC2086
sudo apt-get install -y $PACKAGES
Expand Down
37 changes: 37 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ OPTION(WANT_CARLA "Include Carla plugin" ON)
OPTION(WANT_CMT "Include Computer Music Toolkit LADSPA plugins" ON)
OPTION(WANT_JACK "Include JACK (Jack Audio Connection Kit) support" ON)
OPTION(WANT_WEAKJACK "Loosely link JACK libraries" ON)
OPTION(WANT_LV2 "Include Lv2 plugins" ON)
OPTION(WANT_SUIL "Include SUIL for plugin UIs" ON)
JohannesLorenz marked this conversation as resolved.
Show resolved Hide resolved
OPTION(WANT_MP3LAME "Include MP3/Lame support" ON)
OPTION(WANT_OGGVORBIS "Include OGG/Vorbis support" ON)
OPTION(WANT_PULSEAUDIO "Include PulseAudio support" ON)
Expand Down Expand Up @@ -182,6 +184,39 @@ IF(NOT SNDFILE_VERSION VERSION_LESS 1.0.26)
SET(LMMS_HAVE_SF_COMPLEVEL TRUE)
ENDIF()

IF(WANT_LV2)
IF(PKG_CONFIG_FOUND)
PKG_CHECK_MODULES(LV2 lv2)
PKG_CHECK_MODULES(LILV lilv-0)
IF(${LV2_FOUND} AND ${LILV_FOUND})
JohannesLorenz marked this conversation as resolved.
Show resolved Hide resolved
SET(LMMS_HAVE_LV2 TRUE)
SET(STATUS_LV2 "OK")
ELSE()
SET(STATUS_LV2 "not found, install it or set PKG_CONFIG_PATH appropriately")
ENDIF()
ELSE()
SET(STATUS_LV2 "not found, requires pkg-config")
ENDIF()
ELSE(WANT_LV2)
SET(STATUS_LV2 "not built as requested")
ENDIF(WANT_LV2)

IF(WANT_SUIL)
IF(PKG_CONFIG_FOUND)
PKG_CHECK_MODULES(SUIL suil-0)
IF(${SUIL_FOUND})
JohannesLorenz marked this conversation as resolved.
Show resolved Hide resolved
SET(LMMS_HAVE_SUIL TRUE)
JohannesLorenz marked this conversation as resolved.
Show resolved Hide resolved
SET(STATUS_SUIL "OK")
ELSE()
SET(STATUS_SUIL "not found, install it or set PKG_CONFIG_PATH appropriately")
ENDIF()
ELSE()
SET(STATUS_SUIL "not found, requires pkg-config")
ENDIF()
ELSE(WANT_SUIL)
SET(STATUS_SUIL "not built as requested")
ENDIF(WANT_SUIL)

IF(WANT_CALF)
SET(LMMS_HAVE_CALF TRUE)
SET(STATUS_CALF "OK")
Expand Down Expand Up @@ -680,6 +715,8 @@ MESSAGE(
MESSAGE(
"Optional plugins\n"
"----------------\n"
"* Lv2 plugins : ${STATUS_LV2}\n"
"* SUIL for plugin UIs : ${STATUS_SUIL}\n"
"* ZynAddSubFX instrument : ${STATUS_ZYN}\n"
"* Carla Patchbay & Rack : ${STATUS_CARLA}\n"
"* SoundFont2 player : ${STATUS_FLUIDSYNTH}\n"
Expand Down
2 changes: 2 additions & 0 deletions cmake/modules/PluginList.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ SET(LMMS_PLUGIN_LIST
HydrogenImport
ladspa_browser
LadspaEffect
Lv2Effect
Lv2Instrument
lb302
MidiImport
MidiExport
Expand Down
11 changes: 11 additions & 0 deletions include/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QtCore/QObject>


#include "lmmsconfig.h"
#include "lmms_export.h"
#include "lmms_basics.h"

Expand Down Expand Up @@ -87,6 +88,13 @@ class LMMS_EXPORT LmmsCore : public QObject
return s_projectJournal;
}

#ifdef LMMS_HAVE_LV2
static class Lv2Manager * getLv2Manager()
{
return s_lv2Manager;
}
#endif

static Ladspa2LMMS * getLADSPAManager()
{
return s_ladspaManager;
Expand Down Expand Up @@ -143,6 +151,9 @@ class LMMS_EXPORT LmmsCore : public QObject
static ProjectJournal * s_projectJournal;
static DummyTrackContainer * s_dummyTC;

#ifdef LMMS_HAVE_LV2
static class Lv2Manager* s_lv2Manager;
#endif
static Ladspa2LMMS * s_ladspaManager;
static void* s_dndPluginKey;

Expand Down
67 changes: 67 additions & 0 deletions include/Lv2Basics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Lv2Basics.h - basic Lv2 utils
*
* Copyright (c) 2018-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 LV2BASICS_H
#define LV2BASICS_H


#include "lmmsconfig.h"

#ifdef LMMS_HAVE_LV2

#include <lilv/lilv.h>
#include <memory>
#include <QString>
#include <string>

struct LilvNodeDeleter
{
void operator()(LilvNode* n) { lilv_node_free(n); }
};

struct LilvNodesDeleter
{
void operator()(LilvNodes* n) { lilv_nodes_free(n); }
};

using AutoLilvNode = std::unique_ptr<LilvNode, LilvNodeDeleter>;
using AutoLilvNodes = std::unique_ptr<LilvNodes, LilvNodesDeleter>;

/**
Return QString from a plugin's node, everything will be freed automatically
@param plug The plugin where the node is
@param getFunc The function to return the node from the plugin
*/
QString qStringFromPluginNode(const LilvPlugin* plug,
LilvNode * (*getFunc)(const LilvPlugin*));

//! Return port name as QString, everything will be freed automatically
QString qStringFromPortName(const LilvPlugin* plug, const LilvPort* port);

//! Return port name as std::string, everything will be freed automatically
std::string stdStringFromPortName(const LilvPlugin* plug, const LilvPort* port);

#endif // LMMS_HAVE_LV2
#endif // LV2BASICS_H
146 changes: 146 additions & 0 deletions include/Lv2ControlBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* Lv2ControlBase.h - Lv2 control base class
*
* Copyright (c) 2018-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 LV2_CONTROL_BASE_H
#define LV2_CONTROL_BASE_H

#include "lmmsconfig.h"

#ifdef LMMS_HAVE_LV2

#include <lilv/lilv.h>

#include "DataFile.h"
#include "LinkedModelGroups.h"
#include "Plugin.h"

class Lv2Proc;
class PluginIssue;

/**
Common base class for Lv2 plugins

This class contains a vector of Lv2Proc, usually 1 (for stereo plugins) or
2 (for mono plugins). Most of the logic is done there, this class primarily
forwards work to the Lv2Proc and collects the results.

This class provides everything Lv2 plugins have in common. It's not
named Lv2Plugin, because
* it does not inherit Instrument
* the Plugin subclass Effect does not inherit this class

This class would usually be a Model subclass. However, Qt doesn't allow
this:
* inhertiting only from Model will cause diamond inheritance for QObject,
which will cause errors with Q_OBJECT
* making this a direct subclass of Instrument resp. EffectControls would
require CRTP, which would make this class a template class, which would
conflict with Q_OBJECT

The consequence is that this class can neither inherit QObject or Model, nor
Instrument or EffectControls, which means in fact:
* this class contains no signals or slots, but it offers stubs for slots
that shall be called by child classes
* this class can not override virtuals of Instrument or EffectControls, so
it will offer functions that must be called by virtuals in its child class
*/
class Lv2ControlBase : public LinkedModelGroups
{
public:
static Plugin::PluginTypes check(const LilvPlugin* m_plugin,
std::vector<PluginIssue> &issues, bool printIssues = false);

const LilvPlugin* getPlugin() const { return m_plugin; }

Lv2Proc *control(std::size_t idx) { return m_procs[idx].get(); }
const Lv2Proc *control(std::size_t idx) const { return m_procs[idx].get(); }

bool hasGui() const { return m_hasGUI; }
void setHasGui(bool val) { m_hasGUI = val; }

protected:
/*
ctor/dtor
*/
//! @param that the class inheriting this class and inheriting Model;
//! this is the same pointer as this, but a different type
//! @param uri the Lv2 URI telling this class what plugin to construct
Lv2ControlBase(class Model *that, const QString& uri);
~Lv2ControlBase() override;
//! Must be checked after ctor or reload
bool isValid() const { return m_valid; }

/*
overrides
*/
LinkedModelGroup* getGroup(std::size_t idx) override;
const LinkedModelGroup* getGroup(std::size_t idx) const override;

/*
utils for the run thread
*/
//! Copy values from all connected models into the respective ports
void copyModelsFromLmms();
//! Copy buffer passed by LMMS into our ports
void copyBuffersFromLmms(const sampleFrame *buf, fpp_t frames);
//! Copy our ports into buffers passed by LMMS
void copyBuffersToLmms(sampleFrame *buf, fpp_t frames) const;
JohannesLorenz marked this conversation as resolved.
Show resolved Hide resolved
//! Run the Lv2 plugin instance for @param frames frames
void run(fpp_t frames);

/*
load/save, must be called from virtuals
*/
void saveSettings(QDomDocument &doc, QDomElement &that);
void loadSettings(const QDomElement &that);
void loadFile(const QString &file);
//! TODO: not implemented
void reloadPlugin();

/*
more functions that must be called from virtuals
*/
std::size_t controlCount() const;
QString nodeName() const { return "lv2controls"; }

private:
//! Return the DataFile settings type
virtual DataFile::Types settingsType() = 0;
//! Inform the plugin about a file name change
virtual void setNameFromFile(const QString &fname) = 0;

//! Independent processors
//! If this is a mono effect, the vector will have size 2 in order to
//! fulfill LMMS' requirement of having stereo input and output
std::vector<std::unique_ptr<Lv2Proc>> m_procs;

bool m_valid = true;
bool m_hasGUI = false;
unsigned m_channelsPerProc;

const LilvPlugin* m_plugin;
};

#endif // LMMS_HAVE_LV2
#endif // LV2_CONTROL_BASE_H
Loading