LMMS
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 {
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
188 void copyBuffersFromCore(const SampleFrame* lmmsBuf,
189 unsigned channel, f_cnt_t frames);
192 void averageWithBuffersFromCore(const SampleFrame* lmmsBuf,
193 unsigned channel, f_cnt_t frames);
196 void copyBuffersToCore(SampleFrame* lmmsBuf,
197 unsigned channel, f_cnt_t frames) const;
198
199 bool isSideChain() const { return m_sidechain; }
200 bool isOptional() const { return m_optional; }
201 bool mustBeUsed() const { return !isSideChain() && !isOptional(); }
202 std::size_t bufferSize() const { return m_buffer.size(); }
203
204private:
206 std::vector<float> m_buffer;
208
209 // the only case when data of m_buffer may be referenced:
211};
212
213struct AtomSeq : public VisitablePort<AtomSeq, PortBase>
214{
215 enum class FlagType
216 {
217 None = 0,
219 };
221
223 {
224 void operator()(LV2_Evbuf* n);
225 };
226 using AutoLv2Evbuf = std::unique_ptr<LV2_Evbuf, Lv2EvbufDeleter>;
228};
229
230struct Unknown : public VisitablePort<Unknown, PortBase>
231{
232};
233
234/*
235 port casts
236*/
237template<class Target>
238struct DCastVisitor : public Visitor
239{
240 Target* m_result = nullptr;
241 void visit(Target& tar) { m_result = &tar; }
242};
243
244template<class Target>
246{
247 const Target* m_result = nullptr;
248 void visit(const Target& tar) { m_result = &tar; }
249};
250
252template<class Target>
253Target* dcast(PortBase* base)
254{
256 base->accept(vis);
257 return vis.m_result;
258}
259
261template<class Target>
262const Target* dcast(const PortBase* base)
263{
265 base->accept(vis);
266 return vis.m_result;
267}
268
269} // namespace Lv2Ports
270
271
272} // namespace lmms
273
274#endif // LMMS_HAVE_LV2
275
276#endif // LMMS_LV2PORTS_H
Definition Control.h:29
Definition Flags.h:34
Definition SampleFrame.h:41
unsigned v[N_MAX]
Definition inflate.c:1584
struct LilvPortImpl LilvPort
Definition lilv.h:84
struct LilvPluginImpl LilvPlugin
Definition lilv.h:82
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
@ Toggled
boolean widget
Definition Lv2Ports.h:74
@ Generic
nothing specific, a generic knob or slider shall be used
Definition Lv2Ports.h:71
@ Integer
counter
Definition Lv2Ports.h:72
Flow
Definition Lv2Ports.h:54
@ Output
Definition Lv2Ports.h:57
@ Input
Definition Lv2Ports.h:56
@ 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:253
Type
Definition Lv2Ports.h:60
@ Unknown
Definition Lv2Ports.h:61
@ AtomSeq
Definition Lv2Ports.h:64
@ Audio
Definition Lv2Ports.h:63
@ Cv
TODO: unused, describe.
Definition Lv2Ports.h:65
Definition AudioAlsa.cpp:35
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
Definition Lv2Proc.cpp:815
Definition Lv2Evbuf.cpp:43
void operator()(LV2_Evbuf *n)
Definition Lv2Ports.cpp:351
Definition Lv2Ports.h:214
FlagType
Definition Lv2Ports.h:216
@ Midi
Definition Lv2Ports.h:218
@ None
Definition Lv2Ports.h:217
AutoLv2Evbuf m_buf
Definition Lv2Ports.h:227
Flags< FlagType > flags
Definition Lv2Ports.h:220
std::unique_ptr< LV2_Evbuf, Lv2EvbufDeleter > AutoLv2Evbuf
Definition Lv2Ports.h:226
Definition Lv2Ports.h:183
void averageWithBuffersFromCore(const SampleFrame *lmmsBuf, unsigned channel, f_cnt_t frames)
Definition Lv2Ports.cpp:327
void copyBuffersFromCore(const SampleFrame *lmmsBuf, unsigned channel, f_cnt_t frames)
Definition Lv2Ports.cpp:315
bool mustBeUsed() const
Definition Lv2Ports.h:201
Audio(std::size_t bufferSize, bool isSidechain)
Definition Lv2Ports.cpp:307
bool isSideChain() const
Definition Lv2Ports.h:199
void copyBuffersToCore(SampleFrame *lmmsBuf, unsigned channel, f_cnt_t frames) const
Definition Lv2Ports.cpp:339
std::size_t bufferSize() const
Definition Lv2Ports.h:202
bool isOptional() const
Definition Lv2Ports.h:200
std::vector< float > m_buffer
the buffer where Lv2 reads/writes the data from/to
Definition Lv2Ports.h:206
bool m_sidechain
Definition Lv2Ports.h:207
Definition Lv2Ports.h:246
void visit(const Target &tar)
Definition Lv2Ports.h:248
const Target * m_result
Definition Lv2Ports.h:247
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:239
Target * m_result
Definition Lv2Ports.h:240
void visit(Target &tar)
Definition Lv2Ports.h:241
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:231
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
int n
Definition crypt.c:458
static ZCONST char Far None[]
Definition unzip.c:380