#pragma once #include #include #include namespace ZShell::internal { class CircularBuffer : public QObject { Q_OBJECT QML_ELEMENT Q_PROPERTY( int capacity READ capacity WRITE setCapacity NOTIFY capacityChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QList values READ values NOTIFY valuesChanged) Q_PROPERTY(qreal maximum READ maximum NOTIFY valuesChanged) Q_PROPERTY( int smoothingRadius READ smoothingRadius WRITE setSmoothingRadius NOTIFY smoothingRadiusChanged) public: explicit CircularBuffer(QObject* parent = nullptr); [[nodiscard]] int capacity() const; void setCapacity(int capacity); [[nodiscard]] int count() const; [[nodiscard]] QList values() const; [[nodiscard]] qreal maximum() const; [[nodiscard]] int smoothingRadius() const; void setSmoothingRadius(int radius); Q_INVOKABLE void push(qreal value); Q_INVOKABLE void clear(); Q_INVOKABLE [[nodiscard]] qreal at(int index) const; Q_INVOKABLE [[nodiscard]] qreal smoothedAt(int index) const; signals: void capacityChanged(); void countChanged(); void valuesChanged(); void smoothingRadiusChanged(); private: void writeSmoothedAt(int logicalIndex); void updateSmoothedTail(); void recomputeAllSmoothed(); QVector m_data; QVector m_smoothed; int m_head = 0; int m_count = 0; int m_capacity = 0; int m_smoothingRadius = 0; }; } // namespace ZShell::internal