Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
quantize_options.h
1// SPDX-FileCopyrightText: © 2019-2021, 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "utils/note_type.h"
7#include "utils/pcg_rand.h"
8#include "utils/units.h"
9
10#define QUANTIZE_OPTIONS_IS_EDITOR(qo) \
11 (PROJECT->quantize_opts_editor_.get () == qo)
12#define QUANTIZE_OPTIONS_IS_TIMELINE(qo) \
13 (PROJECT->quantize_opts_timeline_.get () == qo)
14#define QUANTIZE_OPTIONS_TIMELINE (PROJECT->quantize_opts_timeline_)
15#define QUANTIZE_OPTIONS_EDITOR (PROJECT->quantize_opts_editor_)
16
17namespace zrythm::engine::session
18{
19class Transport;
20}
21
22namespace zrythm::gui::old_dsp
23{
24
25class QuantizeOptions final
26{
27public:
28 static constexpr auto MAX_SNAP_POINTS = 120096;
29 using NoteLength = utils::NoteLength;
30 using NoteType = utils::NoteType;
31
32public:
33 QuantizeOptions () = default;
34 QuantizeOptions (NoteLength note_length) { init (note_length); }
35
36 void init (NoteLength note_length);
37
42
43 float get_swing () const;
44
45 float get_amount () const;
46
47 float get_randomization () const;
48
49 void set_swing (float swing);
50
51 void set_amount (float amount);
52
53 void set_randomization (float randomization);
54
59 to_string (NoteLength note_length, NoteType note_type);
60
72 std::pair<units::precise_tick_t, double>
73 quantize_position (units::precise_tick_t pos);
74
75private:
76 static constexpr auto kNoteLengthKey = "noteLength"sv;
77 static constexpr auto kNoteTypeKey = "noteType"sv;
78 static constexpr auto kAdjustStartKey = "adjustStart"sv;
79 static constexpr auto kAdjustEndKey = "adjustEnd"sv;
80 static constexpr auto kAmountKey = "amount"sv;
81 static constexpr auto kSwingKey = "swing"sv;
82 static constexpr auto kRandomizationTicksKey = "randTicks"sv;
83 friend void to_json (nlohmann::json &j, const QuantizeOptions &p)
84 {
85 j = nlohmann::json{
86 { kNoteLengthKey, p.note_length_ },
87 { kNoteTypeKey, p.note_type_ },
88 { kAdjustStartKey, p.adjust_start_ },
89 { kAdjustEndKey, p.adjust_end_ },
90 { kAmountKey, p.amount_ },
91 { kSwingKey, p.swing_ },
92 { kRandomizationTicksKey, p.randomization_ticks_ },
93 };
94 }
95 friend void from_json (const nlohmann::json &j, QuantizeOptions &p)
96 {
97 j.at (kNoteLengthKey).get_to (p.note_length_);
98 j.at (kNoteTypeKey).get_to (p.note_type_);
99 j.at (kAdjustStartKey).get_to (p.adjust_start_);
100 j.at (kAdjustEndKey).get_to (p.adjust_end_);
101 j.at (kAmountKey).get_to (p.amount_);
102 j.at (kSwingKey).get_to (p.swing_);
103 j.at (kRandomizationTicksKey).get_to (p.randomization_ticks_);
104 }
105
106 units::precise_tick_t get_prev_point (units::precise_tick_t pos) const;
107 units::precise_tick_t get_next_point (units::precise_tick_t pos) const;
108
109public:
118 std::vector<units::precise_tick_t> q_points_;
119
121 NoteLength note_length_{};
122
124 NoteType note_type_{};
125
127 float amount_ = 100.f;
128
130 bool adjust_start_ = true;
131
133 bool adjust_end_ = false;
134
136 float swing_ = 0.f;
137
140
141 PCGRand rand_;
142};
143
144}; // namespace zrythm::dsp
Random number generator.
Definition pcg_rand.h:12
The Transport class represents the transport controls and state for an audio engine.
Definition transport.h:45
void update_quantize_points(const zrythm::dsp::Transport &transport)
Updates snap points.
std::vector< units::precise_tick_t > q_points_
Quantize points.
double randomization_ticks_
Number of ticks for randomization.
bool adjust_end_
Adjust end position or not (only applies to objects with length.
std::pair< units::precise_tick_t, double > quantize_position(units::precise_tick_t pos)
Quantizes the given Position using the given QuantizeOptions.
float amount_
Percentage to apply quantize (0-100).
static utils::Utf8String to_string(NoteLength note_length, NoteType note_type)
Returns the grid intensity as a human-readable string.
bool adjust_start_
Adjust start position or not (only applies to objects with length.
Lightweight UTF-8 string wrapper with safe conversions.
Definition utf8_string.h:38