#include "engine/enginemaster.h"
#include <QtDebug>
#include <QList>
#include <QPair>
#include "preferences/usersettings.h"
#include "control/controlaudiotaperpot.h"
#include "control/controlaudiotaperpot.h"
#include "control/controlpotmeter.h"
#include "control/controlpushbutton.h"
#include "effects/effectsmanager.h"
#include "engine/channelmixer.h"
#include "engine/effects/engineeffectsmanager.h"
#include "engine/enginebuffer.h"
#include "engine/enginebuffer.h"
#include "engine/channels/enginechannel.h"
#include "engine/channels/enginedeck.h"
#include "engine/enginedelay.h"
#include "engine/enginetalkoverducking.h"
#include "engine/enginevumeter.h"
#include "engine/engineworkerscheduler.h"
#include "engine/enginexfader.h"
#include "engine/sidechain/enginesidechain.h"
#include "engine/sync/enginesync.h"
#include "mixer/playermanager.h"
#include "util/defs.h"
#include "util/sample.h"
#include "util/timer.h"
#include "util/trace.h"
EngineMaster::EngineMaster(UserSettingsPointer pConfig,
const char* group,
EffectsManager* pEffectsManager,
ChannelHandleFactoryPointer pChannelHandleFactory,
bool bEnableSidechain)
: m_pChannelHandleFactory(pChannelHandleFactory),
m_pEngineEffectsManager(pEffectsManager ? pEffectsManager->getEngineEffectsManager() : NULL),
m_masterGainOld(0.0),
m_boothGainOld(0.0),
m_headphoneMasterGainOld(0.0),
m_headphoneGainOld(1.0),
m_balleftOld(1.0),
m_balrightOld(1.0),
m_masterHandle(registerChannelGroup(group)),
m_headphoneHandle(registerChannelGroup("[Headphone]")),
m_masterOutputHandle(registerChannelGroup("[MasterOutput]")),
m_busTalkoverHandle(registerChannelGroup("[BusTalkover]")),
m_busCrossfaderLeftHandle(registerChannelGroup("[BusLeft]")),
m_busCrossfaderCenterHandle(registerChannelGroup("[BusCenter]")),
m_busCrossfaderRightHandle(registerChannelGroup("[BusRight]")) {
pEffectsManager->registerInputChannel(m_masterHandle);
pEffectsManager->registerInputChannel(m_headphoneHandle);
pEffectsManager->registerOutputChannel(m_masterHandle);
pEffectsManager->registerOutputChannel(m_headphoneHandle);
pEffectsManager->registerInputChannel(m_masterOutputHandle);
pEffectsManager->registerInputChannel(m_busTalkoverHandle);
pEffectsManager->registerInputChannel(m_busCrossfaderLeftHandle);
pEffectsManager->registerInputChannel(m_busCrossfaderCenterHandle);
pEffectsManager->registerInputChannel(m_busCrossfaderRightHandle);
m_bBusOutputConnected[EngineChannel::LEFT] = false;
m_bBusOutputConnected[EngineChannel::CENTER] = false;
m_bBusOutputConnected[EngineChannel::RIGHT] = false;
m_bExternalRecordBroadcastInputConnected = false;
m_pWorkerScheduler = new EngineWorkerScheduler(this);
m_pWorkerScheduler->start(QThread::HighPriority);
// Master sample rate
m_pMasterSampleRate = new ControlObject(ConfigKey(group, "samplerate"), true, true);
m_pMasterSampleRate->set(44100.);
// Latency control
m_pMasterLatency = new ControlObject(ConfigKey(group, "latency"), true, true);
m_pMasterAudioBufferSize = new ControlObject(ConfigKey(group, "audio_buffer_size"));
m_pAudioLatencyOverloadCount = new ControlObject(ConfigKey(group, "audio_latency_overload_count"), true, true);
m_pAudioLatencyUsage = new ControlPotmeter(ConfigKey(group, "audio_latency_usage"), 0.0, 0.25);
m_pAudioLatencyOverload = new ControlPotmeter(ConfigKey(group, "audio_latency_overload"), 0.0, 1.0);
// Master sync controller
m_pMasterSync = new EngineSync(pConfig);
// The last-used bpm value is saved in the destructor of EngineSync.
double default_bpm = pConfig->getValue(
ConfigKey("[InternalClock]", "bpm"), 124.0);
ControlObject::getControl(ConfigKey("[InternalClock]","bpm"))->set(default_bpm);
// Crossfader
m_pCrossfader = new ControlPotmeter(ConfigKey(group, "crossfader"), -1., 1.);
// Balance
m_pBalance = new ControlPotmeter(ConfigKey(group, "balance"), -1., 1.);
// Master gain
m_pMasterGain = new ControlAudioTaperPot(ConfigKey(group, "gain"), -14, 14, 0.5);
// Booth gain
m_pBoothGain = new ControlAudioTaperPot(ConfigKey(group, "booth_gain"), -14, 14, 0.5);
// Legacy: the master "gain" control used to be named "volume" in Mixxx
// 1.11.0 and earlier. See Bug #1306253.
ControlDoublePrivate::insertAlias(ConfigKey(group, "volume"),
ConfigKey(group, "gain"));
// VU meter:
m_pVumeter = new EngineVuMeter(group);
m_pMasterDelay = new EngineDelay(group, ConfigKey(group, "delay"));
m_pHeadDelay = new EngineDelay(group, ConfigKey(group, "headDelay"));
m_pBoothDelay = new EngineDelay(group, ConfigKey(group, "boothDelay"));
m_pLatencyCompensationDelay = new EngineDelay(group,
ConfigKey(group