lmms
Cross-platform music production software
Loading...
Searching...
No Matches
Lv2Ports.h
Go to the documentation of this file.
1/*
2 * Lv2Ports.h - Lv2 port classes definitions
3 *
4 * Copyright (c) 2019-2020 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_LV2PORTS_H
26#define LMMS_LV2PORTS_H
27
28#include "lmmsconfig.h"
29
30#ifdef LMMS_HAVE_LV2
31
32#include <lilv/lilv.h>
33#include <memory>
34#include <vector>
35
36#include "Flags.h"
37#include "LmmsTypes.h"
38#include "PluginIssue.h"
39
40
41namespace lmms
42{
43
44class SampleFrame;
45
47using LV2_Evbuf = struct LV2_Evbuf_Impl;
48
49namespace Lv2Ports {
50
51/*
52 port structs
53*/
54enum class Flow {
56 Input,
57 Output
58};
59
67
76
77const char* toStr(Lv2Ports::Flow pf);
78const char* toStr(Lv2Ports::Type pt);
79const char* toStr(Lv2Ports::Vis pv);
80
81struct ControlPortBase;
82struct Control;
83struct Audio;
84struct Cv;
85struct AtomSeq;
86struct Unknown;
87
89{
90 virtual void visit(const Lv2Ports::ControlPortBase& ) {}
91 virtual void visit(const Lv2Ports::Control& ) {}
92 virtual void visit(const Lv2Ports::Audio& ) {}
93 virtual void visit(const Lv2Ports::Cv& ) {}
94 virtual void visit(const Lv2Ports::AtomSeq& ) {}
95 virtual void visit(const Lv2Ports::Unknown& ) {}
96
97 virtual ~ConstVisitor() = default;
98};
99
101{
103 virtual void visit(Lv2Ports::Control& ) {}
104 virtual void visit(Lv2Ports::Audio& ) {}
105 virtual void visit(Lv2Ports::Cv& ) {}
106 virtual void visit(Lv2Ports::AtomSeq& ) {}
107 virtual void visit(Lv2Ports::Unknown& ) {}
108
109 virtual ~Visitor() = default;
110};
111
112struct Meta
113{
117
118 bool m_logarithmic = false;
119
120 bool m_optional = false;
121 bool m_used = true;
122
123 std::vector<PluginIssue> get(const LilvPlugin* plugin, std::size_t portNum);
124
125 float def() const { return m_def; }
126 float min(sample_rate_t sr) const { return m_sampleRate ? sr * m_min : m_min; }
127 float max(sample_rate_t sr) const { return m_sampleRate ? sr * m_max : m_max; }
128private:
129 float m_def = .0f, m_min = .0f, m_max = .0f;
130 bool m_sampleRate = false;
131};
132
133struct PortBase : public Meta
134{
135 const LilvPort* m_port = nullptr;
136 const LilvPlugin* m_plugin = nullptr;
137
138 virtual void accept(Visitor& v) = 0;
139 virtual void accept(ConstVisitor& v) const = 0;
140
141 QString name() const;
142 QString uri() const;
143
144 virtual ~PortBase() = default;
145};
146
147template<typename Derived, typename Base>
148struct VisitablePort : public Base
149{
150 void accept(Visitor& v) override { v.visit(static_cast<Derived&>(*this)); }
151 void accept(ConstVisitor& v) const override { v.visit(static_cast<const Derived&>(*this)); }
152};
153
154struct ControlPortBase : public VisitablePort<ControlPortBase, PortBase>
155{
158 std::unique_ptr<class AutomatableModel> m_connectedModel;
159
163 std::vector<float> m_scalePointMap;
164};
165
166struct Control : public VisitablePort<Control, ControlPortBase>
167{
171 float m_val;
172};
173
174struct Cv : public VisitablePort<Cv, ControlPortBase>
175{
179 std::vector<float> m_buffer;
180};
181
182struct Audio : public VisitablePort<Audio, PortBase>
183{
184 Audio(std::size_t bufferSize, bool isSidechain);
185
190 void copyBuffersFromCore(const SampleFrame* lmmsBuf, unsigned channel, f_cnt_t frames);
191
196 void averageWithBuffersFromCore(const SampleFrame* lmmsBuf, unsigned channel, f_cnt_t frames);
197
202 void copyBuffersToCore(SampleFrame* lmmsBuf, unsigned channel, f_cnt_t frames) const;
203
204 bool isSideChain() const { return m_sidechain; }
205 bool isOptional() const { return m_optional; }
206 bool mustBeUsed() const { return !isSideChain() && !isOptional(); }
207 std::size_t bufferSize() const { return m_buffer.size(); }
208
209private:
210 std::vector<float> m_buffer;
212
213 // the only case when data of m_buffer may be referenced:
215};
216
217struct AtomSeq : public VisitablePort<AtomSeq, PortBase>
218{
219 enum class FlagType
220 {
221 None = 0,
222 Midi = 1
223 };
225
227 {
228 void operator()(LV2_Evbuf* n);
229 };
230 using AutoLv2Evbuf = std::unique_ptr<LV2_Evbuf, Lv2EvbufDeleter>;
232};
233
234struct Unknown : public VisitablePort<Unknown, PortBase>
235{
236};
237
238/*
239 port casts
240*/
241template<class Target>
242struct DCastVisitor : public Visitor
243{
244 Target* m_result = nullptr;
245 void visit(Target& tar) { m_result = &tar; }
246};
247
248template<class Target>
250{
251 const Target* m_result = nullptr;
252 void visit(const Target& tar) { m_result = &tar; }
253};
254
256template<class Target>
257Target* dcast(PortBase* base)
258{
260 base->accept(vis);
261 return vis.m_result;
262}
263
265template<class Target>
266const Target* dcast(const PortBase* base)
267{
269 base->accept(vis);
270 return vis.m_result;
271}
272
273} // namespace Lv2Ports
274
275
276} // namespace lmms
277
278#endif // LMMS_HAVE_LV2
279
280#endif // LMMS_LV2PORTS_H
Definition Flags.h:34
Definition SampleFrame.h:41
Definition Lv2Ports.cpp:41
const char * toStr(Flow pf)
Definition Lv2Ports.cpp:46
Vis
Definition Lv2Ports.h:70
@ Enumeration
selection from enumerated values
Definition Lv2Ports.h:73
@ Generic
nothing specific, a generic knob or slider shall be used
Definition Lv2Ports.h:71
Flow
Definition Lv2Ports.h:54
@ Unknown
Definition Lv2Ports.h:55
Target * dcast(PortBase *base)
If you don't want to use a whole visitor, you can use dcast.
Definition Lv2Ports.h:257
Type
Definition Lv2Ports.h:60
@ Unknown
Definition Lv2Ports.h:61
Definition RemotePluginBase.cpp:34
std::uint32_t sample_rate_t
Definition LmmsTypes.h:42
struct LV2_Evbuf_Impl LV2_Evbuf
Definition Lv2Evbuf.h:50
std::uint64_t f_cnt_t
Definition LmmsTypes.h:43
@ None
Definition LadspaBase.h:49
@ Toggled
Definition LadspaBase.h:49
@ Integer
Definition LadspaBase.h:49
Definition Lv2Proc.cpp:826
Definition Lv2Evbuf.cpp:43
void operator()(LV2_Evbuf *n)
Definition Lv2Ports.cpp:351
Definition Lv2Ports.h:218
FlagType
Definition Lv2Ports.h:220
@ None
Definition Lv2Ports.h:221
AutoLv2Evbuf m_buf
Definition Lv2Ports.h:231
Flags< FlagType > flags
Definition Lv2Ports.h:224
std::unique_ptr< LV2_Evbuf, Lv2EvbufDeleter > AutoLv2Evbuf
Definition Lv2Ports.h:230
Definition Lv2Ports.h:183
void averageWithBuffersFromCore(const SampleFrame *lmmsBuf, unsigned channel, f_cnt_t frames)
Add buffer passed by LMMS into our ports, and halve the result.
Definition Lv2Ports.cpp:327
void copyBuffersFromCore(const SampleFrame *lmmsBuf, unsigned channel, f_cnt_t frames)
Copy buffer passed by LMMS into our ports.
Definition Lv2Ports.cpp:315
bool mustBeUsed() const
Definition Lv2Ports.h:206
Audio(std::size_t bufferSize, bool isSidechain)
Definition Lv2Ports.cpp:307
bool isSideChain() const
Definition Lv2Ports.h:204
void copyBuffersToCore(SampleFrame *lmmsBuf, unsigned channel, f_cnt_t frames) const
Copy our ports into buffers passed by LMMS.
Definition Lv2Ports.cpp:339
std::size_t bufferSize() const
Definition Lv2Ports.h:207
bool isOptional() const
Definition Lv2Ports.h:205
std::vector< float > m_buffer
The buffer where Lv2 reads/writes the data from/to.
Definition Lv2Ports.h:210
bool m_sidechain
Definition Lv2Ports.h:211
Definition Lv2Ports.h:250
void visit(const Target &tar)
Definition Lv2Ports.h:252
const Target * m_result
Definition Lv2Ports.h:251
Definition Lv2Ports.h:89
virtual void visit(const Lv2Ports::ControlPortBase &)
Definition Lv2Ports.h:90
virtual void visit(const Lv2Ports::Unknown &)
Definition Lv2Ports.h:95
virtual void visit(const Lv2Ports::Cv &)
Definition Lv2Ports.h:93
virtual void visit(const Lv2Ports::Control &)
Definition Lv2Ports.h:91
virtual ~ConstVisitor()=default
virtual void visit(const Lv2Ports::Audio &)
Definition Lv2Ports.h:92
virtual void visit(const Lv2Ports::AtomSeq &)
Definition Lv2Ports.h:94
Definition Lv2Ports.h:167
float m_val
Definition Lv2Ports.h:171
Definition Lv2Ports.h:155
std::unique_ptr< class AutomatableModel > m_connectedModel
Definition Lv2Ports.h:158
std::vector< float > m_scalePointMap
Definition Lv2Ports.h:163
Definition Lv2Ports.h:175
std::vector< float > m_buffer
Definition Lv2Ports.h:179
Definition Lv2Ports.h:243
Target * m_result
Definition Lv2Ports.h:244
void visit(Target &tar)
Definition Lv2Ports.h:245
Definition Lv2Ports.h:113
Type m_type
Definition Lv2Ports.h:114
std::vector< PluginIssue > get(const LilvPlugin *plugin, std::size_t portNum)
Definition Lv2Ports.cpp:91
bool m_optional
Definition Lv2Ports.h:120
float m_min
Definition Lv2Ports.h:129
bool m_logarithmic
Definition Lv2Ports.h:118
float max(sample_rate_t sr) const
Definition Lv2Ports.h:127
bool m_used
Definition Lv2Ports.h:121
float min(sample_rate_t sr) const
Definition Lv2Ports.h:126
float m_max
Definition Lv2Ports.h:129
float def() const
Definition Lv2Ports.h:125
bool m_sampleRate
Definition Lv2Ports.h:130
Flow m_flow
Definition Lv2Ports.h:115
float m_def
Definition Lv2Ports.h:129
Vis m_vis
Definition Lv2Ports.h:116
Definition Lv2Ports.h:134
virtual void accept(ConstVisitor &v) const =0
QString uri() const
Definition Lv2Ports.cpp:299
const LilvPlugin * m_plugin
Definition Lv2Ports.h:136
virtual ~PortBase()=default
virtual void accept(Visitor &v)=0
QString name() const
Definition Lv2Ports.cpp:289
const LilvPort * m_port
Definition Lv2Ports.h:135
Definition Lv2Ports.h:235
Definition Lv2Ports.h:149
void accept(Visitor &v) override
Definition Lv2Ports.h:150
void accept(ConstVisitor &v) const override
Definition Lv2Ports.h:151
Definition Lv2Ports.h:101
virtual void visit(Lv2Ports::Unknown &)
Definition Lv2Ports.h:107
virtual void visit(Lv2Ports::Control &)
Definition Lv2Ports.h:103
virtual void visit(Lv2Ports::Cv &)
Definition Lv2Ports.h:105
virtual void visit(Lv2Ports::ControlPortBase &)
Definition Lv2Ports.h:102
virtual ~Visitor()=default
virtual void visit(Lv2Ports::Audio &)
Definition Lv2Ports.h:104
virtual void visit(Lv2Ports::AtomSeq &)
Definition Lv2Ports.h:106