-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathLv2ViewBase.cpp
More file actions
291 lines (222 loc) · 6.79 KB
/
Lv2ViewBase.cpp
File metadata and controls
291 lines (222 loc) · 6.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*
* Lv2ViewBase.cpp - base class for Lv2 plugin views
*
* Copyright (c) 2018-2023 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 "Lv2ViewBase.h"
#ifdef LMMS_HAVE_LV2
#include <format>
#include <QGridLayout>
#include <QPushButton>
#include <QHBoxLayout>
#include <QLabel>
#include <lilv/lilv.h>
#include <lv2/port-props/port-props.h>
#include "AudioEngine.h"
#include "Controls.h"
#include "Engine.h"
#include "GuiApplication.h"
#include "embed.h"
#include "FontHelper.h"
#include "lmms_math.h"
#include "Lv2ControlBase.h"
#include "Lv2Manager.h"
#include "Lv2Proc.h"
#include "Lv2Ports.h"
#include "MainWindow.h"
#include "SubWindow.h"
namespace lmms::gui
{
Lv2ViewProc::Lv2ViewProc(QWidget* parent, Lv2Proc* proc, int colNum) :
LinkedModelGroupView (parent, proc, colNum)
{
class SetupTheWidget : public Lv2Ports::ConstVisitor
{
public:
QWidget* m_parent; // input
const LilvNode* m_commentUri; // input
Control* m_control = nullptr; // output
void visit(const Lv2Ports::Control& port) override
{
if (port.m_flow == Lv2Ports::Flow::Input)
{
using PortVis = Lv2Ports::Vis;
switch (port.m_vis)
{
case PortVis::Generic:
m_control = new KnobControl(port.name(), m_parent);
break;
case PortVis::Integer:
{
const sample_rate_t sr = Engine::audioEngine()->outputSampleRate();
const auto numDigits = std::max(
std::formatted_size("{}", static_cast<long>(std::round(port.min(sr)))),
std::formatted_size("{}", static_cast<long>(std::round(port.max(sr))))
);
m_control = new LcdControl(numDigits, m_parent);
break;
}
case PortVis::Enumeration:
m_control = new ComboControl(m_parent);
break;
case PortVis::Toggled:
m_control = new CheckControl(m_parent);
break;
}
m_control->setText(port.name());
AutoLilvNodes props(lilv_port_get_value(
port.m_plugin, port.m_port, m_commentUri));
LILV_FOREACH(nodes, itr, props.get())
{
const LilvNode* nod = lilv_nodes_get(props.get(), itr);
m_control->topWidget()->setToolTip(lilv_node_as_string(nod));
break;
}
}
}
};
AutoLilvNode commentUri = uri(LILV_NS_RDFS "comment");
proc->foreach_port(
[this, &commentUri](const Lv2Ports::PortBase* port)
{
if(!lilv_port_has_property(port->m_plugin, port->m_port,
uri(LV2_PORT_PROPS__notOnGUI).get()))
{
SetupTheWidget setup;
setup.m_parent = this;
setup.m_commentUri = commentUri.get();
port->accept(setup);
if (setup.m_control)
{
addControl(setup.m_control,
lilv_node_as_string(lilv_port_get_symbol(
port->m_plugin, port->m_port)),
port->name().toUtf8().data(),
false);
}
}
});
}
AutoLilvNode Lv2ViewProc::uri(const char *uriStr)
{
return Engine::getLv2Manager()->uri(uriStr);
}
Lv2ViewBase::Lv2ViewBase(QWidget* meAsWidget, Lv2ControlBase *ctrlBase) :
m_helpWindowEventFilter(this)
{
auto grid = new QGridLayout(meAsWidget);
auto btnBox = new QHBoxLayout();
if (/* DISABLES CODE */ (false))
{
m_reloadPluginButton = new QPushButton(QObject::tr("Reload Plugin"),
meAsWidget);
btnBox->addWidget(m_reloadPluginButton, 0);
}
if (/* DISABLES CODE */ (false)) // TODO: check if the plugin has the UI extension
{
m_toggleUIButton = new QPushButton(QObject::tr("Show GUI"),
meAsWidget);
m_toggleUIButton->setCheckable(true);
m_toggleUIButton->setChecked(false);
m_toggleUIButton->setIcon(embed::getIconPixmap("zoom"));
m_toggleUIButton->setFont(adjustedToPixelSize(m_toggleUIButton->font(), SMALL_FONT_SIZE));
btnBox->addWidget(m_toggleUIButton, 0);
}
btnBox->addStretch(1);
meAsWidget->setAcceptDrops(true);
// note: the lifetime of C++ objects ends after the top expression in the
// expression syntax tree, so the AutoLilvNode gets freed after the function
// has been called
AutoLilvNodes props(lilv_plugin_get_value(ctrlBase->getPlugin(),
uri(LILV_NS_RDFS "comment").get()));
LILV_FOREACH(nodes, itr, props.get())
{
const LilvNode* node = lilv_nodes_get(props.get(), itr);
auto infoLabel = new QLabel(QString(lilv_node_as_string(node)).trimmed() + "\n");
infoLabel->setWordWrap(true);
infoLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
m_helpButton = new QPushButton(QObject::tr("Help"));
m_helpButton->setCheckable(true);
btnBox->addWidget(m_helpButton);
m_helpWindow = getGUI()->mainWindow()->addWindowedWidget(infoLabel);
m_helpWindow->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Expanding);
m_helpWindow->installEventFilter(&m_helpWindowEventFilter);
m_helpWindow->setAttribute(Qt::WA_DeleteOnClose, false);
m_helpWindow->hide();
break;
}
if (m_reloadPluginButton || m_toggleUIButton || m_helpButton)
{
grid->addLayout(btnBox, Rows::ButtonRow, 0, 1, m_colNum);
}
else { delete btnBox; }
m_procView = new Lv2ViewProc(meAsWidget, ctrlBase->control(0), m_colNum);
grid->addWidget(m_procView, Rows::ProcRow, 0);
}
Lv2ViewBase::~Lv2ViewBase() {
closeHelpWindow();
// TODO: hide UI if required
}
void Lv2ViewBase::toggleUI()
{
}
void Lv2ViewBase::toggleHelp(bool visible)
{
if (m_helpWindow)
{
if (visible) { m_helpWindow->show(); m_helpWindow->raise(); }
else { m_helpWindow->hide(); }
}
}
void Lv2ViewBase::closeHelpWindow()
{
if (m_helpWindow) { m_helpWindow->close(); }
}
void Lv2ViewBase::modelChanged(Lv2ControlBase *ctrlBase)
{
// reconnect models
if (m_toggleUIButton)
{
m_toggleUIButton->setChecked(ctrlBase->hasGui());
}
LinkedModelGroupsView::modelChanged(ctrlBase);
}
AutoLilvNode Lv2ViewBase::uri(const char *uriStr)
{
return Engine::getLv2Manager()->uri(uriStr);
}
void Lv2ViewBase::onHelpWindowClosed()
{
m_helpButton->setChecked(true);
}
HelpWindowEventFilter::HelpWindowEventFilter(Lv2ViewBase* viewBase) :
m_viewBase(viewBase) {}
bool HelpWindowEventFilter::eventFilter(QObject* , QEvent* event)
{
if (event->type() == QEvent::Close) {
m_viewBase->m_helpButton->setChecked(false);
return true;
}
return false;
}
} // namespace lmms::gui
#endif // LMMS_HAVE_LV2