Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SoundManager: Restore qHash() behavior #2801

Merged
merged 2 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions src/soundio/soundmanagerutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ bool ChannelGroup::clashesWith(const ChannelGroup &other) const {
* @param channels the number of channels used.
*/
AudioPath::AudioPath(unsigned char channelBase, unsigned char channels)
: m_type(INVALID),
m_channelGroup(channelBase, channels),
: m_channelGroup(channelBase, channels),
m_type(INVALID),
m_index(0) {
}

Expand All @@ -92,15 +92,6 @@ unsigned char AudioPath::getIndex() const {
return m_index;
}

/**
* Defines equality for AudioPath objects.
* @return true of this and other share a common type and index.
*/
bool AudioPath::operator==(const AudioPath &other) const {
return m_type == other.m_type
&& m_index == other.m_index;
}

/**
* Checks if this AudioPath's channels clash with another's
* (see ChannelGroup::clashesWith).
Expand Down
37 changes: 30 additions & 7 deletions src/soundio/soundmanagerutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ class ChannelGroup {
unsigned char getChannelCount() const;
bool clashesWith(const ChannelGroup& other) const;

uint hashValue() const {
return (m_channels << 8) |
m_channelBase;
}
friend uint qHash(
const ChannelGroup& group,
uint seed = 0) {
return qHash(group.m_channelBase, seed) |
qHash(group.m_channels, seed);
return qHash(group.hashValue(), seed);
}

friend bool operator==(
Expand Down Expand Up @@ -70,7 +73,6 @@ class AudioPath {
AudioPathType getType() const;
ChannelGroup getChannelGroup() const;
unsigned char getIndex() const;
bool operator==(const AudioPath &other) const;
bool channelsClash(const AudioPath &other) const;
QString getString() const;
static QString getStringFromType(AudioPathType type);
Expand All @@ -87,21 +89,42 @@ class AudioPath {
// AudioPathType.
static unsigned char maxChannelsForType(AudioPathType type);

uint hashValue() const {
// Exclude m_channelGroup from hash value!
// See also: operator==()
// TODO: Why??
return (m_type << 8) |
m_index;
}
friend uint qHash(
const AudioPath& path,
uint seed = 0) {
return qHash(static_cast<uint>(path.m_type), seed) ^
qHash(path.m_channelGroup, seed) ^
qHash(path.m_index, seed);
return qHash(path.hashValue(), seed);
}

friend bool operator==(
const AudioPath& lhs,
const AudioPath& rhs) {
// Exclude m_channelGroup from comparison!
// See also: hashValue()/qHash()
// TODO: Why??
return lhs.m_type == rhs.m_type &&
lhs.m_index == rhs.m_index;
}

protected:
virtual void setType(AudioPathType type) = 0;
AudioPathType m_type;
ChannelGroup m_channelGroup;
AudioPathType m_type;
unsigned char m_index;
};

inline bool operator!=(
const AudioPath& lhs,
const AudioPath& rhs) {
return !(lhs == rhs);
}

/// A source of audio in Mixxx that is to be output to a group of
/// channels on an audio interface.
class AudioOutput : public AudioPath {
Expand Down