Skip to content

Commit

Permalink
PlayerManager: Identify players by ChannelHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
xeruf committed Jul 27, 2020
1 parent 0d9e4b9 commit a54e894
Show file tree
Hide file tree
Showing 17 changed files with 217 additions and 159 deletions.
42 changes: 24 additions & 18 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.) of
/// audio in the engine.
///
/// 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 @@ -219,5 +227,3 @@ class ChannelHandleMap {
container_type m_data;
T m_dummy;
};

#endif /* CHANNELHANDLE,_H */
3 changes: 2 additions & 1 deletion src/engine/channels/enginedeck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
#include "util/sample.h"
#include "waveform/waveformwidgetfactory.h"

EngineDeck::EngineDeck(const ChannelHandleAndGroup& handle_group,
EngineDeck::EngineDeck(
const ChannelHandleAndGroup& handle_group,
UserSettingsPointer pConfig,
EngineMaster* pMixingEngine,
EffectsManager* pEffectsManager,
Expand Down
3 changes: 2 additions & 1 deletion src/engine/channels/enginedeck.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class ControlPushButton;
class EngineDeck : public EngineChannel, public AudioDestination {
Q_OBJECT
public:
EngineDeck(const ChannelHandleAndGroup& handle_group,
EngineDeck(
const ChannelHandleAndGroup& handle_group,
UserSettingsPointer pConfig,
EngineMaster* pMixingEngine,
EffectsManager* pEffectsManager,
Expand Down
4 changes: 2 additions & 2 deletions src/engine/enginemaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class EngineMaster : public QObject, public AudioSource {
// be called by SoundManager.
const CSAMPLE* buffer(AudioOutput output) const;

ChannelHandleAndGroup registerChannelGroup(const QString& group) {
ChannelHandleAndGroup registerChannelGroup(const QString& group) const {
return ChannelHandleAndGroup(
m_pChannelHandleFactory->getOrCreateHandle(group), group);
}
Expand Down Expand Up @@ -119,7 +119,7 @@ class EngineMaster : public QObject, public AudioSource {
const CSAMPLE* getChannelBuffer(QString name) const;
const CSAMPLE* getSidechainBuffer() const;

EngineSideChain* getSideChain() const {
const EngineSideChain* getSideChain() const {
return m_pEngineSideChain;
}

Expand Down
10 changes: 1 addition & 9 deletions src/library/autodj/autodjfeature.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
// AutoDJfeature.h
// FORK FORK FORK on 11/1/2009 by Albert Santoni (alberts@mixxx.org)
// Created 8/23/2009 by RJ Ryan (rryan@mit.edu)

#ifndef AUTODJFEATURE_H
#define AUTODJFEATURE_H
#pragma once

#include <QAction>
#include <QIcon>
Expand Down Expand Up @@ -107,6 +102,3 @@ class AutoDJFeature : public LibraryFeature {
// of tracks in the playlist
void slotRandomQueue(int numTracksToAdd);
};


#endif /* AUTODJFEATURE_H */
58 changes: 31 additions & 27 deletions src/mixer/basetrackplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,35 @@ BaseTrackPlayer::BaseTrackPlayer(QObject* pParent, const QString& group)
: BasePlayer(pParent, group) {
}

BaseTrackPlayerImpl::BaseTrackPlayerImpl(QObject* pParent,
BaseTrackPlayerImpl::BaseTrackPlayerImpl(
QObject* pParent,
UserSettingsPointer pConfig,
EngineMaster* pMixingEngine,
EffectsManager* pEffectsManager,
VisualsManager* pVisualsManager,
EngineChannel::ChannelOrientation defaultOrientation,
const QString& group,
const ChannelHandleAndGroup& handle_group,
bool defaultMaster,
bool defaultHeadphones,
bool primaryDeck)
: BaseTrackPlayer(pParent, group),
: BaseTrackPlayer(pParent, handle_group.name()),
m_pConfig(pConfig),
m_pEngineMaster(pMixingEngine),
m_pLoadedTrack(),
m_replaygainPending(false),
m_pChannelToCloneFrom(nullptr) {
ChannelHandleAndGroup channelGroup =
pMixingEngine->registerChannelGroup(group);
m_pChannel = new EngineDeck(channelGroup, pConfig, pMixingEngine, pEffectsManager, defaultOrientation, primaryDeck);

m_pInputConfigured = make_parented<ControlProxy>(group, "input_configured", this);
m_pChannel = new EngineDeck(handle_group,
pConfig,
pMixingEngine,
pEffectsManager,
defaultOrientation,
primaryDeck);

m_pInputConfigured = make_parented<ControlProxy>(getGroup(), "input_configured", this);
#ifdef __VINYLCONTROL__
m_pVinylControlEnabled = make_parented<ControlProxy>(group, "vinylcontrol_enabled", this);
m_pVinylControlEnabled = make_parented<ControlProxy>(getGroup(), "vinylcontrol_enabled", this);
m_pVinylControlEnabled->connectValueChanged(this, &BaseTrackPlayerImpl::slotVinylControlEnabled);
m_pVinylControlStatus = make_parented<ControlProxy>(group, "vinylcontrol_status", this);
m_pVinylControlStatus = make_parented<ControlProxy>(getGroup(), "vinylcontrol_status", this);
#endif

EngineBuffer* pEngineBuffer = m_pChannel->getEngineBuffer();
Expand Down Expand Up @@ -111,79 +115,79 @@ BaseTrackPlayerImpl::BaseTrackPlayerImpl(QObject* pParent,
// This acts somewhat like a ControlPotmeter, but the normal _up/_down methods
// do not work properly with this CO.
m_pWaveformZoom =
std::make_unique<ControlObject>(ConfigKey(group, "waveform_zoom"));
std::make_unique<ControlObject>(ConfigKey(getGroup(), "waveform_zoom"));
m_pWaveformZoom->connectValueChangeRequest(this,
&BaseTrackPlayerImpl::slotWaveformZoomValueChangeRequest,
Qt::DirectConnection);
m_pWaveformZoom->set(1.0);
m_pWaveformZoomUp = std::make_unique<ControlPushButton>(
ConfigKey(group, "waveform_zoom_up"));
ConfigKey(getGroup(), "waveform_zoom_up"));
connect(m_pWaveformZoomUp.get(),
SIGNAL(valueChanged(double)),
this,
SLOT(slotWaveformZoomUp(double)));
m_pWaveformZoomDown = std::make_unique<ControlPushButton>(
ConfigKey(group, "waveform_zoom_down"));
ConfigKey(getGroup(), "waveform_zoom_down"));
connect(m_pWaveformZoomDown.get(),
SIGNAL(valueChanged(double)),
this,
SLOT(slotWaveformZoomDown(double)));
m_pWaveformZoomSetDefault = std::make_unique<ControlPushButton>(
ConfigKey(group, "waveform_zoom_set_default"));
ConfigKey(getGroup(), "waveform_zoom_set_default"));
connect(m_pWaveformZoomSetDefault.get(),
SIGNAL(valueChanged(double)),
this,
SLOT(slotWaveformZoomSetDefault(double)));

m_pPreGain = make_parented<ControlProxy>(group, "pregain", this);
m_pPreGain = make_parented<ControlProxy>(getGroup(), "pregain", this);

m_pShiftCuesEarlier = std::make_unique<ControlPushButton>(
ConfigKey(group, "shift_cues_earlier"));
ConfigKey(getGroup(), "shift_cues_earlier"));
connect(m_pShiftCuesEarlier.get(),
&ControlObject::valueChanged,
this,
[this](double value) { slotShiftCuesMillisButton(value, -kShiftCuesOffsetMillis); });
m_pShiftCuesLater = std::make_unique<ControlPushButton>(
ConfigKey(group, "shift_cues_later"));
ConfigKey(getGroup(), "shift_cues_later"));
connect(m_pShiftCuesLater.get(),
&ControlObject::valueChanged,
this,
[this](double value) { slotShiftCuesMillisButton(value, kShiftCuesOffsetMillis); });
m_pShiftCuesEarlierSmall = std::make_unique<ControlPushButton>(
ConfigKey(group, "shift_cues_earlier_small"));
ConfigKey(getGroup(), "shift_cues_earlier_small"));
connect(m_pShiftCuesEarlierSmall.get(),
&ControlObject::valueChanged,
this,
[this](double value) {
slotShiftCuesMillisButton(value, -kShiftCuesOffsetSmallMillis);
});
m_pShiftCuesLaterSmall = std::make_unique<ControlPushButton>(
ConfigKey(group, "shift_cues_later_small"));
ConfigKey(getGroup(), "shift_cues_later_small"));
connect(m_pShiftCuesLaterSmall.get(),
&ControlObject::valueChanged,
this,
[this](double value) {
slotShiftCuesMillisButton(value, kShiftCuesOffsetSmallMillis);
});
m_pShiftCues = std::make_unique<ControlObject>(
ConfigKey(group, "shift_cues"));
ConfigKey(getGroup(), "shift_cues"));
connect(m_pShiftCues.get(),
&ControlObject::valueChanged,
this,
&BaseTrackPlayerImpl::slotShiftCuesMillis);

// BPM of the current song
m_pFileBPM = std::make_unique<ControlObject>(ConfigKey(group, "file_bpm"));
m_pKey = make_parented<ControlProxy>(group, "file_key", this);
m_pFileBPM = std::make_unique<ControlObject>(ConfigKey(getGroup(), "file_bpm"));
m_pKey = make_parented<ControlProxy>(getGroup(), "file_key", this);

m_pReplayGain = make_parented<ControlProxy>(group, "replaygain", this);
m_pPlay = make_parented<ControlProxy>(group, "play", this);
m_pReplayGain = make_parented<ControlProxy>(getGroup(), "replaygain", this);
m_pPlay = make_parented<ControlProxy>(getGroup(), "play", this);
m_pPlay->connectValueChanged(this, &BaseTrackPlayerImpl::slotPlayToggled);

m_pRateRatio = make_parented<ControlProxy>(group, "rate_ratio", this);
m_pPitchAdjust = make_parented<ControlProxy>(group, "pitch_adjust", this);
m_pRateRatio = make_parented<ControlProxy>(getGroup(), "rate_ratio", this);
m_pPitchAdjust = make_parented<ControlProxy>(getGroup(), "pitch_adjust", this);

pVisualsManager->addDeck(group);
pVisualsManager->addDeck(getGroup());
}

BaseTrackPlayerImpl::~BaseTrackPlayerImpl() {
Expand Down
2 changes: 1 addition & 1 deletion src/mixer/basetrackplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class BaseTrackPlayerImpl : public BaseTrackPlayer {
EffectsManager* pEffectsManager,
VisualsManager* pVisualsManager,
EngineChannel::ChannelOrientation defaultOrientation,
const QString& group,
const ChannelHandleAndGroup& handle_group,
bool defaultMaster,
bool defaultHeadphones,
bool primaryDeck);
Expand Down
11 changes: 9 additions & 2 deletions src/mixer/deck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ Deck::Deck(QObject* pParent,
EffectsManager* pEffectsManager,
VisualsManager* pVisualsManager,
EngineChannel::ChannelOrientation defaultOrientation,
const QString& group)
: BaseTrackPlayerImpl(pParent, pConfig, pMixingEngine, pEffectsManager, pVisualsManager, defaultOrientation, group, /*defaultMaster*/ true,
const ChannelHandleAndGroup& handle_group)
: BaseTrackPlayerImpl(pParent,
pConfig,
pMixingEngine,
pEffectsManager,
pVisualsManager,
defaultOrientation,
handle_group,
/*defaultMaster*/ true,
/*defaultHeadphones*/ false,
/*primaryDeck*/ true) {
}
17 changes: 7 additions & 10 deletions src/mixer/deck.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef MIXER_DECK_H
#define MIXER_DECK_H
#pragma once

#include <QObject>

Expand All @@ -9,13 +8,11 @@ class Deck : public BaseTrackPlayerImpl {
Q_OBJECT
public:
Deck(QObject* pParent,
UserSettingsPointer pConfig,
EngineMaster* pMixingEngine,
EffectsManager* pEffectsManager,
VisualsManager* pVisualsManager,
EngineChannel::ChannelOrientation defaultOrientation,
const QString& group);
UserSettingsPointer pConfig,
EngineMaster* pMixingEngine,
EffectsManager* pEffectsManager,
VisualsManager* pVisualsManager,
EngineChannel::ChannelOrientation defaultOrientation,
const ChannelHandleAndGroup& handle_group);
~Deck() override = default;
};

#endif // MIXER_DECK_H
Loading

0 comments on commit a54e894

Please sign in to comment.