Zrythm v2.0.0-alpha.1
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
quantize_options.h
1// SPDX-FileCopyrightText: © 2019-2021, 2024-2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "dsp/note_type.h"
7#include "dsp/transport.h"
8#include "utils/pcg_rand.h"
9#include "utils/units.h"
10#include "utils/utf8_string.h"
11
12#define QUANTIZE_OPTIONS_IS_EDITOR(qo) \
13 (PROJECT->quantize_opts_editor_.get () == qo)
14#define QUANTIZE_OPTIONS_IS_TIMELINE(qo) \
15 (PROJECT->quantize_opts_timeline_.get () == qo)
16#define QUANTIZE_OPTIONS_TIMELINE (PROJECT->quantize_opts_timeline_)
17#define QUANTIZE_OPTIONS_EDITOR (PROJECT->quantize_opts_editor_)
18
19using namespace std::string_view_literals;
20
21namespace zrythm::gui::old_dsp
22{
23
24class QuantizeOptions final
25{
26public:
27 static constexpr auto MAX_SNAP_POINTS = 120096;
28 using NoteLength = dsp::notes::NoteLength;
29 using NoteType = dsp::notes::NoteType;
30
31public:
32 QuantizeOptions () = default;
33 QuantizeOptions (NoteLength note_length) { init (note_length); }
34
35 void init (NoteLength note_length);
36
41
42 float get_swing () const;
43
44 float get_amount () const;
45
46 float get_randomization () const;
47
48 void set_swing (float swing);
49
50 void set_amount (float amount);
51
52 void set_randomization (float randomization);
53
58 to_string (NoteLength note_length, NoteType note_type);
59
71 std::pair<units::precise_tick_t, double>
72 quantize_position (units::precise_tick_t pos);
73
74private:
75 static constexpr auto kNoteLengthKey = "noteLength"sv;
76 static constexpr auto kNoteTypeKey = "noteType"sv;
77 static constexpr auto kAdjustStartKey = "adjustStart"sv;
78 static constexpr auto kAdjustEndKey = "adjustEnd"sv;
79 static constexpr auto kAmountKey = "amount"sv;
80 static constexpr auto kSwingKey = "swing"sv;
81 static constexpr auto kRandomizationTicksKey = "randTicks"sv;
82 friend void to_json (nlohmann::json &j, const QuantizeOptions &p);
83 friend void from_json (const nlohmann::json &j, QuantizeOptions &p);
84
85 units::precise_tick_t get_prev_point (units::precise_tick_t pos) const;
86 units::precise_tick_t get_next_point (units::precise_tick_t pos) const;
87
88public:
97 std::vector<units::precise_tick_t> q_points_;
98
100 NoteLength note_length_{};
101
103 NoteType note_type_{};
104
106 float amount_ = 100.f;
107
109 bool adjust_start_ = true;
110
112 bool adjust_end_ = false;
113
115 float swing_ = 0.f;
116
119
120 PCGRand rand_;
121};
122
123}; // 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:48
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:37