Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
|
The Transport class represents the transport controls and state for an audio engine. More...
#include <src/engine/session/transport.h>
Public Types | |
enum class | Display { BBT , Time } |
Corrseponts to "transport-display" in the gsettings. More... | |
enum class | RecordingMode { OverwriteEvents , MergeEvents , Takes , TakesMuted } |
Recording mode for MIDI and audio. More... | |
using | Position = zrythm::dsp::Position |
using | PortIdentifier = zrythm::dsp::PortIdentifier |
using | PortFlow = zrythm::dsp::PortFlow |
![]() | |
enum class | PlayState { RollRequested , Rolling , PauseRequested , Paused } |
![]() | |
using | TrackUuid = dsp::PortIdentifier::TrackUuid |
using | PluginUuid = dsp::PortIdentifier::PluginUuid |
using | PortUuid = dsp::PortIdentifier::PortUuid |
Public Member Functions | |
Transport (Project *parent=nullptr) | |
void | setLoopEnabled (bool enabled) |
Q_SIGNAL void | loopEnabledChanged (bool enabled) |
void | setRecordEnabled (bool enabled) |
Q_SIGNAL void | recordEnabledChanged (bool enabled) |
PlayState | getPlayState () const |
void | setPlayState (PlayState state) |
Q_SIGNAL void | playStateChanged (PlayState state) |
dsp::PlayheadQmlWrapper * | getPlayhead () const |
PositionProxy * | getCuePosition () const |
PositionProxy * | getLoopStartPosition () const |
PositionProxy * | getLoopEndPosition () const |
PositionProxy * | getPunchInPosition () const |
PositionProxy * | getPunchOutPosition () const |
Q_INVOKABLE void | moveBackward () |
Q_INVOKABLE void | moveForward () |
void | set_port_metadata_from_owner (dsp::PortIdentifier &id, PortRange &range) const override |
Function that will be called by the Port to update the identifier's relevant members based on this port owner. | |
utils::Utf8String | get_full_designation_for_port (const dsp::PortIdentifier &id) const override |
Q_INVOKABLE bool | isRolling () const |
Q_INVOKABLE bool | isPaused () const |
bool | is_looping () const |
bool | is_recording () const |
void | init_loaded (Project *project) |
Initialize loaded transport. | |
void | prepare_audio_regions_for_stretch (std::optional< structure::arrangement::ArrangerObjectSpan > sel_var) |
Prepares audio regions for stretching (sets the Region.before_length). | |
void | stretch_regions (std::optional< structure::arrangement::ArrangerObjectSpan > sel_var, bool with_fixed_ratio, double time_ratio, bool force) |
Stretches regions. | |
void | set_punch_mode_enabled (bool enabled) |
void | set_start_playback_on_midi_input (bool enabled) |
void | set_recording_mode (RecordingMode mode) |
void | set_metronome_enabled (bool enabled) |
Sets whether metronome is enabled or not. | |
void | add_to_playhead_in_audio_thread (signed_frame_t nframes) |
Moves the playhead by the time corresponding to given samples, taking into account the loop end point. | |
Q_INVOKABLE void | requestPause (bool with_wait) |
Request pause. | |
Q_INVOKABLE void | requestRoll (bool with_wait) |
Request playback. | |
void | set_play_state_rt_safe (PlayState state) |
signed_frame_t | get_playhead_position_in_audio_thread () const override |
Get the playhead position. | |
Position | get_playhead_position_in_gui_thread () const |
nframes_t | is_loop_point_met_in_audio_thread (const signed_frame_t g_start_frames, const nframes_t nframes) const override |
Returns the number of processable frames until and excluding the loop end point as a positive number (>= 1) if the loop point was met between g_start_frames and (g_start_frames + nframes), otherwise returns 0;. | |
void | move_backward (bool with_wait) |
Move to the previous snap point on the timeline. | |
void | move_forward (bool with_wait) |
Move to the next snap point on the timeline. | |
bool | can_user_move_playhead () const |
Returns whether the user can currently move the playhead (eg, via the UI or via scripts). | |
void | move_playhead (double target_ticks, bool panic, bool set_cue_point, bool fire_events) |
Moves playhead to given pos. | |
void | set_loop (bool enabled, bool with_wait) |
Enables or disables loop. | |
void | goto_start_marker () |
Moves the playhead to the start Marker. | |
void | goto_end_marker () |
Moves the playhead to the end Marker. | |
void | goto_prev_marker () |
Moves the playhead to the prev Marker. | |
void | goto_next_marker () |
Moves the playhead to the next Marker. | |
void | update_positions (bool update_from_ticks) |
Updates the frames in all transport positions. | |
signed_frame_t | get_playhead_position_after_adding_frames_in_audio_thread (signed_frame_t frames) const override |
Gets the playhead position, similarly to get_playhead_position(), except that it adjusts the new position if the loop end point was crossed. | |
double | get_ppqn () const |
Returns the PPQN (Parts/Ticks Per Quarter Note). | |
std::pair< Position, Position > | get_range_positions () const |
Returns the selected range positions. | |
std::pair< signed_frame_t, signed_frame_t > | get_loop_range_positions () const override |
Returns the loop range positions in samples. | |
PlayState | get_play_state () const override |
void | set_has_range (bool has_range) |
Sets if the project has range and updates UI. | |
void | set_range (bool range1, const Position *start_pos, const Position *pos, bool snap) |
Set the range1 or range2 position. | |
void | set_loop_range (bool start, const Position *start_pos, const Position *pos, bool snap) |
Set the loop range. | |
bool | position_is_inside_punch_range (Position pos) |
bool | get_loop_enabled () const override |
void | recalculate_total_bars (std::optional< structure::arrangement::ArrangerObjectSpan > objects=std::nullopt) |
Recalculates the total bars based on the last object's position. | |
void | update_total_bars (int total_bars, bool fire_events) |
Updates the total bars. | |
void | update_caches (int beats_per_bar, int beat_unit) |
void | set_recording (bool record, bool with_wait) |
Sets recording on/off. | |
![]() | |
virtual void | on_control_change_event (const PortUuid &port_uuid, const dsp::PortIdentifier &id, float val) |
Will be called when a control port's value changes. | |
virtual void | on_midi_activity (const dsp::PortIdentifier &id) |
Called during processing if the MIDI port contains new MIDI events. | |
virtual bool | should_sum_data_from_backend () const |
Whether during processing, the port should sum the data from its backend buffers coming in. | |
virtual bool | should_bounce_to_master (utils::audio::BounceStep step) const |
Whether the port should add its data to the master output when bouncing. | |
virtual bool | are_events_on_midi_channel_approved (midi_byte_t channel) const |
Returns whether MIDI events on this channel on an input port should be processed (not ignored). | |
Static Public Member Functions | |
static const char * | preroll_count_to_str (PrerollCountBars bars) |
static int | preroll_count_bars_enum_to_int (PrerollCountBars bars) |
Data Fields | |
int | total_bars_ = 0 |
Total bars in the song. | |
dsp::Playhead | playhead_ |
Playhead position. | |
utils::QObjectUniquePtr< dsp::PlayheadQmlWrapper > | playhead_adapter_ |
PositionProxy * | cue_pos_ = nullptr |
Cue point position. | |
PositionProxy * | loop_start_pos_ = nullptr |
Loop start position. | |
PositionProxy * | loop_end_pos_ = nullptr |
Loop end position. | |
PositionProxy * | punch_in_pos_ = nullptr |
Punch in position. | |
PositionProxy * | punch_out_pos_ = nullptr |
Punch out position. | |
Position | range_1_ |
Selected range. | |
Position | range_2_ |
bool | has_range_ = false |
Whether range should be displayed or not. | |
int | ticks_per_beat_ = 0 |
int | ticks_per_bar_ = 0 |
int | sixteenths_per_beat_ = 0 |
int | sixteenths_per_bar_ = 0 |
nframes_t | position_ = 0 |
Transport position in frames. | |
bool | loop_ = false |
Looping or not. | |
bool | punch_mode_ = false |
Whether punch in/out mode is enabled. | |
bool | recording_ = false |
Whether MIDI/audio recording is enabled (recording toggle in transport bar). | |
bool | metronome_enabled_ = false |
Metronome enabled or not. | |
signed_frame_t | preroll_frames_remaining_ = 0 |
Recording preroll frames remaining. | |
signed_frame_t | countin_frames_remaining_ = 0 |
Metronome countin frames remaining. | |
bool | start_playback_on_midi_input_ = false |
Whether to start playback on MIDI input. | |
RecordingMode | recording_mode_ = (RecordingMode) 0 |
double | playhead_before_pause_ {} |
Position of the playhead before pausing, in ticks. | |
std::unique_ptr< MidiPort > | roll_ |
Roll/play MIDI port. | |
std::unique_ptr< MidiPort > | stop_ |
Stop MIDI port. | |
std::unique_ptr< MidiPort > | backward_ |
Backward MIDI port. | |
std::unique_ptr< MidiPort > | forward_ |
Forward MIDI port. | |
std::unique_ptr< MidiPort > | loop_toggle_ |
Loop toggle MIDI port. | |
std::unique_ptr< MidiPort > | rec_toggle_ |
Rec toggle MIDI port. | |
PlayState | play_state_ = {} |
Play state. | |
RtTimePoint | last_manual_playhead_change_ = 0 |
Last timestamp the playhead position was changed manually. | |
Project * | project_ = nullptr |
Pointer to owner, if any. | |
Properties | |
QML_ELEMENT bool | loopEnabled |
bool | recordEnabled |
PlayState | playState |
dsp::PlayheadQmlWrapper * | playhead |
PositionProxy * | cuePosition |
PositionProxy * | loopStartPosition |
PositionProxy * | loopEndPosition |
PositionProxy * | punchInPosition |
PositionProxy * | punchOutPosition |
Friends | |
void | init_from (Transport &obj, const Transport &other, utils::ObjectCloneType clone_type) |
void | to_json (nlohmann::json &j, const Transport &transport) |
void | from_json (const nlohmann::json &j, Transport &transport) |
The Transport class represents the transport controls and state for an audio engine.
It manages playback, recording, and other transport-related functionality.
Definition at line 48 of file transport.h.
using zrythm::engine::session::Transport::PortFlow = zrythm::dsp::PortFlow |
Definition at line 128 of file transport.h.
Definition at line 127 of file transport.h.
Definition at line 126 of file transport.h.
|
strong |
Corrseponts to "transport-display" in the gsettings.
Definition at line 76 of file transport.h.
|
strong |
Recording mode for MIDI and audio.
In all cases, only objects created during the current recording cycle can be changed. Previous objects shall not be touched.
Definition at line 89 of file transport.h.
|
overridevirtual |
Reimplemented from IPortOwner.
|
inlineoverridevirtual |
Implements zrythm::dsp::ITransport.
Definition at line 438 of file transport.h.
|
overridevirtual |
Returns the loop range positions in samples.
Implements zrythm::dsp::ITransport.
|
inlineoverridevirtual |
Implements zrythm::dsp::ITransport.
Definition at line 407 of file transport.h.
|
overridevirtual |
Gets the playhead position, similarly to get_playhead_position(), except that it adjusts the new position if the loop end point was crossed.
Implements zrythm::dsp::ITransport.
|
inlineoverridevirtual |
Get the playhead position.
Implements zrythm::dsp::ITransport.
Definition at line 284 of file transport.h.
void zrythm::engine::session::Transport::init_loaded | ( | Project * | project | ) |
Initialize loaded transport.
engine | Owner engine, if any. |
tempo_track | Tempo track, used to initialize the caches. Only needed on the active project transport. |
|
inlineoverridevirtual |
Returns the number of processable frames until and excluding the loop end point as a positive number (>= 1) if the loop point was met between g_start_frames and (g_start_frames + nframes), otherwise returns 0;.
Implements zrythm::dsp::ITransport.
Definition at line 294 of file transport.h.
|
inline |
Definition at line 201 of file transport.h.
|
inline |
Definition at line 203 of file transport.h.
|
inline |
Definition at line 196 of file transport.h.
|
inline |
Definition at line 191 of file transport.h.
void zrythm::engine::session::Transport::move_playhead | ( | double | target_ticks, |
bool | panic, | ||
bool | set_cue_point, | ||
bool | fire_events ) |
Moves playhead to given pos.
This is only for moves other than while playing and for looping while playing.
Should not be used during exporting.
target_ticks | Position to set to. |
panic | Send MIDI panic or not FIXME unused. |
set_cue_point | Also set the cue point at this position. |
void zrythm::engine::session::Transport::prepare_audio_regions_for_stretch | ( | std::optional< structure::arrangement::ArrangerObjectSpan > | sel_var | ) |
Prepares audio regions for stretching (sets the Region.before_length).
selections | If nullptr, all audio regions are used. If non-nullptr, only the regions in the selections are used. |
|
inlinestatic |
Definition at line 169 of file transport.h.
|
inlinestatic |
Definition at line 164 of file transport.h.
void zrythm::engine::session::Transport::recalculate_total_bars | ( | std::optional< structure::arrangement::ArrangerObjectSpan > | objects = std::nullopt | ) |
Recalculates the total bars based on the last object's position.
sel | If given, only these objects will be checked, otherwise every object in the project will be checked. |
FIXME: use signals to update the total bars.
Q_INVOKABLE void zrythm::engine::session::Transport::requestPause | ( | bool | with_wait | ) |
Request pause.
Must only be called in-between engine processing calls.
with_wait | Wait for lock before requesting. |
Q_INVOKABLE void zrythm::engine::session::Transport::requestRoll | ( | bool | with_wait | ) |
Request playback.
Must only be called in-between engine processing calls.
with_wait | Wait for lock before requesting. |
void zrythm::engine::session::Transport::set_loop_range | ( | bool | start, |
const Position * | start_pos, | ||
const Position * | pos, | ||
bool | snap ) |
Set the loop range.
start | True to set start pos, false to set end pos. |
|
overridevirtual |
Function that will be called by the Port to update the identifier's relevant members based on this port owner.
id | The identifier to update. |
Implements IPortOwner.
void zrythm::engine::session::Transport::set_range | ( | bool | range1, |
const Position * | start_pos, | ||
const Position * | pos, | ||
bool | snap ) |
Set the range1 or range2 position.
range1 | True to set range1, false to set range2. |
void zrythm::engine::session::Transport::stretch_regions | ( | std::optional< structure::arrangement::ArrangerObjectSpan > | sel_var, |
bool | with_fixed_ratio, | ||
double | time_ratio, | ||
bool | force ) |
Stretches regions.
selections | If nullptr, all regions are used. If non-nullptr, only the regions in the selections are used. |
with_fixed_ratio | Stretch all regions with a fixed ratio. If this is off, the current region length and Region.before_length will be used to calculate the ratio. |
force | Force stretching, regardless of musical mode. |
ZrythmException | if stretching fails. |
void zrythm::engine::session::Transport::update_positions | ( | bool | update_from_ticks | ) |
Updates the frames in all transport positions.
update_from_ticks | Whether to update the positions based on ticks (true) or frames (false). |
|
friend |
Definition at line 509 of file transport.h.
|
friend |
Definition at line 487 of file transport.h.
std::unique_ptr<MidiPort> zrythm::engine::session::Transport::backward_ |
Backward MIDI port.
Definition at line 639 of file transport.h.
signed_frame_t zrythm::engine::session::Transport::countin_frames_remaining_ = 0 |
Metronome countin frames remaining.
Definition at line 610 of file transport.h.
PositionProxy* zrythm::engine::session::Transport::cue_pos_ = nullptr |
Cue point position.
Definition at line 551 of file transport.h.
std::unique_ptr<MidiPort> zrythm::engine::session::Transport::forward_ |
Forward MIDI port.
Definition at line 642 of file transport.h.
bool zrythm::engine::session::Transport::has_range_ = false |
Whether range should be displayed or not.
Definition at line 577 of file transport.h.
RtTimePoint zrythm::engine::session::Transport::last_manual_playhead_change_ = 0 |
Last timestamp the playhead position was changed manually.
Definition at line 654 of file transport.h.
bool zrythm::engine::session::Transport::loop_ = false |
Looping or not.
Definition at line 594 of file transport.h.
PositionProxy* zrythm::engine::session::Transport::loop_end_pos_ = nullptr |
Loop end position.
Definition at line 557 of file transport.h.
PositionProxy* zrythm::engine::session::Transport::loop_start_pos_ = nullptr |
Loop start position.
Definition at line 554 of file transport.h.
std::unique_ptr<MidiPort> zrythm::engine::session::Transport::loop_toggle_ |
Loop toggle MIDI port.
Definition at line 645 of file transport.h.
bool zrythm::engine::session::Transport::metronome_enabled_ = false |
Metronome enabled or not.
Definition at line 604 of file transport.h.
PlayState zrythm::engine::session::Transport::play_state_ = {} |
Play state.
Definition at line 651 of file transport.h.
dsp::Playhead zrythm::engine::session::Transport::playhead_ |
Playhead position.
Definition at line 547 of file transport.h.
utils::QObjectUniquePtr<dsp::PlayheadQmlWrapper> zrythm::engine::session::Transport::playhead_adapter_ |
Definition at line 548 of file transport.h.
double zrythm::engine::session::Transport::playhead_before_pause_ {} |
Position of the playhead before pausing, in ticks.
Used by UndoableAction.
Definition at line 622 of file transport.h.
nframes_t zrythm::engine::session::Transport::position_ = 0 |
signed_frame_t zrythm::engine::session::Transport::preroll_frames_remaining_ = 0 |
Recording preroll frames remaining.
Definition at line 607 of file transport.h.
Project* zrythm::engine::session::Transport::project_ = nullptr |
Pointer to owner, if any.
Definition at line 657 of file transport.h.
PositionProxy* zrythm::engine::session::Transport::punch_in_pos_ = nullptr |
Punch in position.
Definition at line 560 of file transport.h.
bool zrythm::engine::session::Transport::punch_mode_ = false |
Whether punch in/out mode is enabled.
Definition at line 597 of file transport.h.
PositionProxy* zrythm::engine::session::Transport::punch_out_pos_ = nullptr |
Punch out position.
Definition at line 563 of file transport.h.
Position zrythm::engine::session::Transport::range_1_ |
Selected range.
This is 2 points instead of start/end because the 2nd point can be dragged past the 1st point so the order gets swapped.
Should be compared each time to see which one is first.
Definition at line 573 of file transport.h.
Position zrythm::engine::session::Transport::range_2_ |
Definition at line 574 of file transport.h.
std::unique_ptr<MidiPort> zrythm::engine::session::Transport::rec_toggle_ |
Rec toggle MIDI port.
Definition at line 648 of file transport.h.
bool zrythm::engine::session::Transport::recording_ = false |
Whether MIDI/audio recording is enabled (recording toggle in transport bar).
Definition at line 601 of file transport.h.
RecordingMode zrythm::engine::session::Transport::recording_mode_ = (RecordingMode) 0 |
Definition at line 615 of file transport.h.
std::unique_ptr<MidiPort> zrythm::engine::session::Transport::roll_ |
Roll/play MIDI port.
Any event received on this port will request a roll.
Definition at line 629 of file transport.h.
int zrythm::engine::session::Transport::sixteenths_per_bar_ = 0 |
Definition at line 585 of file transport.h.
int zrythm::engine::session::Transport::sixteenths_per_beat_ = 0 |
Definition at line 584 of file transport.h.
bool zrythm::engine::session::Transport::start_playback_on_midi_input_ = false |
Whether to start playback on MIDI input.
Definition at line 613 of file transport.h.
std::unique_ptr<MidiPort> zrythm::engine::session::Transport::stop_ |
Stop MIDI port.
Any event received on this port will request a stop/pause.
Definition at line 636 of file transport.h.
int zrythm::engine::session::Transport::ticks_per_bar_ = 0 |
Definition at line 583 of file transport.h.
int zrythm::engine::session::Transport::ticks_per_beat_ = 0 |
Definition at line 582 of file transport.h.
int zrythm::engine::session::Transport::total_bars_ = 0 |
Total bars in the song.
Definition at line 544 of file transport.h.
|
read |
Definition at line 62 of file transport.h.
|
readwrite |
Definition at line 52 of file transport.h.
|
read |
Definition at line 65 of file transport.h.
|
read |
Definition at line 63 of file transport.h.
|
read |
Definition at line 61 of file transport.h.
|
readwrite |
Definition at line 58 of file transport.h.
|
read |
Definition at line 66 of file transport.h.
|
read |
Definition at line 67 of file transport.h.
|
readwrite |
Definition at line 55 of file transport.h.