Files
qt5-legatus-legacy/Lts/Plugins/EffectManagement/Gui/SoundArea/efm_sound_area.h
T
2026-08-13 18:33:10 +02:00

110 lines
2.8 KiB
C++
Executable File

/**
* @RDE_HEADER@
* SoundArea class.
* $Id$
* $HeadURL$
* $Author$
* Created by Filip Biedziak, NLE, 2020-08-10
*/
#pragma once
#include <InfrastructureManagement/ism.hpp>
#include <SoundManagement/som.hpp>
#include <QHash>
#include <QVector>
namespace EffectManagement
{
using SoundKey = QPair<int32_t, int32_t>;
struct SoundArea
{
SoundArea() = default;
explicit SoundArea(const InfrastructureManagement::EffectArea &effectArea)
: id(effectArea.id())
, areaEgcuId(effectArea.areaEgcuId())
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
, egcuIds(QVector<int>(effectArea.egcuIds().begin(), effectArea.egcuIds().end()))
#else
, egcuIds(QVector<int>::fromStdVector(effectArea.egcuIds()))
#endif
, displayName(QString::fromStdString(effectArea.name()))
{
}
bool addActiveSound(const SoundManagement::SoundState &soundState)
{
if (activeSounds.contains(soundState.id()))
return false;
activeSounds.insert(soundState.id(), soundState);
return true;
}
bool removeActiveSound(const SoundManagement::SoundState &soundState)
{
return removeActiveSound(soundState.id());
}
bool removeActiveSound(const int &id)
{
return activeSounds.remove(id) == 1;
}
bool hasActiveSound(const SoundManagement::SoundCategory &category, const int &id) const
{
for (const auto &sound : qAsConst(activeSounds))
if ( (sound.category() == category) && (sound.soundId() == id) )
return true;
return false;
}
bool hasActiveSound(const int32_t &category, const int32_t &id) const
{
for (const auto &sound : qAsConst(activeSounds))
if ( (static_cast<int32_t>(sound.category().underlying()) == category) && (sound.soundId() == id) )
return true;
return false;
}
bool hasActiveSound(const SoundKey &key) const
{
for (const auto &sound : qAsConst(activeSounds))
if ( (static_cast<int32_t>(sound.category().underlying()) == key.first) && (sound.soundId() == key.second) )
return true;
return false;
}
QString toString() const
{
QString str;
str += QStringLiteral("SoundArea ") + QString::number(id);
str += QStringLiteral(" displayName: ") + displayName;
str += QStringLiteral(" areaEgcuId: ") + QString::number(areaEgcuId);
return str;
}
std::ostream& operator << (std::ostream& os) const
{
os << toString().toStdString();
return os;
}
bool operator == (const SoundArea &other) const
{
return id == other.id;
}
bool operator != (const SoundArea &other) const
{
return id != other.id;
}
int id{-1};
int32_t areaEgcuId{-1};
QVector<int32_t> egcuIds;
QString displayName;
QHash<int32_t, SoundManagement::SoundState> activeSounds;
};
} // namespace EffectManagement