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/note_type.h"
7#include "dsp/transport.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
18using namespace std::string_view_literals;
19
20namespace zrythm::gui::old_dsp
21{
22
23class QuantizeOptions final
24{
25public:
26 static constexpr auto MAX_SNAP_POINTS = 120096;
27 using NoteLength = dsp::notes::NoteLength;
28 using NoteType = dsp::notes::NoteType;
29
30public:
31 QuantizeOptions () = default;
32 QuantizeOptions (NoteLength note_length) { init (note_length); }
33
34 void init (NoteLength note_length);
35
40
41 float get_swing () const;
42
43 float get_amount () const;
44
45 float get_randomization () const;
46
47 void set_swing (float swing);
48
49 void set_amount (float amount);
50
51 void set_randomization (float randomization);
52
57 to_string (NoteLength note_length, NoteType note_type);
58
70 std::pair<units::precise_tick_t, double>
71 quantize_position (units::precise_tick_t pos);
72
73private:
74 static constexpr auto kNoteLengthKey = "noteLength"sv;
75 static constexpr auto kNoteTypeKey = "noteType"sv;
76 static constexpr auto kAdjustStartKey = "adjustStart"sv;
77 static constexpr auto kAdjustEndKey = "adjustEnd"sv;
78 static constexpr auto kAmountKey = "amount"sv;
79 static constexpr auto kSwingKey = "swing"sv;
80 static constexpr auto kRandomizationTicksKey = "randTicks"sv;
81 friend void to_json (nlohmann::json &j, const QuantizeOptions &p);
82 friend void from_json (const nlohmann::json &j, QuantizeOptions &p);
83
84 units::precise_tick_t get_prev_point (units::precise_tick_t pos) const;
85 units::precise_tick_t get_next_point (units::precise_tick_t pos) const;
86
87public:
96 std::vector<units::precise_tick_t> q_points_;
97
99 NoteLength note_length_{};
100
102 NoteType note_type_{};
103
105 float amount_ = 100.f;
106
108 bool adjust_start_ = true;
109
111 bool adjust_end_ = false;
112
114 float swing_ = 0.f;
115
118
119 PCGRand rand_;
120};
121
122}; // 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:37