Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
expandable_tick_range.h
1// SPDX-FileCopyrightText: © 2025-2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <QObject>
7
8namespace zrythm::utils
9{
10class ExpandableTickRange
11{
12public:
13 ExpandableTickRange (
14 std::optional<std::pair<double, double>> range = std::nullopt)
15 {
16 if (range.has_value ())
17 {
18 assert (range->second >= range->first);
19 start_ = range->first;
20 end_ = range->second;
21 is_full_content_ = false;
22 }
23 }
24
29 bool is_full_content () const { return is_full_content_; }
30
34 void expand (std::pair<double, double> range_to_add)
35 {
36 // full content takes precedence
37 if (is_full_content ())
38 return;
39
40 assert (range_to_add.second >= range_to_add.first);
41 start_ = std::min (start_, range_to_add.first);
42 end_ = std::max (end_, range_to_add.second);
43 }
44
45 void expand_to_full ()
46 {
47 is_full_content_ = true;
48 start_ = 0;
49 end_ = 0;
50 }
51
52 void expand (const ExpandableTickRange &range_to_add)
53 {
54 if (range_to_add.is_full_content ())
55 {
56 expand_to_full ();
57 }
58 else
59 {
60 expand (range_to_add.range ().value ());
61 }
62 }
63
67 auto range () const -> std::optional<std::pair<double, double>>
68 {
69 if (is_full_content ())
70 {
71 return std::nullopt;
72 }
73
74 return std::make_pair (start_, end_);
75 }
76
77private:
78 double start_{};
79 double end_{};
80 bool is_full_content_{ true };
81};
82
83auto
84format_as (const ExpandableTickRange &range) -> std::string;
85}
86
87Q_DECLARE_METATYPE (zrythm::utils::ExpandableTickRange)
bool is_full_content() const
Returns whether the range is the full content (ie, there is no range).
void expand(std::pair< double, double > range_to_add)
Expands to the given range.
auto range() const -> std::optional< std::pair< double, double > >
Returns the range, or nullopt if the full content is covered.
String utilities.