diff --git a/src/effects/defs.h b/src/effects/defs.h index c6ce474f90e..6393cf4b329 100644 --- a/src/effects/defs.h +++ b/src/effects/defs.h @@ -22,8 +22,10 @@ enum class SignalProcessingStage { Postfader }; -inline uint qHash(SignalProcessingStage stage) { - return static_cast(stage); +inline uint qHash( + SignalProcessingStage stage, + uint seed = 0) { + return qHash(static_cast(stage), seed); }; enum class EffectChainMixMode { diff --git a/src/engine/channelhandle.h b/src/engine/channelhandle.h index 239f0c20dc3..86d891c324f 100644 --- a/src/engine/channelhandle.h +++ b/src/engine/channelhandle.h @@ -66,8 +66,10 @@ inline QDebug operator<<(QDebug stream, const ChannelHandle& h) { return stream; } -inline uint qHash(const ChannelHandle& handle) { - return qHash(handle.handle()); +inline uint qHash( + const ChannelHandle& handle, + uint seed = 0) { + return qHash(handle.handle(), seed); } // Convenience class that mimics QPair except with @@ -104,8 +106,10 @@ inline QDebug operator<<(QDebug stream, const ChannelHandleAndGroup& g) { return stream; } -inline uint qHash(const ChannelHandleAndGroup& handle_group) { - return qHash(handle_group.handle()); +inline uint qHash( + const ChannelHandleAndGroup& handle_group, + uint seed = 0) { + return qHash(handle_group.handle(), seed); } // A helper class used by EngineMaster to assign ChannelHandles to channel group diff --git a/src/preferences/configobject.h b/src/preferences/configobject.h index 93d1b242523..6f261ebb635 100644 --- a/src/preferences/configobject.h +++ b/src/preferences/configobject.h @@ -64,8 +64,11 @@ inline QDebug operator<<(QDebug stream, const ConfigKey& configKey) { } // QHash hash function for ConfigKey objects. -inline uint qHash(const ConfigKey& key) { - return qHash(key.group) ^ qHash(key.item); +inline uint qHash( + const ConfigKey& key, + uint seed = 0) { + return qHash(key.group, seed) ^ + qHash(key.item, seed); } // The value corresponding to a key. The basic value is a string, but can be @@ -97,8 +100,10 @@ inline bool operator!=(const ConfigValue& lhs, const ConfigValue& rhs) { return !(lhs == rhs); } -inline uint qHash(const ConfigValue& key) { - return qHash(key.value.toUpper()); +inline uint qHash( + const ConfigValue& key, + uint seed = 0) { + return qHash(key.value.toUpper(), seed); } class ConfigValueKbd : public ConfigValue { diff --git a/src/soundio/soundmanagerutil.cpp b/src/soundio/soundmanagerutil.cpp index 91041ad1b28..36eadb4fd94 100644 --- a/src/soundio/soundmanagerutil.cpp +++ b/src/soundio/soundmanagerutil.cpp @@ -41,16 +41,6 @@ unsigned char ChannelGroup::getChannelCount() const { return m_channels; } -/** - * Defines equality between two ChannelGroups. - * @return true if the two ChannelGroups share a common base channel - * and channel count, otherwise false. - */ -bool ChannelGroup::operator==(const ChannelGroup &other) const { - return m_channelBase == other.m_channelBase - && m_channels == other.m_channels; -} - /** * Checks if another ChannelGroup shares channels with this one. * @param other the other ChannelGroup to check for a clash with. @@ -69,14 +59,6 @@ bool ChannelGroup::clashesWith(const ChannelGroup &other) const { || m_channelBase == other.m_channelBase; } -/** - * Generates a hash of this ChannelGroup, so it can act as a key in a QHash. - * @return a hash for this ChannelGroup - */ -unsigned int ChannelGroup::getHash() const { - return 0 | (m_channels << 8) | m_channelBase; -} - /** * Constructs an AudioPath object (must be called by a child class's * constructor, AudioPath is abstract). @@ -119,14 +101,6 @@ bool AudioPath::operator==(const AudioPath &other) const { && m_index == other.m_index; } -/** - * Generates a hash of this AudioPath, so it can act as a key in a QHash. - * @return a hash for this AudioPath - */ -unsigned int AudioPath::getHash() const { - return 0 | (m_type << 8) | m_index; -} - /** * Checks if this AudioPath's channels clash with another's * (see ChannelGroup::clashesWith). @@ -469,24 +443,3 @@ QString SoundDeviceId::debugName() const { return name + QStringLiteral(", ") + alsaHwDevice + QStringLiteral(", ") + QString::number(portAudioIndex); } } - -/** - * Defined for QHash, so ChannelGroup can be used as a QHash key. - */ -unsigned int qHash(const ChannelGroup &group) { - return group.getHash(); -} - -/** - * Defined for QHash, so AudioOutput can be used as a QHash key. - */ -unsigned int qHash(const AudioOutput &output) { - return output.getHash(); -} - -/** - * Defined for QHash, so AudioInput can be used as a QHash key. - */ -unsigned int qHash(const AudioInput &input) { - return input.getHash(); -} diff --git a/src/soundio/soundmanagerutil.h b/src/soundio/soundmanagerutil.h index 6cd757e00de..a98f34ad5d6 100644 --- a/src/soundio/soundmanagerutil.h +++ b/src/soundio/soundmanagerutil.h @@ -1,20 +1,4 @@ -/** - * @file soundmanagerutil.h - * @author Bill Good - * @date 20100611 - */ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ - -#ifndef SOUNDMANAGERUTIL_U -#define SOUNDMANAGERUTIL_U +#pragma once #include #include @@ -24,36 +8,50 @@ #include "util/types.h" #include "util/fifo.h" -/** - * @class ChannelGroup - * @brief Describes a group of channels, typically a pair for stereo sound in - * Mixxx. - */ +/// Describes a group of channels, typically a pair for stereo sound in Mixxx. class ChannelGroup { -public: + public: ChannelGroup(unsigned char channelBase, unsigned char channels); unsigned char getChannelBase() const; unsigned char getChannelCount() const; - bool operator==(const ChannelGroup &other) const; - bool clashesWith(const ChannelGroup &other) const; - unsigned int getHash() const; -private: + bool clashesWith(const ChannelGroup& other) const; + + friend uint qHash( + const ChannelGroup& group, + uint seed = 0) { + return qHash(group.m_channelBase, seed) | + qHash(group.m_channels, seed); + } + + friend bool operator==( + const ChannelGroup& lhs, + const ChannelGroup& rhs) { + return lhs.m_channelBase == rhs.m_channelBase && + lhs.m_channels == rhs.m_channels; + } + + private: unsigned char m_channelBase; // base (first) channel used on device unsigned char m_channels; // number of channels used (s/b 2 in most cases) }; -/** - * @class AudioPath - * @brief Describes a path for audio to take. - * @note This needs a new name, the current one sucks. If you find one, - * feel free to rename as necessary. - */ +inline bool operator!=( + const ChannelGroup& lhs, + const ChannelGroup& rhs) { + return !(lhs == rhs); +} + +/// Describes a path for audio to take. +/// +/// TODO: Choose a better name for this class class AudioPath { public: - // XXX if you add a new type here, be sure to add it to the various - // methods including getStringFromType, isIndexed, getTypeFromInt, - // channelsNeededForType (if necessary), the subclasses' getSupportedTypes - // (if necessary), etc. -- bkgood + /// Predefined types. + /// + /// If you add a new type here, be sure to add it to the various + /// methods including getStringFromType, isIndexed, getTypeFromInt, + /// channelsNeededForType (if necessary), the subclasses' getSupportedTypes + /// (if necessary), etc. enum AudioPathType { MASTER, HEADPHONES, @@ -67,11 +65,12 @@ class AudioPath { INVALID, // if this isn't last bad things will happen -bkgood }; AudioPath(unsigned char channelBase, unsigned char channels); + virtual ~AudioPath() = default; + AudioPathType getType() const; ChannelGroup getChannelGroup() const; unsigned char getIndex() const; bool operator==(const AudioPath &other) const; - unsigned int getHash() const; bool channelsClash(const AudioPath &other) const; QString getString() const; static QString getStringFromType(AudioPathType type); @@ -80,14 +79,22 @@ class AudioPath { static bool isIndexed(AudioPathType type); static AudioPathType getTypeFromInt(int typeInt); - // Returns the minimum number of channels needed on a sound device for an - // AudioPathType. + /// Returns the minimum number of channels needed on a sound device for an + /// AudioPathType. static unsigned char minChannelsForType(AudioPathType type); // Returns the maximum number of channels needed on a sound device for an // AudioPathType. static unsigned char maxChannelsForType(AudioPathType type); + friend uint qHash( + const AudioPath& path, + uint seed = 0) { + return qHash(static_cast(path.m_type), seed) ^ + qHash(path.m_channelGroup, seed) ^ + qHash(path.m_index, seed); + } + protected: virtual void setType(AudioPathType type) = 0; AudioPathType m_type; @@ -95,18 +102,14 @@ class AudioPath { unsigned char m_index; }; -/** - * @class AudioOutput - * @extends AudioPath - * @brief A source of audio in Mixxx that is to be output to a group of - * channels on an audio interface. - */ +/// A source of audio in Mixxx that is to be output to a group of +/// channels on an audio interface. class AudioOutput : public AudioPath { public: AudioOutput(AudioPathType type, unsigned char channelBase, unsigned char channels, unsigned char index = 0); - virtual ~AudioOutput(); + ~AudioOutput() override; QDomElement toXML(QDomElement *element) const; static AudioOutput fromXML(const QDomElement &xml); static QList getSupportedTypes(); @@ -123,22 +126,19 @@ class AudioOutputBuffer : public AudioOutput { m_pBuffer(pBuffer) { }; + ~AudioOutputBuffer() override = default; inline const CSAMPLE* getBuffer() const { return m_pBuffer; } private: const CSAMPLE* m_pBuffer; }; -/** - * @class AudioInput - * @extends AudioPath - * @brief A source of audio at a group of channels on an audio interface - * that is be processed in Mixxx. - */ +/// A source of audio at a group of channels on an audio interface +/// that is be processed in Mixxx. class AudioInput : public AudioPath { public: AudioInput(AudioPathType type = INVALID, unsigned char channelBase = 0, unsigned char channels = 0, unsigned char index = 0); - virtual ~AudioInput(); + ~AudioInput() override; QDomElement toXML(QDomElement *element) const; static AudioInput fromXML(const QDomElement &xml); static QList getSupportedTypes(); @@ -155,6 +155,7 @@ class AudioInputBuffer : public AudioInput { m_pBuffer(pBuffer) { } + ~AudioInputBuffer() override = default; inline CSAMPLE* getBuffer() const { return m_pBuffer; } private: CSAMPLE* m_pBuffer; @@ -163,45 +164,49 @@ class AudioInputBuffer : public AudioInput { class AudioSource { public: + virtual ~AudioSource() = default; + virtual const CSAMPLE* buffer(AudioOutput output) const = 0; - // This is called by SoundManager whenever an output is connected for this - // source. When this is called it is guaranteed that no callback is - // active. + /// This is called by SoundManager whenever an output is connected for this + /// source. When this is called it is guaranteed that no callback is + /// active. virtual void onOutputConnected(AudioOutput output) { Q_UNUSED(output); }; - // This is called by SoundManager whenever an output is disconnected for - // this source. When this is called it is guaranteed that no callback is - // active. + /// This is called by SoundManager whenever an output is disconnected for + /// this source. When this is called it is guaranteed that no callback is + /// active. virtual void onOutputDisconnected(AudioOutput output) { Q_UNUSED(output); }; }; class AudioDestination { public: - // This is called by SoundManager whenever there are new samples from the - // configured input to be processed. This is run in the clock reference - // callback thread + virtual ~AudioDestination() = default; + + /// This is called by SoundManager whenever there are new samples from the + /// configured input to be processed. This is run in the clock reference + /// callback thread virtual void receiveBuffer(AudioInput input, const CSAMPLE* pBuffer, unsigned int iNumFrames) = 0; - // This is called by SoundManager whenever an input is configured for this - // destination. When this is called it is guaranteed that no callback is - // active. + /// This is called by SoundManager whenever an input is configured for this + /// destination. When this is called it is guaranteed that no callback is + /// active. virtual void onInputConfigured(AudioInput input) { Q_UNUSED(input); }; - // This is called by SoundManager whenever an input is unconfigured for this - // destination. When this is called it is guaranteed that no callback is - // active. + /// This is called by SoundManager whenever an input is unconfigured for this + /// destination. When this is called it is guaranteed that no callback is + /// active. virtual void onInputUnconfigured(AudioInput input) { Q_UNUSED(input); }; }; typedef AudioPath::AudioPathType AudioPathType; -class SoundDeviceId { +class SoundDeviceId final { public: QString name; - // The "hw:X,Y" device name. Remains an empty string if not using ALSA - // or using a non-hw ALSA device such as "default" or "pulse". + /// The "hw:X,Y" device name. Remains an empty string if not using ALSA + /// or using a non-hw ALSA device such as "default" or "pulse". QString alsaHwDevice; int portAudioIndex; @@ -211,33 +216,39 @@ class SoundDeviceId { : portAudioIndex(-1) {} }; -// This must be registered with QMetaType::registerComparators for -// QVariant::operator== to use it, which is required for QComboBox::findData to -// work in DlgPrefSoundItem. -inline bool operator==(const SoundDeviceId& lhs, const SoundDeviceId& rhs) { +/// This must be registered with QMetaType::registerComparators for +/// QVariant::operator== to use it, which is required for QComboBox::findData to +/// work in DlgPrefSoundItem. +inline bool operator==( + const SoundDeviceId& lhs, + const SoundDeviceId& rhs) { return lhs.name == rhs.name && lhs.alsaHwDevice == rhs.alsaHwDevice && lhs.portAudioIndex == rhs.portAudioIndex; } -// There is not really a use case for this, but it is required for QMetaType::registerComparators. +inline bool operator!=( + const SoundDeviceId& lhs, + const SoundDeviceId& rhs) { + return !(lhs == rhs); +} + +/// There is not really a use case for this, but it is required for QMetaType::registerComparators. inline bool operator<(const SoundDeviceId& lhs, const SoundDeviceId& rhs) { + DEBUG_ASSERT(!"should never be invoked"); return lhs.portAudioIndex < rhs.portAudioIndex; } Q_DECLARE_METATYPE(SoundDeviceId); -inline unsigned int qHash(const SoundDeviceId& id) { - return qHash(id.name) + qHash(id.alsaHwDevice) + id.portAudioIndex; +inline uint qHash( + const SoundDeviceId& id, + uint seed = 0) { + return qHash(id.name, seed) ^ + qHash(id.alsaHwDevice, seed) ^ + qHash(id.portAudioIndex, seed); } inline QDebug operator<<(QDebug dbg, const SoundDeviceId& soundDeviceId) { return dbg << QString("SoundDeviceId(" + soundDeviceId.debugName() + ")"); } - -// globals for QHash -unsigned int qHash(const ChannelGroup &group); -unsigned int qHash(const AudioOutput &output); -unsigned int qHash(const AudioInput &input); - -#endif diff --git a/src/track/trackfile.h b/src/track/trackfile.h index 96c73f4a3aa..7e037840a94 100644 --- a/src/track/trackfile.h +++ b/src/track/trackfile.h @@ -124,6 +124,8 @@ inline QDebug operator<<(QDebug debug, const TrackFile& trackFile) { #endif } -inline uint qHash(const TrackFile& key, uint seed) { +inline uint qHash( + const TrackFile& key, + uint seed = 0) { return qHash(key.location(), seed); } diff --git a/src/track/trackref.h b/src/track/trackref.h index 7a60e045cef..ef238dad0e6 100644 --- a/src/track/trackref.h +++ b/src/track/trackref.h @@ -116,6 +116,10 @@ std::ostream& operator<<(std::ostream& os, const TrackRef& trackRef); QDebug operator<<(QDebug debug, const TrackRef& trackRef); -inline uint qHash(const TrackRef& key, uint seed) { - return qHash(key.getLocation(), seed) ^ qHash(key.getId(), seed); +inline uint qHash( + const TrackRef& key, + uint seed = 0) { + return qHash( + key.getLocation(), seed) ^ + qHash(key.getId(), seed); } diff --git a/src/util/db/dbid.h b/src/util/db/dbid.h index bbbd433f56c..a5d68f4a8f7 100644 --- a/src/util/db/dbid.h +++ b/src/util/db/dbid.h @@ -102,8 +102,10 @@ class DbId { return debug << dbId.m_value; } - friend uint qHash(const DbId& dbId) { - return qHash(dbId.m_value); + friend uint qHash( + const DbId& dbId, + uint seed = 0) { + return qHash(dbId.m_value, seed); } private: