Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::structure::tracks::TrackProcessor Class Referencefinal

A TrackProcessor is a standalone processor that is used as the first step when processing a track in the DSP graph. More...

#include <src/structure/tracks/track_processor.h>

Inheritance diagram for zrythm::structure::tracks::TrackProcessor:
Collaboration diagram for zrythm::structure::tracks::TrackProcessor:

Public Types

enum class  Capabilities : uint8_t { PianoRoll = 1 << 0 , MidiCC = 1 << 1 , AudioTrack = 1 << 2 , Recording = 1 << 3 }
enum class  MonitorMode : uint8_t { Off , On , Auto }
enum class  ActiveMidiEventProviders : uint8_t {
  Timeline = 1 << 0 , ClipLauncher = 1 << 1 , PianoRoll = 1 << 2 , Recording = 1 << 3 ,
  Custom = 1 << 4
}
enum class  ActiveAudioProviders : uint8_t { Timeline = 1 << 0 , ClipLauncher = 1 << 1 , Recording = 1 << 2 , Custom = 1 << 3 }
using StereoPortPair = std::pair<std::span<float>, std::span<float>>
using ConstStereoPortPair
using FillEventsCallback
 Function called during processing to fill events.
using RecordingCallbackRT
 Callback to record the given audio or MIDI data.
using AppendMidiInputsToOutputsFunc
 Custom logic to use when appending the MIDI input events to the output events.
using TransformMidiInputsFunc = std::function<void (dsp::MidiEventVector &)>
 Function to transform the given MIDI inputs.
using EnabledProvider = std::function<bool ()>
 Function that returns if the track for this processor is enabled.
using TrackNameProvider = std::function<utils::Utf8String ()>
using MidiEventProviderProcessFunc

Public Member Functions

 TrackProcessor (const dsp::TempoMap &tempo_map, dsp::PortType signal_type, TrackNameProvider track_name_provider, EnabledProvider enabled_provider, Capabilities capabilities, ProcessorBaseDependencies dependencies, std::optional< FillEventsCallback > fill_events_cb=std::nullopt, std::optional< TransformMidiInputsFunc > transform_midi_inputs_func=std::nullopt, std::optional< AppendMidiInputsToOutputsFunc > append_midi_inputs_to_outputs_func=std::nullopt, RecordingCallbackRT recording_cb=[](units::sample_t, const dsp::ITransport &, const dsp::MidiEventVector *, std::optional< ConstStereoPortPair >) { }, QObject *parent=nullptr)
 Creates a new track processor for the given track.
bool is_audio () const
constexpr bool is_midi () const
utils::Utf8String get_full_designation_for_port (const dsp::Port &port) const
void custom_process_block (dsp::graph::ProcessBlockInfo time_nfo, const dsp::ITransport &transport, const dsp::TempoMap &tempo_map) noexcept override
 Process the TrackProcessor.
void custom_prepare_for_processing (const dsp::graph::GraphNode *node, units::sample_rate_t sample_rate, units::sample_u32_t max_block_length) override
void custom_release_resources () override
dsp::AudioPortget_stereo_in_port () const
dsp::AudioPortget_stereo_out_port () const
dsp::ProcessorParameterget_mono_param () const
dsp::ProcessorParameterget_input_gain_param () const
dsp::ProcessorParameterget_output_gain_param () const
dsp::ProcessorParameterget_monitor_audio_param () const
dsp::ProcessorParameterget_recording_param () const
bool is_recording_armed () const
bool is_recording_armed_rt () const noexcept
void set_recording_armed (bool armed)
dsp::ProcessorParameterget_midi_cc_param (midi_byte_t channel, midi_byte_t control_no)
dsp::MidiPortget_midi_in_port () const
 MIDI in Port.
dsp::MidiPortget_midi_out_port () const
 MIDI out port, if MIDI.
dsp::MidiPortget_piano_roll_port () const
 MIDI input for receiving MIDI signals from the piano roll (i.e., MIDI notes inside regions) or other sources.
arrangement::AudioTimelineDataProvidertimeline_audio_data_provider ()
arrangement::MidiTimelineDataProvidertimeline_midi_data_provider ()
ClipPlaybackDataProviderclip_playback_data_provider ()
void set_midi_providers_active (ActiveMidiEventProviders event_providers, bool active)
 Used to enable or disable MIDI event providers.
void set_audio_providers_active (ActiveAudioProviders audio_providers, bool active)
 Used to enable or disable audio providers.
void set_custom_midi_event_provider (MidiEventProviderProcessFunc process_func)
 Replaces the "Custom" MIDI event provider.
void fill_midi_events (const dsp::graph::ProcessBlockInfo &time_nfo, const dsp::ITransport &transport, dsp::MidiEventVector &midi_events)
 Wrapper for MIDI/instrument/chord tracks to fill in MidiEvents from the timeline data.
void fill_audio_events (const dsp::graph::ProcessBlockInfo &time_nfo, const dsp::ITransport &transport, StereoPortPair stereo_ports)
 Wrapper for audio tracks to fill in StereoPorts from the timeline data.
Public Member Functions inherited from zrythm::dsp::ProcessorBase
 ProcessorBase (ProcessorBaseDependencies dependencies, utils::Utf8String name={ u8"ProcessorBase" })
void set_name (const utils::Utf8String &name)
 Set a custom name to be used in the DSP graph.
void add_input_port (const dsp::PortUuidReference &uuid)
void add_output_port (const dsp::PortUuidReference &uuid)
void add_parameter (const dsp::ProcessorParameterUuidReference &uuid)
auto & get_input_ports () const
auto & get_output_ports () const
auto & get_parameters () const
const ParameterChangeTrackerchange_tracker () const noexcept
 Returns the change tracker.
utils::Utf8String get_node_name () const final
 Returns a human friendly name of the node.
void process_block (dsp::graph::ProcessBlockInfo time_nfo, const dsp::ITransport &transport, const dsp::TempoMap &tempo_map) noexcept final
 Calls custom_process_block() internally after processing all the parameters.
void prepare_for_processing (const graph::GraphNode *node, units::sample_rate_t sample_rate, units::sample_u32_t max_block_length) final
 Called to allocate resources required for processing.
void release_resources () final
 Called to release resources allocated by prepare_for_processing().
Public Member Functions inherited from zrythm::dsp::graph::IProcessable
virtual units::sample_u32_t get_single_playback_latency () const
 Returns the latency of only the given processable, without adding the previous/next latencies (zero latency by default).

Friends

void to_json (nlohmann::json &j, const TrackProcessor &tp)
void from_json (const nlohmann::json &j, TrackProcessor &tp)
void init_from (TrackProcessor &obj, const TrackProcessor &other, utils::ObjectCloneType clone_type)

Additional Inherited Members

Protected Member Functions inherited from zrythm::dsp::ProcessorBase
auto dependencies () const

Detailed Description

A TrackProcessor is a standalone processor that is used as the first step when processing a track in the DSP graph.

See also
Channel and ChannelTrack.

Definition at line 28 of file track_processor.h.

Member Typedef Documentation

◆ AppendMidiInputsToOutputsFunc

Initial value:
std::function<void (
dsp::MidiEventVector &out_events,
const dsp::MidiEventVector &in_events,
const dsp::graph::ProcessBlockInfo &time_nfo)>
A lock-free thread-safe vector of MidiEvents.
Definition midi_event.h:74
Common struct to pass around during processing to avoid repeating the data in function arguments.
Definition graph_node.h:51

Custom logic to use when appending the MIDI input events to the output events.

If not explicitly set, this will simply copy the events over.

Mainly used by ChordTrack to transform input MIDI notes into multiple output notes that match the chord.

Definition at line 76 of file track_processor.h.

◆ ConstStereoPortPair

using zrythm::structure::tracks::TrackProcessor::ConstStereoPortPair
Initial value:
std::pair<std::span<const float>, std::span<const float>>

Definition at line 37 of file track_processor.h.

◆ EnabledProvider

Function that returns if the track for this processor is enabled.

Used to conditionally skip processing if disabled.

Definition at line 93 of file track_processor.h.

◆ FillEventsCallback

Initial value:
std::function<void (
const dsp::ITransport &transport,
dsp::MidiEventVector * midi_events,
std::optional<StereoPortPair> stereo_ports)>
Interface for transport.
Definition itransport.h:16

Function called during processing to fill events.

For regions, a helper method is provided for filling events from a single region. Implementations of this are supposed to call that for all their regions (including muted/disabled/etc.).

Definition at line 47 of file track_processor.h.

◆ MidiEventProviderProcessFunc

using zrythm::structure::tracks::TrackProcessor::MidiEventProviderProcessFunc
Initial value:
std::function<void (
dsp::MidiEventVector &output_buffer)>

Definition at line 112 of file track_processor.h.

◆ RecordingCallbackRT

Initial value:
std::function<void (
units::sample_t timeline_position,
const dsp::ITransport &transport,
const dsp::MidiEventVector * midi_events,
std::optional<ConstStereoPortPair> stereo_ports)>

Callback to record the given audio or MIDI data.

Parameters
timeline_positionThe absolute timeline position of this data.
transportTransport state (for recording_enabled check).
midi_eventsMIDI events that should be recorded, if any.
stereo_portsAudio data that should be recorded, if any.

Definition at line 61 of file track_processor.h.

◆ StereoPortPair

using zrythm::structure::tracks::TrackProcessor::StereoPortPair = std::pair<std::span<float>, std::span<float>>

Definition at line 36 of file track_processor.h.

◆ TrackNameProvider

using zrythm::structure::tracks::TrackProcessor::TrackNameProvider = std::function<utils::Utf8String ()>

Definition at line 95 of file track_processor.h.

◆ TransformMidiInputsFunc

Function to transform the given MIDI inputs.

This is used to, for example, change the channel of all events.

Definition at line 86 of file track_processor.h.

Member Enumeration Documentation

◆ ActiveAudioProviders

enum class zrythm::structure::tracks::TrackProcessor::ActiveAudioProviders : uint8_t
strong

Definition at line 125 of file track_processor.h.

◆ ActiveMidiEventProviders

enum class zrythm::structure::tracks::TrackProcessor::ActiveMidiEventProviders : uint8_t
strong

Definition at line 116 of file track_processor.h.

◆ Capabilities

enum class zrythm::structure::tracks::TrackProcessor::Capabilities : uint8_t
strong

Definition at line 97 of file track_processor.h.

◆ MonitorMode

enum class zrythm::structure::tracks::TrackProcessor::MonitorMode : uint8_t
strong

Definition at line 105 of file track_processor.h.

Constructor & Destructor Documentation

◆ TrackProcessor()

zrythm::structure::tracks::TrackProcessor::TrackProcessor ( const dsp::TempoMap & tempo_map,
dsp::PortType signal_type,
TrackNameProvider track_name_provider,
EnabledProvider enabled_provider,
Capabilities capabilities,
ProcessorBaseDependencies dependencies,
std::optional< FillEventsCallback > fill_events_cb = std::nullopt,
std::optional< TransformMidiInputsFunc > transform_midi_inputs_func = std::nullopt,
std::optional< AppendMidiInputsToOutputsFunc > append_midi_inputs_to_outputs_func = std::nullopt,
RecordingCallbackRT recording_cb = [](units::sample_t, const dsp::ITransport &, const dsp::MidiEventVector *, std::optional< ConstStereoPortPair >) { },
QObject * parent = nullptr )

Creates a new track processor for the given track.

Parameters
capabilitiesFlags describing what features this processor supports.

Member Function Documentation

◆ custom_prepare_for_processing()

void zrythm::structure::tracks::TrackProcessor::custom_prepare_for_processing ( const dsp::graph::GraphNode * node,
units::sample_rate_t sample_rate,
units::sample_u32_t max_block_length )
overridevirtual

Reimplemented from zrythm::dsp::ProcessorBase.

◆ custom_process_block()

void zrythm::structure::tracks::TrackProcessor::custom_process_block ( dsp::graph::ProcessBlockInfo time_nfo,
const dsp::ITransport & transport,
const dsp::TempoMap & tempo_map )
overridevirtualnoexcept

Process the TrackProcessor.

This function performs the following:

  • produce output audio/MIDI into stereo out or midi out, based on any audio/MIDI regions, if has piano roll or is audio track
  • produce additional output MIDI events based on any MIDI CC automation regions, if applicable
  • change MIDI CC control port values based on any MIDI input, if recording — at this point the output is ready —
  • handle recording (create events in regions and automation, including MIDI CC automation, based on the MIDI CC control ports)

Reimplemented from zrythm::dsp::ProcessorBase.

◆ custom_release_resources()

void zrythm::structure::tracks::TrackProcessor::custom_release_resources ( )
overridevirtual

Reimplemented from zrythm::dsp::ProcessorBase.

◆ fill_audio_events()

void zrythm::structure::tracks::TrackProcessor::fill_audio_events ( const dsp::graph::ProcessBlockInfo & time_nfo,
const dsp::ITransport & transport,
StereoPortPair stereo_ports )

Wrapper for audio tracks to fill in StereoPorts from the timeline data.

Note
The engine splits the cycle so transport loop related logic is not needed.
Parameters
stereo_portsStereoPorts to fill.

◆ fill_midi_events()

void zrythm::structure::tracks::TrackProcessor::fill_midi_events ( const dsp::graph::ProcessBlockInfo & time_nfo,
const dsp::ITransport & transport,
dsp::MidiEventVector & midi_events )

Wrapper for MIDI/instrument/chord tracks to fill in MidiEvents from the timeline data.

Note
The engine splits the cycle so transport loop related logic is not needed.
Parameters
midi_eventsMidiEvents to fill.

◆ get_midi_cc_param()

dsp::ProcessorParameter & zrythm::structure::tracks::TrackProcessor::get_midi_cc_param ( midi_byte_t channel,
midi_byte_t control_no )
Parameters
channelChannel (0-15)
control_noControl (0-127)

◆ get_midi_in_port()

dsp::MidiPort & zrythm::structure::tracks::TrackProcessor::get_midi_in_port ( ) const
inline

MIDI in Port.

This port is for receiving MIDI signals from an external MIDI source.

This is also where piano roll, midi in and midi manual press will be routed to and this will be the port used to pass midi to the plugins.

Definition at line 234 of file track_processor.h.

◆ get_midi_out_port()

dsp::MidiPort & zrythm::structure::tracks::TrackProcessor::get_midi_out_port ( ) const
inline

MIDI out port, if MIDI.

Definition at line 243 of file track_processor.h.

◆ get_piano_roll_port()

dsp::MidiPort & zrythm::structure::tracks::TrackProcessor::get_piano_roll_port ( ) const
inline

MIDI input for receiving MIDI signals from the piano roll (i.e., MIDI notes inside regions) or other sources.

This bypasses any MIDI transformations by transform_midi_inputs_func_.

Definition at line 255 of file track_processor.h.

◆ get_stereo_in_port()

dsp::AudioPort & zrythm::structure::tracks::TrackProcessor::get_stereo_in_port ( ) const
inline

Definition at line 196 of file track_processor.h.

◆ get_stereo_out_port()

dsp::AudioPort & zrythm::structure::tracks::TrackProcessor::get_stereo_out_port ( ) const
inline

Definition at line 201 of file track_processor.h.

◆ is_audio()

bool zrythm::structure::tracks::TrackProcessor::is_audio ( ) const
inline

Definition at line 159 of file track_processor.h.

◆ is_midi()

bool zrythm::structure::tracks::TrackProcessor::is_midi ( ) const
inlineconstexpr

Definition at line 161 of file track_processor.h.

◆ set_audio_providers_active()

void zrythm::structure::tracks::TrackProcessor::set_audio_providers_active ( ActiveAudioProviders audio_providers,
bool active )

Used to enable or disable audio providers.

For example, when a clip is launched this should be called once to disable the timeline and once more to enable the clip provider.

Note
Changes will take effect during the next processing cycle.

◆ set_midi_providers_active()

void zrythm::structure::tracks::TrackProcessor::set_midi_providers_active ( ActiveMidiEventProviders event_providers,
bool active )

Used to enable or disable MIDI event providers.

For example, when a clip is launched this should be called once to disable the timeline and once more to enable the clip provider.

Note
Changes will take effect during the next processing cycle.

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