Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
playback_cache_activity_aggregator.h
1// SPDX-FileCopyrightText: © 2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <unordered_map>
7
8#include "structure/tracks/track_collection.h"
9
10#include <QMetaObject>
11#include <QTimer>
12#include <QtQmlIntegration/qqmlintegration.h>
13
14namespace zrythm::structure::tracks
15{
16
33class PlaybackCacheActivityAggregator : public QObject
34{
35 Q_OBJECT
36 Q_PROPERTY (
37 zrythm::structure::tracks::TrackCollection * collection READ collection
38 WRITE setCollection NOTIFY collectionChanged)
39 Q_PROPERTY (
40 int cachePendingCount READ cachePendingCount NOTIFY cachePendingCountChanged)
41 Q_PROPERTY (
42 int cacheCompleteCount READ cacheCompleteCount NOTIFY
43 cacheCompleteCountChanged)
44 QML_ELEMENT
45
46public:
47 explicit PlaybackCacheActivityAggregator (QObject * parent = nullptr);
48 ~PlaybackCacheActivityAggregator () noexcept override;
49
50 TrackCollection * collection () const;
51 void setCollection (TrackCollection * collection);
52 Q_SIGNAL void collectionChanged ();
53
54 int cachePendingCount () const;
55 Q_SIGNAL void cachePendingCountChanged ();
56
57 // cacheCompleteCountChanged is debounced (100ms) to avoid flooding QML
58 // during rapid cache regeneration. cachePendingCountChanged fires
59 // immediately for real-time responsiveness.
60 int cacheCompleteCount () const;
61 Q_SIGNAL void cacheCompleteCountChanged ();
62
63private:
64 void connectToTracker (PlaybackCacheActivityTracker * tracker);
65 void disconnectFromTracker (PlaybackCacheActivityTracker * tracker);
66 void disconnectAll ();
67
68 void connectToTrack (Track * track);
69 void disconnectFromTrack (Track * track);
70
71 void updateCachePendingCount (
73 bool new_pending);
74 void updateCacheCompleteCount (
76 int new_count);
77
78 TrackCollection * collection_ = nullptr;
79
80 struct TrackerState
81 {
82 bool is_pending = false;
83 int entry_count = 0;
84 };
85 std::unordered_map<PlaybackCacheActivityTracker *, TrackerState>
86 tracker_states_;
87
88 int cache_pending_count_ = 0;
89 int cache_complete_count_ = 0;
90
91 QTimer cache_complete_count_timer_{ this };
92
93 QMetaObject::Connection rows_inserted_conn_;
94 QMetaObject::Connection rows_about_to_be_removed_conn_;
95 QMetaObject::Connection model_about_to_be_reset_conn_;
96};
97
98} // namespace zrythm::structure::tracks
Helper that manages cache activity state for a cache-holding object.
A collection of tracks that provides a QAbstractListModel interface.
Represents a track in the project.
Definition track.h:54