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
|
/***************************************************************************
enginedeck.cpp - description
-------------------
begin : Sun Apr 28 2002
copyright : (C) 2002 by
email :
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include "engine/enginedeck.h"
#include "control/controlpushbutton.h"
#include "effects/effectsmanager.h"
#include "engine/effects/engineeffectsmanager.h"
#include "engine/enginebuffer.h"
#include "engine/enginefilterbessel4.h"
#include "engine/enginepregain.h"
#include "engine/enginevumeter.h"
#include "util/sample.h"
EngineDeck::EngineDeck(const ChannelHandleAndGroup& handle_group,
UserSettingsPointer pConfig,
EngineMaster* pMixingEngine,
EffectsManager* pEffectsManager,
EngineChannel::ChannelOrientation defaultOrientation)
: EngineChannel(handle_group, defaultOrientation, pEffectsManager),
m_pConfig(pConfig),
m_pInputConfigured(new ControlObject(ConfigKey(getGroup(), "input_configured"))),
m_pPassing(new ControlPushButton(ConfigKey(getGroup(), "passthrough"))),
// Need a +1 here because the CircularBuffer only allows its size-1
// items to be held at once (it keeps a blank spot open persistently)
m_wasActive(false) {
m_pInputConfigured->setReadOnly();
// Set up passthrough utilities and fields
m_pPassing->setButtonMode(ControlPushButton::POWERWINDOW);
m_bPassthroughIsActive = false;
m_bPassthroughWasActive = false;
// Ensure that input is configured before enabling passthrough
m_pPassing->connectValueChangeRequest(
this, SLOT(slotPassthroughChangeRequest(double)),
Qt::DirectConnection);
// Set up passthrough toggle button
connect(m_pPassing, SIGNAL(valueChangedFromEngine(double)),
this, SLOT(slotPassingToggle(double)),
Qt::DirectConnection);
m_pPregain = new EnginePregain(getGroup());
m_pBuffer = new EngineBuffer(getGroup(), pConfig, this, pMixingEngine);
}
EngineDeck::~EngineDeck() {
delete m_pPassing;
delete m_pBuffer;
delete m_pPregain;
}
void EngineDeck::process(CSAMPLE* pOut, const int iBufferSize) {
// Feed the incoming audio through if passthrough is active
const CSAMPLE* sampleBuffer = m_sampleBuffer; // save pointer on stack
if (isPassthroughActive() && sampleBuffer) {
SampleUtil::copy(pOut, sampleBuffer, iBufferSize);
m_bPassthroughWasActive = true;
m_sampleBuffer = NULL;
m_pPregain->setSpeedAndScratching(1, false);
} else {
// If passthrough is no longer enabled, zero out the buffer
if (m_bPassthroughWasActive) {
SampleUtil::clear(pOut, iBufferSize);
m_bPassthroughWasActive = false;
return;
}
// Process the raw audio
m_pBuffer->process(pOut, iBufferSize);
m_pPregain->setSpeedAndScratching(m_pBuffer->getSpeed(), m_pBuffer->getScratching());
m_bPassthroughWasActive = false;
}
// Apply pregain
m_pPregain->process(pOut, iBufferSize);
EngineEffectsManager* pEngineEffectsManager = m_pEffectsManager->getEngineEffectsManager();
if (pEngineEffectsManager != nullptr) {
pEngineEffectsManager->processPreFaderInPlace(
m_group.handle(), m_pEffectsManager->getMasterHandle(),
pOut, iBufferSize, m_pSampleRate->get());
}
// Update VU meter
m_vuMeter.process(pOut, iBufferSize);
}
void EngineDeck::collectFeatures(GroupFeatureState* pGroupFeatures) const {
m_pBuffer->collectFeatures(pGroupFeatures);
m_vuMeter.collectFeatures(pGroupFeatures);
m_pPregain->collectFeatures(pGroupFeatures);
}
void EngineDeck::postProcess(const int iBufferSize) {
m_pBuffer->postProcess(iBufferSize);
}
EngineBuffer* EngineDeck::getEngineBuffer() {
return m_pBuffer;
}
bool EngineDeck::isActive() {
bool active = false;
if (m_bPassthroughWasActive && !m_bPassthroughIsActive) {
active = true;
} else {
active = m_pBuffer->isTrackLoaded() || isPassthroughActive();
}
if (!active && m_wasActive) {
m_vuMeter.reset();
}
m_wasActive = active;
return active;
}
void EngineDeck::receiveBuffer(AudioInput input, const CSAMPLE* pBuffer, unsigned int nFrames) {
Q_UNUSED(input);
Q_UNUSED(nFrames);
// Skip receiving audio input if passthrough is not active
if (!m_bPassthroughIsActive) {
m_sampleBuffer = NULL;
return;
} else {
m_sampleBuffer = pBuffer;
}
}
void EngineDeck::onInputConfigured(AudioInput input) {
if (input.getType() != AudioPath::VINYLCONTROL) {
// This is an error!
qDebug() << "WARNING: EngineDeck connected to AudioInput for a non-vinylcontrol type!";
return;
}
m_pInputConfigured->forceSet(1.0);
m_sampleBuffer = NULL;
}
void EngineDeck::onInputUnconfigured(AudioInput input) {
if (input.getType() != AudioPath::VINYLCONTROL) {
// This is an error!
qDebug() << "WARNING: EngineDeck connected to AudioInput for a non-vinylcontrol type!";
return;
}
m_pInputConfigured->forceSet(0.0);
m_sampleBuffer = NULL;
}
bool EngineDeck::isPassthroughActive() const {
return (m_bPassthroughIsActive && m_sampleBuffer);
}
void EngineDeck::slotPassingToggle(double v) {
m_bPassthroughIsActive = v > 0;
}
void EngineDeck::slotPassthroughChangeRequest(double v) {
if (v <= 0 || m_pInputConfigured->get() > 0) {
m_pPassing->setAndConfirm(v);
} else {
emit noPassthroughInputConfigured();
}
}
|