Zrythm v2.0.0-alpha.1
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
timebase.h
1// SPDX-FileCopyrightText: © 2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <optional>
7
8#include <QObject>
9#include <QPointer>
10#include <QtQmlIntegration/qqmlintegration.h>
11
12namespace zrythm::dsp
13{
14
20namespace timebase
21{
22
23Q_NAMESPACE
24
33enum class Timebase : std::uint8_t
34{
35 Musical,
36 Absolute,
37};
38Q_ENUM_NS (Timebase)
39
40
59class TimebaseProvider : public QObject
60{
61 Q_OBJECT
62 Q_PROPERTY (
63 Timebase effectiveTimebase READ effectiveTimebase NOTIFY
64 effectiveTimebaseChanged)
65 QML_ELEMENT
66 QML_UNCREATABLE ("")
67
68public:
69 explicit TimebaseProvider (QObject * parent = nullptr);
72 void setSource (TimebaseProvider * source);
75 void setOverride (Timebase t);
76 void clearOverride ();
77
78 [[nodiscard]] bool hasOverride () const { return override_.has_value (); }
79 [[nodiscard]] std::optional<Timebase> overrideValue () const
80 {
81 return override_;
82 }
85 [[nodiscard]] Timebase effectiveTimebase () const;
86
87 Q_SIGNAL void effectiveTimebaseChanged ();
88 Q_SIGNAL void overrideChanged ();
89
90private:
93 static constexpr int kMaxChainDepth = 64;
94
95 void recompute_and_emit_if_changed ();
96
97 QPointer<TimebaseProvider> source_;
98 std::optional<Timebase> override_;
99 Timebase cached_effective_ = Timebase::Musical;
100};
101
102} // namespace timebase
103
106using Timebase = timebase::Timebase;
109using TimebaseProvider = timebase::TimebaseProvider;
110
111} // namespace zrythm::dsp
112
113Q_DECLARE_METATYPE (zrythm::dsp::timebase::Timebase)
Self-nesting timebase provider that resolves an effective timebase through a chain of providers.
Definition timebase.h:60
void setSource(TimebaseProvider *source)
Sets the parent provider to observe. Pass nullptr to detach.
void setOverride(Timebase t)
Forces a specific timebase value, taking precedence over the source.
Nested namespace isolating the timebase enum and provider together with the Qt meta-object registrati...
Definition timebase.h:21
Timebase
Per-track timebase that controls how clip content maps to the project timeline.
Definition timebase.h:34