Zrythm v2.0.0-alpha.1
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
audio_clip.h
1// SPDX-FileCopyrightText: © 2019-2022, 2024-2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "dsp/timestretch_engine.h"
7#include "structure/arrangement/arranger_object_owner.h"
8#include "structure/arrangement/audio_source_object.h"
9#include "structure/arrangement/clip.h"
10#include "structure/arrangement/fadeable_object.h"
11
12#include <juce_audio_basics/juce_audio_basics.h>
13
14namespace zrythm::structure::arrangement
15{
16
23class AudioClip final : public Clip, public ArrangerObjectOwner<AudioSourceObject>
24{
25 Q_OBJECT
26 Q_PROPERTY (double sourceBpm READ sourceBpm CONSTANT)
27 Q_PROPERTY (
28 zrythm::dsp::StretchOptions::Algorithm stretchAlgorithm READ
29 stretchAlgorithm WRITE setStretchAlgorithm NOTIFY stretchAlgorithmChanged)
30 Q_PROPERTY (float gain READ gain WRITE setGain NOTIFY gainChanged)
31 Q_PROPERTY (
33 fadeRange CONSTANT)
34 DEFINE_ARRANGER_OBJECT_OWNER_QML_PROPERTIES (
35 AudioClip,
36 audioSources,
38 QML_ELEMENT
39 QML_UNCREATABLE ("")
40
41public:
42 static constexpr int BUILTIN_FADE_FRAMES = 10;
43
44 AudioClip (
45 const dsp::TempoMapWrapper &tempo_map_wrapper,
46 utils::IObjectRegistry &object_registry,
47 QObject * parent = nullptr) noexcept;
48
49 ArrangerObjectFadeRange * fadeRange () const { return fade_range_.get (); }
50
51 [[nodiscard]] dsp::StretchOptions::Algorithm stretchAlgorithm () const
52 {
53 return algorithm_;
54 }
55 void setStretchAlgorithm (dsp::StretchOptions::Algorithm a);
56 Q_SIGNAL void stretchAlgorithmChanged (dsp::StretchOptions::Algorithm a);
57
59 effectiveStretchAlgorithm () const
60 {
61 return algorithm_;
62 }
63
64 double sourceBpm () const;
65
66 float gain () const { return gain_.load (); }
67 void setGain (float gain)
68 {
69 gain = std::clamp (gain, 0.f, 2.f);
70 if (qFuzzyCompare (gain_, gain))
71 return;
72 gain_.store (gain);
73 Q_EMIT gainChanged (gain);
74 }
75 Q_SIGNAL void gainChanged (float gain);
76
77 void set_source (const ArrangerObjectUuidReference &source);
78
79 juce::PositionableAudioSource &get_audio_source () const;
80
81 std::string
82 get_field_name_for_serialization (const AudioSourceObject *) const override
83 {
84 return "audioSources";
85 }
86
87 std::vector<ArrangerObjectListModel *> get_child_list_models () const override
88 {
89 return { ArrangerObjectOwner<AudioSourceObject>::get_model () };
90 }
91
92 void shift_all_children (dsp::ContentTick delta) override;
93
94 std::optional<dsp::ContentTick> first_child_position () const override;
95
96private:
97 friend void init_from (
98 AudioClip &obj,
99 const AudioClip &other,
100 utils::ObjectCloneType clone_type);
101
102 void init_length_from_clip ();
103 void update_warp_configuration ();
104
105 static constexpr auto kGainKey = "gain"sv;
106 static constexpr auto kAlgorithmKey = "stretchAlgorithm"sv;
107 static constexpr auto kFadeRangeKey = "fadeRange"sv;
108 friend void to_json (nlohmann::json &j, const AudioClip &clip);
109 friend void from_json (const nlohmann::json &j, AudioClip &clip);
110
111 std::atomic<float> gain_ = 1.0f;
113 dsp::StretchOptions::Algorithm::Polyphonic
114 };
116
117 BOOST_DESCRIBE_CLASS (AudioClip, (Clip), (), (), (gain_, algorithm_))
118};
119
120} // namespace zrythm::structure::arrangement
virtual std::optional< dsp::ContentTick > first_child_position() const =0
Returns the position of the first child, if any.
Abstract interface for a UUID-keyed object registry.
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:36
Algorithm
Material-aware timestretch algorithm.