forked from LMMS/lmms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLv2ControlBase.cpp
More file actions
190 lines (124 loc) · 3.8 KB
/
Lv2ControlBase.cpp
File metadata and controls
190 lines (124 loc) · 3.8 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
/*
* Lv2ControlBase.cpp - Lv2 control base class
*
* Copyright (c) 2018-2019 Johannes Lorenz <j.git$$$lorenz-ho.me, $$$=@>
*
* 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 "Lv2ControlBase.h"
#ifdef LMMS_HAVE_LV2
#include <QtGlobal>
#include "Engine.h"
#include "Lv2Manager.h"
#include "Lv2Proc.h"
Plugin::PluginTypes Lv2ControlBase::check(const LilvPlugin *plugin,
std::vector<PluginIssue> &issues, bool printIssues)
{
// for some reason, all checks can be done by one processor...
return Lv2Proc::check(plugin, issues, printIssues);
}
Lv2ControlBase::Lv2ControlBase(Model* that, const QString &uri) :
m_plugin(Engine::getLv2Manager()->getPlugin(uri))
{
if (m_plugin)
{
int channelsLeft = DEFAULT_CHANNELS; // LMMS plugins are stereo
while (channelsLeft > 0)
{
std::unique_ptr<Lv2Proc> newOne(new Lv2Proc(m_plugin, that));
if (newOne->isValid())
{
channelsLeft -= std::max(
1 + static_cast<bool>(newOne->inPorts().m_right),
1 + static_cast<bool>(newOne->outPorts().m_right));
Q_ASSERT(channelsLeft >= 0);
m_procs.push_back(std::move(newOne));
}
else
{
qCritical() << "Failed instantiating LV2 processor";
m_valid = false;
channelsLeft = 0;
}
}
if (m_valid)
{
m_channelsPerProc = DEFAULT_CHANNELS / m_procs.size();
linkAllModels();
}
}
else
{
qCritical() << "No Lv2 plugin found for URI" << uri;
m_valid = false;
}
}
Lv2ControlBase::~Lv2ControlBase() {}
LinkedModelGroup *Lv2ControlBase::getGroup(std::size_t idx)
{
return (m_procs.size() > idx) ? m_procs[idx].get() : nullptr;
}
const LinkedModelGroup *Lv2ControlBase::getGroup(std::size_t idx) const
{
return (m_procs.size() > idx) ? m_procs[idx].get() : nullptr;
}
void Lv2ControlBase::copyModelsFromLmms() {
for (std::unique_ptr<Lv2Proc>& c : m_procs) { c->copyModelsFromCore(); }
}
void Lv2ControlBase::copyBuffersFromLmms(const sampleFrame *buf, fpp_t frames) {
unsigned offset = 0;
for (std::unique_ptr<Lv2Proc>& c : m_procs) {
c->copyBuffersFromCore(buf, offset, m_channelsPerProc, frames);
offset += m_channelsPerProc;
}
}
void Lv2ControlBase::copyBuffersToLmms(sampleFrame *buf, fpp_t frames) const {
unsigned offset = 0;
for (const std::unique_ptr<Lv2Proc>& c : m_procs) {
c->copyBuffersToCore(buf, offset, m_channelsPerProc, frames);
offset += m_channelsPerProc;
}
}
void Lv2ControlBase::run(fpp_t frames) {
for (std::unique_ptr<Lv2Proc>& c : m_procs) { c->run(frames); }
}
void Lv2ControlBase::saveSettings(QDomDocument &doc, QDomElement &that)
{
LinkedModelGroups::saveSettings(doc, that);
// TODO: save state if supported by plugin
}
void Lv2ControlBase::loadSettings(const QDomElement &that)
{
LinkedModelGroups::loadSettings(that);
// TODO: load state if supported by plugin
}
void Lv2ControlBase::loadFile(const QString &file)
{
(void)file;
}
void Lv2ControlBase::reloadPlugin()
{
// TODO
}
std::size_t Lv2ControlBase::controlCount() const {
std::size_t res = 0;
for (const std::unique_ptr<Lv2Proc>& c : m_procs) { res += c->controlCount(); }
return res;
}
#endif // LMMS_HAVE_LV2