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
|
#include "effects/effectsmanager.h"
#include <QDir>
#include <QMetaType>
#include "control/controlpotmeter.h"
#include "effects/effectslot.h"
#include "effects/effectsmessenger.h"
#include "effects/chains/standardeffectchain.h"
#include "effects/chains/quickeffectchain.h"
#include "effects/chains/outputeffectchain.h"
#include "effects/chains/equalizereffectchain.h"
#include "effects/presets/effectpresetmanager.h"
#include "effects/presets/effectxmlelements.h"
#include "effects/visibleeffectslist.h"
#include "engine/effects/engineeffectsmanager.h"
#include "util/assert.h"
namespace {
const unsigned int kEffectMessagePipeFifoSize = 2048;
const QString kEffectsXmlFile = QStringLiteral("effects.xml");
} // anonymous namespace
EffectsManager::EffectsManager(
UserSettingsPointer pConfig,
std::shared_ptr<ChannelHandleFactory> pChannelHandleFactory)
: m_pConfig(pConfig),
m_pChannelHandleFactory(pChannelHandleFactory),
m_loEqFreq(ConfigKey("[Mixer Profile]", "LoEQFrequency"), 0., 22040),
m_hiEqFreq(ConfigKey("[Mixer Profile]", "HiEQFrequency"), 0., 22040) {
qRegisterMetaType<EffectChainMixMode>("EffectChainMixMode");
m_pBackendManager = EffectsBackendManagerPointer(new EffectsBackendManager());
QPair<EffectsRequestPipe*, EffectsResponsePipe*> requestPipes =
TwoWayMessagePipe<EffectsRequest*, EffectsResponse>::makeTwoWayMessagePipe(
kEffectMessagePipeFifoSize, kEffectMessagePipeFifoSize);
m_pMessenger = EffectsMessengerPointer(new EffectsMessenger(
requestPipes.first, requestPipes.second));
m_pEngineEffectsManager = new EngineEffectsManager(requestPipes.second);
m_pEffectPresetManager = EffectPresetManagerPointer(
new EffectPresetManager(pConfig, m_pBackendManager));
m_pChainPresetManager = EffectChainPresetManagerPointer(
new EffectChainPresetManager(pConfig, m_pBackendManager));
m_pVisibleEffectsList = VisibleEffectsListPointer(new VisibleEffectsList());
}
EffectsManager::~EffectsManager() {
m_pMessenger->initiateShutdown();
saveEffectsXml();
// The EffectChains must be deleted before the EffectsBackends in case
// there is an LV2 effect currently loaded.
// ~LV2GroupState calls lilv_instance_free, which will segfault if called
// after ~LV2Backend calls lilv_world_free.
m_equalizerEffectChains.clear();
m_quickEffectChains.clear();
m_standardEffectChains.clear();
m_outputEffectChain.clear();
m_effectChainSlotsByGroup.clear();
m_pMessenger->processEffectsResponses();
}
void EffectsManager::setup() {
// Add postfader effect chain slots
addStandardEffectChains();
addOutputEffectChain();
// EQ and QuickEffect chain slots are initialized when PlayerManager creates decks.
readEffectsXml();
}
void EffectsManager::registerInputChannel(const ChannelHandleAndGroup& handle_group) {
VERIFY_OR_DEBUG_ASSERT(!m_registeredInputChannels.contains(handle_group)) {
return;
}
m_registeredInputChannels.insert(handle_group);
// EqualizerEffectChains, QuickEffectChains, and OutputEffectChains
// only process one input channel, so they do not need to have new input
// channels registered.
for (EffectChainPointer pChainSlot : std::as_const(m_standardEffectChains)) {
pChainSlot->registerInputChannel(handle_group);
}
}
void EffectsManager::registerOutputChannel(const ChannelHandleAndGroup& handle_group) {
VERIFY_OR_DEBUG_ASSERT(!m_registeredOutputChannels.contains(handle_group)) {
return;
}
m_registeredOutputChannels.insert(handle_group);
}
void EffectsManager::addStandardEffectChains() {
for (int i = 0; i < kNumStandardEffectUnits; ++i) {
VERIFY_OR_DEBUG_ASSERT(!m_effectChainSlotsByGroup.contains(
StandardEffectChain::formatEffectChainGroup(i))) {
continue;
}
auto pChainSlot = StandardEffectChainPointer(
new StandardEffectChain(i, this, m_pMessenger));
m_standardEffectChains.append(pChainSlot);
m_effectChainSlotsByGroup.insert(pChainSlot->group(), pChainSlot);
}
}
void EffectsManager::addOutputEffectChain() {
m_outputEffectChain = OutputEffectChainPointer(
new OutputEffectChain(this, m_pMessenger));
m_effectChainSlotsByGroup.insert(m_outputEffectChain->group(), m_outputEffectChain);
}
EffectChainPointer EffectsManager::getOutputEffectChain() const {
return m_outputEffectChain;
}
EffectChainPointer EffectsManager::getStandardEffectChain(int unitNumber) const {
VERIFY_OR_DEBUG_ASSERT(0 <= unitNumber || unitNumber < m_standardEffectChains.size()) {
return EffectChainPointer();
}
return m_standardEffectChains.at(unitNumber);
}
void EffectsManager::addDeck(const QString& deckGroupName) {
addEqualizerEffectChain(deckGroupName);
addQuickEffectChain(deckGroupName);
}
void EffectsManager::addEqualizerEffectChain(const QString& deckGroupName) {
VERIFY_OR_DEBUG_ASSERT(!m_equalizerEffectChains.contains(
EqualizerEffectChain::formatEffectChainGroup(deckGroupName))) {
return;
}
auto pChainSlot = EqualizerEffectChainPointer(
new EqualizerEffectChain(deckGroupName, this, m_pMessenger));
m_equalizerEffectChains.insert(deckGroupName, pChainSlot);
m_effectChainSlotsByGroup.insert(pChainSlot->group(), pChainSlot);
}
void EffectsManager::addQuickEffectChain(const QString& deckGroupName) {
VERIFY_OR_DEBUG_ASSERT(!m_quickEffectChains.contains(
QuickEffectChain::formatEffectChainGroup(deckGroupName))) {
return;
}
auto pChainSlot = QuickEffectChainPointer(
new QuickEffectChain(deckGroupName, this, m_pMessenger));
m_quickEffectChains.insert(deckGroupName, pChainSlot);
m_effectChainSlotsByGroup.insert(pChainSlot->group(), pChainSlot);
}
EffectChainPointer EffectsManager::getEffectChain(
const QString& group) const {
return m_effectChainSlotsByGroup.value(group);
}
bool EffectsManager::isAdoptMetaknobValueEnabled() const {
return m_pConfig->getValue(ConfigKey("[Effects]", "AdoptMetaknobValue"), true);
}
void EffectsManager::readEffectsXml() {
QDir settingsPath(m_pConfig->getSettingsPath());
QFile file(settingsPath.absoluteFilePath(kEffectsXmlFile));
QDomDocument doc;
if (file.open(QIODevice::ReadOnly)) {
doc.setContent(&file);
}
file.close();
QStringList deckStrings;
for (auto it = m_quickEffectChains.begin(); it != m_quickEffectChains.end(); it++) {
deckStrings << it.key();
}
EffectsXmlData data = m_pChainPresetManager->readEffectsXml(doc, deckStrings);
for (int i = 0; i < data.standardEffectChainPresets.size(); i++) {
m_standardEffectChains.value(i)->loadChainPreset(data.standardEffectChainPresets.at(i));
}
for (auto it = data.quickEffectChainPresets.begin();
it != data.quickEffectChainPresets.end();
it++) {
auto pChainSlot = m_quickEffectChains.value(it.key());
if (pChainSlot) {
pChainSlot->loadChainPreset(it.value());
}
}
m_pVisibleEffectsList->readEffectsXml(doc, m_pBackendManager);
}
void EffectsManager::saveEffectsXml() {
QDomDocument doc(EffectXml::Root);
doc.setContent(EffectXml::FileHeader);
QDomElement rootElement = doc.createElement(EffectXml::Root);
rootElement.setAttribute(
"schemaVersion", QString::number(EffectXml::kXmlSchemaVersion));
doc.appendChild(rootElement);
QHash<QString, EffectChainPresetPointer> quickEffectChainPresets;
for (auto it = m_quickEffectChains.begin(); it != m_quickEffectChains.end(); it++) {
auto pPreset = EffectChainPresetPointer::create(it.value().data());
quickEffectChainPresets.insert(it.key(), pPreset);
}
QList<EffectChainPresetPointer> standardEffectChainPresets;
for (const auto& pChainSlot : std::as_const(m_standardEffectChains)) {
auto pPreset = EffectChainPresetPointer::create(pChainSlot.data());
standardEffectChainPresets.append(pPreset);
}
m_pChainPresetManager->saveEffectsXml(&doc,
EffectsXmlData{
quickEffectChainPresets, standardEffectChainPresets});
m_pVisibleEffectsList->saveEffectsXml(&doc);
QDir settingsPath(m_pConfig->getSettingsPath());
if (!settingsPath.exists()) {
return;
}
QFile file(settingsPath.absoluteFilePath(kEffectsXmlFile));
if (!file.open(QIODevice::Truncate | QIODevice::WriteOnly)) {
qWarning() << "EffectsManager: could not save effects.xml file";
return;
}
file.write(doc.toString().toUtf8());
file.close();
}
|