Skip to content

Commit

Permalink
Merge pull request #2969 from xerus2000/playermanager-handle
Browse files Browse the repository at this point in the history
PlayerManager: Identify players by ChannelHandle
  • Loading branch information
Holzhaus authored Jul 31, 2020
2 parents 759b3fc + a1722e8 commit 1ea7cea
Show file tree
Hide file tree
Showing 32 changed files with 330 additions and 319 deletions.
24 changes: 12 additions & 12 deletions src/effects/effectchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ void EffectChain::setEnabled(bool enabled) {
emit enabledChanged(enabled);
}

void EffectChain::enableForInputChannel(const ChannelHandleAndGroup& handle_group) {
void EffectChain::enableForInputChannel(const ChannelHandleAndGroup& handleGroup) {
// TODO(Be): remove m_enabledChannels from this class and move this logic
// to EffectChainSlot
bool bWasAlreadyEnabled = m_enabledInputChannels.contains(handle_group);
bool bWasAlreadyEnabled = m_enabledInputChannels.contains(handleGroup);
if (!bWasAlreadyEnabled) {
m_enabledInputChannels.insert(handle_group);
m_enabledInputChannels.insert(handleGroup);
}

// The allocation of EffectStates below may be expensive, so avoid it if
Expand All @@ -172,7 +172,7 @@ void EffectChain::enableForInputChannel(const ChannelHandleAndGroup& handle_grou
EffectsRequest* request = new EffectsRequest();
request->type = EffectsRequest::ENABLE_EFFECT_CHAIN_FOR_INPUT_CHANNEL;
request->pTargetChain = m_pEngineEffectChain;
request->EnableInputChannelForChain.pChannelHandle = &handle_group.handle();
request->EnableInputChannelForChain.pChannelHandle = &handleGroup.handle();

// Allocate EffectStates here in the main thread to avoid allocating
// memory in the realtime audio callback thread. Pointers to the
Expand All @@ -191,7 +191,7 @@ void EffectChain::enableForInputChannel(const ChannelHandleAndGroup& handle_grou
if (m_effects[i] != nullptr) {
for (const auto& outputChannel : m_pEffectsManager->registeredOutputChannels()) {
if (kEffectDebugOutput) {
qDebug() << debugString() << "EffectChain::enableForInputChannel creating EffectState for input" << handle_group << "output" << outputChannel;
qDebug() << debugString() << "EffectChain::enableForInputChannel creating EffectState for input" << handleGroup << "output" << outputChannel;
}
statesMap.insert(outputChannel.handle(),
m_effects[i]->createState(bufferParameters));
Expand All @@ -208,25 +208,25 @@ void EffectChain::enableForInputChannel(const ChannelHandleAndGroup& handle_grou
request->EnableInputChannelForChain.pEffectStatesMapArray = pEffectStatesMapArray;

m_pEffectsManager->writeRequest(request);
emit channelStatusChanged(handle_group.name(), true);
emit channelStatusChanged(handleGroup.name(), true);
}

bool EffectChain::enabledForChannel(const ChannelHandleAndGroup& handle_group) const {
return m_enabledInputChannels.contains(handle_group);
bool EffectChain::enabledForChannel(const ChannelHandleAndGroup& handleGroup) const {
return m_enabledInputChannels.contains(handleGroup);
}

void EffectChain::disableForInputChannel(const ChannelHandleAndGroup& handle_group) {
if (m_enabledInputChannels.remove(handle_group)) {
void EffectChain::disableForInputChannel(const ChannelHandleAndGroup& handleGroup) {
if (m_enabledInputChannels.remove(handleGroup)) {
if (!m_bAddedToEngine) {
return;
}
EffectsRequest* request = new EffectsRequest();
request->type = EffectsRequest::DISABLE_EFFECT_CHAIN_FOR_INPUT_CHANNEL;
request->pTargetChain = m_pEngineEffectChain;
request->DisableInputChannelForChain.pChannelHandle = &handle_group.handle();
request->DisableInputChannelForChain.pChannelHandle = &handleGroup.handle();
m_pEffectsManager->writeRequest(request);

emit channelStatusChanged(handle_group.name(), false);
emit channelStatusChanged(handleGroup.name(), false);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/effects/effectchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class EffectChain : public QObject {
void setEnabled(bool enabled);

// Activates EffectChain processing for the provided channel.
void enableForInputChannel(const ChannelHandleAndGroup& handle_group);
bool enabledForChannel(const ChannelHandleAndGroup& handle_group) const;
void enableForInputChannel(const ChannelHandleAndGroup& handleGroup);
bool enabledForChannel(const ChannelHandleAndGroup& handleGroup) const;
const QSet<ChannelHandleAndGroup>& enabledChannels() const;
void disableForInputChannel(const ChannelHandleAndGroup& handle_group);
void disableForInputChannel(const ChannelHandleAndGroup& handleGroup);

EffectChainPointer prototype() const;

Expand Down
14 changes: 7 additions & 7 deletions src/effects/effectchainmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ EffectChainManager::~EffectChainManager() {
//qDebug() << debugString() << "destroyed";
}

void EffectChainManager::registerInputChannel(const ChannelHandleAndGroup& handle_group) {
VERIFY_OR_DEBUG_ASSERT(!m_registeredInputChannels.contains(handle_group)) {
void EffectChainManager::registerInputChannel(const ChannelHandleAndGroup& handleGroup) {
VERIFY_OR_DEBUG_ASSERT(!m_registeredInputChannels.contains(handleGroup)) {
return;
}
m_registeredInputChannels.insert(handle_group);
m_registeredInputChannels.insert(handleGroup);

for (auto& pRack : m_standardEffectRacks) {
pRack->registerInputChannel(handle_group);
pRack->registerInputChannel(handleGroup);
}
}

void EffectChainManager::registerOutputChannel(const ChannelHandleAndGroup& handle_group) {
VERIFY_OR_DEBUG_ASSERT(!m_registeredOutputChannels.contains(handle_group)) {
void EffectChainManager::registerOutputChannel(const ChannelHandleAndGroup& handleGroup) {
VERIFY_OR_DEBUG_ASSERT(!m_registeredOutputChannels.contains(handleGroup)) {
return;
}
m_registeredOutputChannels.insert(handle_group);
m_registeredOutputChannels.insert(handleGroup);
}

StandardEffectRackPointer EffectChainManager::addStandardEffectRack() {
Expand Down
4 changes: 2 additions & 2 deletions src/effects/effectchainmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class EffectChainManager : public QObject {
EffectsManager* pEffectsManager);
virtual ~EffectChainManager();

void registerInputChannel(const ChannelHandleAndGroup& handle_group);
void registerInputChannel(const ChannelHandleAndGroup& handleGroup);
const QSet<ChannelHandleAndGroup>& registeredInputChannels() const {
return m_registeredInputChannels;
}

void registerOutputChannel(const ChannelHandleAndGroup& handle_group);
void registerOutputChannel(const ChannelHandleAndGroup& handleGroup);
const QSet<ChannelHandleAndGroup>& registeredOutputChannels() const {
return m_registeredOutputChannels;
}
Expand Down
31 changes: 15 additions & 16 deletions src/effects/effectchainslot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ void EffectChainSlot::updateRoutingSwitches() {
}
for (const ChannelInfo* pChannelInfo : m_channelInfoByName) {
if (pChannelInfo->pEnabled->toBool()) {
m_pEffectChain->enableForInputChannel(pChannelInfo->handle_group);
m_pEffectChain->enableForInputChannel(pChannelInfo->handleGroup);
} else {
m_pEffectChain->disableForInputChannel(pChannelInfo->handle_group);
m_pEffectChain->disableForInputChannel(pChannelInfo->handleGroup);
}
}
}
Expand Down Expand Up @@ -314,27 +314,26 @@ EffectSlotPointer EffectChainSlot::addEffectSlot(const QString& group) {
return pSlot;
}

void EffectChainSlot::registerInputChannel(const ChannelHandleAndGroup& handle_group) {
VERIFY_OR_DEBUG_ASSERT(!m_channelInfoByName.contains(handle_group.name())) {
void EffectChainSlot::registerInputChannel(const ChannelHandleAndGroup& handleGroup) {
VERIFY_OR_DEBUG_ASSERT(!m_channelInfoByName.contains(handleGroup.name())) {
return;
}

double initialValue = 0.0;
int deckNumber;
if (PlayerManager::isDeckGroup(handle_group.name(), &deckNumber) &&
(m_iChainSlotNumber + 1) == (unsigned) deckNumber) {
if (PlayerManager::isDeckGroup(handleGroup.name(), &deckNumber) &&
(m_iChainSlotNumber + 1) == (unsigned)deckNumber) {
initialValue = 1.0;
}
ControlPushButton* pEnableControl = new ControlPushButton(
ConfigKey(m_group, QString("group_%1_enable").arg(handle_group.name())),
true, initialValue);
ConfigKey(m_group, QString("group_%1_enable").arg(handleGroup.name())),
true,
initialValue);
pEnableControl->setButtonMode(ControlPushButton::POWERWINDOW);

ChannelInfo* pInfo = new ChannelInfo(handle_group, pEnableControl);
m_channelInfoByName[handle_group.name()] = pInfo;
connect(pEnableControl, &ControlPushButton::valueChanged,
this, [this, handle_group] { slotChannelStatusChanged(handle_group.name()); });

ChannelInfo* pInfo = new ChannelInfo(handleGroup, pEnableControl);
m_channelInfoByName[handleGroup.name()] = pInfo;
connect(pEnableControl, &ControlPushButton::valueChanged, this, [this, handleGroup] { slotChannelStatusChanged(handleGroup.name()); });
}

void EffectChainSlot::slotEffectLoaded(EffectPointer pEffect, unsigned int slotNumber) {
Expand Down Expand Up @@ -433,12 +432,12 @@ void EffectChainSlot::slotControlChainPrevPreset(double v) {
void EffectChainSlot::slotChannelStatusChanged(const QString& group) {
if (m_pEffectChain) {
ChannelInfo* pChannelInfo = m_channelInfoByName.value(group, NULL);
if (pChannelInfo != NULL && pChannelInfo->pEnabled != NULL) {
if (pChannelInfo != nullptr && pChannelInfo->pEnabled != nullptr) {
bool bEnable = pChannelInfo->pEnabled->toBool();
if (bEnable) {
m_pEffectChain->enableForInputChannel(pChannelInfo->handle_group);
m_pEffectChain->enableForInputChannel(pChannelInfo->handleGroup);
} else {
m_pEffectChain->disableForInputChannel(pChannelInfo->handle_group);
m_pEffectChain->disableForInputChannel(pChannelInfo->handleGroup);
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/effects/effectchainslot.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class EffectChainSlot : public QObject {
EffectChainPointer getEffectChain() const;
EffectChainPointer getOrCreateEffectChain(EffectsManager* pEffectsManager);

void registerInputChannel(const ChannelHandleAndGroup& handle_group);
void registerInputChannel(const ChannelHandleAndGroup& handleGroup);

double getSuperParameter() const;
void setSuperParameter(double value, bool force = false);
Expand Down Expand Up @@ -153,15 +153,14 @@ class EffectChainSlot : public QObject {

struct ChannelInfo {
// Takes ownership of pEnabled.
ChannelInfo(const ChannelHandleAndGroup& handle_group, ControlObject* pEnabled)
: handle_group(handle_group),
ChannelInfo(const ChannelHandleAndGroup& handleGroup, ControlObject* pEnabled)
: handleGroup(handleGroup),
pEnabled(pEnabled) {

}
~ChannelInfo() {
delete pEnabled;
}
ChannelHandleAndGroup handle_group;
ChannelHandleAndGroup handleGroup;
ControlObject* pEnabled;
};
QMap<QString, ChannelInfo*> m_channelInfoByName;
Expand Down
22 changes: 11 additions & 11 deletions src/effects/effectrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ void EffectRack::removeFromEngine() {
m_pEngineEffectRack = NULL;
}

void EffectRack::registerInputChannel(const ChannelHandleAndGroup& handle_group) {
void EffectRack::registerInputChannel(const ChannelHandleAndGroup& handleGroup) {
foreach (EffectChainSlotPointer pChainSlot, m_effectChainSlots) {
pChainSlot->registerInputChannel(handle_group);
pChainSlot->registerInputChannel(handleGroup);
}
}

Expand Down Expand Up @@ -260,8 +260,8 @@ EffectChainSlotPointer StandardEffectRack::addEffectChainSlot() {
// Register all the existing channels with the new EffectChain.
const QSet<ChannelHandleAndGroup>& registeredChannels =
m_pEffectChainManager->registeredInputChannels();
for (const ChannelHandleAndGroup& handle_group : registeredChannels) {
pChainSlot->registerInputChannel(handle_group);
for (const ChannelHandleAndGroup& handleGroup : registeredChannels) {
pChainSlot->registerInputChannel(handleGroup);
}

EffectChainSlotPointer pChainSlotPointer = EffectChainSlotPointer(pChainSlot);
Expand Down Expand Up @@ -300,9 +300,9 @@ OutputEffectRack::OutputEffectRack(EffectsManager* pEffectsManager,
// TODO(Be): Remove this hideous hack to get the ChannelHandleAndGroup
const QSet<ChannelHandleAndGroup>& registeredChannels =
m_pEffectChainManager->registeredInputChannels();
for (const ChannelHandleAndGroup& handle_group : registeredChannels) {
if (handle_group.name() == "[MasterOutput]") {
masterHandleAndGroup = &handle_group;
for (const ChannelHandleAndGroup& handleGroup : registeredChannels) {
if (handleGroup.name() == "[MasterOutput]") {
masterHandleAndGroup = &handleGroup;
break;
}
}
Expand Down Expand Up @@ -349,10 +349,10 @@ void PerGroupRack::setupForGroup(const QString& groupName) {

// TODO(rryan): remove.
const ChannelHandleAndGroup* handleAndGroup = nullptr;
for (const ChannelHandleAndGroup& handle_group :
m_pEffectChainManager->registeredInputChannels()) {
if (handle_group.name() == groupName) {
handleAndGroup = &handle_group;
for (const ChannelHandleAndGroup& handleGroup :
m_pEffectChainManager->registeredInputChannels()) {
if (handleGroup.name() == groupName) {
handleAndGroup = &handleGroup;
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/effects/effectrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class EffectRack : public QObject {
void removeFromEngine();
EngineEffectRack* getEngineEffectRack();

void registerInputChannel(const ChannelHandleAndGroup& handle_group);
void registerInputChannel(const ChannelHandleAndGroup& handleGroup);
int numEffectChainSlots() const;
EffectChainSlotPointer getEffectChainSlot(int i);

Expand Down
8 changes: 4 additions & 4 deletions src/effects/effectsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ void EffectsManager::slotBackendRegisteredEffect(EffectManifestPointer pManifest
m_pNumEffectsAvailable->forceSet(m_availableEffectManifests.size());
}

void EffectsManager::registerInputChannel(const ChannelHandleAndGroup& handle_group) {
m_pEffectChainManager->registerInputChannel(handle_group);
void EffectsManager::registerInputChannel(const ChannelHandleAndGroup& handleGroup) {
m_pEffectChainManager->registerInputChannel(handleGroup);
}

const QSet<ChannelHandleAndGroup>& EffectsManager::registeredInputChannels() const {
return m_pEffectChainManager->registeredInputChannels();
}

void EffectsManager::registerOutputChannel(const ChannelHandleAndGroup& handle_group) {
m_pEffectChainManager->registerOutputChannel(handle_group);
void EffectsManager::registerOutputChannel(const ChannelHandleAndGroup& handleGroup) {
m_pEffectChainManager->registerOutputChannel(handleGroup);
}

const QSet<ChannelHandleAndGroup>& EffectsManager::registeredOutputChannels() const {
Expand Down
4 changes: 2 additions & 2 deletions src/effects/effectsmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class EffectsManager : public QObject {
// takes ownership of the backend, and will delete it when EffectsManager is
// being deleted. Not thread safe -- use only from the GUI thread.
void addEffectsBackend(EffectsBackend* pEffectsBackend);
void registerInputChannel(const ChannelHandleAndGroup& handle_group);
void registerOutputChannel(const ChannelHandleAndGroup& handle_group);
void registerInputChannel(const ChannelHandleAndGroup& handleGroup);
void registerOutputChannel(const ChannelHandleAndGroup& handleGroup);
const QSet<ChannelHandleAndGroup>& registeredInputChannels() const;
const QSet<ChannelHandleAndGroup>& registeredOutputChannels() const;

Expand Down
46 changes: 26 additions & 20 deletions src/engine/channelhandle.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#ifndef CHANNELHANDLE_H
#define CHANNELHANDLE_H
#pragma once

#include <QHash>
#include <QString>
#include <QVarLengthArray>
#include <QtDebug>
#include <memory>

#include "util/assert.h"

// ChannelHandle defines a unique identifier for channels of audio in the engine
// (e.g. headphone output, master output, deck 1, microphone 3). Previously we
// used the group string of the channel in the engine to uniquely identify it
Expand All @@ -12,21 +20,13 @@
// and equality of ChannelHandles are simple to calculate and a QVarLengthArray
// can be used to create a fast associative container backed by a simple array
// (since the keys are numbered [0, num_channels]).
//
// A helper class, ChannelHandleFactory, keeps a running count of handles that
// have been assigned.

#include <QHash>
#include <QString>
#include <QVarLengthArray>
#include <QtDebug>
#include <memory>

#include "util/assert.h"

// A wrapper around an integer handle. Used to uniquely identify and refer to
// channels (headphone output, master output, deck 1, microphone 4, etc.) of
// audio in the engine.
/// A wrapper around an integer handle. Used to uniquely identify and refer to
/// channels (headphone output, master output, deck 1, microphone 4, etc.) while
/// avoiding slow QString comparisons incurred when using the group.
///
/// A helper class, ChannelHandleFactory, keeps a running count of handles that
/// have been assigned.
class ChannelHandle {
public:
ChannelHandle() : m_iHandle(-1) {
Expand Down Expand Up @@ -54,6 +54,14 @@ class ChannelHandle {
friend class ChannelHandleFactory;
};

inline bool operator>(const ChannelHandle& h1, const ChannelHandle& h2) {
return h1.handle() > h2.handle();
}

inline bool operator<(const ChannelHandle& h1, const ChannelHandle& h2) {
return h1.handle() < h2.handle();
}

inline bool operator==(const ChannelHandle& h1, const ChannelHandle& h2) {
return h1.handle() == h2.handle();
}
Expand Down Expand Up @@ -108,9 +116,9 @@ inline QDebug operator<<(QDebug stream, const ChannelHandleAndGroup& g) {
}

inline uint qHash(
const ChannelHandleAndGroup& handle_group,
const ChannelHandleAndGroup& handleGroup,
uint seed = 0) {
return qHash(handle_group.handle(), seed);
return qHash(handleGroup.handle(), seed);
}

// A helper class used by EngineMaster to assign ChannelHandles to channel group
Expand Down Expand Up @@ -219,5 +227,3 @@ class ChannelHandleMap {
container_type m_data;
T m_dummy;
};

#endif /* CHANNELHANDLE,_H */
4 changes: 2 additions & 2 deletions src/engine/channels/engineaux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include "engine/effects/engineeffectsmanager.h"
#include "util/sample.h"

EngineAux::EngineAux(const ChannelHandleAndGroup& handle_group, EffectsManager* pEffectsManager)
: EngineChannel(handle_group, EngineChannel::CENTER, pEffectsManager,
EngineAux::EngineAux(const ChannelHandleAndGroup& handleGroup, EffectsManager* pEffectsManager)
: EngineChannel(handleGroup, EngineChannel::CENTER, pEffectsManager,
/*isTalkoverChannel*/ false,
/*isPrimaryDeck*/ false),
m_pInputConfigured(new ControlObject(ConfigKey(getGroup(), "input_configured"))),
Expand Down
Loading

0 comments on commit 1ea7cea

Please sign in to comment.