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 "dsp/transport.h"
7#include "utils/note_type.h"
8#include "utils/pcg_rand.h"
9#include "utils/units.h"
10
11#define QUANTIZE_OPTIONS_IS_EDITOR(qo) \
12 (PROJECT->quantize_opts_editor_.get () == qo)
13#define QUANTIZE_OPTIONS_IS_TIMELINE(qo) \
14 (PROJECT->quantize_opts_timeline_.get () == qo)
15#define QUANTIZE_OPTIONS_TIMELINE (PROJECT->quantize_opts_timeline_)
16#define QUANTIZE_OPTIONS_EDITOR (PROJECT->quantize_opts_editor_)
17
18namespace zrythm::gui::old_dsp
19{
20
21class QuantizeOptions final
22{
23public:
24 static constexpr auto MAX_SNAP_POINTS = 120096;
25 using NoteLength = utils::NoteLength;
26 using NoteType = utils::NoteType;
27
28public:
29 QuantizeOptions () = default;
30 QuantizeOptions (NoteLength note_length) { init (note_length); }
31
32 void init (NoteLength note_length);
33
38
39 float get_swing () const;
40
41 float get_amount () const;
42
43 float get_randomization () const;
44
45 void set_swing (float swing);
46
47 void set_amount (float amount);
48
49 void set_randomization (float randomization);
50
55 to_string (NoteLength note_length, NoteType note_type);
56
68 std::pair<units::precise_tick_t, double>
69 quantize_position (units::precise_tick_t pos);
70
71private:
72 static constexpr auto kNoteLengthKey = "noteLength"sv;
73 static constexpr auto kNoteTypeKey = "noteType"sv;
74 static constexpr auto kAdjustStartKey = "adjustStart"sv;
75 static constexpr auto kAdjustEndKey = "adjustEnd"sv;
76 static constexpr auto kAmountKey = "amount"sv;
77 static constexpr auto kSwingKey = "swing"sv;
78 static constexpr auto kRandomizationTicksKey = "randTicks"sv;
79 friend void to_json (nlohmann::json &j, const QuantizeOptions &p)
80 {
81 j = nlohmann::json{
82 { kNoteLengthKey, p.note_length_ },
83 { kNoteTypeKey, p.note_type_ },
84 { kAdjustStartKey, p.adjust_start_ },
85 { kAdjustEndKey, p.adjust_end_ },
86 { kAmountKey, p.amount_ },
87 { kSwingKey, p.swing_ },
88 { kRandomizationTicksKey, p.randomization_ticks_ },
89 };
90 }
91 friend void from_json (const nlohmann::json &j, QuantizeOptions &p)
92 {
93 j.at (kNoteLengthKey).get_to (p.note_length_);
94 j.at (kNoteTypeKey).get_to (p.note_type_);
95 j.at (kAdjustStartKey).get_to (p.adjust_start_);
96 j.at (kAdjustEndKey).get_to (p.adjust_end_);
97 j.at (kAmountKey).get_to (p.amount_);
98 j.at (kSwingKey).get_to (p.swing_);
99 j.at (kRandomizationTicksKey).get_to (p.randomization_ticks_);
100 }
101
102 units::precise_tick_t get_prev_point (units::precise_tick_t pos) const;
103 units::precise_tick_t get_next_point (units::precise_tick_t pos) const;
104
105public:
114 std::vector<units::precise_tick_t> q_points_;
115
117 NoteLength note_length_{};
118
120 NoteType note_type_{};
121
123 float amount_ = 100.f;
124
126 bool adjust_start_ = true;
127
129 bool adjust_end_ = false;
130
132 float swing_ = 0.f;
133
136
137 PCGRand rand_;
138};
139
140}; // 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