6#include "structure/tracks/automatable_track.h"
7#include "utils/types.h"
9#define P_TEMPO_TRACK (TRACKLIST->getTempoTrack ())
11namespace zrythm::structure::tracks
13constexpr float TEMPO_TRACK_MAX_BPM = 420.f;
14constexpr float TEMPO_TRACK_MIN_BPM = 40.f;
15constexpr float TEMPO_TRACK_DEFAULT_BPM = 140.f;
16constexpr int TEMPO_TRACK_DEFAULT_BEATS_PER_BAR = 4;
17constexpr int TEMPO_TRACK_MIN_BEATS_PER_BAR = 1;
18constexpr int TEMPO_TRACK_MAX_BEATS_PER_BAR = 16;
19constexpr auto TEMPO_TRACK_DEFAULT_BEAT_UNIT = BeatUnit::Four;
20constexpr auto TEMPO_TRACK_MIN_BEAT_UNIT = BeatUnit::Two;
21constexpr auto TEMPO_TRACK_MAX_BEAT_UNIT = BeatUnit::Sixteen;
32 public AutomatableTrack,
38 DEFINE_AUTOMATABLE_TRACK_QML_PROPERTIES (
TempoTrack)
39 Q_PROPERTY (
double bpm READ getBpm WRITE setBpm NOTIFY bpmChanged FINAL)
41 friend class InitializableObject;
50 double getBpm ()
const;
51 void setBpm (
double bpm);
52 Q_SIGNAL
void bpmChanged (
double bpm);
53 Q_INVOKABLE
int getBeatUnit ()
const;
54 Q_INVOKABLE
int getBeatsPerBar ()
const;
66 init_loaded (PluginRegistry &plugin_registry, PortRegistry &port_registry)
74 friend void init_from (
84 std::string get_current_bpm_as_str ()
const;
85 void set_bpm_from_str (
const std::string &str);
100 static constexpr int beat_unit_enum_to_int (
BeatUnit ebeat_unit)
108 case BeatUnit::Eight:
110 case BeatUnit::Sixteen:
113 z_return_val_if_reached (0);
117 void set_beat_unit_from_enum (
BeatUnit ebeat_unit);
119 BeatUnit get_beat_unit_enum ()
const
121 return beat_unit_to_enum (get_beat_unit ());
124 static BeatUnit beat_unit_to_enum (
int beat_unit);
126 void set_beat_unit (
int beat_unit);
133 int get_beats_per_bar ()
const;
135 int get_beat_unit ()
const;
138 const PortUuid &port_uuid,
140 float value)
override;
143 append_ports (std::vector<Port *> &ports,
bool include_plugins)
const final;
147 return *std::get<ControlPort *> (bpm_port_->get_object ());
151 return *std::get<ControlPort *> (beats_per_bar_port_->get_object ());
155 return *std::get<ControlPort *> (beat_unit_port_->get_object ());
159 static constexpr auto kBpmPortKey =
"bpmPort"sv;
160 static constexpr auto kBeatsPerBarPortKey =
"beatsPerBarPort"sv;
161 static constexpr auto kBeatUnitPortKey =
"beatUnitPort"sv;
162 friend void to_json (nlohmann::json &j,
const TempoTrack &track)
164 to_json (j,
static_cast<const Track &
> (track));
165 to_json (j,
static_cast<const AutomatableTrack &
> (track));
166 j[kBpmPortKey] = track.bpm_port_;
167 j[kBeatsPerBarPortKey] = track.beats_per_bar_port_;
168 j[kBeatUnitPortKey] = track.beat_unit_port_;
170 friend void from_json (
const nlohmann::json &j, TempoTrack &track)
172 from_json (j,
static_cast<Track &
> (track));
173 from_json (j,
static_cast<AutomatableTrack &
> (track));
174 j.at (kBpmPortKey).get_to (track.bpm_port_);
175 j.at (kBeatsPerBarPortKey).get_to (track.beats_per_bar_port_);
176 j.at (kBeatUnitPortKey).get_to (track.beat_unit_port_);
182 PortRegistry &port_registry_;
185 std::optional<PortUuidReference> bpm_port_;
188 std::optional<PortUuidReference> beats_per_bar_port_;
191 std::optional<PortUuidReference> beat_unit_port_;
Struct used to identify Ports in the project.
Represents a track that controls the tempo of the audio.
void clear_objects() override
Removes all objects from the tempo track.
void on_control_change_event(const PortUuid &port_uuid, const dsp::PortIdentifier &id, float value) override
Will be called when a control port's value changes.
void set_beats_per_bar(int beats_per_bar)
Updates beat unit and anything depending on it.
bpm_t get_current_bpm() const
Returns the current BPM.
void init_loaded(PluginRegistry &plugin_registry, PortRegistry &port_registry) override
Adds additional metadata to track members after deserialization.
void set_bpm(bpm_t bpm, bpm_t start_bpm, bool temporary, bool fire_events)
Sets the BPM.
void append_ports(std::vector< Port * > &ports, bool include_plugins) const final
Appends all channel ports and optionally plugin ports to the array.
bpm_t get_bpm_at_pos(Position pos)
Returns the BPM at the given pos.
A factory class for creating initializable objects using static polymorphism.