LMMS
Loading...
Searching...
No Matches
Lv2Proc.h
Go to the documentation of this file.
1/*
2 * Lv2Proc.h - Lv2 processor class
3 *
4 * Copyright (c) 2019-2022 Johannes Lorenz <jlsf2013$users.sourceforge.net, $=@>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef LMMS_LV2_PROC_H
26#define LMMS_LV2_PROC_H
27
28#include "lmmsconfig.h"
29
30#ifdef LMMS_HAVE_LV2
31
32#include <lilv/lilv.h>
33#include <memory>
34#include <optional>
35
36#include <ringbuffer/ringbuffer.h>
37
38#include "LinkedModelGroups.h"
39#include "LmmsSemaphore.h"
40#include "Lv2Basics.h"
41#include "Lv2Features.h"
42#include "Lv2Options.h"
43#include "Lv2Worker.h"
44#include "Plugin.h"
45#include "TimePos.h"
46
47
48namespace lmms
49{
50
51class PluginIssue;
52class SampleFrame;
53
54// forward declare port structs/enums
55namespace Lv2Ports
56{
57 struct Audio;
58 struct PortBase;
59 struct AtomSeq;
60}
61
62
66{
67 friend class Lv2ProcSuspender;
68public:
69 static Plugin::Type check(const LilvPlugin* plugin,
70 std::vector<PluginIssue> &issues);
71
72 /*
73 ctor/dtor/reload
74 */
75 Lv2Proc(const LilvPlugin* plugin, Model *parent);
76 ~Lv2Proc() override;
77 void reload();
79
80 /*
81 port access
82 */
84 {
89 };
90
92 const StereoPortRef& inPorts() const { return m_inPorts; }
94 const StereoPortRef& outPorts() const { return m_outPorts; }
95 template<class Functor>
96 void foreach_port(const Functor& ftor)
97 {
98 for (std::unique_ptr<Lv2Ports::PortBase>& port : m_ports)
99 {
100 ftor(port.get());
101 }
102 }
103 template<class Functor>
104 void foreach_port(const Functor& ftor) const
105 {
106 for (const std::unique_ptr<Lv2Ports::PortBase>& port : m_ports)
107 {
108 ftor(port.get());
109 }
110 }
111
113 void dumpPorts();
114
115 /*
116 utils for the run thread
117 */
120 void copyModelsFromCore();
122 void copyModelsToCore();
134 void copyBuffersFromCore(const SampleFrame* buf,
135 unsigned firstChan, unsigned num, f_cnt_t frames);
147 void copyBuffersToCore(SampleFrame* buf, unsigned firstChan, unsigned num,
148 f_cnt_t frames) const;
150 void run(f_cnt_t frames);
151
152 void handleMidiInputEvent(const class MidiEvent &event,
153 const TimePos &time, f_cnt_t offset);
154
155 /*
156 misc
157 */
158 class AutomatableModel *modelAtPort(const QString &uri); // unused currently
159 std::size_t controlCount() const { return LinkedModelGroup::modelNum(); }
160 bool hasNoteInput() const;
161
162protected:
163 /*
164 load and save
165 */
167 void initPlugin();
169 void shutdownPlugin();
170
171private:
175
176 // options
178
179 // worker
180 std::optional<Lv2Worker> m_worker;
181 Semaphore m_workLock; // this must be shared by different workers
182
183 // full list of ports
184 std::vector<std::unique_ptr<Lv2Ports::PortBase>> m_ports;
185 // quick reference to specific, unique ports
187 Lv2Ports::AtomSeq *m_midiIn = nullptr, *m_midiOut = nullptr;
188
189 // MIDI
190 // many things here may be moved into the `Instrument` class
191 constexpr const static std::size_t m_maxMidiInputEvents = 1024;
193 std::atomic_flag m_ringLock = ATOMIC_FLAG_INIT;
194
196 ringbuffer_t<struct MidiInputEvent> m_midiInputBuf;
198 ringbuffer_reader_t<struct MidiInputEvent> m_midiInputReader;
199
200 // other
201 static int32_t defaultEvbufSize() { return 1 << 15; /* ardour uses this*/ }
202
206 std::map<std::string, AutomatableModel *> m_connectedModels;
207
208 void initMOptions();
210
212 void loadFileInternal(const QString &file);
214 void createPorts();
216 void createPort(std::size_t portNum);
218 void connectPort(std::size_t num);
219
220 void dumpPort(std::size_t num);
221
222 static bool portIsSideChain(const LilvPlugin* plugin, const LilvPort *port);
223 static bool portIsOptional(const LilvPlugin* plugin, const LilvPort *port);
224 static AutoLilvNode uri(const char* uriStr);
225};
226
227
228} // namespace lmms
229
230#endif // LMMS_HAVE_LV2
231
232#endif // LMMS_LV2_PROC_H
#define check(expr)
Definition blargg_source.h:32
Definition AutomatableModel.h:77
std::size_t modelNum() const
Definition LinkedModelGroups.h:99
LinkedModelGroup(Model *parent)
Definition LinkedModelGroups.h:61
Definition Lv2Features.h:55
Definition Lv2Options.h:62
void copyBuffersFromCore(const SampleFrame *buf, unsigned firstChan, unsigned num, f_cnt_t frames)
Definition Lv2Proc.cpp:327
Lv2Options m_options
Definition Lv2Proc.h:177
const StereoPortRef & inPorts() const
Definition Lv2Proc.h:92
void copyModelsToCore()
Bring values from all ports to the LMMS core.
Definition Lv2Proc.cpp:302
void foreach_port(const Functor &ftor) const
Definition Lv2Proc.h:104
class AutomatableModel * modelAtPort(const QString &uri)
Definition Lv2Proc.cpp:426
void initPluginSpecificFeatures()
Definition Lv2Proc.cpp:527
void copyBuffersToCore(SampleFrame *buf, unsigned firstChan, unsigned num, f_cnt_t frames) const
Definition Lv2Proc.cpp:352
void initMOptions()
initialize m_options
Definition Lv2Proc.cpp:499
~Lv2Proc() override
Definition Lv2Proc.cpp:207
static bool portIsSideChain(const LilvPlugin *plugin, const LilvPort *port)
Definition Lv2Proc.cpp:894
void dumpPort(std::size_t num)
Definition Lv2Proc.cpp:849
void shutdownPlugin()
Deactivate instance.
Definition Lv2Proc.cpp:474
Lv2Features m_features
Definition Lv2Proc.h:174
constexpr static const std::size_t m_maxMidiInputEvents
Definition Lv2Proc.h:191
std::map< std::string, AutomatableModel * > m_connectedModels
Definition Lv2Proc.h:206
Lv2Ports::AtomSeq * m_midiOut
Definition Lv2Proc.h:187
void dumpPorts()
Debug function to print ports to stdout.
Definition Lv2Proc.cpp:217
friend class Lv2ProcSuspender
Definition Lv2Proc.h:67
Lv2Ports::AtomSeq * m_midiIn
Definition Lv2Proc.h:187
ringbuffer_t< struct MidiInputEvent > m_midiInputBuf
MIDI ringbuffer (for MIDI events going to the plugin).
Definition Lv2Proc.h:196
StereoPortRef m_outPorts
Definition Lv2Proc.h:186
std::atomic_flag m_ringLock
spinlock for the MIDI ringbuffer (for MIDI events going to the plugin)
Definition Lv2Proc.h:193
void loadFileInternal(const QString &file)
load a file in the plugin, but don't do anything in LMMS
Definition Lv2Proc.cpp:547
void connectPort(std::size_t num)
connect m_ports[portNum] with Lv2
Definition Lv2Proc.cpp:838
Semaphore m_workLock
Definition Lv2Proc.h:181
void copyModelsFromCore()
Definition Lv2Proc.cpp:230
void reload()
Definition Lv2Proc.cpp:212
void createPort(std::size_t portNum)
fill m_ports[portNum] with metadata
Definition Lv2Proc.cpp:555
const LilvPlugin * m_plugin
Definition Lv2Proc.h:172
std::vector< std::unique_ptr< Lv2Ports::PortBase > > m_ports
Definition Lv2Proc.h:184
void handleMidiInputEvent(const class MidiEvent &event, const TimePos &time, f_cnt_t offset)
Definition Lv2Proc.cpp:394
Lv2Proc(const LilvPlugin *plugin, Model *parent)
Definition Lv2Proc.cpp:193
static int32_t defaultEvbufSize()
Definition Lv2Proc.h:201
static bool portIsOptional(const LilvPlugin *plugin, const LilvPort *port)
Definition Lv2Proc.cpp:903
bool hasNoteInput() const
Definition Lv2Proc.cpp:487
const StereoPortRef & outPorts() const
Definition Lv2Proc.h:94
StereoPortRef & outPorts()
Definition Lv2Proc.h:93
void run(f_cnt_t frames)
Run the Lv2 plugin instance for.
Definition Lv2Proc.cpp:371
void foreach_port(const Functor &ftor)
Definition Lv2Proc.h:96
LilvInstance * m_instance
Definition Lv2Proc.h:173
void onSampleRateChanged()
ringbuffer_reader_t< struct MidiInputEvent > m_midiInputReader
MIDI ringbuffer reader.
Definition Lv2Proc.h:198
std::size_t controlCount() const
Definition Lv2Proc.h:159
StereoPortRef & inPorts()
Definition Lv2Proc.h:91
void initPlugin()
Create ports and instance, connect ports, activate plugin.
Definition Lv2Proc.cpp:435
std::optional< Lv2Worker > m_worker
Definition Lv2Proc.h:180
StereoPortRef m_inPorts
Definition Lv2Proc.h:186
void createPorts()
allocate m_ports, fill all with metadata, and assign meaning of ports
Definition Lv2Proc.cpp:721
static AutoLilvNode uri(const char *uriStr)
Definition Lv2Proc.cpp:912
Definition MidiEvent.h:37
Definition Model.h:37
Type
Definition Plugin.h:76
Issue type bundled with informational string.
Definition PluginIssue.h:66
Definition SampleFrame.h:41
Definition LmmsSemaphore.h:67
Definition TimePos.h:68
static uintptr_t parent
Definition pugl.h:1644
struct LilvPortImpl LilvPort
Definition lilv.h:84
struct LilvPluginImpl LilvPlugin
Definition lilv.h:82
struct LilvInstanceImpl LilvInstance
Definition lilv.h:89
static SordNode * uri(SordWorld *world, int num)
Definition sord_test.c:47
int int32_t
Definition mid.cpp:97
Definition Lv2Ports.cpp:41
Definition AudioAlsa.cpp:35
std::unique_ptr< LilvNode, LilvNodeDeleter > AutoLilvNode
Definition Lv2Basics.h:63
std::uint64_t f_cnt_t
Definition LmmsTypes.h:43
Definition Lv2Ports.h:214
Definition Lv2Ports.h:183
Definition Lv2Ports.h:134
Definition Lv2Proc.h:84
Lv2Ports::Audio * m_right
unused, or right port in case of stereo
Definition Lv2Proc.h:88
Lv2Ports::Audio * m_left
mono port or left port in case of stereo
Definition Lv2Proc.h:86
struct zdirent * file
Definition win32.c:1500