Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
Transport Class Referencefinal

The Transport class represents the transport controls and state for an audio engine. More...

#include <src/gui/dsp/transport.h>

Inheritance diagram for Transport:
Collaboration diagram for Transport:

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
 
- Public Types inherited from zrythm::dsp::ITransport
enum class  PlayState { RollRequested , Rolling , PauseRequested , Paused }
 
- Public Types inherited from IPortOwner
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)
 
PositionProxygetPlayheadPosition () const
 
PositionProxygetCuePosition () const
 
PositionProxygetLoopStartPosition () const
 
PositionProxygetLoopEndPosition () const
 
PositionProxygetPunchInPosition () const
 
PositionProxygetPunchOutPosition () const
 
Q_INVOKABLE void moveBackward ()
 
Q_INVOKABLE void moveForward ()
 
bool is_in_active_project () const override
 
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, const TempoTrack *tempo_track)
 Initialize loaded transport.
 
void prepare_audio_regions_for_stretch (std::optional< ArrangerObjectSpan > sel_var)
 Prepares audio regions for stretching (sets the Region.before_length).
 
void stretch_regions (std::optional< 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 (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_playhead_pos_rt_safe (Position pos)
 Setter for playhead Position.
 
void set_playhead_to_bar (int bar)
 
void set_play_state_rt_safe (PlayState state)
 
void get_playhead_pos (Position *pos)
 Getter for playhead Position.
 
Position get_playhead_position () const override
 
nframes_t is_loop_point_met (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 (const Position &target, 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.
 
void position_add_frames (Position &pos, signed_frame_t frames) const override
 Adds frames to the given position similar to Position::add_frames, 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, Positionget_range_positions () const
 Returns the selected range positions.
 
std::pair< Position, Positionget_loop_range_positions () const override
 Returns the loop range positions.
 
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< 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.
 
void init_after_cloning (const Transport &other, ObjectCloneType clone_type) override
 Initializes the cloned object.
 
Q_INVOKABLE QString getPlayheadPositionString (const TempoTrack *tempo_track) const
 
- Public Member Functions inherited from ICloneable< Transport >
std::unique_ptr< Transportclone_unique (ObjectCloneType clone_type=ObjectCloneType::Snapshot, Args &&... args) const
 
std::shared_ptr< Transportclone_shared (ObjectCloneType clone_type=ObjectCloneType::Snapshot, Args &&... args) const
 
Transportclone_raw_ptr (ObjectCloneType clone_type=ObjectCloneType::Snapshot, Args &&... args) const
 
Transportclone_qobject (QObject *parent, ObjectCloneType clone_type=ObjectCloneType::Snapshot, Args &&... args) const
 
QScopedPointer< Transportclone_unique_qobject (QObject *parent, ObjectCloneType clone_type=ObjectCloneType::Snapshot, Args &&... args) const
 
- Public Member Functions inherited from IPortOwner
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)
 
static void get_playhead_pos_static (Transport *self, Position *pos)
 

Data Fields

int total_bars_ = 0
 Total bars in the song.
 
PositionProxyplayhead_pos_ = nullptr
 Playhead position.
 
PositionProxycue_pos_ = nullptr
 Cue point position.
 
PositionProxyloop_start_pos_ = nullptr
 Loop start position.
 
PositionProxyloop_end_pos_ = nullptr
 Loop end position.
 
PositionProxypunch_in_pos_ = nullptr
 Punch in position.
 
PositionProxypunch_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
 
Position playhead_before_pause_
 Position of the playhead before pausing.
 
std::unique_ptr< MidiPortroll_
 Roll/play MIDI port.
 
std::unique_ptr< MidiPortstop_
 Stop MIDI port.
 
std::unique_ptr< MidiPortbackward_
 Backward MIDI port.
 
std::unique_ptr< MidiPortforward_
 Forward MIDI port.
 
std::unique_ptr< MidiPortloop_toggle_
 Loop toggle MIDI port.
 
std::unique_ptr< MidiPortrec_toggle_
 Rec toggle MIDI port.
 
PlayState play_state_ = {}
 Play state.
 
RtTimePoint last_manual_playhead_change_ = 0
 Last timestamp the playhead position was changed manually.
 
Projectproject_ = nullptr
 Pointer to owner, if any.
 
- Data Fields inherited from ICloneable< Transport >
friend Derived
 

Properties

QML_ELEMENT bool loopEnabled
 
bool recordEnabled
 
PlayState playState
 
PositionProxyplayheadPosition
 
PositionProxycuePosition
 
PositionProxyloopStartPosition
 
PositionProxyloopEndPosition
 
PositionProxypunchInPosition
 
PositionProxypunchOutPosition
 

Friends

void to_json (nlohmann::json &j, const Transport &transport)
 
void from_json (const nlohmann::json &j, Transport &transport)
 

Detailed Description

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 49 of file transport.h.

Member Typedef Documentation

◆ PortFlow

using Transport::PortFlow = zrythm::dsp::PortFlow

Definition at line 133 of file transport.h.

◆ PortIdentifier

◆ Position

Definition at line 131 of file transport.h.

Member Enumeration Documentation

◆ Display

enum class Transport::Display
strong

Corrseponts to "transport-display" in the gsettings.

Definition at line 81 of file transport.h.

◆ RecordingMode

enum class Transport::RecordingMode
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.

Enumerator
OverwriteEvents 

Overwrite events in first recorded region.

In the case of MIDI, this will remove existing MIDI notes during recording.

In the case of audio, this will act exactly the same as RECORDING_MODE_TAKES_MUTED.

MergeEvents 

Merge events in existing region.

In the case of MIDI, this will append MIDI notes.

In the case of audio, this will act exactly the same as RECORDING_MODE_TAKES.

Takes 

Events get put in new lanes each time recording starts/resumes (eg, when looping or entering/leaving the punch range).

TakesMuted 

Same as RECORDING_MODE_TAKES, except previous takes (since recording started) are muted.

Definition at line 94 of file transport.h.

Member Function Documentation

◆ get_full_designation_for_port()

utils::Utf8String Transport::get_full_designation_for_port ( const dsp::PortIdentifier & id) const
overridevirtual

Reimplemented from IPortOwner.

◆ get_loop_enabled()

bool Transport::get_loop_enabled ( ) const
inlineoverridevirtual

Implements zrythm::dsp::ITransport.

Definition at line 457 of file transport.h.

◆ get_loop_range_positions()

std::pair< Position, Position > Transport::get_loop_range_positions ( ) const
overridevirtual

Returns the loop range positions.

Implements zrythm::dsp::ITransport.

◆ get_play_state()

PlayState Transport::get_play_state ( ) const
inlineoverridevirtual

Implements zrythm::dsp::ITransport.

Definition at line 426 of file transport.h.

◆ get_playhead_pos_static()

static void Transport::get_playhead_pos_static ( Transport * self,
Position * pos )
inlinestatic

Definition at line 304 of file transport.h.

◆ get_playhead_position()

Position Transport::get_playhead_position ( ) const
inlineoverridevirtual

Implements zrythm::dsp::ITransport.

Definition at line 309 of file transport.h.

◆ init_after_cloning()

void Transport::init_after_cloning ( const Transport & other,
ObjectCloneType clone_type )
overridevirtual

Initializes the cloned object.

Note
Only final classes should implement this.
Exceptions
ZrythmExceptionIf the object could not be cloned.

Implements ICloneable< Transport >.

◆ init_loaded()

void Transport::init_loaded ( Project * project,
const TempoTrack * tempo_track )

Initialize loaded transport.

Parameters
engineOwner engine, if any.
tempo_trackTempo track, used to initialize the caches. Only needed on the active project transport.

◆ is_in_active_project()

bool Transport::is_in_active_project ( ) const
overridevirtual

Implements IPortOwner.

◆ is_loop_point_met()

nframes_t Transport::is_loop_point_met ( const signed_frame_t g_start_frames,
const nframes_t nframes ) const
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 314 of file transport.h.

◆ is_looping()

bool Transport::is_looping ( ) const
inline

Definition at line 208 of file transport.h.

◆ is_recording()

bool Transport::is_recording ( ) const
inline

Definition at line 210 of file transport.h.

◆ isPaused()

Q_INVOKABLE bool Transport::isPaused ( ) const
inline

Definition at line 203 of file transport.h.

◆ isRolling()

Q_INVOKABLE bool Transport::isRolling ( ) const
inline

Definition at line 198 of file transport.h.

◆ move_playhead()

void Transport::move_playhead ( const Position & target,
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.

Parameters
targetPosition to set to.
panicSend MIDI panic or not FIXME unused.
set_cue_pointAlso set the cue point at this position.

◆ position_add_frames()

void Transport::position_add_frames ( Position & pos,
signed_frame_t frames ) const
overridevirtual

Adds frames to the given position similar to Position::add_frames, except that it adjusts the new Position if the loop end point was crossed.

Implements zrythm::dsp::ITransport.

◆ prepare_audio_regions_for_stretch()

void Transport::prepare_audio_regions_for_stretch ( std::optional< ArrangerObjectSpan > sel_var)

Prepares audio regions for stretching (sets the Region.before_length).

Parameters
selectionsIf nullptr, all audio regions are used. If non-nullptr, only the regions in the selections are used.

◆ preroll_count_bars_enum_to_int()

static int Transport::preroll_count_bars_enum_to_int ( PrerollCountBars bars)
inlinestatic

Definition at line 174 of file transport.h.

◆ preroll_count_to_str()

static const char * Transport::preroll_count_to_str ( PrerollCountBars bars)
inlinestatic

Definition at line 169 of file transport.h.

◆ recalculate_total_bars()

void Transport::recalculate_total_bars ( std::optional< ArrangerObjectSpan > objects = std::nullopt)

Recalculates the total bars based on the last object's position.

Parameters
selIf given, only these objects will be checked, otherwise every object in the project will be checked.

FIXME: use signals to update the total bars.

◆ requestPause()

Q_INVOKABLE void Transport::requestPause ( bool with_wait)

Request pause.

Must only be called in-between engine processing calls.

Parameters
with_waitWait for lock before requesting.

◆ requestRoll()

Q_INVOKABLE void Transport::requestRoll ( bool with_wait)

Request playback.

Must only be called in-between engine processing calls.

Parameters
with_waitWait for lock before requesting.

◆ set_loop_range()

void Transport::set_loop_range ( bool start,
const Position * start_pos,
const Position * pos,
bool snap )

Set the loop range.

Parameters
startTrue to set start pos, false to set end pos.

◆ set_port_metadata_from_owner()

void Transport::set_port_metadata_from_owner ( dsp::PortIdentifier & id,
PortRange & range ) const
overridevirtual

Function that will be called by the Port to update the identifier's relevant members based on this port owner.

Parameters
idThe identifier to update.

Implements IPortOwner.

◆ set_range()

void Transport::set_range ( bool range1,
const Position * start_pos,
const Position * pos,
bool snap )

Set the range1 or range2 position.

Parameters
range1True to set range1, false to set range2.

◆ stretch_regions()

void Transport::stretch_regions ( std::optional< ArrangerObjectSpan > sel_var,
bool with_fixed_ratio,
double time_ratio,
bool force )

Stretches regions.

Parameters
selectionsIf nullptr, all regions are used. If non-nullptr, only the regions in the selections are used.
with_fixed_ratioStretch 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.
forceForce stretching, regardless of musical mode.
Exceptions
ZrythmExceptionif stretching fails.

◆ update_positions()

void Transport::update_positions ( bool update_from_ticks)

Updates the frames in all transport positions.

Parameters
update_from_ticksWhether to update the positions based on ticks (true) or frames (false).

Friends And Related Symbol Documentation

◆ from_json

void from_json ( const nlohmann::json & j,
Transport & transport )
friend

Definition at line 528 of file transport.h.

◆ to_json

void to_json ( nlohmann::json & j,
const Transport & transport )
friend

Definition at line 506 of file transport.h.

Field Documentation

◆ backward_

std::unique_ptr<MidiPort> Transport::backward_

Backward MIDI port.

Definition at line 657 of file transport.h.

◆ countin_frames_remaining_

signed_frame_t Transport::countin_frames_remaining_ = 0

Metronome countin frames remaining.

Definition at line 628 of file transport.h.

◆ cue_pos_

PositionProxy* Transport::cue_pos_ = nullptr

Cue point position.

Definition at line 569 of file transport.h.

◆ forward_

std::unique_ptr<MidiPort> Transport::forward_

Forward MIDI port.

Definition at line 660 of file transport.h.

◆ has_range_

bool Transport::has_range_ = false

Whether range should be displayed or not.

Definition at line 595 of file transport.h.

◆ last_manual_playhead_change_

RtTimePoint Transport::last_manual_playhead_change_ = 0

Last timestamp the playhead position was changed manually.

Definition at line 672 of file transport.h.

◆ loop_

bool Transport::loop_ = false

Looping or not.

Definition at line 612 of file transport.h.

◆ loop_end_pos_

PositionProxy* Transport::loop_end_pos_ = nullptr

Loop end position.

Definition at line 575 of file transport.h.

◆ loop_start_pos_

PositionProxy* Transport::loop_start_pos_ = nullptr

Loop start position.

Definition at line 572 of file transport.h.

◆ loop_toggle_

std::unique_ptr<MidiPort> Transport::loop_toggle_

Loop toggle MIDI port.

Definition at line 663 of file transport.h.

◆ metronome_enabled_

bool Transport::metronome_enabled_ = false

Metronome enabled or not.

Definition at line 622 of file transport.h.

◆ play_state_

PlayState Transport::play_state_ = {}

Play state.

Definition at line 669 of file transport.h.

◆ playhead_before_pause_

Position Transport::playhead_before_pause_

Position of the playhead before pausing.

Used by UndoableAction.

Definition at line 640 of file transport.h.

◆ playhead_pos_

PositionProxy* Transport::playhead_pos_ = nullptr

Playhead position.

Definition at line 566 of file transport.h.

◆ position_

nframes_t Transport::position_ = 0

Transport position in frames.

FIXME is this used?

Definition at line 609 of file transport.h.

◆ preroll_frames_remaining_

signed_frame_t Transport::preroll_frames_remaining_ = 0

Recording preroll frames remaining.

Definition at line 625 of file transport.h.

◆ project_

Project* Transport::project_ = nullptr

Pointer to owner, if any.

Definition at line 675 of file transport.h.

◆ punch_in_pos_

PositionProxy* Transport::punch_in_pos_ = nullptr

Punch in position.

Definition at line 578 of file transport.h.

◆ punch_mode_

bool Transport::punch_mode_ = false

Whether punch in/out mode is enabled.

Definition at line 615 of file transport.h.

◆ punch_out_pos_

PositionProxy* Transport::punch_out_pos_ = nullptr

Punch out position.

Definition at line 581 of file transport.h.

◆ range_1_

Position 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 591 of file transport.h.

◆ range_2_

Position Transport::range_2_

Definition at line 592 of file transport.h.

◆ rec_toggle_

std::unique_ptr<MidiPort> Transport::rec_toggle_

Rec toggle MIDI port.

Definition at line 666 of file transport.h.

◆ recording_

bool Transport::recording_ = false

Whether MIDI/audio recording is enabled (recording toggle in transport bar).

Definition at line 619 of file transport.h.

◆ recording_mode_

RecordingMode Transport::recording_mode_ = (RecordingMode) 0

Definition at line 633 of file transport.h.

◆ roll_

std::unique_ptr<MidiPort> Transport::roll_

Roll/play MIDI port.

Any event received on this port will request a roll.

Definition at line 647 of file transport.h.

◆ sixteenths_per_bar_

int Transport::sixteenths_per_bar_ = 0

Definition at line 603 of file transport.h.

◆ sixteenths_per_beat_

int Transport::sixteenths_per_beat_ = 0

Definition at line 602 of file transport.h.

◆ start_playback_on_midi_input_

bool Transport::start_playback_on_midi_input_ = false

Whether to start playback on MIDI input.

Definition at line 631 of file transport.h.

◆ stop_

std::unique_ptr<MidiPort> Transport::stop_

Stop MIDI port.

Any event received on this port will request a stop/pause.

Definition at line 654 of file transport.h.

◆ ticks_per_bar_

int Transport::ticks_per_bar_ = 0

Definition at line 601 of file transport.h.

◆ ticks_per_beat_

int Transport::ticks_per_beat_ = 0

Definition at line 600 of file transport.h.

◆ total_bars_

int Transport::total_bars_ = 0

Total bars in the song.

Definition at line 563 of file transport.h.

Property Documentation

◆ cuePosition

PositionProxy * Transport::cuePosition
read

Definition at line 67 of file transport.h.

◆ loopEnabled

QML_ELEMENT bool Transport::loopEnabled
readwrite

Definition at line 57 of file transport.h.

◆ loopEndPosition

PositionProxy * Transport::loopEndPosition
read

Definition at line 70 of file transport.h.

◆ loopStartPosition

PositionProxy * Transport::loopStartPosition
read

Definition at line 68 of file transport.h.

◆ playheadPosition

PositionProxy * Transport::playheadPosition
read

Definition at line 66 of file transport.h.

◆ playState

PlayState Transport::playState
readwrite

Definition at line 63 of file transport.h.

◆ punchInPosition

PositionProxy * Transport::punchInPosition
read

Definition at line 71 of file transport.h.

◆ punchOutPosition

PositionProxy * Transport::punchOutPosition
read

Definition at line 72 of file transport.h.

◆ recordEnabled

bool Transport::recordEnabled
readwrite

Definition at line 60 of file transport.h.


The documentation for this class was generated from the following file: