Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
playback_cache_activity_tracker.h
1// SPDX-FileCopyrightText: © 2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <functional>
7#include <vector>
8
9#include "dsp/timeline_data_cache.h"
10#include "utils/playback_cache_scheduler.h"
11
12#include <QTimer>
13#include <QtQmlIntegration/qqmlintegration.h>
14
15namespace zrythm::structure::tracks
16{
17
22{
23 Q_GADGET
24 Q_PROPERTY (qint64 id MEMBER id)
25 Q_PROPERTY (double startTick MEMBER startTick)
26 Q_PROPERTY (double endTick MEMBER endTick)
27 Q_PROPERTY (bool isFullContent MEMBER isFullContent)
28 QML_VALUE_TYPE (playbackCacheActivityEntry)
29 QML_UNCREATABLE ("")
30
31public:
32 qint64 id{};
33 double startTick{};
34 double endTick{};
35 bool isFullContent{};
36 std::chrono::milliseconds createdAtMs;
37};
38
43{
44 Q_GADGET
45 Q_PROPERTY (double startTick MEMBER startTick)
46 Q_PROPERTY (double endTick MEMBER endTick)
47 QML_VALUE_TYPE (cachedTickRange)
48 QML_UNCREATABLE ("")
49
50public:
51 double startTick{};
52 double endTick{};
53};
54
66class PlaybackCacheActivityTracker : public QObject
67{
68 Q_OBJECT
69 Q_PROPERTY (bool pending READ isPending NOTIFY pendingChanged)
70 Q_PROPERTY (QVariantList entries READ entries NOTIFY entriesChanged)
71 Q_PROPERTY (
72 QVariantList cachedRanges READ cachedRanges NOTIFY cachedRangesChanged)
73 QML_ELEMENT
74 QML_UNCREATABLE ("")
75
76public:
77 static constexpr auto kMaxEntries = 100zu;
78 static constexpr auto kEntryLifetimeMs = std::chrono::milliseconds (300);
79
83 using SampleToTickConverter = std::function<double (units::sample_t)>;
84
94 const dsp::TimelineDataCache &cache,
95 SampleToTickConverter sample_to_tick,
96 QObject * parent = nullptr);
97
105
106 [[nodiscard]] bool isPending () const { return pending_; }
107 [[nodiscard]] QVariantList entries () const;
108 [[nodiscard]] size_t entryCount () const { return entries_.size (); }
109 [[nodiscard]] QVariantList cachedRanges () const;
110
111Q_SIGNALS:
112 void pendingChanged ();
113 void entriesChanged ();
114 void cachedRangesChanged ();
115
116private:
117 void sweepExpiredEntries ();
118
119 bool pending_ = false;
120 std::vector<PlaybackCacheActivityEntry> entries_;
121 std::vector<CachedTickRange> cached_ranges_;
122 qint64 next_id_ = 0;
123
124 QTimer sweep_timer_;
125};
126
127} // namespace zrythm::structure::tracks
128
Base class for timeline data caches.
PlaybackCacheActivityTracker(utils::PlaybackCacheScheduler *scheduler, const dsp::TimelineDataCache &cache, SampleToTickConverter sample_to_tick, QObject *parent=nullptr)
void onRegenerationComplete(utils::ExpandableTickRange affectedRange)
Called when cache regeneration completes.
std::function< double(units::sample_t)> SampleToTickConverter
Function type for converting sample position to tick position.
Cache request handler for a tick range, with built-in debouncing and expanding of the range.
A tick range representing currently valid cached content.
A single completed cache regeneration entry for debug visualization.